Friday, November 1, 2013

added IN transfer queing/dequeing routines in IE_stm32_usb.c

void    stm32_usb_cancel_IN_transfers(unsigned int wdEndP);
void    stm32_usb_dequeue_IN_transfers(unsigned int wdEndP);
void    stm32_usb_queue_IN_transfers(unsigned int  wdEndP,\
                                     unsigned char *ptrBuffer,\
                                     unsigned int  wdSize);



/*
 **********************************************************************
 *#define constants for USB enumeration
 **********************************************************************
 */
struct  STR_USB_PKT_XFER{
                        unsigned char   *ptrCtrlBuf;
                        int     wdCtrlSize;

                        unsigned char   *ptrUserBuf;
                        int     wdUserSize;
                        }strUsbPktXfer;
 
 
 
/*
 **********************************************************************
 *description:  tx transfer cancel routine
 *input:        unsigned int    wdEndP     = endpoint number
 *note:         called at post_reset and whenever the need arises
 **********************************************************************
 */
void
stm32_usb_cancel_IN_transfers(unsigned int  wdEndP)
{
if(wdEndP == STMUSB_ENDP_USER_NUM)
        strUsbPktXfer.wdUserSize = -1;
else
        strUsbPktXfer.wdCtrlSize = -1;
}





/*
 **********************************************************************
 *description:  tx transfer dequeue routine
 *input:        unsigned int    wdEndP     = endpoint number
 *note:         be prepared to deal with zero length packets
 **********************************************************************
 */
void
stm32_usb_dequeue_IN_transfers(unsigned int  wdEndP)
{
unsigned char   *ptrBuf, **ptrPtrBuf;
int     *ptrCount, wdCount, wdEndPSize;


if(wdEndP == STMUSB_ENDP_USER_NUM)
        {
        ptrBuf    = strUsbPktXfer.ptrUserBuf;
        ptrPtrBuf = (unsigned char **)&strUsbPktXfer.ptrUserBuf;
        ptrCount  = &strUsbPktXfer.wdUserSize;

        wdCount   = *ptrCount;
        wdEndPSize= STMUSB_ENDP_USER_SIZE;
        }
else
        {
        ptrBuf    = (unsigned char *)strUsbPktXfer.ptrCtrlBuf;
        ptrPtrBuf = (unsigned char **)&strUsbPktXfer.ptrCtrlBuf;
        ptrCount  = &strUsbPktXfer.wdCtrlSize;

        wdCount   = *ptrCount;
        wdEndPSize= STMUSB_ENDP_CTRL_SIZE;
        }
                

/*check if xfer is >= 0, return if its -1*/
if(wdCount < 0)                         /*check xfer == -1 or xfer >=0 */
        return;
else
        {
        if(wdCount == 0)                /*should we generate a zero length packet*/
                {
                *ptrCount = -1;         /*end future xfers*/
                stm32_usb_endp_send_packet(wdEndP,\
                                           ptrBuf,\
                                           wdEndPSize,\
                                           0);
                }
        else
                {
                if(wdCount >= wdEndPSize)
                        wdCount = wdEndPSize;

                stm32_usb_endp_send_packet(wdEndP,\
                                           ptrBuf,\
                                           wdEndPSize,\
                                           wdCount);

                /*update variables*/
                *(ptrPtrBuf) = (unsigned char *)(ptrBuf + wdCount);
                *(ptrCount) -= wdCount;


                /*
                 *******************************************************
                 *prep for a zlp on the next interrupt if 
                 *this is the last transfer (wdCount == 0) and
                 *the transfer size matches the endpoint buffer size
                 *******************************************************
                 */
                if(wdCount == wdEndPSize &&\
                   (*ptrCount) == 0)
                        ;               /*do nothing here*/
                else
                        (*ptrCount) = -1;
                }
        }
}       





/*
 **********************************************************************
 *description:  tx transfer queue routine
 *input:        unsigned int    wdEndP     = endpoint number
 *              unsigned char   *ptrBuffer = pointer to buffer
 *              unsigned int    wdSize     = buffer size in bytes
 *notes:        store pointers to the global record. stores count of 
 *              records
 **********************************************************************
 */
void
stm32_usb_queue_IN_transfers(unsigned int  wdEndP,\
                             unsigned char *ptrBuffer,\
                             unsigned int  wdSize)
{
if(wdEndP == STMUSB_ENDP_USER_NUM)
        {
        strUsbPktXfer.ptrUserBuf = ptrBuffer;
        strUsbPktXfer.wdUserSize = wdSize;
        }
else
        {
        strUsbPktXfer.ptrCtrlBuf = ptrBuffer;
        strUsbPktXfer.wdCtrlSize = wdSize;
        }
}




No comments:

Post a Comment