rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
mass_storage_device.h
Go to the documentation of this file.
1/**
2 * @file mass_storage_device.h
3 *
4 * @date April 9, 2021
5 * @author Matthew Kennedy, (c) 2021
6 *
7 * This file implements a USB mass storage device with multiple LUNs, so multiple drives can be mounted at once.
8 */
9
10#include "hal_usb_msd.h"
11#include "thread_controller.h"
12
13#if HAL_USE_USB_MSD
14
15class MassStorageController : public ThreadController<USB_MSD_THREAD_WA_SIZE> {
16public:
17 MassStorageController(USBDriver* usb);
18
19 void attachLun(uint8_t lunIndex, BaseBlockDevice *blkdev, uint8_t *blkbuf, size_t blkbufsize,
20 const scsi_inquiry_response_t *inquiry,
21 const scsi_unit_serial_number_inquiry_response_t *serialInquiry);
22protected:
23 void ThreadTask() override;
24
25private:
26 static bool cbwValid(const msd_cbw_t& cbw, msg_t status);
27 static bool cbwMeaningful(const msd_cbw_t& cbw);
28
29 void sendCsw(uint8_t status, uint32_t residue);
30
31 usbmsdstate_t m_state;
32
33 USBDriver* const m_usb;
34
35 // temporary storage
36 msd_cbw_t m_cbw;
37 msd_csw_t m_csw;
38
39 SCSITransport m_scsiTransport;
40 usb_scsi_transport_handler_t m_scsiTransportHandler;
41
42 chibios_rt::Mutex m_lunMutex;
43
44 struct LunEntry {
45 SCSITarget target;
46 SCSITargetConfig config;
47 };
48
49 LunEntry m_luns[USB_MSD_LUN_COUNT];
50};
51
52#endif // HAL_USE_USB_MSD
void sendCsw(uint8_t status, uint32_t residue)
void attachLun(uint8_t lunIndex, BaseBlockDevice *blkdev, uint8_t *blkbuf, size_t blkbufsize, const scsi_inquiry_response_t *inquiry, const scsi_unit_serial_number_inquiry_response_t *serialInquiry)
LunEntry m_luns[USB_MSD_LUN_COUNT]
static bool cbwValid(const msd_cbw_t &cbw, msg_t status)
chibios_rt::Mutex m_lunMutex
static bool cbwMeaningful(const msd_cbw_t &cbw)
usb_scsi_transport_handler_t m_scsiTransportHandler
A base class for a controller that requires its own thread.
uint8_t blkbuf[4 *MMCSD_BLOCK_SIZE]
Definition mmc_card.cpp:292
SCSITarget target
SCSITargetConfig config