6.11 Polled Bulk Transfer Example
The following code illustrates the EZ-USB registers used for a simple bulk transfer. In
this example, 8051 register R1 keeps track of the number of endpoint 2-IN transfers and
register R2 keeps track of the number of endpoint 2-OUT transfers (mod-256). Every
endpoint 2-IN transfer consists of 64 bytes of a decrementing count, with the first byte
replaced by the number of IN transfers and the second byte replaced by the number of
OUT transfers.
1
2
3
4
5
6
7
start:
fill:
mov
mov
mov
mov
movx
inc
djnz
SP,#STACK-1
dptr,#IN2BUF
r7,#64
a,r7
@dptr,a
dptr
; set stack
; fill EP2IN buffer with
; decrementing counter
r7,rill
8
;
9
mov
mov
mov
mov
movx
r1,#0
r2,#0
dptr,#IN2BC
a,#40h
@dptr,a
; r1 is IN token counter
; r2 is OUT token counter
; Point to EP2 Byte Count register
; 64-byte transfer
10
11
12
13
14
; arm the IN2 transfer
;
15 loop:
16 movx
17
18
19
20
mov
a,@dptr
jnb
mov
movx
jb
dptr,#IN2CS
; poll the EP2-IN Status
; not busy--keep looping
acc.1,serviceIN2
dptr,#OUT2CS
a,@dptr
acc.1,loop
; EP2OUT is busy--keep looping
21
;
22 serviceOUT2:
23
24
25
26
inc
mov
movx
sjmp
r2
; OUT packet counter
; load byte count register to re-arm
; (any value)
dptr,#OUT2BC
@dptr,a
loop
27
;
28 serviceIN2:
29
30
31
32
33
34
35
36
37
38
39
inc
mov
mov
movx
inc
mov
movx
mov
mov
movx
sjmp
r1
; IN packet counter
; update the first data byte
; in EP2IN buffer
dptr,3IN2BUF
a,r1
@dptr,a
dptr
; second byte in buffer
; get number of OUT packets
a,r2
@dptr,a
dptr,#IN2BC
a,#40h
@dptr,a
loop
; point to EP2IN Byte Count Register
; load bc=64 to re-arm IN2
40
41
;
END
Figure 6-6. Example Code for a Simple (Polled) BULK Transfer
EZ-USB TRM v1.9
Chapter 6. EZ-USB CPU
Page 6-13