1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 **/
1818
19-
20-
21-
2219#include <eputils.h>
2320
2421#include <fx2regs.h>
@@ -33,11 +30,7 @@ void readep0( BYTE* dst, WORD len) {
3330 WORD read = 0 ; // n bytes read
3431 BYTE c ,avail ;
3532 while (read < len ) {
36- EP0BCH = 0 ;
37- // NOTE need syncdelay?
38- EP0BCL = 0 ; // re-arm ep so host can send more
39- while (EP0CS & bmEPBUSY );
40- avail = EP0BCL ; // max size fits in one byte (64 bytes)
33+ avail = ep0_recv ();
4134 for (c = 0 ;c < avail ;++ c )
4235 dst [read + c ] = EP0BUF [c ];
4336 read += avail ;
@@ -49,12 +42,46 @@ void writeep0( BYTE* src, WORD len) {
4942 WORD written = 0 ;
5043 BYTE c ;
5144 while ( written < len ) {
52- while ( EP0CS & bmEPBUSY ); // wait
45+ ep0_busywait ();
5346 for (c = 0 ;c < 64 && written < len ;++ c ) {
5447 EP0BUF [c ] = src [written ++ ];
5548 }
56- EP0BCH = 0 ;
57- EP0BCL = c ;
58- printf ( "Write %d bytes\n" , c );
49+ ep0_load_length (c );
50+ printf ("Write %d bytes\n" , c );
5951 }
6052}
53+
54+ void ep0_send_descriptor (__xdata BYTE * src ) {
55+ // The ep0_load_length will be read out of the descriptor.
56+ ep0_mode (EP0_DATA_AUTO , EP0_LENGTH_AUTO );
57+ ep0_load_sudptr (src );
58+ }
59+
60+ void ep0_send_auto (__xdata BYTE * src , WORD len ) {
61+ ep0_mode (EP0_DATA_AUTO , EP0_LENGTH_MANUAL );
62+ ep0_load_length (len );
63+ ep0_load_sudptr (src );
64+ }
65+
66+ void ep0_send_byte (BYTE data ) {
67+ ep0_mode (EP0_DATA_MANUAL , EP0_LENGTH_MANUAL );
68+ EP0BUF [0 ] = data ;
69+ ep0_load_length (sizeof (data ));
70+ }
71+
72+ void ep0_send_word (WORD data ) {
73+ ep0_mode (EP0_DATA_MANUAL , EP0_LENGTH_MANUAL );
74+ EP0BUF [0 ] = MSB (data );
75+ EP0BUF [1 ] = LSB (data );
76+ ep0_load_length (sizeof (data ));
77+ }
78+
79+ BYTE ep0_recv () {
80+ BYTE len = 0 ;
81+ ep0_mode (EP0_DATA_MANUAL , EP0_LENGTH_MANUAL );
82+ ep0_arm (); //ep0_load_length(len);
83+ ep0_busywait ();
84+ len = ep0_get_length ();
85+ // EP0BUF now has the requested data
86+ return len ;
87+ }
0 commit comments