Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 {
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
void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
Definition: usb_msd.c:1126
uint8_t removable
Definition: usb_msd.h:98
uint8_t version
Definition: usb_msd.h:99
uint8_t flags
Definition: usb_msd.h:70
BlockDeviceInfo block_dev_info
Definition: usb_msd.h:177
uint32_t data_len
Definition: usb_msd.h:69
uint8_t peripheral
Definition: usb_msd.h:97
uint8_t cmdque
Definition: usb_msd.h:104
bool msdRequestsHook(USBDriver *usbp)
Default requests hook.
Definition: usb_msd.c:205
msd_state_t state
Definition: usb_msd.h:178
usbep_t bulk_ep
Index of the USB endpoint to use for transfers.
Definition: usb_msd.h:137
uint8_t status
Definition: usb_msd.h:83
msd_state_t
Possible states for the USB mass storage driver.
Definition: usb_msd.h:113
Response to a READ_CAPACITY_10 SCSI command.
Definition: usb_msd.c:113
uint8_t additional_length
Definition: usb_msd.h:101
thread_t * thread
Definition: usb_msd.h:175
const USBMassStorageConfig * config
Definition: usb_msd.h:173
event_source_t evt_ejected
Definition: usb_msd.h:176
uint32_t data_residue
Definition: usb_msd.h:82
uint32_t signature
Definition: usb_msd.h:67
void msdInit(USBMassStorageDriver *msdp)
Initializes a USB mass storage driver.
Definition: usb_msd.c:815
uint8_t scsi_cmd_len
Definition: usb_msd.h:72
USB mass storage driver structure.
Definition: usb_msd.h:172
void msdConfigureHookI(USBMassStorageDriver *msdp)
USB device configured handler.
Definition: usb_msd.c:188
Driver configuration structure.
Definition: usb_msd.h:123
unsigned long uint32_t
Definition: types.h:18
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
bool reconfigured_or_reset_event
Definition: usb_msd.h:183
USBDriver * usbp
USB driver to use for communication.
Definition: usb_msd.h:127
static USBMassStorageConfig msdConfig
Definition: usbStorage.c:58
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
#define PACK_STRUCT_BEGIN
Definition: usb_msd.h:36
uint8_t response_data_format
Definition: usb_msd.h:100
void msdStart(USBMassStorageDriver *msdp, const USBMassStorageConfig *config)
Starts a USB mass storage driver.
Definition: usb_msd.c:855
unsigned char uint8_t
Definition: types.h:14
#define byte
static const struct usb_config_descriptor config
Definition: usb_ser_hw.c:199
uint8_t sccstp
Definition: usb_msd.h:102
#define PACK_STRUCT_END
Definition: usb_msd.h:37
void msdStop(USBMassStorageDriver *msdp)
Stops a USB mass storage driver.
Definition: usb_msd.c:900
binary_semaphore_t bsem
Definition: usb_msd.h:174
void deinit_msd_driver(void)
Definition: usb_msd.c:1121
uint32_t tag
Definition: usb_msd.h:68
msd_scsi_inquiry_response_t inquiry
Definition: usb_msd.h:182
BaseBlockDevice * bbdp
Block device to use for storage.
Definition: usb_msd.h:132
msd_scsi_sense_response_t sense
Definition: usb_msd.h:181
uint8_t bqueetc
Definition: usb_msd.h:103