Information Technology Reference
In-Depth Information
Receiving Data from the USB Host
If the data-transport phase is host-to-device, firmware calls the MSD-
DataOut function to get data received from the host.
void MSDDataOut(void)
{
// To enable receiving data, give ownership of the endpoint's buffer to the SIE.
mUSBBufferReady(MSD_BD_OUT);
// Service USB interrupts. (See Microchip's Framework firmware for details.)
USBDriverService();
// Wait until the SIE has returned ownership of the endpoint buffer to the CPU,
// indicating that data was received.
while (mMSDRxIsBusy())
{
USBDriverService();
}
// Subtract the number of received bytes from dCBWDataTransferLength in the CBW.
gblCBW.dCBWDataTransferLength -= MSD_BD_OUT.Cnt;
// Subtract the number of received bytes from dCSWDataResidue in the CSW.
msd_csw.dCSWDataResidue -= MSD_BD_OUT.Cnt;
// For the next transaction, set the OUT endpoint's count to the endpoint size.
MSD_BD_OUT.Cnt = MSD_OUT_EP_SIZE;
// Increment the OUT endpoint's address by endpoint-size bytes
// in case there is more data to receive.
MSD_BD_OUT.ADR += MSD_OUT_EP_SIZE;
}
Sending the CSW
Firmware calls the SendCSW function after completing the com-
mand-transport and data-transport (if required) phases of a command. The
Search WWH ::




Custom Search