LPCOpen Platform  v1.03
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

Detailed Description

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

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.

Macros

#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 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

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.
 
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.
 

Macro Definition Documentation

#define DISK_READ_ONLY   false

Indicates if the disk is write protected or not.

Definition at line 98 of file usbmsdev.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 89 of file usbmsdev.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 80 of file usbmsdev.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 86 of file usbmsdev.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 77 of file usbmsdev.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 83 of file usbmsdev.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 95 of file usbmsdev.h.

#define TOTAL_LUNS   1

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

Definition at line 92 of file usbmsdev.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 ramdisk.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 ramdisk.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 ramdisk.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
Note
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.

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

Mass Storage class driver callback function.

Parameters
MSInterfaceInfo: Pointer to a structure containing a Mass Storage Class configuration and state.
Returns
Boolean true if the SCSI command was successfully processed, false otherwise.

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

Mass Storage class driver callback for the user processing of a received SCSI command. This callback will fire each time the host sends a SCSI command which requires processing by the user application. Inside this callback the user is responsible for the processing of the received SCSI command from the host. The SCSI command is available in the CommandBlock structure inside the Mass Storage class state structure passed as a parameter to the callback function.

Returns
Nothing
Note
The reception of SCSI commands from the host, which must be processed

Definition at line 332 of file usbmsdev.c.

void DataRam_Initialize ( void  )

DataRAM Initilisation function.

Returns
None
Note
This function will initialise the file system.

Definition at line 235 of file ramdisk.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
Note
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.

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

Definition at line 186 of file ramdisk.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
Note
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.

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

Definition at line 158 of file ramdisk.c.

void EVENT_USB_Device_ConfigurationChanged ( void  )

USB Device configuration change event callback.

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

Event handler for the library USB Configuration Changed event.

Event for USB configuration number changed. This event fires when a the USB host changes the selected configuration number while in device mode. This event should be hooked in device applications to create the endpoints and configure the device for the selected configuration.

This event is time-critical; exceeding OS-specific delays within this event handler (typically of around one second) will prevent the device from enumerating correctly.

This event fires after the value of USB_Device_ConfigurationNumber has been changed.

Note
This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see USB Interface Management documentation).

Event handler for the library USB Configuration Changed event.

USB Device configuration change event callback.

Returns
Nothing

Definition at line 317 of file usbmsdev.c.

void EVENT_USB_Device_Connect ( void  )

USB Device connect event callback.

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

Event handler for the library USB Connection event.

Event for USB device connection. This event fires when the microcontroller is in USB Device mode and the device is connected to a USB host, beginning the enumeration process measured by a rising level on the microcontroller's VBUS sense pin.

This event is time-critical; exceeding OS-specific delays within this event handler (typically of around two seconds) will prevent the device from enumerating correctly.

Note
For the microcontrollers with limited USB controller functionality, VBUS sensing is not available. this means that the current connection state is derived from the bus suspension and wake up events by default, which is not always accurate (host may suspend the bus while still connected). If the actual connection state needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection and disconnection events may be manually fired, and the USB_DeviceState global changed manually.

This event may fire multiple times during device enumeration on the microcontrollers with limited USB controllers if NO_LIMITED_CONTROLLER_CONNECT is not defined.
See Also
USB Interface Management for more information on the USB management task and reducing CPU usage.

Event handler for the library USB Connection event.

USB Device connect event callback.

Returns
Nothing

Definition at line 309 of file usbmsdev.c.

void EVENT_USB_Device_ControlRequest ( void  )

USB Device control request receive event callback.

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

Event handler for the library USB Control Request reception event.

Event for control requests. This event fires when a the USB host issues a control request to the mandatory device control endpoint (of address 0). This may either be a standard request that the library may have a handler code for internally, or a class specific request issued to the device which must be handled appropriately. If a request is not processed in the user application via this event, it will be passed to the library for processing internally if a suitable handler exists.

This event is time-critical; each packet within the request transaction must be acknowledged or sent within 50ms or the host will abort the transfer.

The library internally handles all standard control requests with the exceptions of SYNC FRAME, SET DESCRIPTOR and SET INTERFACE. These and all other non-standard control requests will be left for the user to process via this event if desired. If not handled in the user application or by the library internally, unknown requests are automatically STALLed.

Note
This event does not exist if the USB_HOST_ONLY token is supplied to the compiler (see USB Interface Management documentation).

Requests should be handled in the same manner as described in the USB 2.0 Specification, or appropriate class specification. In all instances, the library has already read the request SETUP parameters into the USB_ControlRequest structure which should then be used by the application to determine how to handle the issued request.

Event handler for the library USB Control Request reception event.

USB Device control request receive event callback.

Returns
Nothing

Definition at line 325 of file usbmsdev.c.

void EVENT_USB_Device_Disconnect ( void  )

USB Device disconnect event callback.

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

Event handler for the library USB Disconnection event.

Event for USB device disconnection. This event fires when the microcontroller is in USB Device mode and the device is disconnected from a host, measured by a falling level on the microcontroller's VBUS sense pin.

Note
For the microcontrollers with limited USB controllers, VBUS sense is not available to the USB controller. this means that the current connection state is derived from the bus suspension and wake up events by default, which is not always accurate (host may suspend the bus while still connected). If the actual connection state needs to be determined, VBUS should be routed to an external pin, and the auto-detect behaviour turned off by passing the NO_LIMITED_CONTROLLER_CONNECT token to the compiler via the -D switch at compile time. The connection and disconnection events may be manually fired, and the USB_DeviceState global changed manually.

This event may fire multiple times during device enumeration on the microcontrollers with limited USB controllers if NO_LIMITED_CONTROLLER_CONNECT is not defined.
See Also
USB Interface Management for more information on the USB management task and reducing CPU usage.

Event handler for the library USB Disconnection event.

USB Device disconnect event callback.

Returns
Nothing

Definition at line 313 of file usbmsdev.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
Note
Reads the data from file system image & return with address & number of available blocks

Definition at line 211 of file ramdisk.c.