VSF Documented
vsf_usbd_CDCNCM.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_CDCNCM_H__
19#define __VSF_USBD_CDCNCM_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED && VSF_USBD_USE_CDCNCM == ENABLED
26
31
32#if defined(__VSF_USBD_CDCNCM_CLASS_IMPLEMENT)
33# undef __VSF_USBD_CDCNCM_CLASS_IMPLEMENT
34# define __VSF_CLASS_IMPLEMENT__
35#endif
36#include "utilities/ooc_class.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/*============================ MACROS ========================================*/
43
44#if VSF_USE_TCPIP != ENABLED
45# error Please enable VSF_USE_TCPIP to use CDCNCM
46#endif
47
48#ifndef VSF_USBD_CDCNCM_SUPPORT_NTB32
49# define VSF_USBD_CDCNCM_SUPPORT_NTB32 ENABLED
50#endif
51#ifndef VSF_USBD_CDCNCM_CFG_MAX_NTB_IN_SIZE
52# define VSF_USBD_CDCNCM_CFG_MAX_NTB_IN_SIZE (4 * 1024)
53#endif
54#ifndef VSF_USBD_CDCNCM_CFG_MAX_NTB_OUT_SIZE
55# define VSF_USBD_CDCNCM_CFG_MAX_NTB_OUT_SIZE (4 * 1024)
56#endif
57
58#define USB_CDC_NCM_PARAM(__INT_IN_EP, __BULK_IN_EP, __BULK_OUT_EP) \
59 .ep = { \
60 .notify = (__INT_IN_EP), \
61 .out = (__BULK_OUT_EP), \
62 .in = (__BULK_IN_EP), \
63 },
64
65#define USB_CDC_NCM_IFS_NUM USB_CDC_IFS_NUM
66#define USB_CDC_NCM_IFS_CONTROL(__CDC_NCM_PARAM) \
67 USB_IFS(&vk_usbd_cdcncm_control, &__CDC_NCM_PARAM)
68#define USB_CDC_NCM_IFS_DATA(__CDC_NCM_PARAM) \
69 USB_IFS(&vk_usbd_cdcncm_data, &__CDC_NCM_PARAM)
70
71
72
73#define __usbd_cdc_ncm_desc_iad(__name, __ifs_start, __i_func, \
74 __int_in_ep, __bulk_in_ep, __bulk_out_ep, \
75 __bulk_ep_size, __int_ep_interval, __i_mac, __max_datagram_size, ...) \
76 USB_DESC_CDC_NCM_IAD((__ifs_start), (__i_func), \
77 (__int_in_ep), (__bulk_in_ep), (__bulk_out_ep), \
78 (__bulk_ep_size), (__int_ep_interval), (__i_mac), \
79 (__max_datagram_size), ##__VA_ARGS__)
80
81#define __usbd_cdc_ncm_func1(__name, __func_id, __str_func, __i_func, __ifs_start,\
82 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
83 __i_mac, __str_mac, __max_datagram_size) \
84 enum { \
85 __##__name##_CDCNCM##__func_id##_IFS_START = (__ifs_start), \
86 __##__name##_CDCNCM##__func_id##_I_FUNC = (__i_func), \
87 __##__name##_CDCNCM##__func_id##_INTIN_EP = (__int_in_ep), \
88 __##__name##_CDCNCM##__func_id##_BULKIN_EP = (__bulk_in_ep), \
89 __##__name##_CDCNCM##__func_id##_BULKOUT_EP = (__bulk_out_ep), \
90 __##__name##_CDCNCM##__func_id##_BULK_EP_SIZE = (__bulk_ep_size),\
91 __##__name##_CDCNCM##__func_id##_BULK_EP_INTERVAL = (__int_ep_interval),\
92 __##__name##_CDCNCM##__func_id##_I_MAC = (__i_mac), \
93 __##__name##_CDCNCM##__func_id##_MAX_DATAGRAM_SIZE = (__max_datagram_size),\
94 }; \
95 usbd_func_str_desc(__name, __func_id, __str_func) \
96 usbd_func_str_desc(__name, __func_id ## _mac, __str_mac) \
97 vk_usbd_cdcncm_t __##__name##_CDCNCM##__func_id = { \
98 USB_CDC_NCM_PARAM((__int_in_ep), (__bulk_in_ep), (__bulk_out_ep))\
99 .max_datagram_size = (__max_datagram_size), \
100 .str_mac = (__##__name##_str_##func##__func_id##_mac.str), \
101 };
102#define __usbd_cdc_ncm_func0(__name, __func_id, __str_func, __i_func, __ifs_start,\
103 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
104 __i_mac, __str_mac) \
105 __usbd_cdc_ncm_func1(__name, __func_id, __str_func, __i_func, __ifs_start,\
106 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
107 __i_mac, __str_mac, (14 + 1500))
108#define __usbd_cdc_ncm_func(__name, __func_id, __str_func, __i_func, __ifs_start,\
109 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
110 __i_mac, __str_mac, ...) \
111 __PLOOC_EVAL(__usbd_cdc_ncm_func, __VA_ARGS__)(__name, __func_id, __str_func, __i_func, __ifs_start,\
112 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
113 __i_mac, __str_mac, ##__VA_ARGS__)
114
115#define __usbd_cdc_ncm_ifs(__name, __func_id) \
116 USB_CDC_NCM_IFS_CONTROL(__##__name##_CDCNCM##__func_id) \
117 USB_CDC_NCM_IFS_DATA(__##__name##_CDCNCM##__func_id)
118
119// prototype: usbd_cdc_ncm_desc_iad(__name, __func_id, \
120 __network_cap = 0, __multicast_filter_num = 0, __power_filter_num = 0)
121#define usbd_cdc_ncm_desc_iad(__name, __func_id, ...) \
122 __usbd_cdc_ncm_desc_iad(__name, \
123 __##__name##_CDCNCM##__func_id##_IFS_START, \
124 4 + __##__name##_CDCNCM##__func_id##_I_FUNC, \
125 __##__name##_CDCNCM##__func_id##_INTIN_EP, \
126 __##__name##_CDCNCM##__func_id##_BULKIN_EP, \
127 __##__name##_CDCNCM##__func_id##_BULKOUT_EP, \
128 __##__name##_CDCNCM##__func_id##_BULK_EP_SIZE, \
129 __##__name##_CDCNCM##__func_id##_BULK_EP_INTERVAL, \
130 __##__name##_CDCNCM##__func_id##_I_MAC, \
131 __##__name##_CDCNCM##__func_id##_MAX_DATAGRAM_SIZE, ##__VA_ARGS__)
132#define usbd_cdc_ncm_desc_table(__name, __func_id) \
133 usbd_func_str_desc_table(__name, __func_id) \
134 VSF_USBD_DESC_STRING(0x0409, __##__name##_CDCNCM##__func_id##_I_MAC,\
135 &__##__name##_str_func##__func_id##_mac, sizeof(__##__name##_str_func##__func_id##_mac)),
136#define usbd_cdc_ncm_func(__name, __func_id, __str_func, __i_func, __ifs_start, \
137 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
138 __i_mac, __str_mac, ...) \
139 __usbd_cdc_ncm_func(__name, __func_id, (__str_func), (__i_func), (__ifs_start),\
140 (__int_in_ep), (__bulk_in_ep), (__bulk_out_ep), (__bulk_ep_size), (__int_ep_interval),\
141 (__i_mac), (__str_mac), ##__VA_ARGS__)
142#define usbd_cdc_ncm_ifs(__name, __func_id) \
143 __usbd_cdc_ncm_ifs(__name, __func_id)
144
145#define usbd_cdcncm_desc_iad(...) usbd_cdc_ncm_desc_iad(__VA_ARGS__)
146#define usbd_cdcncm_desc_table(...) usbd_cdc_ncm_desc_table(__VA_ARGS__)
147#define usbd_cdcncm_func(...) usbd_cdc_ncm_func(__VA_ARGS__)
148#define usbd_cdcncm_ifs(...) usbd_cdc_ncm_ifs(__VA_ARGS__)
149
150/*============================ MACROFIED FUNCTIONS ===========================*/
151/*============================ TYPES =========================================*/
152
154 public_member(
155 implement(vk_usbd_cdc_t)
156 uint16_t max_datagram_size;
157 const usb_unicode_t *str_mac;
159 private_member(
160 vsf_eda_t *thread;
161 vsf_sem_t sem;
162
163 vk_usbd_dev_t *dev;
164 vk_usbd_trans_t transact_in;
165 vk_usbd_trans_t transact_out;
166
167 vk_netdrv_t netdrv;
168
169 uint16_t seq;
170 uint16_t ntb_format;
171 uint16_t crc_mode;
172 uint16_t packet_filter;
173 bool is_tx_busy;
174 uint8_t connect_state;
175 usb_cdcncm_ntb_input_size_t ntb_input_size;
176 uint32_t cur_rx_size;
179 )
180};
181
182/*============================ GLOBAL VARIABLES ==============================*/
183
184extern const vk_usbd_class_op_t vk_usbd_cdcncm_control;
185extern const vk_usbd_class_op_t vk_usbd_cdcncm_data;
186
187/*============================ PROTOTYPES ====================================*/
188
189#ifdef __cplusplus
190}
191#endif
192
193#endif // VSF_USE_USB_DEVICE && VSF_USBD_USE_CDCNCM
194#endif // __VSF_USBD_CDCNCM_H__
Definition vsf_netdrv.h:99
Definition vsf_usbd_CDC.h:74
Definition vsf_usbd_CDCNCM.h:153
Definition vsf_usbd.h:402
Definition vsf_eda.h:766
Definition vsf_eda.h:864
unsigned short uint16_t
Definition lvgl.h:41
unsigned int uint32_t
Definition lvgl.h:43
unsigned char uint8_t
Definition lvgl.h:40
#define vsf_class(__name)
Definition ooc_class.h:48
Definition vsf_usb_CDCNCM.h:62
#define usb_unicode_t
Definition vsf_usbd.h:112
const vk_usbd_class_op_t vk_usbd_cdcncm_data
#define VSF_USBD_CDCNCM_CFG_MAX_NTB_IN_SIZE
Definition vsf_usbd_CDCNCM.h:52
#define VSF_USBD_CDCNCM_CFG_MAX_NTB_OUT_SIZE
Definition vsf_usbd_CDCNCM.h:55
const vk_usbd_class_op_t vk_usbd_cdcncm_control