Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
66PACK_STRUCT_BEGIN typedef struct {
75
79PACK_STRUCT_BEGIN typedef struct {
80 uint32_t signature;
81 uint32_t tag;
85
89PACK_STRUCT_BEGIN typedef struct {
90 uint8_t byte[18];
91} PACK_STRUCT_STRUCT msd_scsi_sense_response_t PACK_STRUCT_END;
92
96PACK_STRUCT_BEGIN typedef struct {
108} PACK_STRUCT_STRUCT msd_scsi_inquiry_response_t PACK_STRUCT_END;
109
119
123typedef struct {
127 USBDriver *usbp;
128
132 BaseBlockDevice *bbdp;
133
137 usbep_t bulk_ep;
138
145 void (*rw_activity_callback)(bool);
146
152
158
164
166
172typedef 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;
187
188#ifdef __cplusplus
189extern "C" {
190#endif
191
195void msdInit(USBMassStorageDriver *msdp);
196
204void msdStart(USBMassStorageDriver *msdp, const USBMassStorageConfig *config);
205
211void msdStop(USBMassStorageDriver *msdp);
212
221
236bool msdRequestsHook(USBDriver *usbp);
237
238
239void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig);
240void deinit_msd_driver(void);
241
246void msd_register_evt_connected(event_listener_t *elp, eventmask_t mask);
247
254void msd_register_evt_ejected(event_listener_t *elp, eventmask_t mask);
255
256
257#ifdef __cplusplus
258}
259#endif
static USBMassStorageConfig msdConfig
Definition usbStorage.c:64
const USBMassStorageConfig * config
Definition usb_msd.h:173
msd_scsi_sense_response_t sense
Definition usb_msd.h:181
bool reconfigured_or_reset_event
Definition usb_msd.h:183
uint32_t signature
Definition usb_msd.h:67
bool msdRequestsHook(USBDriver *usbp)
Default requests hook.
Definition usb_msd.c:205
uint8_t short_product_id[16]
Short product identification.
Definition usb_msd.h:157
void init_msd_driver(void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
Definition usb_msd.c:1126
#define PACK_STRUCT_STRUCT
Definition usb_msd.h:35
BlockDeviceInfo block_dev_info
Definition usb_msd.h:177
#define PACK_STRUCT_END
Definition usb_msd.h:37
BaseBlockDevice * bbdp
Block device to use for storage.
Definition usb_msd.h:132
uint8_t short_product_version[4]
Short product revision.
Definition usb_msd.h:163
usbep_t bulk_ep
Index of the USB endpoint to use for transfers.
Definition usb_msd.h:137
msd_state_t state
Definition usb_msd.h:178
uint8_t response_data_format
Definition usb_msd.h:100
uint8_t peripheral
Definition usb_msd.h:97
uint8_t removable
Definition usb_msd.h:98
uint8_t version
Definition usb_msd.h:99
uint8_t product_rev[4]
Definition usb_msd.h:107
event_source_t evt_ejected
Definition usb_msd.h:176
#define PACK_STRUCT_BEGIN
Definition usb_msd.h:36
void msdStart(USBMassStorageDriver *msdp, const USBMassStorageConfig *config)
Starts a USB mass storage driver.
Definition usb_msd.c:855
uint8_t scsi_cmd_len
Definition usb_msd.h:72
uint8_t product_id[16]
Definition usb_msd.h:106
msd_scsi_inquiry_response_t inquiry
Definition usb_msd.h:182
void msdInit(USBMassStorageDriver *msdp)
Initializes a USB mass storage driver.
Definition usb_msd.c:815
void(* rw_activity_callback)(bool)
Optional callback that will be called whenever there is read/write activity.
Definition usb_msd.h:145
uint8_t vendor_id[8]
Definition usb_msd.h:105
void msdConfigureHookI(USBMassStorageDriver *msdp)
USB device configured handler.
Definition usb_msd.c:188
void msd_register_evt_connected(event_listener_t *elp, eventmask_t mask)
register connected event source in local event mask
Definition usb_msd.c:1144
void msd_register_evt_ejected(event_listener_t *elp, eventmask_t mask)
register ejected event source in local event mask
Definition usb_msd.c:1149
USBDriver * usbp
USB driver to use for communication.
Definition usb_msd.h:127
event_source_t evt_connected
Definition usb_msd.h:176
void msdStop(USBMassStorageDriver *msdp)
Stops a USB mass storage driver.
Definition usb_msd.c:900
uint8_t scsi_cmd_data[16]
Definition usb_msd.h:73
uint8_t additional_length
Definition usb_msd.h:101
uint32_t data_residue
Definition usb_msd.h:82
uint8_t short_vendor_id[8]
Short vendor identification.
Definition usb_msd.h:151
thread_t * thread
Definition usb_msd.h:175
uint32_t data_len
Definition usb_msd.h:69
void deinit_msd_driver(void)
Definition usb_msd.c:1121
binary_semaphore_t bsem
Definition usb_msd.h:174
msd_state_t
Possible states for the USB mass storage driver.
Definition usb_msd.h:113
@ MSD_READ_COMMAND_BLOCK
Definition usb_msd.h:115
@ MSD_IDLE
Definition usb_msd.h:114
@ MSD_EJECTED
Definition usb_msd.h:116
@ MSD_BOT_RESET
Definition usb_msd.h:117
Driver configuration structure.
Definition usb_msd.h:123
USB mass storage driver structure.
Definition usb_msd.h:172
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.