out the bit streams.
.equ EP8FIFOCFG,0E61BH
;;
.equ INPKTEND,0E648H
+ .equ OUTPKTEND,0E649H
.equ GPIFCTLCFG,0E6C3H
.equ GPIFABORT,0E6F5H
.equ GPIFIDLECTL,0E6C2H
.equ EP6GPIFFLGSEL,0E6E2H
.equ EP6GPIFPDFSTOP,0E6E3H
.equ EP6GPIFTRIG,0E6E4H
+ .equ GPIFTCB3,0E6CEH
+ .equ GPIFTCB2,0E6CFH
+ .equ GPIFTCB1,0E6D0H
+ .equ GPIFTCB0,0E6D1H
+ .equ EP4GPIFFLGSEL,0E6DAH
+ .equ EP4GPIFPFSTOP,0E6DBH
;;
;; endpoint control
.equ EP2CS,0E6A3H
.equ CMD_FLAG,90h ; flag if next IN transf is DIO
.equ SGLCHANNEL,91h ; channel for INSN
+ .equ PWMFLAG,92h ; PWM
.equ DIOSTAT0,98h ; last status of the digital port
.equ DIOSTAT1,99h ; same for the second counter
ep0in_isr:
ep0out_isr:
ep1in_isr:
-ep1out_isr:
ibn_isr:
ep0ping_isr:
ep1ping_isr:
ep8isoerr_isr:
ep6_isr:
ep2_isr:
-
+ep4_isr:
push dps
push dpl
lcall init_timer
mloop2: nop
- nop
- nop
- nop
- nop
- nop
- nop
+
+;;; pwm
+ mov r0,#PWMFLAG ; pwm on?
+ mov a,@r0 ; get info
+ jz mloop2 ; it's off
+
+ mov a,GPIFTRIG ; GPIF status
+ anl a,#80h ; done bit
+ jz mloop2 ; GPIF still busy
+
+ mov a,#01h ; WR,EP4, 01 = EP4
+ mov GPIFTRIG,a ; restart it
sjmp mloop2 ; loop for ever
+;;; GPIF waveform for PWM
+waveform:
+ ;; 0 1 2 3 4 5 6 7(not used)
+ ;; len (gives 50.007Hz)
+ .db 195, 195, 195, 195, 195, 195, 1, 1
+
+ ;; opcode
+ .db 002H, 006H, 002H, 002H, 002H, 002H, 002H, 002H
+
+ ;; out
+ .db 0ffH, 0ffH, 0ffH, 0ffH, 0ffH, 0ffH, 0ffH, 0ffH
+
+ ;; log
+ .db 000H, 000H, 000H, 000H, 000H, 000H, 000H, 000H
+
+
+stopPWM:
+ mov r0,#PWMFLAG ; flag for PWM
+ mov a,#0 ; PWM (for the main loop)
+ mov @r0,a ; set it
+
+ mov dptr,#IFCONFIG ; switch off GPIF
+ mov a,#10000000b ; gpif, 30MHz, internal IFCLK
+ lcall syncdelaywr
+ ret
+
+
+;;; init PWM
+startPWM:
+ mov dptr,#IFCONFIG ; switch on IFCLK signal
+ mov a,#10000010b ; gpif, 30MHz, internal IFCLK
+ lcall syncdelaywr
+
+ mov OEB,0FFH ; output to port B
+
+ mov DPTR,#EP4CFG
+ mov a,#10100000b ; valid, out, bulk
+ movx @DPTR,a
+
+ ;; reset the endpoint
+ mov dptr,#FIFORESET
+ mov a,#80h ; NAK
+ lcall syncdelaywr
+ mov a,#84h ; reset EP4 + NAK
+ lcall syncdelaywr
+ mov a,#0 ; normal op
+ lcall syncdelaywr
+
+ mov dptr,#EP4BCL
+ mov a,#0H ; discard packets
+ lcall syncdelaywr ; empty FIFO buffer
+ lcall syncdelaywr ; empty FIFO buffer
+
+ ;; aborts all transfers by the GPIF
+ mov dptr,#GPIFABORT
+ mov a,#0ffh ; abort all transfers
+ lcall syncdelaywr
+
+ ;; wait for GPIF to finish
+wait_f_abort:
+ mov a,GPIFTRIG ; GPIF status
+ anl a,#80h ; done bit
+ jz wait_f_abort ; GPIF busy
+
+ mov dptr,#GPIFCTLCFG
+ mov a,#10000000b ; tri state for CTRL
+ lcall syncdelaywr
+
+ mov dptr,#GPIFIDLECTL
+ mov a,#11110000b ; all CTL outputs low
+ lcall syncdelaywr
+
+ ;; abort if FIFO is empty
+ mov a,#00000001b ; abort if empty
+ mov dptr,#EP4GPIFFLGSEL
+ lcall syncdelaywr
+
+ ;;
+ mov a,#00000001b ; stop if GPIF flg
+ mov dptr,#EP4GPIFPFSTOP
+ lcall syncdelaywr
+
+ ;; transaction counter
+ mov a,#0ffH
+ mov dptr,#GPIFTCB3
+ lcall syncdelaywr
+
+ ;; transaction counter
+ mov a,#0ffH
+ mov dptr,#GPIFTCB2
+ lcall syncdelaywr
+
+ ;; transaction counter
+ mov a,#0ffH ; 512 bytes
+ mov dptr,#GPIFTCB1
+ lcall syncdelaywr
+
+ ;; transaction counter
+ mov a,#0ffH
+ mov dptr,#GPIFTCB0
+ lcall syncdelaywr
+
+ ;; RDY pins. Not used here.
+ mov a,#0
+ mov dptr,#GPIFREADYCFG
+ lcall syncdelaywr
+
+ ;; drives the output in the IDLE state
+ mov a,#1
+ mov dptr,#GPIFIDLECS
+ lcall syncdelaywr
+
+ ;; direct data transfer from the EP to the GPIF
+ mov dptr,#EP4FIFOCFG
+ mov a,#00010000b ; autoout=1, byte-wide
+ lcall syncdelaywr
+
+ ;; waveform 0 is used for FIFO out
+ mov dptr,#GPIFWFSELECT
+ mov a,#00000000b
+ movx @dptr,a
+ lcall syncdelay
+
+ ;; transfer the delay byte from the EP to the waveform
+ mov dptr,#0e781h ; EP1 buffer
+ movx a,@dptr ; get the delay
+ mov dptr,#waveform ; points to the waveform
+ mov r2,#6 ; fill 6 bytes
+timloop:
+ movx @dptr,a ; save timing in a xxx
+ inc dptr
+ djnz r2,timloop ; fill the 6 delay bytes
+
+ ;; load waveform
+ mov AUTOPTRH2,#0E4H ; XDATA0H
+ lcall syncdelay
+ mov AUTOPTRL2,#00H ; XDATA0L
+ lcall syncdelay
+
+ mov dptr,#waveform ; points to the waveform
+
+ mov AUTOPTRSETUP,#7 ; autoinc and enable
+ lcall syncdelay
+
+ mov r2,#20H ; 32 bytes to transfer
+
+wavetr:
+ movx a,@dptr
+ inc dptr
+ push dpl
+ push dph
+ push dpl1
+ push dph1
+ mov dptr,#XAUTODAT2
+ movx @dptr,a
+ lcall syncdelay
+ pop dph1
+ pop dpl1
+ pop dph
+ pop dpl
+ djnz r2,wavetr
+
+ mov dptr,#OUTPKTEND
+ mov a,#084H
+ lcall syncdelaywr
+ lcall syncdelaywr
+
+ mov r0,#PWMFLAG ; flag for PWM
+ mov a,#1 ; PWM (for the main loop)
+ mov @r0,a ; set it
+
+ ret
+
+
+
;;; initialise the ports for the AD-converter
initAD:
mov OEA,#27H ;PortA0,A1,A2,A5 Outputs
movx @DPTR,a ; can receive data
lcall syncdelay ; wait to sync
- mov DPTR,#EP4CFG
+ mov DPTR,#EP1OUTCFG
mov a,#10100000b ; valid
movx @dptr,a
- mov dptr,#EP4FIFOCFG
- mov a,#00000000b ; manual
- movx @dptr,a
-
- mov dptr,#EP4BCL ; "arm" it
+ mov dptr,#EP1OUTBC ; "arm" it
mov a,#00h
movx @DPTR,a ; can receive data
lcall syncdelay ; wait until we can write again
movx @DPTR,a ;
mov dptr,#EPIE ; interrupt enable
- mov a,#10100000b ; enable irq for ep4,8
+ mov a,#10001000b ; enable irq for ep1out,8
movx @dptr,a ; do it
mov dptr,#EPIRQ ; clear IRQs
lcall syncdelaywr
ret
-
-;;; interrupt-routine for ep4
+;;; interrupt-routine for ep1out
;;; receives the channel list and other commands
-ep4_isr:
+ep1out_isr:
push dps
push dpl
push dph
push 06h ; R6
push 07h ; R7
- mov dptr,#0f400h ; FIFO buffer of EP4
+ mov dptr,#0E780h ; FIFO buffer of EP1OUT
movx a,@dptr ; get the first byte
mov r0,#CMD_FLAG ; pointer to the command byte
mov @r0,a ; store the command byte for ep8
- mov dptr,#ep4_jmp ; jump table for the different functions
+ mov dptr,#ep1out_jmp; jump table for the different functions
rl a ; multiply by 2: sizeof sjmp
jmp @a+dptr ; jump to the jump table
;; jump table, corresponds to the command bytes defined
;; in usbdux.c
-ep4_jmp:
+ep1out_jmp:
sjmp storechannellist; a=0
sjmp single_da ; a=1
sjmp config_digital_b; a=2
sjmp storesglchannel ; a=4
sjmp readcounter ; a=5
sjmp writecounter ; a=6
+ sjmp pwm_on ; a=7
+ sjmp pwm_off ; a=8
+
+pwm_on:
+ lcall startPWM
+ sjmp over_da
+
+pwm_off:
+ lcall stopPWM
+ sjmp over_da
;; read the counter
readcounter:
;; write zeroes to the counters
writecounter:
- mov dptr,#0f401h ; buffer
+ mov dptr,#0e781h ; buffer
mov r0,#CTR0 ; r0 points to counter 0
movx a,@dptr ; channel number
jz wrctr0 ; first channel
storesglchannel:
mov r0,#SGLCHANNEL ; the conversion bytes are now stored in 80h
- mov dptr,#0f401h ; FIFO buffer of EP4
+ mov dptr,#0e781h ; FIFO buffer of EP1OUT
movx a,@dptr ;
mov @r0,a
storechannellist:
mov r0,#CHANNELLIST ; the conversion bytes are now stored in 80h
mov r2,#9 ; counter
- mov dptr,#0f401h ; FIFO buffer of EP4
+ mov dptr,#0e781h ; FIFO buffer of EP1OUT
chanlloop:
movx a,@dptr ;
mov @r0,a
;;; Single DA conversion. The 2 bytes are in the FIFO buffer
single_da:
- mov dptr,#0f401h ; FIFO buffer of EP4
+ mov dptr,#0e781h ; FIFO buffer of EP1OUT
lcall dalo ; conversion
sjmp over_da
;;; configure the port B as input or output (bitwise)
config_digital_b:
- mov dptr,#0f401h ; FIFO buffer of EP4
+ mov dptr,#0e781h ; FIFO buffer of EP1OUT
movx a,@dptr ; get the second byte
mov OEB,a ; set the output enable bits
sjmp over_da
;;; Write one byte to the external digital port B
;;; and prepare for digital read
write_digital_b:
- mov dptr,#0f401h ; FIFO buffer of EP4
+ mov dptr,#0e781h ; FIFO buffer of EP1OUT
movx a,@dptr ; get the second byte
mov OEB,a ; output enable
inc dptr ; next byte
;;
;; for all commands the same
over_da:
- mov dptr,#EP4BCL
+ mov dptr,#EP1OUTBC
mov a,#00h
lcall syncdelaywr ; arm
lcall syncdelaywr ; arm
mov EXIF,a ; Note: EXIF reg is not 8051 bit-addressable
mov DPTR,#EPIRQ ;
- mov a,#00100000b ; clear the ep4irq
+ mov a,#00001000b ; clear the ep1outirq
movx @DPTR,a
pop 07h
:030000000201A258
-:03000B000202F8F6
+:03000B00020416D6
:03004300020100B7
-:1001000002017F000203390002017F0002017F002B
+:1001000002017F000204570002017F0002017F000C
:1001100002017F0002017F0002017F0002017F00D7
-:1001200002017F0002017F0002017F0002017F00C7
-:1001300002017F000203E40002017F000205630068
+:1001200002017F0002017F0002017F000205020040
+:1001300002017F0002017F0002017F0002068F00A2
:1001400002017F0002017F0002017F0002017F00A7
:1001500002017F0002017F0002017F0002017F0097
:1001600002017F0002017F0002017F0002017F0087
:1001700002017F0002017F0002017F0002017FC0B7
:1001800086C082C083C084C085C0E0C0D0E591C273
:10019000E4F591D0D0D0E0D085D084D083D082D087
-:1001A000863290E60074101205B990E60B740312C3
-:1001B00005B975B80075F8FF90E66874081205B9BE
-:1001C0001201D212025A1201D900000000000000F0
-:1001D00080F775B22775802222758E01758A107599
-:1001E0008C0075A882758900D28C22547C4481C20F
-:1001F000817A0830E704D2828002C282D280C28033
-:1002000023DAF0C2827A05D280C280DAFA7C007AE0
-:10021000047D08D280C280E58030E403EC4DFCED23
-:1002200003FDDAEF7B007A087D80D280C280E58012
-:1002300030E403EB4DFBED03FDDAEFD28122759A3A
-:10024000F8759B0075AF077880E6F990E67B08E6C5
-:100250001201EBEBF0ECF0D9F52290E6047480F09B
-:100260007402F07404F07406F07408F07400F090F6
-:10027000E6127492F090E6187400F090E691740023
-:10028000F01205AFF01205AFF01205AF90E613744F
-:10029000A0F090E6197400F090E6957400F0120555
-:1002A000AFF01205AF90E61474D2F090E61574E04A
-:1002B000F090E65E74A0F090E65F74A0F090E65CCB
-:1002C0007402F075E80175A88022E590FD5B600678
-:1002D000E4F70CF7801FE66D5D5C6019ED5A700C59
-:1002E000E714F7B4FF0F09E714F78009E704F77084
-:1002F0000409E704F7EDF622C086C0E0C0D0C000D4
-:10030000C001C002C003C004C005789879A0740180
-:10031000FC23FA23FB1202CA080909EB2323FC235E
-:10032000FA23FB1202CAD005D004D003D002D001B8
-:10033000D000D0D0D0E0D08632C086C082C083C08A
-:1003400084C085C0E0C0D0C000C001C002C003C0EE
-:1003500004C005C006C007E5AA5420701312023E6F
-:1003600090E69874001205B990E69974101205B9D8
-:10037000E5AA5401701190F0001204B790E6917450
-:10038000001205B91205B9E591C2E4F59190E65D58
-:100390007402F0D007D006D005D004D003D002D02C
-:1003A00001D000D0D0D0E0D085D084D083D082D00E
-:1003B000863290E60474801205B990E6047408123F
-:1003C00005B990E60474001205B92290E604748021
-:1003D0001205B990E60474061205B990E60474009B
-:1003E0001205B922C086C082C083C084C085C0E027
-:1003F000C0D0C000C001C002C003C004C005C00618
-:10040000C00790F400E07890F690040E23738039D2
-:10041000804C805280588022800280081203B212E1
-:10042000050B805A90F40178A0E06005F90808D91E
-:10043000FCA3E0F608A3E0F68044789190F401E094
-:10044000F61203B212050B803578807A0990F40118
-:10045000E0F6A308DAFA1203CB1204F7802090F436
-:10046000011204B7801890F401E0F5B3801090F405
-:1004700001E0F5B3A3E0F5901203B212050B90E68C
-:100480009574001205B91205B91205B9E591C2E4D7
-:10049000F59190E65F7420F0D007D006D005D00427
-:1004A000D003D002D001D000D0D0D0E0D085D0840D
-:1004B000D083D082D08632E0A3F8E0FBA3E0FCA397
-:1004C000E0A31204C8D8F32254C044304CC2857A49
-:1004D0000830E704D2828002C282D280C28023DA4E
-:1004E000F0EB7A0830E704D2828002C282D280C266
-:1004F0008023DAF0D2852212023E90E69874001230
-:1005000005B990E69974101205B92290FC01E4F047
-:1005100090FC007890E6F090051C237380448042A4
-:100520008040802580138002803878A090FC02797A
-:1005300008E6F008A3D9FA80197891E61201EB9049
-:10054000FC02EBF0A3ECF0800990FC02E590F0A334
-:10055000E4F090E69C74001205B990E69D741012C8
-:1005600005B922C086C082C083C084C085C0E0C0F7
-:10057000D0C000C001C002C003C004C005C006C096
-:100580000712050BE591C2E4F59190E65F7480F0E7
-:10059000D007D006D005D004D003D002D001D000BF
-:1005A000D0D0D0E0D085D084D083D082D086320025
-:0E05B000000000000000000022F01205AF2243
+:1001A000863290E60074101206E590E60B74031296
+:1001B00006E575B80075F8FF90E66874081206E564
+:1001C0001202F612037E1202FD007892E660FAE552
+:1001D000BB548060F47401F5BB80EEC3C3C3C3C3DA
+:1001E000C301010206020202020202FFFFFFFFFF3B
+:1001F000FFFFFF000000000000000078927400F68E
+:1002000090E60174801206E52290E60174821206DF
+:10021000E585FFB390E61374A0F090E604748012B5
+:1002200006E574841206E574001206E590E69574FE
+:10023000001206E51206E590E6F574FF1206E5E504
+:10024000BB548060FA90E6C374801206E590E6C263
+:1002500074F01206E5740190E6DA1206E574019076
+:10026000E6DB1206E574FF90E6CE1206E574FF9019
+:10027000E6CF1206E574FF90E6D01206E574FF9013
+:10028000E6D11206E5740090E6F31206E5740190DB
+:10029000E6C11206E590E61974101206E590E6C074
+:1002A0007400F01206DB90E781E09001DB7A06F043
+:1002B000A3DAFC759DE41206DB759E001206DB9046
+:1002C00001DB75AF071206DB7A20E0A3C082C08392
+:1002D000C084C08590E67CF01206DBD085D084D047
+:1002E00083D082DAE590E64974841206E51206E5C9
+:1002F00078927401F62275B22775802222758E01DC
+:10030000758A10758C0075A882758900D28C22546C
+:100310007C4481C2817A0830E704D2828002C282A2
+:10032000D280C28023DAF0C2827A05D280C280DA1B
+:10033000FA7C007A047D08D280C280E58030E40334
+:10034000EC4DFCED03FDDAEF7B007A087D80D28076
+:10035000C280E58030E403EB4DFBED03FDDAEFD224
+:100360008122759AF8759B0075AF077880E6F99041
+:10037000E67B08E612030FEBF0ECF0D9F52290E6ED
+:10038000047480F07402F07404F07406F07408F0E1
+:100390007400F090E6127492F090E6187400F090F9
+:1003A000E6917400F01206DBF01206DBF01206DBB9
+:1003B00090E61074A0F090E68D7400F01206DBF069
+:1003C0001206DB90E61474D2F090E61574E0F0901B
+:1003D000E65E7488F090E65F74A0F090E65C7402CC
+:1003E000F075E80175A88022E590FD5B6006E4F7F2
+:1003F0000CF7801FE66D5D5C6019ED5A700CE71418
+:10040000F7B4FF0F09E714F78009E704F770040950
+:10041000E704F7EDF622C086C0E0C0D0C000C001FE
+:10042000C002C003C004C005789879A07401FC2301
+:10043000FA23FB1203E8080909EB2323FC23FA2320
+:10044000FB1203E8D005D004D003D002D001D000C5
+:10045000D0D0D0E0D08632C086C082C083C084C0F5
+:1004600085C0E0C0D0C000C001C002C003C004C04D
+:1004700005C006C007E5AA5420701312036290E677
+:100480009874001206E590E69974101206E5E5AA44
+:100490005401701190F0001205E390E6917400127F
+:1004A00006E51206E5E591C2E4F59190E65D740279
+:1004B000F0D007D006D005D004D003D002D001D0B0
+:1004C00000D0D0D0E0D085D084D083D082D0863206
+:1004D00090E60474801206E590E60474081206E5BE
+:1004E00090E60474001206E52290E6047480120679
+:1004F000E590E60474061206E590E6047400120620
+:10050000E522C086C082C083C084C085C0E0C0D060
+:10051000C000C001C002C003C004C005C006C007BF
+:1005200090E780E07890F690052C23738047805AFE
+:100530008060806680308010801680028005120204
+:100540000980671201FB80621204D0120637805ABC
+:1005500090E78178A0E06005F90808D9FCA3E0F6EF
+:1005600008A3E0F68044789190E781E0F61204D089
+:10057000120637803578807A0990E781E0F6A30883
+:10058000DAFA1204E9120623802090E7811205E3CB
+:10059000801890E781E0F5B3801090E781E0F5B333
+:1005A000A3E0F5901204D012063790E68D74001285
+:1005B00006E51206E51206E5E591C2E4F59190E63E
+:1005C0005F7408F0D007D006D005D004D003D00265
+:1005D000D001D000D0D0D0E0D085D084D083D082DC
+:1005E000D08632E0A3F8E0FBA3E0FCA3E0A3120571
+:1005F000F4D8F32254C044304CC2857A0830E70462
+:10060000D2828002C282D280C28023DAF0EB7A08E2
+:1006100030E704D2828002C282D280C28023DAF024
+:10062000D2852212036290E69874001206E590E6E5
+:100630009974101206E52290FC01E4F090FC007819
+:1006400090E6F090064823738044804280408025E5
+:1006500080138002803878A090FC027908E6F008C8
+:10066000A3D9FA80197891E612030F90FC02EBF0FF
+:10067000A3ECF0800990FC02E590F0A3E4F090E692
+:100680009C74001206E590E69D74101206E522C0E7
+:1006900086C082C083C084C085C0E0C0D0C000C016
+:1006A00001C002C003C004C005C006C0071206375F
+:1006B000E591C2E4F59190E65F7480F0D007D00632
+:1006C000D005D004D003D002D001D000D0D0D0E0EB
+:1006D000D085D084D083D082D08632000000000044
+:0A06E0000000000022F01206DB22E9
:00000001FF