typedef struct { BYTE (* MediaInitialize)(); DWORD (* ReadCapacity)(); WORD (* ReadSectorSize)(); BYTE (* MediaDetect)(); BYTE (* SectorRead)(DWORD sector_addr, BYTE* buffer); BYTE (* WriteProtectState)(); BYTE (* SectorWrite)(DWORD sector_addr, BYTE* buffer, BYTE allowWriteToZero); } LUN_FUNCTIONS;
LUN_FUNCTIONS is a structure of function pointers that tells the stack where to find each of the physical layer functions it is looking for. This structure needs to be defined for any project for PIC24F or PIC32.
Typical Usage:
LUN_FUNCTIONS LUN[MAX_LUN + 1] = { { &MDD_SDSPI_MediaInitialize, &MDD_SDSPI_ReadCapacity, &MDD_SDSPI_ReadSectorSize, &MDD_SDSPI_MediaDetect, &MDD_SDSPI_SectorRead, &MDD_SDSPI_WriteProtectState, &MDD_SDSPI_SectorWrite } };
In the above code we are passing the address of the SDSPI functions to the corresponding member of the LUN_FUNCTIONS structure. In the above case we have created an array of LUN_FUNCTIONS structures so that it is possible to have multiple physical layers by merely increasing the MAX_LUN variable and by adding one more set of entries in the array. Please take caution to insure that each function is in the the correct location in the structure. Incorrect alignment will cause the USB stack to call the incorrect function for a given command.
See the MDD File System Library for additional information about the available physical media, their requirements, and how to use their associated functions.
Members |
Description |
BYTE (* MediaInitialize)(); |
Function pointer to the MediaInitialize() function of the physical media being used. |
DWORD (* ReadCapacity)(); |
Function pointer to the ReadCapacity() function of the physical media being used. |
WORD (* ReadSectorSize)(); |
Function pointer to the ReadSectorSize() function of the physical media being used. |
BYTE (* MediaDetect)(); |
Function pointer to the MediaDetect() function of the physical media being used. |
BYTE (* SectorRead)(DWORD sector_addr, BYTE* buffer); |
Function pointer to the SectorRead() function of the physical media being used. |
BYTE (* WriteProtectState)(); |
Function pointer to the WriteProtectState() function of the physical media being used. |
BYTE (* SectorWrite)(DWORD sector_addr, BYTE* buffer, BYTE allowWriteToZero); |
Function pointer to the SectorWrite() function of the physical media being used. |