Description
Source
Call Graph
Start Line: 862
char USBD_Write(unsigned char bEndpoint, const void *pData, unsigned int size, TransferCallback callback, void *pArg)
{
Endpoint *pEndpoint = &(endpoints[bEndpoint]);
Transfer *pTransfer = &(pEndpoint->transfer);
// Check that the endpoint is in Idle state
if (pEndpoint->state != UDP_ENDPOINT_IDLE) {
return USBD_STATUS_LOCKED;
}
TRACE_DEBUG_WP("Write%d(%d) ", bEndpoint, dLength);
// Setup the transfer descriptor
pTransfer->pData = (void *) pData;
pTransfer->remaining = dLength;
pTransfer->buffered = 0;
pTransfer->transferred = 0;
pTransfer->fCallback = fCallback;
pTransfer->pArgument = pArgument;
// Send the first packet
pEndpoint->state = UDP_ENDPOINT_SENDING;
while((AT91C_BASE_UDP->UDP_CSR[bEndpoint]&AT91C_UDP_TXPKTRDY)==AT91C_UDP_TXPKTRDY);
UDP_WritePayload(bEndpoint);
SET_CSR(bEndpoint, AT91C_UDP_TXPKTRDY);
// If double buffering is enabled and there is data remaining,
// prepare another packet
if ((BOARD_USB_ENDPOINTS_BANKS(bEndpoint) > 1) && (pTransfer->remaining > 0)) {
UDP_WritePayload(bEndpoint);
}
// Enable interrupt on endpoint
AT91C_BASE_UDP->UDP_IER = 1 << bEndpoint;
return USBD_STATUS_SUCCESS;
}