msc.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2019-2021 Mesotic SAS
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
19 #include <stdint.h>
20 #include "usb/usbus.h"
21 #include "usb/usbus/msc/scsi.h"
22 #include "mtd.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
31 #if defined(MODULE_PERIPH_USBDEV_HS_UTMI) || defined(MODULE_PERIPH_USBDEV_HS_ULPI)
32 #define USBUS_MSC_EP_DATA_SIZE 512
33 #else
34 #define USBUS_MSC_EP_DATA_SIZE 64
35 #endif
36 
40 #define USBUS_MSC_EP_IN_REQUIRED_NUMOF 1
41 
45 #define USBUS_MSC_EP_OUT_REQUIRED_NUMOF 1
46 
50 typedef enum {
55  GEN_CSW
57 
61 typedef struct usbus_msc_lun {
63  uint32_t block_nb;
64  uint32_t block_size;
66 
70 typedef struct usbus_msc_device {
75  uint8_t *out_buf;
76  uint8_t *in_buf;
82  uint8_t *buffer;
83  uint32_t buffer_size;
84  uint32_t block;
85  uint16_t block_nb;
87  uint16_t block_offset;
90 
99 
112 
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
SCSI protocol definitions for USBUS.
USBUS Command Block Wrapper information.
Definition: scsi.h:260
event structure
Definition: event.h:142
MTD device descriptor.
Definition: mtd.h:111
USBUS descriptor generator.
Definition: usbus.h:294
USBUS endpoint context.
Definition: usbus.h:304
USBUS handler struct.
Definition: usbus.h:432
USBUS interface.
Definition: usbus.h:349
USBUS MSC device interface context.
Definition: msc.h:70
uint32_t buffer_size
Size of the internal buffer used for data transfer.
Definition: msc.h:83
usbus_t * usbus
Pointer to the USBUS context.
Definition: msc.h:78
uint8_t * in_buf
Pointer to internal in endpoint buffer.
Definition: msc.h:76
usbus_endpoint_t * ep_out
Data endpoint out.
Definition: msc.h:74
cbw_info_t cmd
Command Block Wrapper information.
Definition: msc.h:79
uint16_t block_offset
Internal offset for endpoint size chunk transfer.
Definition: msc.h:87
event_t rx_event
Transmit ready event.
Definition: msc.h:80
uint32_t block
First block to transfer data from/to.
Definition: msc.h:84
usbus_handler_t handler_ctrl
Control interface handler.
Definition: msc.h:71
usbus_msc_lun_t * lun_dev
Array holding exported logical unit descriptor.
Definition: msc.h:88
uint8_t * buffer
Pointer to the current data transfer buffer.
Definition: msc.h:82
usbus_interface_t iface
MSC interface.
Definition: msc.h:72
usbus_descr_gen_t msc_descr
MSC descriptor generator.
Definition: msc.h:77
usbus_msc_state_t state
Internal state machine for msc.
Definition: msc.h:81
uint16_t block_nb
Number of block to transfer for READ and WRITE operations.
Definition: msc.h:85
usbus_endpoint_t * ep_in
Data endpoint in.
Definition: msc.h:73
uint8_t * out_buf
Pointer to internal out endpoint buffer.
Definition: msc.h:75
USBUS MSC Logical Unit descriptor.
Definition: msc.h:61
uint32_t block_size
Reported USB block size.
Definition: msc.h:64
mtd_dev_t * mtd
Pointer to the current mtd device used.
Definition: msc.h:62
uint32_t block_nb
Reported USB block number.
Definition: msc.h:63
USBUS context struct.
Definition: usbus.h:444
struct usbus_msc_device usbus_msc_device_t
USBUS MSC device interface context.
int usbus_msc_remove_lun(usbus_t *usbus, mtd_dev_t *dev)
Unregister a MTD device as a MSC LUN.
int usbus_msc_init(usbus_t *usbus, usbus_msc_device_t *handler)
MSC initialization function.
usbus_msc_state_t
USBUS MSC internal state machine enum.
Definition: msc.h:50
@ GEN_CSW
Generate CSW response to host w/ the current transfer status.
Definition: msc.h:55
@ DATA_TRANSFER_OUT
Ongoing transfer on USB MSC OUT endpoint.
Definition: msc.h:54
@ WAIT_FOR_TRANSFER
Wait for a single packet transfer before sending CSW.
Definition: msc.h:52
@ WAITING
Initial state, wait for USB setup.
Definition: msc.h:51
@ DATA_TRANSFER_IN
Ongoing transfer on USB MSC IN endpoint.
Definition: msc.h:53
int usbus_msc_add_lun(usbus_t *usbus, mtd_dev_t *dev)
Register a MTD device as a MSC LUN (Logical Unit Number)
struct usbus_msc_lun usbus_msc_lun_t
USBUS MSC Logical Unit descriptor.
USBUS basic interface.