Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
usb_msd.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Gautier Hattenberger, Alexandre Bustico
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 /*
23  * @file modules/loggers/sdlog_chibios/usb_msd.h
24  *
25  */
26 
27 #pragma once
28 
29 
30 #include "ch.h"
31 #include "hal.h"
32 #include "chdebug.h"
34 
35 #define PACK_STRUCT_STRUCT __attribute__((packed))
36 #define PACK_STRUCT_BEGIN
37 #define PACK_STRUCT_END
38 
39 /* endpoint index */
40 #define USB_MS_DATA_EP 1
41 
42 
43 
44 #define USBD USBD1
45 
46 #define SEM_TAKEN
47 #define SEM_RELEASED
48 
49 #define EVT_USB_RESET (1 << 0)
50 #define EVT_BOT_RESET (1 << 1)
51 #define EVT_SEM_TAKEN (1 << 2)
52 #define EVT_SEM_RELEASED (1 << 3)
53 #define EVT_USB_CONFIGURED (1 << 4)
54 #define EVT_SCSI_REQ_TEST_UNIT_READY (1 << 5)
55 #define EVT_SCSI_REQ_READ_FMT_CAP (1 << 6)
56 #define EVT_SCSI_REQ_SENSE6 (1 << 7)
57 #define EVT_SCSI_REQ_SENSE10 (1 << 8)
58 #define EVT_WAIT_FOR_COMMAND_BLOCK (1 << 9)
59 #define EVT_SCSI_REQ_SEND_DIAGNOSTIC (1 << 10)
60 #define EVT_SCSI_REQ_READ_CAP10 (1 << 11)
61 #define EVT_SCSI_PROC_INQ (1 << 12)
62 
66 PACK_STRUCT_BEGIN typedef struct {
73  uint8_t scsi_cmd_data[16];
75 
79 PACK_STRUCT_BEGIN typedef struct {
80  uint32_t signature;
81  uint32_t tag;
85 
89 PACK_STRUCT_BEGIN typedef struct {
90  uint8_t byte[18];
91 } PACK_STRUCT_STRUCT msd_scsi_sense_response_t PACK_STRUCT_END;
92 
96 PACK_STRUCT_BEGIN typedef struct {
105  uint8_t vendor_id[8];
106  uint8_t product_id[16];
107  uint8_t product_rev[4];
108 } PACK_STRUCT_STRUCT msd_scsi_inquiry_response_t PACK_STRUCT_END;
109 
113 typedef enum {
118 } msd_state_t;
119 
123 typedef struct {
127  USBDriver *usbp;
128 
132  BaseBlockDevice *bbdp;
133 
137  usbep_t bulk_ep;
138 
145  void (*rw_activity_callback)(bool);
146 
151  uint8_t short_vendor_id[8];
152 
157  uint8_t short_product_id[16];
158 
163  uint8_t short_product_version[4];
164 
166 
172 typedef struct {
174  binary_semaphore_t bsem;
175  thread_t *thread;
176  event_source_t evt_connected, evt_ejected;
177  BlockDeviceInfo block_dev_info;
179  msd_cbw_t cbw;
180  msd_csw_t csw;
181  msd_scsi_sense_response_t sense;
182  msd_scsi_inquiry_response_t inquiry;
184  bool result;
185  bool bot_reset;
187 
188 #ifdef __cplusplus
189 extern "C" {
190 #endif
191 
195 void msdInit(USBMassStorageDriver *msdp);
196 
205 
211 void msdStop(USBMassStorageDriver *msdp);
212 
221 
236 bool msdRequestsHook(USBDriver *usbp);
237 
238 
239 void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig);
240 void deinit_msd_driver(void);
241 
246 void msd_register_evt_connected(event_listener_t *elp, eventmask_t mask);
247 
254 void msd_register_evt_ejected(event_listener_t *elp, eventmask_t mask);
255 
256 
257 #ifdef __cplusplus
258 }
259 #endif
USBMassStorageConfig::usbp
USBDriver * usbp
USB driver to use for communication.
Definition: usb_msd.h:127
PACK_STRUCT_STRUCT::data_residue
uint32_t data_residue
Definition: usb_msd.h:82
PACK_STRUCT_STRUCT::data_len
uint32_t data_len
Definition: usb_msd.h:69
MSD_IDLE
@ MSD_IDLE
Definition: usb_msd.h:114
PACK_STRUCT_STRUCT::lun
uint8_t lun
Definition: usb_msd.h:71
PACK_STRUCT_STRUCT
Response to a READ_CAPACITY_10 SCSI command.
Definition: usb_msd.c:113
msd_register_evt_ejected
void msd_register_evt_ejected(event_listener_t *elp, eventmask_t mask)
register ejected event source in local event mask
Definition: usb_msd.c:1147
USBMassStorageDriver::evt_ejected
event_source_t evt_ejected
Definition: usb_msd.h:176
msdInit
void msdInit(USBMassStorageDriver *msdp)
Initializes a USB mass storage driver.
Definition: usb_msd.c:815
msdStart
void msdStart(USBMassStorageDriver *msdp, const USBMassStorageConfig *config)
Starts a USB mass storage driver.
Definition: usb_msd.c:855
USBMassStorageDriver::bsem
binary_semaphore_t bsem
Definition: usb_msd.h:174
PACK_STRUCT_STRUCT::bqueetc
uint8_t bqueetc
Definition: usb_msd.h:103
usb_msd.h
USBMassStorageDriver::config
const USBMassStorageConfig * config
Definition: usb_msd.h:173
uint32_t
unsigned long uint32_t
Definition: types.h:18
PACK_STRUCT_STRUCT::sccstp
uint8_t sccstp
Definition: usb_msd.h:102
PACK_STRUCT_STRUCT::removable
uint8_t removable
Definition: usb_msd.h:98
PACK_STRUCT_STRUCT::response_data_format
uint8_t response_data_format
Definition: usb_msd.h:100
msdStop
void msdStop(USBMassStorageDriver *msdp)
Stops a USB mass storage driver.
Definition: usb_msd.c:900
USBMassStorageDriver::state
msd_state_t state
Definition: usb_msd.h:178
USBMassStorageDriver::inquiry
msd_scsi_inquiry_response_t inquiry
Definition: usb_msd.h:182
USBMassStorageDriver::cbw
msd_cbw_t cbw
Definition: usb_msd.h:179
PACK_STRUCT_STRUCT::flags
uint8_t flags
Definition: usb_msd.h:70
msd_register_evt_connected
void msd_register_evt_connected(event_listener_t *elp, eventmask_t mask)
register connected event source in local event mask
Definition: usb_msd.c:1142
USBMassStorageConfig
Driver configuration structure.
Definition: usb_msd.h:123
init_msd_driver
void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
Definition: usb_msd.c:1126
USBMassStorageDriver::reconfigured_or_reset_event
bool reconfigured_or_reset_event
Definition: usb_msd.h:183
config
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:200
PACK_STRUCT_STRUCT::additional_length
uint8_t additional_length
Definition: usb_msd.h:101
USBMassStorageConfig::bbdp
BaseBlockDevice * bbdp
Block device to use for storage.
Definition: usb_msd.h:132
USBMassStorageDriver::csw
msd_csw_t csw
Definition: usb_msd.h:180
USBMassStorageDriver
USB mass storage driver structure.
Definition: usb_msd.h:172
USBMassStorageDriver::result
bool result
Definition: usb_msd.h:184
PACK_STRUCT_STRUCT::version
uint8_t version
Definition: usb_msd.h:99
uint8_t
unsigned char uint8_t
Definition: types.h:14
MSD_READ_COMMAND_BLOCK
@ MSD_READ_COMMAND_BLOCK
Definition: usb_msd.h:115
msdConfigureHookI
void msdConfigureHookI(USBMassStorageDriver *msdp)
USB device configured handler.
Definition: usb_msd.c:188
PACK_STRUCT_END
#define PACK_STRUCT_END
Definition: usb_msd.h:37
deinit_msd_driver
void deinit_msd_driver(void)
Definition: usb_msd.c:1121
USBMassStorageDriver::bot_reset
bool bot_reset
Definition: usb_msd.h:185
USBMassStorageConfig::bulk_ep
usbep_t bulk_ep
Index of the USB endpoint to use for transfers.
Definition: usb_msd.h:137
PACK_STRUCT_STRUCT::cmdque
uint8_t cmdque
Definition: usb_msd.h:104
PACK_STRUCT_STRUCT::scsi_cmd_len
uint8_t scsi_cmd_len
Definition: usb_msd.h:72
PACK_STRUCT_STRUCT::status
uint8_t status
Definition: usb_msd.h:83
USBMassStorageDriver::block_dev_info
BlockDeviceInfo block_dev_info
Definition: usb_msd.h:177
PACK_STRUCT_STRUCT::tag
uint32_t tag
Definition: usb_msd.h:68
msdConfig
static USBMassStorageConfig msdConfig
Definition: usbStorage.c:58
PACK_STRUCT_STRUCT::peripheral
uint8_t peripheral
Definition: usb_msd.h:97
msd_state_t
msd_state_t
Possible states for the USB mass storage driver.
Definition: usb_msd.h:113
MSD_EJECTED
@ MSD_EJECTED
Definition: usb_msd.h:116
USBMassStorageDriver::sense
msd_scsi_sense_response_t sense
Definition: usb_msd.h:181
msdRequestsHook
bool msdRequestsHook(USBDriver *usbp)
Default requests hook.
Definition: usb_msd.c:205
PACK_STRUCT_STRUCT::signature
uint32_t signature
Definition: usb_msd.h:67
MSD_BOT_RESET
@ MSD_BOT_RESET
Definition: usb_msd.h:117
PACK_STRUCT_BEGIN
#define PACK_STRUCT_BEGIN
Definition: usb_msd.h:36
USBMassStorageDriver::thread
thread_t * thread
Definition: usb_msd.h:175