• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * drivers/usbdev/cdcacm.h
3  *
4  *   Copyright (C) 2011-2012, 2015, 2017 Gregory Nutt. All rights reserved.
5  *   Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
6  *   Author: Gregory Nutt <gnutt@nuttx.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  * 3. Neither the name NuttX nor the names of its contributors may be
19  *    used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  ****************************************************************************/
36 /****************************************************************************
37  * Notice of Export Control Law
38  * ===============================================
39  * Huawei LiteOS may be subject to applicable export control laws and regulations,
40  * which might include those applicable to Huawei LiteOS of U.S. and the country in
41  * which you are located.
42  * Import, export and usage of Huawei LiteOS in any manner by you shall be in
43  * compliance with such applicable export control laws and regulations.
44  ****************************************************************************/
45 
46 #ifndef __DRIVERS_USBDEV_CDCACM_H
47 #define __DRIVERS_USBDEV_CDCACM_H
48 
49 /****************************************************************************
50  * Included Files
51  ****************************************************************************/
52 
53 #include "gadget/composite.h"
54 
55 /* Interface IDs:
56  *
57  * CDCACM_NINTERFACES              Two interfaces
58  * CDCACM_NOTIFID                  ID of the notifier interface
59  * CDCACM_NOTALTIFID               No alternate for the notifier interface
60  * CDCACM_DATAIFID                 ID of the data interface
61  * CDCACM_DATAALTIFID              No alternate for the data interface
62  */
63 
64 #define CDCACM_NOTALTIFID          (0)
65 #define CDCACM_DATAALTIFID         (0)
66 
67 /* Buffer big enough for any of our descriptors (the config descriptor is the
68  * biggest).
69  */
70 
71 #define CDCACM_MXDESCLEN           (64)
72 #define CDCACM_MAXSTRLEN           (CDCACM_MXDESCLEN-2)
73 
74 /* Device descriptor values */
75 
76 #define CDCACM_VERSIONNO           (0x0101) /* Device version number 1.1 (BCD) */
77 
78 /* String language */
79 
80 #define CDCACM_STR_LANGUAGE        (0x0409) /* en-us */
81 
82 /* Descriptor strings.  If there serial device is part of a composite device
83  * then the manufacturer, product, and serial number strings will be provided
84  * by the composite logic.
85  */
86 
87 #ifndef CONFIG_CDCACM_COMPOSITE
88 #define CDCACM_LASTBASESTRID     (4)
89 #define CDCACM_STRBASE           (0)
90 #else
91 #define CDCACM_STRBASE           CONFIG_CDCACM_STRBASE
92 #define CDCACM_LASTBASESTRID     CONFIG_CDCACM_STRBASE
93 #endif
94 
95 /* These string IDs only exist if a user-defined string is provided */
96 
97 #ifdef CONFIG_CDCACM_NOTIFSTR
98 #define CDCACM_NOTIFSTRID        (CDCACM_LASTBASESTRID+1)
99 #else
100 #define CDCACM_NOTIFSTRID        CDCACM_LASTBASESTRID
101 #endif
102 
103 #ifdef CONFIG_CDCACM_DATAIFSTR
104 #define CDCACM_DATAIFSTRID       (CDCACM_NOTIFSTRID+1)
105 #else
106 #define CDCACM_DATAIFSTRID       CDCACM_NOTIFSTRID
107 #endif
108 
109 #define CDCACM_LASTSTRID           CDCACM_DATAIFSTRID
110 #define CDCACM_NSTRIDS             (CDCACM_LASTSTRID - CDCACM_STRBASE)
111 
112 #define CDCACM_EP_INTIN_IDX        (0)
113 #define CDCACM_EP_BULKIN_IDX       (1)
114 #define CDCACM_EP_BULKOUT_IDX      (2)
115 
116 /* Endpoint configuration ****************************************************/
117 
118 #define CDCACM_MKEPINTIN(desc)     ((desc)->epno[CDCACM_EP_INTIN_IDX])
119 
120 #define CDCACM_MKEPBULKIN(desc)    ((desc)->epno[CDCACM_EP_BULKIN_IDX])
121 
122 #define CDCACM_MKEPBULKOUT(desc)   ((desc)->epno[CDCACM_EP_BULKOUT_IDX])
123 
124 /* Device driver definitions ************************************************/
125 /* A CDC/ACM device is specific by a minor number in the range of 0-255.
126  * This maps to a character device at /dev/ttyACMx, x=0..255.
127  */
128 
129 #define CDCACM_DEVNAME_FORMAT      "/dev/ttyGS0"
130 #define CDCACM_DEVNAME_SIZE        16
131 
132 /* Misc Macros **************************************************************/
133 /* MIN/MAX macros */
134 
135 #ifndef MIN
136 #define MIN(a,b) ((a)<(b)?(a):(b))
137 #endif
138 
139 #ifndef MAX
140 #define MAX(a,b) ((a)>(b)?(a):(b))
141 #endif
142 
143 #define CDCACM_NUM_EPS             (3)
144 
145 #define CDCACM_NCONFIGS            (1)      /* Number of configurations supported */
146 
147 /* Configuration descriptor values */
148 
149 #define CDCACM_CONFIGID            (1)      /* The only supported configuration ID */
150 #define CDCACM_NINTERFACES         (2)      /* Number of interfaces in the configuration */
151 
152 /* Table 69: UART State Bitmap Values */
153 
154 #define CDC_UART_RXCARRIER      (1 << 0) /* bRxCarrier State of receiver carrier detection
155                                           * mechanism of device. This signal corresponds to
156                                           * V.24 signal 109 and RS-232 signal DCD.
157                                           */
158 #define CDC_UART_TXCARRIER      (1 << 1) /* bTxCarrier State of transmission carrier. This
159                                           * signal corresponds to V.24 signal 106 and RS-232
160                                           * signal DSR.
161                                           */
162 
163 /* CDC/ACM friendly naming */
164 
165 #define CDCACM_UART_DCD          CDC_UART_RXCARRIER
166 #define CDCACM_UART_DSR          CDC_UART_TXCARRIER
167 
168 /* "SerialState is used like a real interrupt status register. Once a notification has been
169  *  sent, the device will reset and reevaluate the different signals.  For the consistent
170  *  signals like carrier detect or transmission carrier, this will mean another notification
171  *  will not be generated until there is a state change.  For the irregular signals like
172  *  break, the incoming ring signal, or the overrun error state, this will reset their values
173  *  to zero and again will not send another notification until their state changes."
174  */
175 
176 #define CDC_UART_CONSISTENT     (CDC_UART_RXCARRIER | CDC_UART_TXCARRIER)
177 
178 #ifndef CONFIG_CDCACM_EPBULKOUT_FSSIZE
179 #define CONFIG_CDCACM_EPBULKOUT_FSSIZE 0x200
180 #endif
181 
182 #ifndef CONFIG_CDCACM_EPBULKOUT_HSSIZE
183 #define CONFIG_CDCACM_EPBULKOUT_HSSIZE 0x400
184 #endif
185 
186 #ifndef CONFIG_CDCACM_EPBULKIN_FSSIZE
187 #define CONFIG_CDCACM_EPBULKIN_FSSIZE 0x200
188 #endif
189 
190 #ifndef CONFIG_CDCACM_EPBULKIN_HSSIZE
191 #define CONFIG_CDCACM_EPBULKIN_HSSIZE 0x400
192 #endif
193 
194 #ifdef LOSCFG_DRIVERS_USB3_DEVICE_CONTROLLER
195 #define DWC3_USB_SERIAL
196 #endif
197 
198 #ifdef DWC3_USB_SERIAL
199 #define MAX_PACKET_SIZE 0x400
200 #else
201 #define MAX_PACKET_SIZE 0x200
202 #endif
203 
204 #define ACM_NOTIFY_SERIAL_STATE 0x20
205 #define ACM_GET_LINE_CODING     0x21 /* Requests current DTE rate, stop-bits, parity, and
206                                       * number-of-character bits. (Optional)
207                                       */
208 #define ACM_SET_LINE_CODING     0x20 /* Configures DTE rate, stop-bits, parity, and
209                                       * number-of-character bits. (Optional)
210                                       */
211 #define ACM_SET_CTRL_LINE_STATE 0x22 /* RS-232 signal used to tell the DCE device the
212                                       * DTE device is now present. (Optional)
213                                       */
214 #define SIZEOF_CDC_LINECODING 7
215 
216 #define USB_SERIAL_READ_EVENT   0x11
217 
218 /* define descriptor */
219 
220 #define DEVICE_VENDOR_ID        0x0525
221 #define DEVICE_PRODUCT_ID       0xa4a7
222 #define DEVICE_VERSION          0x0100
223 
224 #define RING_BUFFER_SIZE 6144U
225 
226 #define STAE_BUFFER_OFFSET 1
227 
228 struct cdcacm_hs_function_descriptor
229 {
230   struct usb_interface_assoc_descriptor ifcad;
231   struct usb_interface_descriptor ifcd; /* acm control interface descriptor */
232   struct usb_cdc_header_descriptor cdc_desc;
233   struct usb_cdc_cm_descriptor cdc_call_desc;
234   struct usb_cdc_acm_descriptor cdc_acm_desc;
235   struct usb_cdc_union_desc cdc_union_desc;
236   struct usb_endpoint_descriptor nepd;
237 #ifdef DWC3_USB_SERIAL
238   struct usb_endpoint_ss_comp_descriptor ncompd;
239 #endif
240   struct usb_interface_descriptor ifdd;
241   struct usb_endpoint_descriptor iepd;
242 #ifdef DWC3_USB_SERIAL
243   struct usb_endpoint_ss_comp_descriptor icompd;
244 #endif
245   struct usb_endpoint_descriptor oepd;
246 #ifdef DWC3_USB_SERIAL
247   struct usb_endpoint_ss_comp_descriptor ocompd;
248 #endif
249 } __packed;
250 
251 /****************************************************************************
252  * Public Types
253  ****************************************************************************/
254 
255 enum cdcacm_epdesc_e
256 {
257   CDCACM_EPINTIN = 0,  /* Interrupt IN endpoint descriptor */
258   CDCACM_EPBULKOUT,    /* Bulk OUT endpoint descriptor */
259   CDCACM_EPBULKIN      /* Bulk IN endpoint descriptor */
260 };
261 
262 /****************************************************************************
263  * Public Data
264  ****************************************************************************/
265 
266 extern struct cdcacm_hs_function_descriptor g_cdcacm_hs_func_desc;
267 
268 /****************************************************************************
269  * Public Function Prototypes
270  ****************************************************************************/
271 
272 void cdcacm_mkdevdesc(uint8_t *buf);
273 
274 /****************************************************************************
275  * Name: cdcacm_mkstrdesc
276  *
277  * Description:
278  *   Construct a string descriptor
279  *
280  ****************************************************************************/
281 
282 int cdcacm_mkstrdesc(uint8_t id, uint8_t *buf);
283 
284 /****************************************************************************
285  * Name: cdcacm_mkcfgdesc
286  *
287  * Description:
288  *   Construct the configuration descriptor
289  *
290  ****************************************************************************/
291 
292 int16_t cdcacm_mkcfgdesc(uint8_t *buf, struct usbdev_devinfo_s *devinfo);
293 
294 void usbdev_cdcacm_initialize_sub(FAR struct composite_devdesc_s *dev, int ifnobase, int minor);
295 #endif /* __DRIVERS_USBDEV_CDCACM_H */
296