English
Language : 

EZ-USB Datasheet, PDF (116/334 Pages) Cypress Semiconductor – The EZ-USB USB Integrated Circuit
4. Write the endpoint 2 transfer program.
1 loop:
jnb got_EP2_data,loop
2
clr got_EP2_data
; clear my flag
3;
4 ; The user sent bytes to OUT2 endpoint using the USB Control Panel.
5 ; Find out how many bytes were sent.
6;
7
mov dptr,#OUT2BC
; point to OUT2 byte count register
8
movx a,@dptr
; get the value
9
mov r7,a
; stash the byte count
10
mov r6,a
; save here also
11 ;
12 ; Transfer the bytes received on the OUT2 endpoint to the IN2 endpoint
13 ; buffer. Number of bytes in r6 and r7.
14 ;
15
mov dptr,#OUT2BUF
; first data pointer points to EP2OUT buffer
16
inc dps
; select the second data pointer
17
mov dptr,#IN2BUF
; second data pointer points to EP2IN buffer
18
inc dps
; back to first data pointer
19 transfer: movx movx
get OUT byte
20
inc dptr
; bump the pointer
21
inc dps
; second data pointer
22
movx @dptr,a
; put into IN buffer
23
inc dptr
; bump the pointer
24
inc dps
; first data pointer
25
djnz r7,transfer
26 ;
27 ; Load the byte count into IN2BC. This arms in IN transfer
28 ;
29
mov dptr,#IN2BC
30
mov a,r6
; get other saved copy of byte count
31
movx @dptr,a
; this arms the IN transfer
32 ;
33 ; Load any byte count into OUT2BC. This arms the next OUT transfer.
34 ;
35
mov dptr,#OUT2BC
36
movx @dptr,a
; use whatever is in acc
37
sjmp loop
; start checking for another OUT2 packet
Figure 6-10. Background Program Transfers Endpoint 2-OUT Data to Endpoint 2-IN
The main program loop tests the “got_EP2_data” flag, waiting until it is set by the end-
point 2 OUT interrupt service routine in Figure 6-10. This indicates that a new data
packet has arrived in OUT2BUF. Then the service routine is entered, where the flag is
cleared in line 2. The number of bytes received in OUT2BUF is retrieved from the
OUT2BC register (Endpoint 2 Byte Count) and saved in registers R6 and R7 in lines 7-10.
The dual data pointers are initialized to the source (OUT2BUF) and destination (IN2BUF)
buffers for the data transfer in lines 15-18. These labels represent the start of the 64-byte
buffers for endpoint 2-OUT and endpoint 2-IN, respectively. Each byte is read from the
OUT2BUF buffer and written to the IN2BUF buffer in lines 19-25. The saved value of
EZ-USB TRM v1.9
Chapter 6. EZ-USB CPU
Page 6-19