VSF Documented
vsf_usbd_MSC.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_USBD_MSC_H__
19#define __VSF_USBD_MSC_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED && VSF_USBD_USE_MSC == ENABLED
26
28#include "./vsf_usbd_MSC_desc.h"
30
31#if defined(__VSF_USBD_MSC_CLASS_IMPLEMENT)
32# undef __VSF_USBD_MSC_CLASS_IMPLEMENT
33# define __VSF_CLASS_IMPLEMENT__
34#endif
35#include "utilities/ooc_class.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*============================ MACROS ========================================*/
42
43#if VSF_USE_SCSI != ENABLED
44# error msc uses scsi!!!
45#endif
46#if VSF_USBD_CFG_STREAM_EN != ENABLED
47# error msc need stream
48#endif
49
50
51
52#define USB_MSC_PARAM(__BULK_IN_EP, __BULK_OUT_EP, __STREAM, __MAX_LUN, __SCSI_PDEVS)\
53 .ep_out = (__BULK_OUT_EP), \
54 .ep_in = (__BULK_IN_EP), \
55 .stream = (__STREAM), \
56 .max_lun = (__MAX_LUN), \
57 .scsi_devs = (__SCSI_PDEVS),
58
59#define USB_MSC_IFS_NUM 1
60#define USB_MSCBOT_IFS_NUM USB_MSC_IFS_NUM
61#define USB_MSC_IFS(__MSC_PARAM) USB_IFS(&vk_usbd_msc, &(__MSC_PARAM))
62
63
64#define __usbd_mscbot_desc(__name, __ifs, __i_func, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size)\
65 USB_DESC_MSCBOT((__ifs), 4 + (__i_func), (__bulk_in_ep), (__bulk_out_ep), (__bulk_ep_size))
66#define __usbd_mscbot_desc_iad(__name, __ifs, __i_func, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size)\
67 USB_DESC_MSCBOT_IAD((__ifs), 4 + (__i_func), (__bulk_in_ep), (__bulk_out_ep), (__bulk_ep_size))
68
69#define __usbd_mscbot_func(__name, __func_id, __str_func, __i_func, __ifs, \
70 __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __stream, ...) \
71 enum { \
72 __##__name##_MSCBOT##__func_id##_IFS = (__ifs), \
73 __##__name##_MSCBOT##__func_id##_I_FUNC = (__i_func), \
74 __##__name##_MSCBOT##__func_id##_BULKIN_EP = (__bulk_in_ep), \
75 __##__name##_MSCBOT##__func_id##_BULKOUT_EP = (__bulk_out_ep), \
76 __##__name##_MSCBOT##__func_id##_BULK_EP_SIZE = (__bulk_ep_size),\
77 }; \
78 usbd_func_str_desc(__name, __func_id, __str_func) \
79 vk_scsi_t * __##__name##_MSC##__scsi_devs[] = { \
80 __VA_ARGS__ \
81 }; \
82 vk_usbd_msc_t __##__name##_MSC##__func_id = { \
83 USB_MSC_PARAM((__bulk_in_ep), (__bulk_out_ep), (__stream), \
84 dimof(__##__name##_MSC##__scsi_devs) - 1, \
85 __##__name##_MSC##__scsi_devs) \
86 };
87
88#define __usbd_msc_ifs(__name, __func_id) \
89 USB_MSC_IFS(__##__name##_MSC##__func_id)
90
91#define usbd_mscbot_desc(__name, __func_id) \
92 __usbd_mscbot_desc(__name, \
93 __##__name##_MSCBOT##__func_id##_IFS, \
94 __##__name##_MSCBOT##__func_id##_I_FUNC, \
95 __##__name##_MSCBOT##__func_id##_BULKIN_EP, \
96 __##__name##_MSCBOT##__func_id##_BULKOUT_EP, \
97 __##__name##_MSCBOT##__func_id##_BULK_EP_SIZE)
98#define usbd_mscbot_desc_iad(__name, __func_id) \
99 __usbd_mscbot_desc_iad(__name, \
100 __##__name##_MSCBOT##__func_id##_IFS, \
101 __##__name##_MSCBOT##__func_id##_I_FUNC, \
102 __##__name##_MSCBOT##__func_id##_BULKIN_EP, \
103 __##__name##_MSCBOT##__func_id##_BULKOUT_EP, \
104 __##__name##_MSCBOT##__func_id##_BULK_EP_SIZE)
105#define usbd_mscbot_func(__name, __func_id, __str_func, __i_func, __ifs, \
106 __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __stream, ...) \
107 __usbd_mscbot_func(__name, __func_id, (__str_func), (__i_func), (__ifs),\
108 (__bulk_in_ep), (__bulk_out_ep), (__bulk_ep_size), \
109 (__stream), __VA_ARGS__)
110#define usbd_mscbot_ifs(__name, __func_id) \
111 __usbd_msc_ifs(__name, __func_id)
112
113// usbd_mscbot_scsi_config MUST be called for each scsi device before usbd startup.
114#define usbd_mscbot_scsi_config(__name, __func_id, __scsi_idx, __is_inited)\
115 extern vk_usbd_msc_t __##__name##_MSC##__func_id; \
116 vk_usbd_mscbot_scsi_config(&__##__name##_MSC##__func_id, (__scsi_idx), (__is_inited))
117
118/*============================ MACROFIED FUNCTIONS ===========================*/
119/*============================ TYPES =========================================*/
120
123 struct {
125 struct {
128 };
129 };
131
133
134 private_member(
135 vsf_eda_t eda;
137 int32_t reply_len;
138 vk_usbd_dev_t *dev;
139 vk_usbd_ep_stream_t ep_stream;
140 uint8_t scsi_inited_mask;
141 uint8_t is_scsi_init : 1;
142 uint8_t is_stream : 1;
143 uint8_t is_scsi_done : 1;
144 uint8_t is_data_done : 1;
145 )
146
147 public_member(
148 const uint8_t ep_out;
149 const uint8_t ep_in;
150 const uint8_t max_lun;
151 vsf_stream_t *stream;
152 vk_scsi_t **scsi_devs;
154};
155
156/*============================ GLOBAL VARIABLES ==============================*/
157
158extern const vk_usbd_class_op_t vk_usbd_msc;
159
160/*============================ PROTOTYPES ====================================*/
161
162// vk_usbd_mscbot_scsi_config MUST be called for each scsi device before usbd startup.
163void vk_usbd_mscbot_scsi_config(vk_usbd_msc_t *msc, uint8_t idx, bool is_inited);
164
165#ifdef __cplusplus
166}
167#endif
168
169#endif // VSF_USE_USB_DEVICE && VSF_USBD_USE_MSC
170#endif // __VSF_USBD_MSC_H__
Definition vsf_scsi.h:146
Definition vsf_usbd_MSC.h:132
Definition vsf_eda.h:766
Definition vsf_simple_stream.h:254
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned uint32_t
Definition stdint.h:9
int int32_t
Definition stdint.h:8
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_usb_MSC.h:35
Definition vsf_usb_MSC.h:46
Definition vsf_usbd_MSC.h:121
usb_msc_csw_t csw
Definition vsf_usbd_MSC.h:124
uint32_t cur_size
Definition vsf_usbd_MSC.h:126
usb_msc_cbw_t cbw
Definition vsf_usbd_MSC.h:122
uint32_t reply_size
Definition vsf_usbd_MSC.h:127
const vk_usbd_class_op_t vk_usbd_msc
void vk_usbd_mscbot_scsi_config(vk_usbd_msc_t *msc, uint8_t idx, bool is_inited)