/* Checks if an ongoing transfer on an endpoint has been completed.  */
static unsigned char UDP_IsTransferFinished(unsigned char bEndpoint)
/* Checks if an ongoing transfer on an endpoint has been completed.  */
static unsigned char UDP_IsTransferFinished(unsigned char bEndpoint)
{
    Endpoint *pEndpoint = &(endpoints[bEndpoint]);
    Transfer *pTransfer = (Transfer*)&(pEndpoint->transfer);
    if ((UDP->UDP_CSR[bEndpoint] & UDP_CSR_EPTYPE_Msk)
        == UDP_CSR_EPTYPE_CTRL) {
        return (pTransfer->buffered < pEndpoint->size);
    }
    else {
        return (pTransfer->buffered <= pEndpoint->size)
               && (pTransfer->remaining == 0);
    }
}