1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Karl Kurbjun
11 * Portions Copyright (C) 2007 by Catalin Patulea
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
38 #include "usb-target.h"
41 /*******************************************************************************
42 * These are the driver specific defines.
43 ******************************************************************************/
46 /* Right now sending blocks till the full transfer has completed, this needs to
47 * be fixed so that it does not require a block. (USB_TRAN_LOCK ideally would
50 #define USB_TRAN_BLOCK
52 /*******************************************************************************
53 * The following functions are all helpers which should not be called directly
54 * from the USB stack. They should only be called by eachother, or the USB
55 * stack visible functions.
56 ******************************************************************************/
58 static volatile unsigned short * pipe_ctrl_addr(int pipe
);
59 static void pipe_handshake(int pipe
, int handshake
);
60 static void pipe_c_select (int pipe
, bool dir
);
61 #if !defined(USB_TRAN_BLOCK)
62 static int pipe_buffer_size (int pipe
);
64 static int pipe_maxpack_size (int pipe
);
65 static void control_received(void);
66 static void transfer_complete(int endpoint
);
67 static int mxx_transmit_receive(int endpoint
);
68 static int mxx_queue(int endpoint
, void * ptr
, int length
, bool send
);
70 struct M66591_epstat
{
71 unsigned char dir
; /* endpoint direction */
72 char *buf
; /* user buffer to store data */
73 int length
; /* how match data will fit */
74 volatile int count
; /* actual data count */
75 bool waiting
; /* is there data to transfer? */
76 bool busy
; /* has the pipe been requested for use? */
79 static struct M66591_epstat M66591_eps
[USB_NUM_ENDPOINTS
];
81 /* This function is used to return the control address for each pipe */
82 static volatile unsigned short * pipe_ctrl_addr(int pipe
) {
84 return &M66591_DCPCTRL
;
86 return &M66591_PIPECTRL1
+ (pipe
-1);
90 /* This function sets the pipe/endpoint handshake */
91 static void pipe_handshake(int pipe
, int handshake
) {
94 if(handshake
== PIPE_SHAKE_STALL
) {
95 if( *(pipe_ctrl_addr(pipe
)) & 0x03 ) {
96 *(pipe_ctrl_addr(pipe
)) = 0x03;
98 *(pipe_ctrl_addr(pipe
)) = 0x02;
101 *(pipe_ctrl_addr(pipe
)) = handshake
;
105 /* This function chooses the pipe desired and waits the required time before
106 * warites/reads are valid */
107 static void pipe_c_select (int pipe
, bool dir
) {
108 M66591_CPORT_CTRL0
= pipe
| (1<<10) | (dir
<<5);
110 // Wait for the Pipe to be valid;
114 #if !defined(USB_TRAN_BLOCK)
115 /* This returns the maximum buffer size of each pipe. On this device the size
118 static int pipe_buffer_size (int pipe
) {
137 /* This function returns the maximum packet size for each endpoint/pipe. It is
138 * Currently only setup to support Highspeed mode.
140 static int pipe_maxpack_size (int pipe
) {
143 /* DCP max packet size is configurable */
144 return M66591_DCP_MXPKSZ
;
158 /* This is a helper function that is only called from the interupt handler. It
159 * copies the control packet information from the PHY and notifies the stack.
161 static void control_received(void) {
162 /* copy setup data from packet */
163 static struct usb_ctrlrequest temp
;
165 memcpy(&temp
, (unsigned char*)&M66591_USB_REQ0
, 8);
167 logf("mxx: bReqType=0x%02x bReq=0x%02x wVal=0x%04x"
168 " wIdx=0x%04x wLen=0x%04x",
169 temp
.bRequestType
, temp
.bRequest
, temp
.wValue
,
170 temp
.wIndex
, temp
.wLength
);
172 /* acknowledge packet recieved (clear valid) */
173 M66591_INTSTAT_MAIN
&= ~(1<<3);
175 usb_core_control_request(&temp
);
178 /* This is a helper function, it is used to notife the stack that a transfer is
181 static void transfer_complete(int endpoint
) {
182 M66591_INTCFG_EMP
&= ~(1 << endpoint
);
183 logf("mxx: ep %d transfer complete", endpoint
);
184 int temp
=M66591_eps
[endpoint
].dir
? USB_DIR_IN
: USB_DIR_OUT
;
185 usb_core_transfer_complete(endpoint
, temp
, 0,
186 M66591_eps
[endpoint
].length
);
189 /* This is the main transmit routine that is typically called from the interrupt
190 * handler (the queue function calls it in some situations)
192 static int mxx_transmit_receive(int endpoint
) {
193 logf("mxx: do start");
195 /* Only the lower 15 bits of the endpoint correlate to the pipe number.
196 * For example pipe 2 will corelate to endpoint 0x82, so the upper bits
197 * need to be masked out.
201 int i
; /* Used as a loop counter */
202 int length
; /* Used in transfers to determine the amount to send/receive */
204 bool send
=M66591_eps
[endpoint
].dir
;
206 /* This is used as the internal buffer pointer */
207 unsigned short *ptrs
;
209 /* Choose the pipe that data is being transfered on */
210 pipe_c_select(endpoint
, send
);
212 /* Check to see if the endpoint is ready and give it some time to become
213 * ready. If it runs out of time exit out as an error.
216 while (!(M66591_CPORT_CTRL1
&(1<<13))) {
218 logf("mxx: FIFO %d not ready", endpoint
);
225 int maxpack
=pipe_maxpack_size(endpoint
);
226 #if defined(USB_TRAN_BLOCK)
227 length
= M66591_eps
[endpoint
].length
;
229 int bufsize
=pipe_buffer_size(endpoint
);
230 length
=MIN(M66591_eps
[endpoint
].length
, bufsize
);
233 /* Calculate the position in the buffer, all transfers should be 2-byte
234 * aligned till the last packet or short packet.
236 ptrs
= (unsigned short *)(M66591_eps
[endpoint
].buf
237 + M66591_eps
[endpoint
].count
);
239 /* Start sending data in 16-bit words */
240 for (i
= 0; i
< (length
>>1); i
++) {
241 /* This wait is dangerous in the event that something happens to
242 * the PHY pipe where it never becomes ready again, should probably
243 * add a timeout, and ideally completely remove.
245 while(!(M66591_CPORT_CTRL1
&(1<<13))){};
247 M66591_CPORT
= *ptrs
++;
248 M66591_eps
[endpoint
].count
+=2;
251 /* If the length is odd, send the last byte after setting the byte width
255 /* Unset MBW (8-bit transfer) */
256 M66591_CPORT_CTRL0
&= ~(1<<10);
257 M66591_CPORT
= *((unsigned char *)ptrs
- 1);
258 M66591_eps
[endpoint
].count
++;
261 /* Set BVAL if length is not a multiple of the maximum packet size */
262 if( (length
== 0) || (length
% maxpack
!= 0) ) {
263 logf("mxx: do set BVAL");
264 M66591_CPORT_CTRL1
|= (1<<15);
267 /* If the transfer is complete set up interrupts to notify when FIFO is
268 * EMPTY, disable READY and let the handler know that there is nothing
269 * left to transfer on this pipe.
271 if(M66591_eps
[endpoint
].count
== M66591_eps
[endpoint
].length
) {
272 /* Enable Empty flag */
273 M66591_INTCFG_EMP
|= 1 << endpoint
;
274 /* Disable ready flag */
275 M66591_INTCFG_RDY
&= ~(1 << endpoint
);
276 /* Nothing left to transfer */
277 M66591_eps
[endpoint
].waiting
=false;
279 /* There is still data to transfer, make sure READY is enabled */
280 M66591_INTCFG_RDY
|= 1 << endpoint
;
283 /* Read data from FIFO */
285 /* Read the number of bytes that the PHY received */
286 int receive_length
=M66591_CPORT_CTRL1
& 0x03FF;
288 /* The number of bytes to actually read is either what's left of the
289 * amount requested, or the amount that the PHY received. Choose the
290 * smaller of the two.
292 length
= MIN(M66591_eps
[endpoint
].length
- M66591_eps
[endpoint
].count
,
295 /* If the length is zero, just clear the buffer as specified in the
296 * datasheet. Otherwise read in the data (in 16-bit pieces */
298 /* Set the BCLR bit */
299 M66591_CPORT_CTRL1
|= 1<<14;
301 /* Set the position in the buffer */
302 ptrs
= (unsigned short *)(M66591_eps
[endpoint
].buf
303 + M66591_eps
[endpoint
].count
);
305 /* Read in the data (buffer size should be even). The PHY cannot
306 * switch from 16-bit mode to 8-bit mode on an OUT buffer.
308 for (i
= 0; i
< ((length
+1)>>1); i
++) {
309 *ptrs
++ = M66591_CPORT
;
310 M66591_eps
[endpoint
].count
+=2;
314 /* If the length was odd subtract 1 from the count */
315 M66591_eps
[endpoint
].count
-= (length
&0x01);
317 /* If the requested size of data was received, or the data received was
318 * less than the maximum packet size end the transfer.
320 if( (M66591_eps
[endpoint
].count
== M66591_eps
[endpoint
].length
)
321 || (length
% pipe_maxpack_size(endpoint
)) ) {
323 /* If the host tries to send anything else the FIFO is not ready/
326 pipe_handshake(endpoint
, PIPE_SHAKE_NAK
);
327 /* Tell the interrupt handler that transfer is complete. */
328 M66591_eps
[endpoint
].waiting
=false;
330 M66591_INTCFG_RDY
&= ~(1 << endpoint
);
332 /* Let the stack know that the transfer is complete */
334 transfer_complete(endpoint
);
338 logf("mxx: do done ep %d %s len: %d cnt: %d", endpoint
,
339 send
? "out" : "in", length
, M66591_eps
[endpoint
].count
);
344 /* This function is used to start transfers. It is a helper function for the
345 * usb_drv_send_nonblocking, usb_drv_send, and usb_drv_receive functions.
347 static int mxx_queue(int endpoint
, void * ptr
, int length
, bool send
) {
349 int flags
= disable_irq_save();
351 /* Only the lower 15 bits of the endpoint correlate to the pipe number.
352 * For example pipe 2 will corelate to endpoint 0x82, so the upper bits
353 * need to be masked out.
357 /* Initialize the enpoint status registers used for the transfer */
358 M66591_eps
[endpoint
].buf
=ptr
;
359 M66591_eps
[endpoint
].length
=length
;
360 M66591_eps
[endpoint
].count
=0;
361 M66591_eps
[endpoint
].dir
=send
;
362 M66591_eps
[endpoint
].waiting
=true;
364 logf("mxx: queue ep %d %s, len: %d", endpoint
, send
? "out" : "in", length
);
366 /* Pick the pipe that communications are happening on */
367 pipe_c_select(endpoint
, send
);
369 /* All transfers start with a BUF handshake */
370 pipe_handshake(endpoint
, PIPE_SHAKE_BUF
);
372 /* This USB PHY takes care of control completion packets by setting the
373 * CCPL bit in EP0 (endpoint 0, or DCP). If the control state is "write no
374 * data tranfer" then we just need to set the CCPL bit (hopefully)
375 * regardless of what the stack said to send.
377 int control_state
= (M66591_INTSTAT_MAIN
& 0x07);
378 if(endpoint
==0 && control_state
==CTRL_WTND
) {
379 logf("mxx: queue ep 0 ctls: 5, set ccpl");
382 M66591_DCPCTRL
|= 1<<2;
384 /* This is the standard case for transmitting data */
386 /* If the pipe is not ready don't try and send right away; instead
387 * just set the READY interrupt so that the handler can initiate
390 if((M66591_CPORT_CTRL1
&(1<<13))) {
391 mxx_transmit_receive(endpoint
);
393 M66591_INTCFG_RDY
|= 1 << endpoint
;
397 transfer_complete(endpoint
);
400 /* When receiving data, just enable the ready interrupt, the PHY
401 * will trigger it and then the reads can start.
403 M66591_INTCFG_RDY
|= 1 << endpoint
;
412 /*******************************************************************************
413 * This is the interrupt handler for this driver. It should be called from the
414 * target interrupt handler routine (eg. GPIO3 on M:Robe 500).
415 ******************************************************************************/
416 void USB_DEVICE(void) {
417 int pipe_restore
=M66591_CPORT_CTRL0
;
418 logf("mxx: INT BEGIN tick: %d\n", (int) current_tick
);
420 logf("mxx: sMAIN0: 0x%04x, sRDY: 0x%04x",
421 M66591_INTSTAT_MAIN
, M66591_INTSTAT_RDY
);
422 logf("mxx: sNRDY: 0x%04x, sEMP: 0x%04x",
423 M66591_INTSTAT_NRDY
, M66591_INTSTAT_EMP
);
425 /* VBUS (connected) interrupt */
426 while ( M66591_INTSTAT_MAIN
& (1<<15) ) {
427 M66591_INTSTAT_MAIN
&= ~(1<<15);
429 /* If device is not clocked, interrupt flag must be set manually */
430 if ( !(M66591_TRN_CTRL
& (1<<10)) ) {
431 M66591_INTSTAT_MAIN
|= (1<<15);
435 /* Resume interrupt: This is not used. Extra logic needs to be added similar
436 * to the VBUS interrupt incase the PHY clock is not running.
438 if(M66591_INTSTAT_MAIN
& (1<<14)) {
439 M66591_INTSTAT_MAIN
&= ~(1<<14);
443 /* Device state transition interrupt: Not used, but useful for debugging */
444 if(M66591_INTSTAT_MAIN
& (1<<12)) {
445 M66591_INTSTAT_MAIN
&= ~(1<<12);
446 logf("mxx: DEV state CHANGE=%d",
447 ((M66591_INTSTAT_MAIN
& (0x07<<4)) >> 4) );
450 /* Control transfer stage interrupt */
451 if(M66591_INTSTAT_MAIN
& (1<<11)) {
452 M66591_INTSTAT_MAIN
&= ~(1<<11);
453 int control_state
= (M66591_INTSTAT_MAIN
& 0x07);
455 logf("mxx: CTRT with CTSQ=%d", control_state
);
457 switch ( control_state
) {
459 transfer_complete(0);
464 // If data is not valid stop
465 if(!(M66591_INTSTAT_MAIN
& (1<<3)) ) {
466 logf("mxx: CTRT interrupt but VALID is false");
473 pipe_handshake(0, PIPE_SHAKE_BUF
);
474 M66591_DCPCTRL
|= 1<<2; // Set CCPL
477 logf("mxx: CTRT with unknown CTSQ");
482 /* FIFO EMPTY interrupt: when this happens the transfer should be complete.
483 * When the interrupt occurs notify the stack.
485 if(M66591_INTSTAT_MAIN
& (1<<10)) {
487 logf("mxx: INT EMPTY: 0x%04x", M66591_INTSTAT_EMP
);
489 for(i
=0; i
<USB_NUM_ENDPOINTS
; i
++) {
490 if(M66591_INTSTAT_EMP
&(1<<i
)) {
491 /* Clear the empty flag */
492 M66591_INTSTAT_EMP
=~(1<<i
);
493 /* Notify the stack */
494 transfer_complete(i
);
499 /* FIFO NOT READY interrupt: This is not used, but included incase the
500 * interrupt is endabled.
502 if(M66591_INTSTAT_MAIN
& (1<<9)) {
503 logf("mxx: INT NOT READY: 0x%04x", M66591_INTSTAT_NRDY
);
504 M66591_INTSTAT_NRDY
= 0;
507 /* FIFO READY interrupt: This just initiates transfers if they are needed */
508 if(M66591_INTSTAT_MAIN
& (1<<8)) {
510 logf("mxx: INT READY: 0x%04x", M66591_INTSTAT_RDY
);
512 for(i
=0; i
<USB_NUM_ENDPOINTS
; i
++) {
513 /* Was this endpoint ready and waiting */
514 if(M66591_INTSTAT_RDY
&(1<<i
) && M66591_eps
[i
].waiting
) {
515 /* Clear the ready flag */
516 M66591_INTSTAT_RDY
=~(1<<i
);
517 /* It was ready and waiting so start a transfer */
518 mxx_transmit_receive(i
);
523 /* Make sure that the INTStatus register is completely cleared. */
524 M66591_INTSTAT_MAIN
= 0;
526 /* Restore the pipe state before the interrupt occured */
527 M66591_CPORT_CTRL0
=pipe_restore
;
528 logf("\nmxx: INT END");
531 /*******************************************************************************
532 * The following functions are all called by and visible to the USB stack.
533 ******************************************************************************/
535 /* The M55691 handles this automatically, nothing to do */
536 void usb_drv_set_address(int address
) {
540 /* This function sets the standard test modes, it is not required, but might as
541 * well implement it since the hardware supports it
543 void usb_drv_set_test_mode(int mode
) {
544 /* This sets the test bits and assumes that mode is from 0 to 0x04 */
545 M66591_TESTMODE
&= 0x0007;
546 M66591_TESTMODE
|= mode
;
549 /* Request an unused endpoint, support for interrupt endpoints needs addition */
550 int usb_drv_request_endpoint(int type
, int dir
) {
554 /* The endpoint/pipes are hard coded: This could be more flexible */
555 if (type
== USB_ENDPOINT_XFER_BULK
) {
556 /* Enalbe double buffer mode */
559 if (dir
== USB_DIR_IN
) {
565 } else if (type
== USB_ENDPOINT_XFER_INT
) {
566 if (dir
== USB_DIR_IN
) {
573 /* Not a supported type */
578 if (!M66591_eps
[ep
].busy
) {
579 M66591_eps
[ep
].busy
= true;
580 M66591_eps
[ep
].dir
= dir
;
582 logf("mxx: ep %d busy", ep
);
586 M66591_PIPE_CFGSEL
=ep
;
588 /* Enable pipe (15) and continuous transfer mode (8) */
589 pipecfg
|= 1<<15 | 1<<8;
591 pipe_handshake(ep
, PIPE_SHAKE_NAK
);
593 /* Setup the flags */
594 M66591_PIPE_CFGWND
=pipecfg
;
596 logf("mxx: ep req ep#: %d config: 0x%04x", ep
, M66591_PIPE_CFGWND
);
601 /* Used by stack to tell the helper functions that the pipe is not in use */
602 void usb_drv_release_endpoint(int ep
) {
606 if (ep
< 1 || ep
> USB_NUM_ENDPOINTS
|| M66591_eps
[ep
].busy
== false)
609 flags
= disable_irq_save();
611 logf("mxx: ep %d release", ep
);
613 M66591_eps
[ep
].busy
= false;
614 M66591_eps
[ep
].dir
= -1;
619 /* Periodically called to check if a cable was plugged into the device */
620 inline int usb_detect(void)
622 if(M66591_INTSTAT_MAIN
&(1<<7))
625 return USB_EXTRACTED
;
628 void usb_enable(bool on
) {
629 logf("mxx: %s: %s", __FUNCTION__
, on
? "true" : "false");
636 /* This is where the driver stuff starts */
637 void usb_drv_init(void) {
638 logf("mxx: Device Init");
640 /* State left behind by m:robe 500i original firmware */
641 M66591_TRN_CTRL
= 0x8001; /* External 48 MHz clock */
642 M66591_TRN_LNSTAT
= 0x0040; /* "Reserved. Set it to '1'." */
644 M66591_PIN_CFG0
= 0x0000;
645 M66591_PIN_CFG1
= 0x8000; /* Drive Current: 3.3V setting */
646 M66591_PIN_CFG2
= 0x0000;
648 M66591_INTCFG_MAIN
= 0x0000; /* All Interrupts Disable for now */
649 M66591_INTCFG_OUT
= 0x0000; /* Sense is edge, polarity is low */
650 M66591_INTCFG_RDY
= 0x0000;
651 M66591_INTCFG_NRDY
= 0x0000;
652 M66591_INTCFG_EMP
= 0x0000;
654 M66591_INTSTAT_MAIN
= 0;
655 M66591_INTSTAT_RDY
= 0;
656 M66591_INTSTAT_NRDY
= 0;
657 M66591_INTSTAT_EMP
= 0;
660 /* fully enable driver */
661 void usb_attach(void) {
664 /* Reset Endpoint states */
665 for(i
=0; i
<USB_NUM_ENDPOINTS
; i
++) {
666 M66591_eps
[i
].dir
= -1;
667 M66591_eps
[i
].buf
= (char *) 0;
668 M66591_eps
[i
].length
= 0;
669 M66591_eps
[i
].count
= 0;
670 M66591_eps
[i
].waiting
= false;
671 M66591_eps
[i
].busy
= false;
674 /* Issue a h/w reset */
678 /* USB Attach Process: This follows the flow diagram in the M66591GP
679 * Reference Manual Rev 1.00, p. 77 */
683 M66591_TRN_CTRL
|= 1<<7;
686 M66591_TRN_CTRL
&= ~(1<<7);
689 /* Enable oscillation buffer */
690 M66591_TRN_CTRL
|= (1<<13);
694 /* Enable reference clock, PLL */
695 M66591_TRN_CTRL
|= (3<<11);
699 /* Enable internal clock supply */
700 M66591_TRN_CTRL
|= (1<<10);
702 /* Disable PIPE ready interrupts */
703 M66591_INTCFG_RDY
= 0;
705 /* Disable PIPE not-ready interrupts */
706 M66591_INTCFG_NRDY
= 0;
708 /* Disable PIPE empyt/size error interrupts */
709 M66591_INTCFG_EMP
= 0;
711 /* Enable all interrupts except NOT READY, RESUME, and VBUS */
712 M66591_INTCFG_MAIN
= 0x1DFF;
714 pipe_c_select(0, false);
716 /* Enable continuous transfer mode on the DCP */
717 M66591_DCP_CNTMD
|= (1<<8);
719 /* Set the threshold that the PHY will automatically transmit from EP0 */
720 M66591_DCP_CTRLEN
= 128;
722 pipe_handshake(0, PIPE_SHAKE_NAK
);
724 /* Set the Max packet size to 64 */
725 M66591_DCP_MXPKSZ
= 64;
727 /* Attach notification to PC (D+ pull-up) */
728 M66591_TRN_CTRL
|= (1<<4);
730 logf("mxx: attached");
733 void usb_drv_exit(void) {
734 /* USB Detach Process: This follows the flow diagram in the M66591GP
735 * Reference Manual Rev 1.00, p. 78.
738 /* Detach notification to PC (disable D+ pull-up) */
739 M66591_TRN_CTRL
&= ~(1<<4);
742 M66591_TRN_CTRL
&= ~0x01;
744 /* Disable internal clock supply */
745 M66591_TRN_CTRL
&= ~(1<<10);
749 M66591_TRN_CTRL
&= ~(1<<11);
752 /* Disable internal reference clock */
753 M66591_TRN_CTRL
&= ~(1<<12);
756 /* Disable oscillation buffer, reenable USB operation */
757 M66591_TRN_CTRL
&= ~(1<<13);
759 M66591_TRN_CTRL
|= 0x01;
761 logf("mxx: detached");
764 /* This function begins a transmit (on an IN endpoint), it should not block
765 * so the actual transmit is done in the interrupt handler.
767 int usb_drv_send_nonblocking(int endpoint
, void* ptr
, int length
)
769 /* The last arguement for queue specifies the dir of data (true==send) */
770 return mxx_queue(endpoint
, ptr
, length
, true);
773 /* This function begins a transmit (on an IN endpoint), it does not block
774 * so the actual transmit is done in the interrupt handler.
776 int usb_drv_send(int endpoint
, void* ptr
, int length
)
778 /* The last arguement for queue specifies the dir of data (true==send) */
779 return mxx_queue(endpoint
, ptr
, length
, true);
782 /* This function begins a receive (on an OUT endpoint), it should not block
783 * so the actual receive is done in the interrupt handler.
785 int usb_drv_recv(int endpoint
, void* ptr
, int length
)
787 /* Last arguement for queue specifies the dir of data (false==receive) */
788 return mxx_queue(endpoint
, ptr
, length
, false);
791 /* This function checks the reset handshake speed status
792 * (Fullspeed or Highspeed)
794 int usb_drv_port_speed(void)
796 int handshake
= (M66591_HSFS
& 0xFF);
798 if( handshake
== 0x02) {
799 return 0; /* Handshook at Full-Speed */
800 } else if( handshake
== 0x03) {
801 return 1; /* Handshook at Hi-Speed */
803 return -1; /* Error, handshake may not be complete */
807 /* This function checks if the endpoint is stalled (error). I am not sure what
808 * the "in" variable is intended for.
810 bool usb_drv_stalled(int endpoint
,bool in
)
814 bool stalled
= (*(pipe_ctrl_addr(endpoint
)) & (0x02)) ? true : false;
816 logf("mxx: stall?: %s ep: %d", stalled
? "true" : "false", endpoint
);
825 /* This function stalls/unstalls the endpoint. Stalls only happen on error so
826 * if the endpoint is functioning properly this should not be called. I am
827 * not sure what the "in" variable is intended for.
829 void usb_drv_stall(int endpoint
, bool stall
,bool in
)
833 logf("mxx: stall - ep: %d", endpoint
);
836 /* Stall the pipe (host needs to intervene/error) */
837 pipe_handshake(endpoint
, PIPE_SHAKE_STALL
);
839 /* Setting this to a NAK, not sure if it is appropriate */
840 pipe_handshake(endpoint
, PIPE_SHAKE_NAK
);
844 /* !!!!!!!!!!This function is likely incomplete!!!!!!!!!!!!!! */
845 void usb_drv_cancel_all_transfers(void)
850 logf("mxx: %s", __func__
);
852 flags
= disable_irq_save();
853 for (endpoint
= 0; endpoint
< USB_NUM_ENDPOINTS
; endpoint
++) {
854 if (M66591_eps
[endpoint
].buf
) {
855 M66591_eps
[endpoint
].buf
= NULL
;