1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** USBX Component */ 17 /** */ 18 /** CDC ACM Class */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* COMPONENT DEFINITION RELEASE */ 27 /* */ 28 /* ux_host_class_cdc_acm.h PORTABLE C */ 29 /* 6.1.10 */ 30 /* AUTHOR */ 31 /* */ 32 /* Chaoqiong Xiao, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file contains all the header and extern functions used by the */ 37 /* USBX CDC ACM class. */ 38 /* */ 39 /* RELEASE HISTORY */ 40 /* */ 41 /* DATE NAME DESCRIPTION */ 42 /* */ 43 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 44 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 45 /* used UX prefix to refer to */ 46 /* TX symbols instead of using */ 47 /* them directly, */ 48 /* resulting in version 6.1 */ 49 /* 08-02-2021 Wen Wang Modified comment(s), */ 50 /* added extern "C" keyword */ 51 /* for compatibility with C++, */ 52 /* resulting in version 6.1.8 */ 53 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ 54 /* added standalone support, */ 55 /* used defined line coding */ 56 /* instead of magic number, */ 57 /* resulting in version 6.1.10 */ 58 /* */ 59 /**************************************************************************/ 60 61 #ifndef UX_HOST_CLASS_CDC_ACM_H 62 #define UX_HOST_CLASS_CDC_ACM_H 63 64 /* Determine if a C++ compiler is being used. If so, ensure that standard 65 C is used to process the API information. */ 66 67 #ifdef __cplusplus 68 69 /* Yes, C++ compiler is present. Use standard C. */ 70 extern "C" { 71 72 #endif 73 74 /* Define CDC ACM Class constants. */ 75 76 #define UX_HOST_CLASS_CDC_ACM_DEVICE_INIT_DELAY 1000 77 #define UX_HOST_CLASS_CDC_ACM_CLASS_TRANSFER_TIMEOUT 300000 78 #define UX_HOST_CLASS_CDC_DATA_CLASS 0x0A 79 #define UX_HOST_CLASS_CDC_CONTROL_CLASS 0x02 80 #define UX_HOST_CLASS_CDC_ACM_SUBCLASS 0X02 81 #define UX_HOST_CLASS_CDC_DLC_SUBCLASS 0X01 82 #define UX_HOST_CLASS_CDC_ACM_CS_INTERFACE 0x24 83 84 /* Define CDC ACM Class descriptor subtypes in functional descriptors. */ 85 #define UX_HOST_CLASS_CDC_ACM_HEADER_DESCRIPTOR 0X00 86 #define UX_HOST_CLASS_CDC_ACM_CALL_MANAGEMENT_DESCRIPTOR 0X01 87 #define UX_HOST_CLASS_CDC_ACM_ABSTRACT_CONTROL_MGT_DESCRIPTOR 0X02 88 #define UX_HOST_CLASS_CDC_ACM_DIRECT_LINE_MGT_DESCRIPTOR 0X03 89 #define UX_HOST_CLASS_CDC_ACM_TELEPHONE_RINGER_DESCRIPTOR 0X04 90 #define UX_HOST_CLASS_CDC_ACM_REPORT_CAPABILITY_DESCRIPTOR 0X05 91 #define UX_HOST_CLASS_CDC_ACM_UNION_DESCRIPTOR 0X06 92 #define UX_HOST_CLASS_CDC_ACM_COUNTRY_SELECTION_DESCRIPTOR 0X07 93 #define UX_HOST_CLASS_CDC_ACM_TELEPHONE_OPERATIONAL_DESCRIPTOR 0X08 94 #define UX_HOST_CLASS_CDC_ACM_USB_TERMINAL_DESCRIPTOR 0X09 95 96 /* Define CDC ACM Class call management descriptors. */ 97 #define UX_HOST_CLASS_CDC_ACM_CALL_MANAGEMENT_CAPABILITIES 0x03 98 #define UX_HOST_CLASS_CDC_ACM_CALL_MANAGEMENT_DCM 0x01 99 #define UX_HOST_CLASS_CDC_ACM_CALL_MANAGEMENT_DCI 0x02 100 101 /* Define CDC ACM Class union interface functional descriptors. */ 102 #define UX_HOST_CLASS_CDC_ACM_UNION_FUNCTIONAL_MASTER 0x03 103 104 /* Define CDC ACM command request values. */ 105 106 #define UX_HOST_CLASS_CDC_ACM_REQ_SEND_ENCAPSULATED_COMMAND 0x00 107 #define UX_HOST_CLASS_CDC_ACM_REQ_GET_ENCAPSULATED_COMMAND 0x01 108 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_COMM_FEATURE 0x02 109 #define UX_HOST_CLASS_CDC_ACM_REQ_GET_COMM_FEATURE 0x03 110 #define UX_HOST_CLASS_CDC_ACM_REQ_CLEAR_COMM_FEATURE 0x04 111 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_AUX_LINE_STATE 0x10 112 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_HOOK_STATE 0x11 113 #define UX_HOST_CLASS_CDC_ACM_REQ_PULSE_SETUP 0x12 114 #define UX_HOST_CLASS_CDC_ACM_REQ_SEND_PULSE 0x13 115 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_PUSLE_TIME 0x14 116 #define UX_HOST_CLASS_CDC_ACM_REQ_RING_AUX_JACK 0x15 117 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_CODING 0x20 118 #define UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_CODING 0x21 119 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_STATE 0x22 120 #define UX_HOST_CLASS_CDC_ACM_REQ_SEND_BREAK 0x23 121 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_RINGER_PARMS 0x30 122 #define UX_HOST_CLASS_CDC_ACM_REQ_GET_RINGER_PARMS 0x31 123 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_OPERATION_PARMS 0x32 124 #define UX_HOST_CLASS_CDC_ACM_REQ_GET_OPERATION_PARMS 0x33 125 #define UX_HOST_CLASS_CDC_ACM_REQ_SET_LINE_PARMS 0x34 126 #define UX_HOST_CLASS_CDC_ACM_REQ_GET_LINE_PARMS 0x35 127 128 /* Define CDC ACM line output control values. */ 129 130 #define UX_HOST_CLASS_CDC_ACM_CTRL_DTR 0x01 131 #define UX_HOST_CLASS_CDC_ACM_CTRL_RTS 0x02 132 133 /* Define CDC ACM line input control values. */ 134 135 #define UX_HOST_CLASS_CDC_ACM_CTRL_DCD 0x01 136 #define UX_HOST_CLASS_CDC_ACM_CTRL_DSR 0x02 137 #define UX_HOST_CLASS_CDC_ACM_CTRL_BRK 0x04 138 #define UX_HOST_CLASS_CDC_ACM_CTRL_RI 0x08 139 140 #define UX_HOST_CLASS_CDC_ACM_CTRL_FRAMING 0x10 141 #define UX_HOST_CLASS_CDC_ACM_CTRL_PARITY 0x20 142 #define UX_HOST_CLASS_CDC_ACM_CTRL_OVERRUN 0x40 143 144 /* Define CDC ACM Class packet equivalences. */ 145 146 #define UX_HOST_CLASS_CDC_ACM_PACKET_SIZE 128 147 148 /* Define CDC ACM default values. */ 149 150 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_RATE 9600 151 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_STOP_BIT 0 152 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_PARITY 0 153 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DEFAULT_DATA_BIT 8 154 155 /* Define CDC ACM line coding definitions. */ 156 157 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT_0 0 158 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT_15 1 159 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT_2 2 160 161 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY_NONE 0 162 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY_ODD 1 163 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY_EVEN 2 164 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY_MARK 3 165 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY_SPACE 4 166 167 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_LENGTH 7 168 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_RATE 0 169 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT 4 170 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_PARITY 5 171 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_DATA_BIT 6 172 173 /* Define CDC ACM line state definitions. */ 174 175 #define UX_HOST_CLASS_CDC_ACM_LINE_STATE_STOP_BIT_0 0 176 #define UX_HOST_CLASS_CDC_ACM_LINE_CODING_STOP_BIT_15 1 177 178 /* Define CDC ACM IOCTL Functions. */ 179 180 #define UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_CODING 0 181 #define UX_HOST_CLASS_CDC_ACM_IOCTL_GET_LINE_CODING 1 182 #define UX_HOST_CLASS_CDC_ACM_IOCTL_SET_LINE_STATE 2 183 #define UX_HOST_CLASS_CDC_ACM_IOCTL_SEND_BREAK 3 184 #define UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_IN_PIPE 5 185 #define UX_HOST_CLASS_CDC_ACM_IOCTL_ABORT_OUT_PIPE 6 186 #define UX_HOST_CLASS_CDC_ACM_IOCTL_NOTIFICATION_CALLBACK 7 187 #define UX_HOST_CLASS_CDC_ACM_IOCTL_GET_DEVICE_STATUS 8 188 #define UX_HOST_CLASS_CDC_ACM_IOCTL_WRITE_CALLBACK 9 189 #define UX_HOST_CLASS_CDC_ACM_IOCTL_GET_WRITE_STATUS 10 190 191 /* Define CDC ACM Reception States. */ 192 193 #define UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STOPPED 0 194 #define UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_STARTED 1 195 #define UX_HOST_CLASS_CDC_ACM_RECEPTION_STATE_IN_TRANSFER 2 196 197 /* Define supported notification types. */ 198 199 #define UX_HOST_CLASS_CDC_ACM_NOTIFICATION_NETWORK_CONNECTION 0x00 200 #define UX_HOST_CLASS_CDC_ACM_NOTIFICATION_RESPONSE_AVAILABLE 0x01 201 #define UX_HOST_CLASS_CDC_ACM_NOTIFICATION_SERIAL_STATE 0x20 202 #define UX_HOST_CLASS_CDC_ACM_NOTIFICATION_CALL_STATE_CHANGE 0x28 203 #define UX_HOST_CLASS_CDC_ACM_NOTIFICATION_LINE_STATE_CHANGE 0x29 204 #define UX_HOST_CLASS_CDC_ACM_NOTIFICATION_SPEED_CHANGE 0x2A 205 206 /* Define notification packet format. */ 207 208 #define UX_HOST_CLASS_CDC_ACM_NPF_REQUEST_TYPE 0x00 209 #define UX_HOST_CLASS_CDC_ACM_NPF_NOTIFICATION_TYPE 0x01 210 #define UX_HOST_CLASS_CDC_ACM_NPF_VALUE 0x02 211 #define UX_HOST_CLASS_CDC_ACM_NPF_INDEX 0x04 212 #define UX_HOST_CLASS_CDC_ACM_NPF_LENGTH 0x06 213 214 /* Define CDC ACM Class instance structure. */ 215 216 typedef struct UX_HOST_CLASS_CDC_ACM_STRUCT 217 { 218 struct UX_HOST_CLASS_CDC_ACM_STRUCT 219 *ux_host_class_cdc_acm_next_instance; 220 UX_HOST_CLASS *ux_host_class_cdc_acm_class; 221 UX_DEVICE *ux_host_class_cdc_acm_device; 222 UX_ENDPOINT *ux_host_class_cdc_acm_bulk_in_endpoint; 223 UX_ENDPOINT *ux_host_class_cdc_acm_bulk_out_endpoint; 224 UX_ENDPOINT *ux_host_class_cdc_acm_interrupt_endpoint; 225 UX_INTERFACE *ux_host_class_cdc_acm_interface; 226 UINT ux_host_class_cdc_acm_instance_status; 227 UINT ux_host_class_cdc_acm_state; 228 ULONG ux_host_class_cdc_acm_notification_count; 229 ULONG ux_host_class_cdc_acm_capabilities; 230 ULONG ux_host_class_cdc_acm_device_state; 231 struct UX_HOST_CLASS_CDC_ACM_RECEPTION_STRUCT 232 *ux_host_class_cdc_acm_reception; 233 234 VOID (*ux_host_class_cdc_acm_device_status_change_callback)(struct UX_HOST_CLASS_CDC_ACM_STRUCT *cdc_acm, 235 ULONG notification_type, ULONG notification_value); 236 #if !defined(UX_HOST_STANDALONE) 237 UX_SEMAPHORE ux_host_class_cdc_acm_semaphore; 238 #else 239 UINT ux_host_class_cdc_acm_status; 240 VOID *ux_host_class_cdc_acm_allocated; 241 ULONG ux_host_class_cdc_acm_interfaces_bitmap; 242 ULONG ux_host_class_cdc_acm_tick; 243 struct UX_HOST_CLASS_CDC_ACM_STRUCT 244 *ux_host_class_cdc_acm_control; 245 ULONG ux_host_class_cdc_acm_write_length; 246 ULONG ux_host_class_cdc_acm_write_count; 247 VOID (*ux_host_class_cdc_acm_write_callback)( 248 struct UX_HOST_CLASS_CDC_ACM_STRUCT *cdc_acm, 249 UINT status, ULONG length); 250 UCHAR ux_host_class_cdc_acm_cmd_state; 251 UCHAR ux_host_class_cdc_acm_read_state; 252 UCHAR ux_host_class_cdc_acm_write_state; 253 UCHAR ux_host_class_cdc_acm_next_state; 254 #endif 255 } UX_HOST_CLASS_CDC_ACM; 256 257 /* Define CDC DLC Class instance structure. */ 258 259 260 typedef struct UX_HOST_CLASS_CDC_DLC_STRUCT 261 { 262 struct UX_HOST_CLASS_CDC_DLC_STRUCT 263 *ux_host_class_cdc_dlc_next_instance; 264 UX_HOST_CLASS *ux_host_class_cdc_dlc_class; 265 UX_DEVICE *ux_host_class_cdc_dlc_device; 266 UX_ENDPOINT *ux_host_class_cdc_dlc_bulk_in_endpoint; 267 UX_ENDPOINT *ux_host_class_cdc_dlc_bulk_out_endpoint; 268 UX_ENDPOINT *ux_host_class_cdc_dlc_interrupt_endpoint; 269 UX_INTERFACE *ux_host_class_cdc_dlc_interface; 270 UINT ux_host_class_cdc_dlc_instance_status; 271 UINT ux_host_class_cdc_dlc_state; 272 ULONG ux_host_class_cdc_dlc_notification_count; 273 ULONG ux_host_class_cdc_dlc_capabilities; 274 struct UX_HOST_CLASS_CDC_DLC_RECEPTION_STRUCT 275 *ux_host_class_cdc_dlc_reception; 276 #if !defined(UX_HOST_STANDALONE) 277 UX_SEMAPHORE ux_host_class_cdc_dlc_semaphore; 278 #else 279 ULONG ux_host_class_cdc_dlc_interfaces_bitmap; 280 struct UX_HOST_CLASS_CDC_ACM_STRUCT 281 *ux_host_class_cdc_dlc_control; 282 ULONG ux_host_class_cdc_dlc_write_length; 283 ULONG ux_host_class_cdc_dlc_write_count; 284 VOID (*ux_host_class_cdc_dlc_write_callback)( 285 struct UX_HOST_CLASS_CDC_ACM_STRUCT *cdc_acm, 286 UINT status, ULONG length); 287 UCHAR ux_host_class_cdc_dlc_cmd_state; 288 UCHAR ux_host_class_cdc_dlc_read_state; 289 UCHAR ux_host_class_cdc_dlc_write_state; 290 UCHAR ux_host_class_cdc_dlc_next_state; 291 #endif 292 } UX_HOST_CLASS_CDC_DLC; 293 294 /* Define CDC ACM reception structure. */ 295 296 typedef struct UX_HOST_CLASS_CDC_ACM_RECEPTION_STRUCT 297 { 298 299 ULONG ux_host_class_cdc_acm_reception_state; 300 ULONG ux_host_class_cdc_acm_reception_block_size; 301 UCHAR *ux_host_class_cdc_acm_reception_data_buffer; 302 ULONG ux_host_class_cdc_acm_reception_data_buffer_size; 303 UCHAR *ux_host_class_cdc_acm_reception_data_head; 304 UCHAR *ux_host_class_cdc_acm_reception_data_tail; 305 VOID (*ux_host_class_cdc_acm_reception_callback)(struct UX_HOST_CLASS_CDC_ACM_STRUCT *cdc_acm, 306 UINT status, 307 UCHAR *reception_buffer, 308 ULONG reception_size); 309 310 } UX_HOST_CLASS_CDC_ACM_RECEPTION; 311 312 /* Define CDC ACM Line Coding IOCTL structure. */ 313 314 typedef struct UX_HOST_CLASS_CDC_ACM_LINE_CODING_STRUCT 315 { 316 317 ULONG ux_host_class_cdc_acm_line_coding_dter; 318 ULONG ux_host_class_cdc_acm_line_coding_stop_bit; 319 ULONG ux_host_class_cdc_acm_line_coding_parity; 320 ULONG ux_host_class_cdc_acm_line_coding_data_bits; 321 322 } UX_HOST_CLASS_CDC_ACM_LINE_CODING; 323 324 /* Define CDC ACM Line State IOCTL structure. */ 325 326 typedef struct UX_HOST_CLASS_CDC_ACM_LINE_STATE_STRUCT 327 { 328 329 ULONG ux_host_class_cdc_acm_line_state_rts; 330 ULONG ux_host_class_cdc_acm_line_state_dtr; 331 332 } UX_HOST_CLASS_CDC_ACM_LINE_STATE; 333 334 /* Define CDC ACM Line break IOCTL structure. */ 335 336 typedef struct UX_HOST_CLASS_CDC_ACM_LINE_BREAK_STRUCT 337 { 338 339 ULONG ux_host_class_cdc_acm_line_break; 340 341 } UX_HOST_CLASS_CDC_ACM_LINE_BREAK; 342 343 /* Define CDC ACM Class function prototypes. */ 344 345 UINT _ux_host_class_cdc_acm_activate(UX_HOST_CLASS_COMMAND *command); 346 UINT _ux_host_class_cdc_acm_configure(UX_HOST_CLASS_CDC_ACM *cdc_acm); 347 UINT _ux_host_class_cdc_acm_deactivate(UX_HOST_CLASS_COMMAND *command); 348 UINT _ux_host_class_cdc_acm_endpoints_get(UX_HOST_CLASS_CDC_ACM *cdc_acm); 349 UINT _ux_host_class_cdc_acm_entry(UX_HOST_CLASS_COMMAND *command); 350 UINT _ux_host_class_cdc_acm_read (UX_HOST_CLASS_CDC_ACM *cdc_acm, UCHAR *data_pointer, 351 ULONG requested_length, ULONG *actual_length); 352 UINT _ux_host_class_cdc_acm_write(UX_HOST_CLASS_CDC_ACM *cdc_acm, UCHAR *data_pointer, 353 ULONG requested_length, ULONG *actual_length); 354 UINT _ux_host_class_cdc_acm_ioctl(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG request, 355 VOID *parameter); 356 UINT _ux_host_class_cdc_acm_command(UX_HOST_CLASS_CDC_ACM *cdc_acm, ULONG command, 357 ULONG value, UCHAR *data_buffer, ULONG data_length); 358 VOID _ux_host_class_cdc_acm_transfer_request_completed(UX_TRANSFER *transfer_request); 359 UINT _ux_host_class_cdc_acm_capabilities_get(UX_HOST_CLASS_CDC_ACM *cdc_acm); 360 UINT _ux_host_class_cdc_acm_reception_stop (UX_HOST_CLASS_CDC_ACM *cdc_acm, 361 UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception); 362 UINT _ux_host_class_cdc_acm_reception_start (UX_HOST_CLASS_CDC_ACM *cdc_acm, 363 UX_HOST_CLASS_CDC_ACM_RECEPTION *cdc_acm_reception); 364 365 VOID _ux_host_class_cdc_acm_reception_callback (UX_TRANSFER *transfer_request); 366 367 UINT _ux_host_class_cdc_acm_write_with_callback(UX_HOST_CLASS_CDC_ACM *cdc_acm, UCHAR *data_pointer, 368 ULONG requested_length); 369 VOID _ux_host_class_cdc_acm_transmission_callback(UX_TRANSFER *transfer_request); 370 371 /* Define CDC ACM Class API prototypes. */ 372 373 #define ux_host_class_cdc_acm_entry _ux_host_class_cdc_acm_entry 374 #define ux_host_class_cdc_acm_read _ux_host_class_cdc_acm_read 375 #define ux_host_class_cdc_acm_write _ux_host_class_cdc_acm_write 376 #define ux_host_class_cdc_acm_ioctl _ux_host_class_cdc_acm_ioctl 377 #define ux_host_class_cdc_acm_reception_start _ux_host_class_cdc_acm_reception_start 378 #define ux_host_class_cdc_acm_reception_stop _ux_host_class_cdc_acm_reception_stop 379 380 #define ux_host_class_cdc_acm_write_with_callback _ux_host_class_cdc_acm_write_with_callback 381 382 /* Determine if a C++ compiler is being used. If so, complete the standard 383 C conditional started above. */ 384 #ifdef __cplusplus 385 } 386 #endif 387 388 #endif 389