/* Transfers a data payload from an endpoint FIFO to the current transfer buffer  */
static void UDP_ReadPayload(unsigned char bEndpoint, int wPacketSize)
/* Transfers a data payload from an endpoint FIFO to the current transfer buffer  */
static void UDP_ReadPayload(unsigned char bEndpoint, int wPacketSize)
{
    Endpoint *pEndpoint = &(endpoints[bEndpoint]);
    Transfer *pTransfer = (Transfer*)&(pEndpoint->transfer);
    if (wPacketSize > pTransfer->remaining) {
        pTransfer->buffered += wPacketSize - pTransfer->remaining;
        wPacketSize = pTransfer->remaining;
    }
    pTransfer->remaining -= wPacketSize;
    pTransfer->transferred += wPacketSize;
    while (wPacketSize > 0) {
        *(pTransfer->pData) = (char) UDP->UDP_FDR[bEndpoint];
        pTransfer->pData++;
        wPacketSize--;
    }
}