Paparazzi UAS  v5.15_devel-88-gb3ad7fe
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
usb_msd.h File Reference
#include "ch.h"
#include "hal.h"
#include "chdebug.h"
#include "modules/loggers/sdlog_chibios/usb_msd.h"
+ Include dependency graph for usb_msd.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PACK_STRUCT_STRUCT
 Response to a READ_CAPACITY_10 SCSI command. More...
 
struct  PACK_STRUCT_STRUCT
 Response to a READ_CAPACITY_10 SCSI command. More...
 
struct  PACK_STRUCT_STRUCT
 Response to a READ_CAPACITY_10 SCSI command. More...
 
struct  PACK_STRUCT_STRUCT
 Response to a READ_CAPACITY_10 SCSI command. More...
 
struct  USBMassStorageConfig
 Driver configuration structure. More...
 
struct  USBMassStorageDriver
 USB mass storage driver structure. More...
 

Macros

#define PACK_STRUCT_STRUCT   __attribute__((packed))
 
#define PACK_STRUCT_BEGIN
 
#define PACK_STRUCT_END
 
#define USB_MS_DATA_EP   1
 
#define USBD   USBD1
 
#define SEM_TAKEN
 
#define SEM_RELEASED
 
#define EVT_USB_RESET   (1 << 0)
 
#define EVT_BOT_RESET   (1 << 1)
 
#define EVT_SEM_TAKEN   (1 << 2)
 
#define EVT_SEM_RELEASED   (1 << 3)
 
#define EVT_USB_CONFIGURED   (1 << 4)
 
#define EVT_SCSI_REQ_TEST_UNIT_READY   (1 << 5)
 
#define EVT_SCSI_REQ_READ_FMT_CAP   (1 << 6)
 
#define EVT_SCSI_REQ_SENSE6   (1 << 7)
 
#define EVT_SCSI_REQ_SENSE10   (1 << 8)
 
#define EVT_WAIT_FOR_COMMAND_BLOCK   (1 << 9)
 
#define EVT_SCSI_REQ_SEND_DIAGNOSTIC   (1 << 10)
 
#define EVT_SCSI_REQ_READ_CAP10   (1 << 11)
 
#define EVT_SCSI_PROC_INQ   (1 << 12)
 

Enumerations

enum  msd_state_t { MSD_IDLE, MSD_READ_COMMAND_BLOCK, MSD_EJECTED, MSD_BOT_RESET }
 Possible states for the USB mass storage driver. More...
 

Functions

void msdInit (USBMassStorageDriver *msdp)
 Initializes a USB mass storage driver. More...
 
void msdStart (USBMassStorageDriver *msdp, const USBMassStorageConfig *config)
 Starts a USB mass storage driver. More...
 
void msdStop (USBMassStorageDriver *msdp)
 Stops a USB mass storage driver. More...
 
void msdConfigureHookI (USBMassStorageDriver *msdp)
 USB device configured handler. More...
 
bool msdRequestsHook (USBDriver *usbp)
 Default requests hook. More...
 
void init_msd_driver (void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
 
void deinit_msd_driver (void)
 
void msd_register_evt_connected (event_listener_t *elp, eventmask_t mask)
 register connected event source in local event mask More...
 
void msd_register_evt_ejected (event_listener_t *elp, eventmask_t mask)
 register ejected event source in local event mask More...
 

Data Structure Documentation

struct PACK_STRUCT_STRUCT

Response to a READ_CAPACITY_10 SCSI command.

structure holding the data to reply to an INQUIRY SCSI command

Structure holding sense data (status/error information)

Command Status Wrapper structure.

Command Block Wrapper structure.

Response to a READ_FORMAT_CAPACITIES SCSI command.

Definition at line 113 of file usb_msd.c.

Data Fields
uint8_t additional_length
uint32_t block_count
uint32_t block_size
uint8_t bqueetc
uint8_t byte[18]
uint8_t capacity_list_length
uint8_t cmdque
uint32_t data_len
uint32_t data_residue
uint32_t desc_and_block_length
uint8_t flags
uint32_t last_block_addr
uint8_t lun
uint8_t peripheral
uint8_t product_id[16]
uint8_t product_rev[4]
uint8_t removable
uint8_t reserved[3]
uint8_t response_data_format
uint8_t sccstp
uint8_t scsi_cmd_data[16]
uint8_t scsi_cmd_len
uint32_t signature
uint8_t status
uint32_t tag
uint8_t vendor_id[8]
uint8_t version
struct PACK_STRUCT_STRUCT

Response to a READ_CAPACITY_10 SCSI command.

structure holding the data to reply to an INQUIRY SCSI command

Structure holding sense data (status/error information)

Command Status Wrapper structure.

Command Block Wrapper structure.

Response to a READ_FORMAT_CAPACITIES SCSI command.

Definition at line 113 of file usb_msd.c.

Data Fields
uint8_t additional_length
uint32_t block_count
uint32_t block_size
uint8_t bqueetc
uint8_t byte[18]
uint8_t capacity_list_length
uint8_t cmdque
uint32_t data_len
uint32_t data_residue
uint32_t desc_and_block_length
uint8_t flags
uint32_t last_block_addr
uint8_t lun
uint8_t peripheral
uint8_t product_id[16]
uint8_t product_rev[4]
uint8_t removable
uint8_t reserved[3]
uint8_t response_data_format
uint8_t sccstp
uint8_t scsi_cmd_data[16]
uint8_t scsi_cmd_len
uint32_t signature
uint8_t status
uint32_t tag
uint8_t vendor_id[8]
uint8_t version
struct PACK_STRUCT_STRUCT

Response to a READ_CAPACITY_10 SCSI command.

structure holding the data to reply to an INQUIRY SCSI command

Structure holding sense data (status/error information)

Command Status Wrapper structure.

Command Block Wrapper structure.

Response to a READ_FORMAT_CAPACITIES SCSI command.

Definition at line 113 of file usb_msd.c.

Data Fields
uint8_t additional_length
uint32_t block_count
uint32_t block_size
uint8_t bqueetc
uint8_t byte[18]
uint8_t capacity_list_length
uint8_t cmdque
uint32_t data_len
uint32_t data_residue
uint32_t desc_and_block_length
uint8_t flags
uint32_t last_block_addr
uint8_t lun
uint8_t peripheral
uint8_t product_id[16]
uint8_t product_rev[4]
uint8_t removable
uint8_t reserved[3]
uint8_t response_data_format
uint8_t sccstp
uint8_t scsi_cmd_data[16]
uint8_t scsi_cmd_len
uint32_t signature
uint8_t status
uint32_t tag
uint8_t vendor_id[8]
uint8_t version
struct PACK_STRUCT_STRUCT

Response to a READ_CAPACITY_10 SCSI command.

structure holding the data to reply to an INQUIRY SCSI command

Structure holding sense data (status/error information)

Command Status Wrapper structure.

Command Block Wrapper structure.

Response to a READ_FORMAT_CAPACITIES SCSI command.

Definition at line 113 of file usb_msd.c.

Data Fields
uint8_t additional_length
uint32_t block_count
uint32_t block_size
uint8_t bqueetc
uint8_t byte[18]
uint8_t capacity_list_length
uint8_t cmdque
uint32_t data_len
uint32_t data_residue
uint32_t desc_and_block_length
uint8_t flags
uint32_t last_block_addr
uint8_t lun
uint8_t peripheral
uint8_t product_id[16]
uint8_t product_rev[4]
uint8_t removable
uint8_t reserved[3]
uint8_t response_data_format
uint8_t sccstp
uint8_t scsi_cmd_data[16]
uint8_t scsi_cmd_len
uint32_t signature
uint8_t status
uint32_t tag
uint8_t vendor_id[8]
uint8_t version
struct USBMassStorageDriver

USB mass storage driver structure.

This structure holds all the states and members of a USB mass storage driver.

Definition at line 172 of file usb_msd.h.

+ Collaboration diagram for USBMassStorageDriver:
Data Fields
BlockDeviceInfo block_dev_info
bool bot_reset
binary_semaphore_t bsem
msd_cbw_t cbw
const USBMassStorageConfig * config
msd_csw_t csw
event_source_t evt_connected
event_source_t evt_ejected
msd_scsi_inquiry_response_t inquiry
bool reconfigured_or_reset_event
bool result
msd_scsi_sense_response_t sense
msd_state_t state
thread_t * thread

Macro Definition Documentation

#define EVT_BOT_RESET   (1 << 1)

Definition at line 50 of file usb_msd.h.

Referenced by msdRequestsHook().

#define EVT_SCSI_PROC_INQ   (1 << 12)

Definition at line 61 of file usb_msd.h.

Referenced by msd_scsi_process_inquiry().

#define EVT_SCSI_REQ_READ_CAP10   (1 << 11)

Definition at line 60 of file usb_msd.h.

Referenced by msd_scsi_process_read_capacity_10().

#define EVT_SCSI_REQ_READ_FMT_CAP   (1 << 6)

Definition at line 55 of file usb_msd.h.

Referenced by msd_scsi_process_read_format_capacities().

#define EVT_SCSI_REQ_SEND_DIAGNOSTIC   (1 << 10)

Definition at line 59 of file usb_msd.h.

#define EVT_SCSI_REQ_SENSE10   (1 << 8)

Definition at line 57 of file usb_msd.h.

Referenced by msd_scsi_process_start_read_write_10().

#define EVT_SCSI_REQ_SENSE6   (1 << 7)

Definition at line 56 of file usb_msd.h.

Referenced by msd_scsi_process_mode_sense_6().

#define EVT_SCSI_REQ_TEST_UNIT_READY   (1 << 5)

Definition at line 54 of file usb_msd.h.

Referenced by msd_scsi_process_test_unit_ready().

#define EVT_SEM_RELEASED   (1 << 3)

Definition at line 52 of file usb_msd.h.

Referenced by msdConfigureHookI().

#define EVT_SEM_TAKEN   (1 << 2)

Definition at line 51 of file usb_msd.h.

Referenced by msd_wait_for_isr(), and msdInit().

#define EVT_USB_CONFIGURED   (1 << 4)

Definition at line 53 of file usb_msd.h.

#define EVT_USB_RESET   (1 << 0)

Definition at line 49 of file usb_msd.h.

Referenced by usbEvent().

#define EVT_WAIT_FOR_COMMAND_BLOCK   (1 << 9)

Definition at line 58 of file usb_msd.h.

Referenced by msd_wait_for_command_block().

#define PACK_STRUCT_BEGIN

Definition at line 36 of file usb_msd.h.

#define PACK_STRUCT_END

Definition at line 37 of file usb_msd.h.

#define PACK_STRUCT_STRUCT   __attribute__((packed))

Definition at line 35 of file usb_msd.h.

#define SEM_RELEASED

Definition at line 47 of file usb_msd.h.

Referenced by msd_handle_end_point_notification(), and msdConfigureHookI().

#define SEM_TAKEN

Definition at line 46 of file usb_msd.h.

Referenced by msd_wait_for_isr().

#define USB_MS_DATA_EP   1

Definition at line 40 of file usb_msd.h.

Referenced by mass_storage_thread().

#define USBD   USBD1

Definition at line 44 of file usb_msd.h.

Referenced by init_msd_driver().

Enumeration Type Documentation

Possible states for the USB mass storage driver.

Enumerator
MSD_IDLE 
MSD_READ_COMMAND_BLOCK 
MSD_EJECTED 
MSD_BOT_RESET 

Definition at line 113 of file usb_msd.h.

Function Documentation

void deinit_msd_driver ( void  )

Definition at line 1121 of file usb_msd.c.

References msdStop().

Referenced by thdUsbStorage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void init_msd_driver ( void *  dbgThreadPtr,
USBMassStorageConfig msdConfig 
)

Definition at line 1126 of file usb_msd.c.

References dbg_printer, msdInit(), msdStart(), and USBD.

Referenced by thdUsbStorage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void msd_register_evt_connected ( event_listener_t *  elp,
eventmask_t  mask 
)

register connected event source in local event mask

This function is a stub to chEvtRegisterMask

Definition at line 1142 of file usb_msd.c.

References USBMassStorageDriver::evt_connected.

Referenced by thdUsbStorage().

+ Here is the caller graph for this function:

void msd_register_evt_ejected ( event_listener_t *  elp,
eventmask_t  mask 
)

register ejected event source in local event mask

This function is a stub to chEvtRegisterMask ejected event is a logical event : when host unmount the filesystem, not a physical event (event is not sent in case of unplugged usb wire)

Definition at line 1147 of file usb_msd.c.

References USBMassStorageDriver::evt_ejected.

void msdConfigureHookI ( USBMassStorageDriver msdp)

USB device configured handler.

Parameters
[in]msdppointer to the USBMassStorageDriver object

Definition at line 188 of file usb_msd.c.

References USBMassStorageDriver::bsem, USBMassStorageConfig::bulk_ep, USBMassStorageDriver::config, debug_snd_evt_inl(), USBMassStorageDriver::evt_connected, EVT_SEM_RELEASED, SEM_RELEASED, and USBMassStorageConfig::usbp.

Referenced by usbEvent().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void msdInit ( USBMassStorageDriver msdp)
bool msdRequestsHook ( USBDriver *  usbp)

Default requests hook.

Applications wanting to use the Mass Storage over USB driver can use this function as requests hook in the USB configuration. The following requests are emulated:

  • MSD_REQ_RESET.
  • MSD_GET_MAX_LUN.
Parameters
[in]usbppointer to the USBDriver object
Returns
The hook status.
Return values
trueMessage handled internally.
falseMessage not handled.
Parameters
[in]usbppointer to the USBDriver object
Returns
The hook status.
Return values
trueMessage handled internally.
falseMessage not handled.

Definition at line 205 of file usb_msd.c.

References USBMassStorageDriver::bot_reset, USBMassStorageDriver::bsem, USBMassStorageConfig::bulk_ep, USBMassStorageDriver::config, debug_snd_evt_i(), EVT_BOT_RESET, MSD_BOT_RESET, MSD_GET_MAX_LUN, MSD_REQ_RESET, MSD_SETUP_INDEX, MSD_SETUP_LENGTH, MSD_SETUP_VALUE, USBMassStorageDriver::state, and USBMassStorageConfig::usbp.

+ Here is the call graph for this function:

void msdStart ( USBMassStorageDriver msdp,
const USBMassStorageConfig config 
)

Starts a USB mass storage driver.

This function is sufficient to have USB mass storage running, it internally runs a thread that handles USB requests and transfers. The block device must be connected but no file system must be mounted, everything is handled by the host system.

Definition at line 855 of file usb_msd.c.

References USBMassStorageConfig::bbdp, USBMassStorageDriver::block_dev_info, USBMassStorageConfig::bulk_ep, config, USBMassStorageDriver::config, USBMassStorageDriver::inquiry, mass_storage_thread(), MSD_IDLE, USBMassStorageConfig::short_product_id, USBMassStorageConfig::short_product_version, USBMassStorageConfig::short_vendor_id, USBMassStorageDriver::state, USBMassStorageDriver::thread, and USBMassStorageConfig::usbp.

Referenced by init_msd_driver().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void msdStop ( USBMassStorageDriver msdp)

Stops a USB mass storage driver.

This function waits for current tasks to be finished, if any, and then stops the mass storage thread.

Definition at line 900 of file usb_msd.c.

References USBMassStorageDriver::bsem, USBMassStorageConfig::bulk_ep, USBMassStorageDriver::config, USBMassStorageDriver::thread, and USBMassStorageConfig::usbp.

Referenced by deinit_msd_driver().

+ Here is the caller graph for this function: