LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
LPCUSBlib Mass Storage Device Dual core example

Data Structures

struct  USB_Descriptor_Configuration_t
 USB Device descriptor structure for Mass Storage Device Type define for the device configuration descriptor structure. This must be defined in the application code, as the configuration descriptor contains several sub-descriptors which vary between devices, and which describe the device's usage to the host. More...
 

Macros

#define MASS_STORAGE_IN_EPNUM   3
 
#define MASS_STORAGE_OUT_EPNUM   2
 
#define MASS_STORAGE_IO_EPSIZE   64
 
#define VIRTUAL_MEMORY_BYTES   DATA_RAM_VIRTUAL_SIZE
 
#define VIRTUAL_MEMORY_BLOCK_SIZE   512
 
#define VIRTUAL_MEMORY_BLOCKS   (VIRTUAL_MEMORY_BYTES / VIRTUAL_MEMORY_BLOCK_SIZE)
 
#define SCSI_SET_SENSE(Key, Acode, Aqual)
 Set sense macro.
 
#define DATA_READ   true
 
#define DATA_WRITE   false
 
#define DEVICE_TYPE_BLOCK   0x00
 
#define DEVICE_TYPE_CDROM   0x05
 
#define LEDMASK_USB_NOTREADY   LEDS_LED1
 
#define LEDMASK_USB_ENUMERATING   (LEDS_LED2 | LEDS_LED3)
 
#define LEDMASK_USB_READY   (LEDS_LED2 | LEDS_LED4)
 
#define LEDMASK_USB_ERROR   (LEDS_LED1 | LEDS_LED3)
 
#define LEDMASK_USB_BUSY   LEDS_LED2
 
#define TOTAL_LUNS   1
 
#define LUN_MEDIA_BLOCKS   (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)
 
#define DISK_READ_ONLY   false
 

Functions

uint16_t CALLBACK_USB_GetDescriptor (const uint16_t wValue, const uint8_t wIndex, const void **const DescriptorAddress) ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3)
 USB Get descriptor callback function.
 
void DataRam_WriteBlocks (USB_ClassInfo_MS_Device_t *const MSInterfaceInfo, const uint32_t BlockAddress, uint16_t TotalBlocks)
 DataRAM write blocks function.
 
void DataRam_ReadBlocks (USB_ClassInfo_MS_Device_t *const MSInterfaceInfo, const uint32_t BlockAddress, uint16_t TotalBlocks)
 DataRAM read blocks function.
 
void DataRam_Initialize (void)
 DataRAM Initilisation function.
 
uint32_t MassStorage_GetAddressInImage (uint32_t startblock, uint16_t requestblocks, uint16_t *availableblocks)
 DataRAM read blocks function.
 
bool SCSI_DecodeSCSICommand (USB_ClassInfo_MS_Device_t *const MSInterfaceInfo)
 SCSI Command processing function.
 
void SetupHardware (void)
 Hardware setup event callback function.
 
void EVENT_USB_Device_Connect (void)
 USB Device connect event callback.
 
void EVENT_USB_Device_Disconnect (void)
 USB Device disconnect event callback.
 
void EVENT_USB_Device_ConfigurationChanged (void)
 USB Device configuration change event callback.
 
void EVENT_USB_Device_ControlRequest (void)
 USB Device control request receive event callback.
 
bool CALLBACK_MS_Device_SCSICommandReceived (USB_ClassInfo_MS_Device_t *const MSInterfaceInfo)
 Mass Storage class driver callback function.
 

Detailed Description

The Mass storage device descriptors module implements the descriptors required by the USB mass storage device configuration. This module is used by the Mass Storage device example module.

The USB Mass Storage data RAM module module implements the functions which handles the storage & retrieval of data in RAM.

The USB Mass Storage device SCSI command processing module handles the SCSI commands

The Mass Storage Device dual core example demonstrates the Mass Storage Device example using LPCUSBlib library. The LPC43XX will be enumerated as as Mass Storage Device when connected to the Host PC. The example can be configured to run on M4/M0 core.

Macro Definition Documentation

#define DATA_READ   true

Macro for the SCSI_Command_ReadWrite_10() function, to indicate that data is to be read from the storage medium.

Definition at line 67 of file SCSI.h.

#define DATA_WRITE   false

Macro for the SCSI_Command_ReadWrite_10() function, to indicate that data is to be written to the storage medium.

Definition at line 70 of file SCSI.h.

#define DEVICE_TYPE_BLOCK   0x00

Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a Block Media device.

Definition at line 73 of file SCSI.h.

#define DEVICE_TYPE_CDROM   0x05

Value for the DeviceType entry in the SCSI_Inquiry_Response_t enum, indicating a CD-ROM device.

Definition at line 76 of file SCSI.h.

#define DISK_READ_ONLY   false

Indicates if the disk is write protected or not.

Definition at line 77 of file MassStorage.h.

#define LEDMASK_USB_BUSY   LEDS_LED2

LED mask for the library LED driver, to indicate that the USB interface is busy.

Definition at line 68 of file MassStorage.h.

#define LEDMASK_USB_ENUMERATING   (LEDS_LED2 | LEDS_LED3)

LED mask for the library LED driver, to indicate that the USB interface is enumerating.

Definition at line 59 of file MassStorage.h.

#define LEDMASK_USB_ERROR   (LEDS_LED1 | LEDS_LED3)

LED mask for the library LED driver, to indicate that an error has occurred in the USB interface.

Definition at line 65 of file MassStorage.h.

#define LEDMASK_USB_NOTREADY   LEDS_LED1

LED mask for the library LED driver, to indicate that the USB interface is not ready.

Definition at line 56 of file MassStorage.h.

#define LEDMASK_USB_READY   (LEDS_LED2 | LEDS_LED4)

LED mask for the library LED driver, to indicate that the USB interface is ready.

Definition at line 62 of file MassStorage.h.

#define LUN_MEDIA_BLOCKS   (VIRTUAL_MEMORY_BLOCKS / TOTAL_LUNS)

Blocks in each LUN, calculated from the total capacity divided by the total number of Logical Units in the device.

Definition at line 74 of file MassStorage.h.

#define MASS_STORAGE_IN_EPNUM   3

Endpoint number of the Mass Storage device-to-host data IN endpoint.

Definition at line 54 of file Descriptors.h.

#define MASS_STORAGE_IO_EPSIZE   64

Definition at line 63 of file Descriptors.h.

#define MASS_STORAGE_OUT_EPNUM   2

Endpoint number of the Mass Storage host-to-device data OUT endpoint.

Definition at line 57 of file Descriptors.h.

#define SCSI_SET_SENSE (   Key,
  Acode,
  Aqual 
)
Value:
MACROS {SenseData.SenseKey = (Key); \
SenseData.AdditionalSenseCode = (Acode); \
SenseData.AdditionalSenseQualifier = (Aqual); } MACROE

Set sense macro.

Parameters
Key: New SCSI sense key to set the sense code to
Acode: New SCSI additional sense key to set the additional sense code to
Aqual: New SCSI additional sense key qualifier to set the additional sense qualifier code to
Returns
None Macro to set the current SCSI sense data to the given key, additional sense code and additional sense qualifier. This is for convenience, as it allows for all three sense values (returned upon request to the host to give information about the last command failure) in a quick and easy manner.

Definition at line 62 of file SCSI.h.

#define TOTAL_LUNS   1

Total number of logical drives within the device - must be non-zero.

Definition at line 71 of file MassStorage.h.

#define VIRTUAL_MEMORY_BLOCK_SIZE   512

Block size of the device. This is kept at 512 to remain compatible with the OS despite the underlying storage media (Dataflash) using a different native block size. Do not change this value.

Definition at line 80 of file DataRam.h.

#define VIRTUAL_MEMORY_BLOCKS   (VIRTUAL_MEMORY_BYTES / VIRTUAL_MEMORY_BLOCK_SIZE)

Total number of blocks of the virtual memory for reporting to the host as the device's total capacity. Do not change this value; change VIRTUAL_MEMORY_BYTES instead to alter the media size.

Definition at line 85 of file DataRam.h.

#define VIRTUAL_MEMORY_BYTES   DATA_RAM_VIRTUAL_SIZE

Start address and size of RAM area which used for disk image Total number of bytes of the storage medium, comprised of one or more Dataflash ICs.

Definition at line 75 of file DataRam.h.

Function Documentation

bool CALLBACK_MS_Device_SCSICommandReceived ( USB_ClassInfo_MS_Device_t *const  MSInterfaceInfo)

Mass Storage class driver callback function.

Parameters
MSInterfaceInfo: Pointer to the Mass Storage class interface configuration structure
Returns
true : On success false : On failure Mass Storage class driver callback function for the reception of SCSI commands from the host, which must be processed.

Mass Storage class driver callback function the reception of SCSI commands from the host, which must be processed.

Definition at line 106 of file MassStorage.c.

uint16_t CALLBACK_USB_GetDescriptor ( const uint16_t  wValue,
const uint8_t  wIndex,
const void **const  DescriptorAddress 
)

USB Get descriptor callback function.

Parameters
wValue: Descriptor type
wIndex: Index of the descriptor
DescriptorAddress: Address of the requested descriptor
Returns
Size of the descriptor This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" documentation) by the application code so that the address and size of a requested descriptor can be given to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function is called so that the descriptor details can be passed back and the appropriate descriptor sent back.

This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" documentation) by the application code so that the address and size of a requested descriptor can be given to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the USB host.

Definition at line 206 of file Descriptors.c.

void DataRam_Initialize ( void  )

DataRAM Initilisation function.

Returns
None This function will initialise the file system.

Definition at line 234 of file DataRam.c.

void DataRam_ReadBlocks ( USB_ClassInfo_MS_Device_t *const  MSInterfaceInfo,
const uint32_t  BlockAddress,
uint16_t  TotalBlocks 
)

DataRAM read blocks function.

Parameters
MSInterfaceInfo: Pointer to a structure containing a Mass Storage Class configuration and state
BlockAddress: Data block starting address for the read sequence
TotalBlocks: Number of blocks of data to read
Returns
None Reads blocks (OS blocks, not DataRAM pages) from the storage medium, the board DataRAM IC(s), into the pre-selected data IN endpoint. This routine reads in DataRAM page sized blocks from the DataRAM and writes them in OS sized blocks to the endpoint.

Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board Dataflash IC(s), into the pre-selected data IN endpoint. This routine reads in Dataflash page sized blocks from the Dataflash and writes them in OS sized blocks to the endpoint.

Parameters
[in]MSInterfaceInfoPointer to a structure containing a Mass Storage Class configuration and state
[in]BlockAddressData block starting address for the read sequence
[in]TotalBlocksNumber of blocks of data to read

Definition at line 185 of file DataRam.c.

void DataRam_WriteBlocks ( USB_ClassInfo_MS_Device_t *const  MSInterfaceInfo,
const uint32_t  BlockAddress,
uint16_t  TotalBlocks 
)

DataRAM write blocks function.

Parameters
MSInterfaceInfo: Pointer to a structure containing a Mass Storage Class configuration and state
BlockAddress: Data block starting address for the write sequence
TotalBlocks: Number of blocks of data to write
Returns
None Writes blocks (OS blocks, not DataRAM pages) to the storage medium, the board DataRAM IC(s), from the pre-selected data OUT endpoint. This routine reads in OS sized blocks from the endpoint and writes them to the DataRAM in DataRAM page sized blocks.

Writes blocks (OS blocks, not Dataflash pages) to the storage medium, the board Dataflash IC(s), from the pre-selected data OUT endpoint. This routine reads in OS sized blocks from the endpoint and writes them to the Dataflash in Dataflash page sized blocks.

Parameters
[in]MSInterfaceInfoPointer to a structure containing a Mass Storage Class configuration and state
[in]BlockAddressData block starting address for the write sequence
[in]TotalBlocksNumber of blocks of data to write

Definition at line 157 of file DataRam.c.

void EVENT_USB_Device_ConfigurationChanged ( void  )

USB Device configuration change event callback.

Returns
None This is the USB Device configuration change event call back function

Event handler for the library USB Configuration Changed event.

Definition at line 92 of file MassStorage.c.

void EVENT_USB_Device_Connect ( void  )

USB Device connect event callback.

Returns
None This is the USB Device connect event call back function

Event handler for the library USB Connection event.

Definition at line 84 of file MassStorage.c.

void EVENT_USB_Device_ControlRequest ( void  )

USB Device control request receive event callback.

Returns
None This is the USB Device control request receive event call back function

Event handler for the library USB Control Request reception event.

Definition at line 100 of file MassStorage.c.

void EVENT_USB_Device_Disconnect ( void  )

USB Device disconnect event callback.

Returns
None This is the USB Device disconnect event call back function

Event handler for the library USB Disconnection event.

Definition at line 88 of file MassStorage.c.

uint32_t MassStorage_GetAddressInImage ( uint32_t  startblock,
uint16_t  requestblocks,
uint16_t *  availableblocks 
)

DataRAM read blocks function.

Parameters
startblock: Starting block number
requestblocks: Number of requested blocks
availableblocks: Pointer to number of available
Returns
Address of file system data Reads the data from file system image & return with address & number of available blocks

Definition at line 210 of file DataRam.c.

bool SCSI_DecodeSCSICommand ( USB_ClassInfo_MS_Device_t *const  MSInterfaceInfo)

SCSI Command processing function.

Parameters
MSInterfaceInfo: Pointer to the Mass Storage class interface structure that the command is associated with.
Returns
true : If the command completed successfully false : If command failed Main routine to process the SCSI command located in the Command Block Wrapper read from the host. This dispatches to the appropriate SCSI command handling routine if the issued command is supported by the device, else it returns a command failure due to a ILLEGAL REQUEST.

Under development, not working yet. Main routine to process the SCSI command located in the Command Block Wrapper read from the host. This dispatches to the appropriate SCSI command handling routine if the issued command is supported by the device, else it returns a command failure due to a ILLEGAL REQUEST.

Definition at line 269 of file SCSI.c.

void SetupHardware ( void  )

Hardware setup event callback function.

Returns
None This is the USB HW set up event call back function

Configures the board hardware and chip peripherals for the demo's functionality.

Under development, not working yet.

Definition at line 97 of file AudioInput.c.