USB_HANDLE USBTransferOnePacket( uint8_t ep, uint8_t dir, uint8_t* data, uint8_t len );
The USBTransferOnePacket() function prepares a USB endpoint so that it may send data to the host (an IN transaction), or receive data from the host (an OUT transaction). The USBTransferOnePacket() function can be used both to receive and send data to the host. This function is the primary API function provided by the USB stack firmware for sending or receiving application data over the USB port.
The USBTransferOnePacket() is intended for use with all application endpoints. It is not used for sending or receiving application data through endpoint 0 by using control transfers. Separate API functions, such as USBEP0Receive(), USBEP0SendRAMPtr(), and USBEP0SendROMPtr() are provided for this purpose.
The USBTransferOnePacket() writes to the Buffer Descriptor Table (BDT) entry associated with an endpoint buffer, and sets the UOWN bit, which prepares the USB hardware to allow the transaction to complete. The application firmware can use the USBHandleBusy() macro to check the status of the transaction, to see if the data has been successfully transmitted yet.
Typical Usage
//make sure that the we are in the configured state if(USBGetDeviceState() == CONFIGURED_STATE) { //make sure that the last transaction isn't busy by checking the handle if(!USBHandleBusy(USBInHandle)) { //Write the new data that we wish to send to the host to the INPacket[] array INPacket[0] = USEFUL_APPLICATION_VALUE1; INPacket[1] = USEFUL_APPLICATION_VALUE2; //INPacket[2] = ... (fill in the rest of the packet data) //Send the data contained in the INPacket[] array through endpoint "EP_NUM" USBInHandle = USBTransferOnePacket(EP_NUM,IN_TO_HOST,(uint8_t*)&INPacket[0],sizeof(INPacket)); } }
Before calling USBTransferOnePacket(), the following should be true.
Return Values |
Description |
handle to the transfer. The handle is a pointer to the BDT entry associated with this transaction. The | |
status of the transaction (ex |
if it is complete or still pending) can be checked using the USBHandleBusy() macro and supplying the USB_HANDLE provided by USBTransferOnePacket(). |
If calling the USBTransferOnePacket() function from within the USBCBInitEP() callback function, the set configuration is still being processed and the USBDeviceState may not be == CONFIGURED_STATE yet. In this special case, the USBTransferOnePacket() may still be called, but make sure that the endpoint has been enabled and initialized by the USBEnableEndpoint() function first.
MLA - USB Library Help Version : 2.16
![]() |