Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
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 #include <ch.h>
30 #include <hal.h>
31 #include "std.h"
32 
33 #ifndef PACK_STRUCT_BEGIN
34 #define PACK_STRUCT_BEGIN
35 #endif
36 
37 #ifndef PACK_STRUCT_END
38 #define PACK_STRUCT_END
39 #endif
40 
41 #ifndef PACK_STRUCT_STRUCT
42 #define PACK_STRUCT_STRUCT __attribute__((packed))
43 #endif
44 
48 PACK_STRUCT_BEGIN typedef struct {
55  uint8_t scsi_cmd_data[16];
57 
61 PACK_STRUCT_BEGIN typedef struct {
62  uint32_t signature;
63  uint32_t tag;
67 
71 PACK_STRUCT_BEGIN typedef struct {
73 } PACK_STRUCT_STRUCT msd_scsi_sense_response_t PACK_STRUCT_END;
74 
78 PACK_STRUCT_BEGIN typedef struct {
87  uint8_t vendor_id[8];
88  uint8_t product_id[16];
89  uint8_t product_rev[4];
90 } PACK_STRUCT_STRUCT msd_scsi_inquiry_response_t PACK_STRUCT_END;
91 
95 typedef enum {
99 } msd_state_t;
100 
104 typedef struct {
108  USBDriver *usbp;
109 
113  BaseBlockDevice *bbdp;
114 
118  usbep_t bulk_ep;
119 
126  void (*rw_activity_callback)(bool);
127 
132  uint8_t short_vendor_id[8];
133 
138  uint8_t short_product_id[16];
139 
144  uint8_t short_product_version[4];
145 
147 
153 typedef struct {
155  binary_semaphore_t bsem;
156  thread_t *thread;
157  event_source_t evt_connected, evt_ejected;
158  BlockDeviceInfo block_dev_info;
160  msd_cbw_t cbw;
161  msd_csw_t csw;
162  msd_scsi_sense_response_t sense;
163  msd_scsi_inquiry_response_t inquiry;
164  bool result;
166 
167 #ifdef __cplusplus
168 extern "C" {
169 #endif
170 
174 void msdInit(USBMassStorageDriver *msdp);
175 
184 
190 void msdStop(USBMassStorageDriver *msdp);
191 
200 
215 bool msdRequestsHook(USBDriver *usbp);
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 
uint8_t removable
Definition: usb_msd.h:80
uint8_t version
Definition: usb_msd.h:81
uint8_t flags
Definition: usb_msd.h:52
BlockDeviceInfo block_dev_info
Definition: usb_msd.h:158
uint32_t data_len
Definition: usb_msd.h:51
uint8_t peripheral
Definition: usb_msd.h:79
uint8_t cmdque
Definition: usb_msd.h:86
bool msdRequestsHook(USBDriver *usbp)
Default requests hook.
Definition: usb_msd.c:188
msd_state_t state
Definition: usb_msd.h:159
usbep_t bulk_ep
Index of the USB endpoint to use for transfers.
Definition: usb_msd.h:118
uint8_t status
Definition: usb_msd.h:65
msd_state_t
Possible states for the USB mass storage driver.
Definition: usb_msd.h:95
Response to a READ_CAPACITY_10 SCSI command.
Definition: usb_msd.c:99
uint8_t additional_length
Definition: usb_msd.h:83
thread_t * thread
Definition: usb_msd.h:156
const USBMassStorageConfig * config
Definition: usb_msd.h:154
event_source_t evt_ejected
Definition: usb_msd.h:157
uint32_t data_residue
Definition: usb_msd.h:64
uint32_t signature
Definition: usb_msd.h:49
void msdInit(USBMassStorageDriver *msdp)
Initializes a USB mass storage driver.
Definition: usb_msd.c:782
uint8_t scsi_cmd_len
Definition: usb_msd.h:54
USB mass storage driver structure.
Definition: usb_msd.h:153
void msdConfigureHookI(USBMassStorageDriver *msdp)
USB device configured handler.
Definition: usb_msd.c:173
Driver configuration structure.
Definition: usb_msd.h:104
unsigned long uint32_t
Definition: types.h:18
USBDriver * usbp
USB driver to use for communication.
Definition: usb_msd.h:108
#define PACK_STRUCT_BEGIN
Definition: usb_msd.h:34
uint8_t response_data_format
Definition: usb_msd.h:82
void msdStart(USBMassStorageDriver *msdp, const USBMassStorageConfig *config)
Starts a USB mass storage driver.
Definition: usb_msd.c:820
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:84
#define PACK_STRUCT_END
Definition: usb_msd.h:38
void msdStop(USBMassStorageDriver *msdp)
Stops a USB mass storage driver.
Definition: usb_msd.c:866
binary_semaphore_t bsem
Definition: usb_msd.h:155
uint32_t tag
Definition: usb_msd.h:50
msd_scsi_inquiry_response_t inquiry
Definition: usb_msd.h:163
BaseBlockDevice * bbdp
Block device to use for storage.
Definition: usb_msd.h:113
msd_scsi_sense_response_t sense
Definition: usb_msd.h:162
uint8_t bqueetc
Definition: usb_msd.h:85