Example #1
0
//*****************************************************************************
//
// Called by the USB stack for any activity involving one of our endpoints
// other than EP0.  This function is a fan out that merely directs the call to
// the correct handler depending upon the endpoint and transaction direction
// signaled in ulStatus.
//
//*****************************************************************************
static void
HandleEndpoints(void *pvInstance, unsigned int ulStatus, unsigned int ulIndex)
{
    const tUSBDBulkDevice *psBulkInst;
    tBulkInstance *psInst;

    ASSERT(pvInstance != 0);

    //
    // Determine if the serial device is in single or composite mode because
    // the meaning of ulIndex is different in both cases.
    //
    psBulkInst = (const tUSBDBulkDevice *)pvInstance;
    psInst = psBulkInst->psPrivateBulkData;

    //
    // Handler for the bulk OUT data endpoint.
    //
    if(ulStatus & (0x10000 << USB_EP_TO_INDEX(psInst->ucOUTEndpoint)))
    {
        //
        // Data is being sent to us from the host.
        //
        ProcessDataFromHost(pvInstance, ulStatus, ulIndex);
    }

    //
    // Handler for the bulk IN data endpoint.
    //
    if(ulStatus & (1 << USB_EP_TO_INDEX(psInst->ucINEndpoint)))
    {
        ProcessDataToHost(pvInstance, ulStatus, ulIndex);
    }
}
Example #2
0
/**
* \brief      This API enables the RX DMA for an endPoint.The API access the CSR
*          register of  the particular endpoint to set appropriate bits. This API is
*          called by the stack to enable DMA when it is requied.
*
* \param      usbDevInst:- USB device instance
*
* \param  ulEndpoint:- Endpoint Number
*
* \return      None.
*
**/
void enableCoreRxDMA(unsigned short usbDevInst, unsigned int ulEndpoint)
{
    unsigned int ulRegister;
    usbInstance *usbInstance;

    usbInstance = &(cppiInfo.usbInst[usbDevInst]);

    /*Find out the RX CSR  address */
    ulRegister = USB_O_RXCSRL1 + EP_OFFSET(ulEndpoint);

    /*Find out the index to usb intance end point array */
    ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);

    /*Enable the scheduler with number entries */
    Cppi41DmaControlScheduler(usbDevInst, ENABLE_CPPIDMA, NUM_OF_SCHEDULER_ENTRIES);

    /*Configure the completion queue */
    Cppi41DmaConfigRxCompletionQueue(usbDevInst, usbInstance->rxEndPoint[ulEndpoint].channel,
                                     usbInstance->rxEndPoint[ulEndpoint].complettionq);

    /* Clear AUTOCLEAR and DMAReqMode */
    HWREGH(usbInstance->usbBaseAddress + ulRegister)&=CPDMA_RX_CLR_AUTO_CLEAR;

    /* Set DMAReqEnab */
    HWREGH(usbInstance->usbBaseAddress + ulRegister)|=CPDMA_RX_SET_REQ_ENABLE;
}
Example #3
0
unsigned int dmaRxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint )
{

    unsigned int bufferAdd;
    usbInstance *usbInstance;

    hostPacketDesc *rx_bd =0;

    usbInstance = &(cppiInfo.usbInst[usbDevInst]);

    ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);

    /*read the compltetion queue */
    rx_bd = (hostPacketDesc *)Cppi41DmaReadCompletionQueue(usbDevInst, usbInstance
            ->rxEndPoint[ulEndpoint].complettionq);


    bufferAdd = rx_bd->buffAdd;


    /*Flush the cache to update the buffer */
    CacheDataInvalidateBuff(rx_bd->buffAdd, rx_bd->buffLength);

    putFreeBd(rx_bd);

    return bufferAdd;
}
Example #4
0
void doDmaRxTransfer(unsigned short usbDevInst, unsigned int length,
                     unsigned char *buff, unsigned int endPoint)
{
    hostPacketDesc *current_bd = 0;
    usbInstance *usbInstance;

    //ASSERT(buff != 0);

    usbInstance = &(cppiInfo.usbInst[usbDevInst]);

    current_bd = getFreeBd();
    //ASSERT(current_bd != 0);

    endPoint = USB_EP_TO_INDEX(endPoint);

    /* Process the BD */
    Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_RX, buff, length, endPoint);

    /* Clean the cache */
    CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));

    /*Submit the BD */
    pushToSubmitQ(usbDevInst, usbInstance->rxEndPoint[endPoint].submitq, current_bd);

}
Example #5
0
unsigned int dmaTxCompletion(unsigned short usbDevInst, unsigned int ulEndpoint )
{

    hostPacketDesc *completed_bd;
    unsigned int ulRegister;
    unsigned int state;
    unsigned int packetid;
    usbInstance *usbInstance;

    usbInstance = &(cppiInfo.usbInst[usbDevInst]);

    ulRegister = USB_O_TXCSRL1 + EP_OFFSET( ulEndpoint);

    ulEndpoint = USB_EP_TO_INDEX(ulEndpoint);


    /*read the compltetion queue */
    completed_bd = (hostPacketDesc *)Cppi41DmaReadCompletionQueue(usbDevInst, usbInstance
                   ->txEndPoint[ulEndpoint].complettionq);
    /*Get the packet ID to update the DMA status */
    packetid = completed_bd->packetId;
    if(packetid == EOP)
        state = DMA_TX_COMPLETED;
    else
        state = DMA_TX_IN_PROGRESS;

    /*wait till Tx completion */
    if(state == DMA_TX_COMPLETED)
        while ((HWREGH(usbInstance->usbBaseAddress + ulRegister) & 0x2) == 0x02);

    CacheDataInvalidateBuff((unsigned int)completed_bd->buffAdd, sizeof(completed_bd->buffAdd));

    cppiDmaFreenBuffer((unsigned int *)completed_bd->buffAdd);

    completed_bd->buffAdd = 0;

    /*put the free buffer */
    putFreeBd(completed_bd);

    return state;

}
Example #6
0
    0,                          // The index for this interface.
    0,                          // The alternate setting for this interface.
    2,                          // The number of endpoints used by this
                                // interface.
    USB_CLASS_VEND_SPECIFIC,    // The interface class
    0,                          // The interface sub-class.
    0,                          // The interface protocol for the sub-class
                                // specified above.
    4,                          // The string index for this interface.

    //
    // Endpoint Descriptor
    //
    7,                               // The size of the endpoint descriptor.
    USB_DTYPE_ENDPOINT,              // Descriptor type is an endpoint.
    USB_EP_DESC_IN | USB_EP_TO_INDEX(DATA_IN_ENDPOINT),
    USB_EP_ATTR_BULK,                // Endpoint is a bulk endpoint.
    USBShort(DATA_IN_EP_MAX_SIZE),   // The maximum packet size.
    0,                               // The polling interval for this endpoint.

    //
    // Endpoint Descriptor
    //
    7,                               // The size of the endpoint descriptor.
    USB_DTYPE_ENDPOINT,              // Descriptor type is an endpoint.
    USB_EP_DESC_OUT | USB_EP_TO_INDEX(DATA_OUT_ENDPOINT),
    USB_EP_ATTR_BULK,                // Endpoint is a bulk endpoint.
    USBShort(DATA_OUT_EP_MAX_SIZE),  // The maximum packet size.
    0,                               // The polling interval for this endpoint.
};
Example #7
0
void doDmaTxTransfer(unsigned short usbDevInst, unsigned char *buff,
                     unsigned int length, unsigned int endPoint)
{
    hostPacketDesc *current_bd = 0;

    unsigned int numOfBlocks =0;
    unsigned int residue;
    unsigned int i;
    usbInstance *usbInstance;

    usbInstance = &(cppiInfo.usbInst[usbDevInst]);

    endPoint = USB_EP_TO_INDEX(endPoint);

    /*This code segment will take care of the transparent mode transaction */
    if(CPDMA_MODE_SET_TRANSPARENT == usbInstance->txEndPoint[endPoint].mode)
    {
        /* If the data length is less than the USB packet size */
        if(length < USB_PACKET_LENGTH)
        {
            /*get a free db from the BD pool     */
            current_bd = getFreeBd();
            //ASSERT(current_bd != 0);
            //ASSERT(buff != 0);

            /*Clean the cache so that buffer will have proper data */
            CacheDataCleanBuff((unsigned int)buff, length);

            /*This API will initialize the BD fields */
            Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX, buff, length, endPoint);

            current_bd->packetId = EOP;

            /*Clean the cache so that bd  will have proper data */
            CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));

            /*Submit the BD to the queue for transaction     */
            pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
                          .submitq, current_bd);
        }

        /*If the length is more than packet size, then packetize it  */
        else
        {
            numOfBlocks = length / USB_PACKET_LENGTH;
            residue = length -  (numOfBlocks * USB_PACKET_LENGTH);

            for(i=0; i < numOfBlocks; i++)
            {
                /*get a free db from the BD pool     */
                current_bd = getFreeBd();
                //ASSERT(current_bd != 0);
                //ASSERT(buff != 0);

                CacheDataCleanBuff((unsigned int)&buff[i*USB_PACKET_LENGTH],
                                   USB_PACKET_LENGTH);

                /*This API will initialize the BD fields */
                Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX,
                                   &buff[i*USB_PACKET_LENGTH], USB_PACKET_LENGTH, endPoint);

                /*Set the packet id to identify the packet position */
                if(numOfBlocks == 1)
                    current_bd->packetId = EOP;
                else if(i==0)
                    current_bd->packetId = SOP;
                else if((numOfBlocks != 1) && (i < (numOfBlocks -1)))
                    current_bd->packetId = MOP;
                else if(i == (numOfBlocks -1) && residue == 0)
                    current_bd->packetId = EOP;
                else
                    current_bd->packetId = MOP;

                CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));

                /*Submit the BD to the queue for transaction     */
                pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
                              .submitq, current_bd);
            }

            /*If there are some remaining data then send it also */
            if(residue)
            {
                /*get a free db from the BD pool     */
                current_bd = getFreeBd();
                //ASSERT(current_bd != 0);

                CacheDataCleanBuff((unsigned int)&buff[i*USB_PACKET_LENGTH], residue);

                /*This API will initialize the BD fields */
                Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX,
                                   &buff[i*USB_PACKET_LENGTH], residue, endPoint);

                current_bd->packetId = EOP;

                /*This API will initialize the BD fields */
                CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));

                /*Submit the BD to the queue for transaction     */
                pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
                              .submitq, current_bd);
            }

        }
    }

    /*This segment of the code will take care of GRNIS mode of transaction */
    else if(usbInstance->txEndPoint[endPoint].mode == CPDMA_MODE_SET_GRNDIS)
    {
        /*get a free db from the BD pool     */
        current_bd = getFreeBd();
        //ASSERT(current_bd != 0);

        CacheDataCleanBuff((unsigned int)buff, length);

        /*This API will initialize the BD fields */
        Cppi41DmaProcessBD(usbDevInst, current_bd, CPDMA_DIR_TX, buff, length, endPoint);

        current_bd->packetId = EOP;

        CacheDataCleanBuff((unsigned int)current_bd,sizeof(hostPacketDesc));

        /*Submit the BD to the queue for transaction     */
        pushToSubmitQ(usbDevInst, usbInstance->txEndPoint[endPoint]
                      .submitq, current_bd);
    }

}
Example #8
0
            break;
        }

        default:
        {
            break;
        }
    }
}

#if USB_USE_CPPI41DMA  

endpointInfo epInfo[]=
{
	{
		USB_EP_TO_INDEX(USB_EP_1),
		CPDMA_DIR_RX,
		CPDMA_MODE_SET_TRANSPARENT,
	},
	
	{
		USB_EP_TO_INDEX(USB_EP_1),
		CPDMA_DIR_TX,
		CPDMA_MODE_SET_GRNDIS,
	},
	
	{
		USB_EP_TO_INDEX(USB_EP_2),
		CPDMA_DIR_RX,
		CPDMA_MODE_SET_TRANSPARENT,
	},