Information Technology Reference
In-Depth Information
Firmware can call a function repeatedly to check the value of the variable
and take any needed action:
#define MSD_WAIT
0
// Waiting for a CBW.
#define MSD_DATA_IN
2
// IN Data State (device to host).
#define MSD_DATA_OUT 3
// OUT Data State (host to device).
byte MSD_State; // Holds the current state of the device.
The msd_buffer array holds a 512-byte block of data:
volatile far char msd_buffer[512];
The mMin macro returns the lower of two values (A or B):
#define mMin(A, B) (A < B) ? A:B
The code that follows uses these macros from Chapter 2: MSD_BD_IN,
MSD_BD_OUT, MSD_IN_EP_SIZE, MSD_OUT_EP_SIZE, mUSB-
BufferReady, and mMSDTxIsBusy. The code also calls the USBDriverSer-
vice function included in Microchip's Framework firmware.
USBDriverService handles interrupts related to USB communications.
Sending Data
The SendData function accepts a pointer to data to send (dataAddr) and the
number of bytes to send (dataSize). The function stores the passed address
in the buffer descriptor's address registers, stores the number of bytes to send
in the byte-count register, and gives ownership of the buffer descriptor to
the SIE. The device sends the data in the next IN transaction on the end-
point.
void SendData(byte* dataAddr, byte dataSize)
{
// Wait for the SIE to give up ownership of the bulk IN endpoint.
while (mMSDTxIsBusy())
{
// Service USB interrupts. See Microchip Framework firmware for details.
USBDriverService();
}
// Set the address in the buffer descriptor to the passed address.
MSD_BD_IN.ADR = dataAddr;
Search WWH ::




Custom Search