1 /*
2 * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016 - 2020, 2023-2024 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_common.h"
10 #include "fsl_component_serial_manager.h"
11 #include "fsl_component_serial_port_internal.h"
12
13 #if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
14 #include "usb_device_config.h"
15 #include "usb.h"
16 #include "usb_device.h"
17
18 #include "usb_device_class.h"
19 #include "usb_device_cdc_acm.h"
20 #include "usb_device_ch9.h"
21
22 #include "usb_device_descriptor.h"
23 #include "fsl_component_serial_port_usb.h"
24 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
25 #if ((defined FSL_FEATURE_SOC_USBPHY_COUNT) && (FSL_FEATURE_SOC_USBPHY_COUNT > 0U))
26 #include "usb_phy.h"
27 #endif
28 #endif
29 #if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
30 #include "fsl_sysmpu.h"
31 #endif /* FSL_FEATURE_SOC_SYSMPU_COUNT */
32
33 /*******************************************************************************
34 * Definitions
35 ******************************************************************************/
36 #ifndef NDEBUG
37 #if (defined(DEBUG_CONSOLE_ASSERT_DISABLE) && (DEBUG_CONSOLE_ASSERT_DISABLE > 0U))
38 #undef assert
39 #define assert(n)
40 #else
41 /* MISRA C-2012 Rule 17.2 */
42 #undef assert
43 #define assert(n) \
44 while (!(n)) \
45 { \
46 ; \
47 }
48 #endif
49 #endif
50
51 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
52 #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
53
54 #endif
55 #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
56 #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
57
58 #endif
59 #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
60 #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
61
62 #endif
63
64 #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
65 #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
66 #endif
67
68 /* Currently configured line coding */
69 #define LINE_CODING_SIZE (0x07)
70 #define LINE_CODING_DTERATE (115200)
71 #define LINE_CODING_CHARFORMAT (0x00)
72 #define LINE_CODING_PARITYTYPE (0x00)
73 #define LINE_CODING_DATABITS (0x08)
74
75 /* Communications feature */
76 #define COMM_FEATURE_DATA_SIZE (0x02)
77 #define STATUS_ABSTRACT_STATE (0x0000)
78 #define COUNTRY_SETTING (0x0000)
79
80 /* Notification of serial state */
81 #define NOTIF_PACKET_SIZE (0x08)
82 #define UART_BITMAP_SIZE (0x02)
83 #define NOTIF_REQUEST_TYPE (0xA1)
84
85 typedef struct _serial_usb_send_state
86 {
87 serial_manager_callback_t callback;
88 void *callbackParam;
89 uint8_t *buffer;
90 uint32_t length;
91 volatile uint8_t busy;
92 volatile uint8_t waiting4Prime;
93 } serial_usb_send_state_t;
94
95 typedef struct _serial_usb_recv_state
96 {
97 serial_manager_callback_t callback;
98 void *callbackParam;
99 volatile uint8_t busy;
100 } serial_usb_recv_state_t;
101
102 /* Define the information relates to abstract control model */
103 typedef struct _usb_cdc_acm_info
104 {
105 uint8_t serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE]; /* Serial state buffer of the CDC device to notify the
106 serial state to host. */
107 bool dtePresent; /* A flag to indicate whether DTE is present. */
108 uint16_t breakDuration; /* Length of time in milliseconds of the break signal */
109 uint8_t dteStatus; /* Status of data terminal equipment */
110 uint8_t currentInterface; /* Current interface index. */
111 uint16_t uartState; /* UART state of the CDC device. */
112 } usb_cdc_acm_info_t;
113
114 /* Define the types for application */
115 typedef struct _serial_usb_cdc_state
116 {
117 struct _serial_usb_cdc_state *next; /* Next pointer of the interface */
118 usb_device_handle deviceHandle; /* USB device handle. */
119 class_handle_t cdcAcmHandle; /* USB CDC ACM class handle. */
120 serial_usb_send_state_t tx;
121 serial_usb_recv_state_t rx;
122 volatile uint8_t attach; /* A flag to indicate whether a usb device is attached. 1: attached, 0: not attached */
123 uint8_t speed; /* Speed of USB device. USB_SPEED_FULL/USB_SPEED_LOW/USB_SPEED_HIGH. */
124 volatile uint8_t
125 startTransactions; /* A flag to indicate whether a CDC device is ready to transmit and receive data. */
126 uint8_t currentConfiguration; /* Current configuration value. */
127 uint8_t currentInterfaceAlternateSetting[USB_CDC_VCOM_INTERFACE_COUNT]; /* Current alternate setting value for each
128 interface. */
129 uint8_t instance; /* The instance of the interface */
130 uint8_t irqNumber; /* The IRQ number of the interface */
131 } serial_usb_cdc_state_t;
132
133 /*******************************************************************************
134 * Prototypes
135 ******************************************************************************/
136
137 static void USB_DeviceIsrEnable(serial_usb_cdc_state_t *serialUsbCdc);
138 #if USB_DEVICE_CONFIG_USE_TASK
139 void USB_DeviceTaskFn(void *deviceHandle);
140 #endif
141
142 static usb_status_t USB_DeviceCdcVcomCallback(class_handle_t handle, uint32_t event, void *param);
143 static usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param);
144
145 /*******************************************************************************
146 * Variables
147 ******************************************************************************/
148
149 static serial_usb_cdc_state_t *s_UsbCdcHead;
150
151 /* Line codinig of cdc device */
152 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
153 static uint8_t s_lineCoding[LINE_CODING_SIZE] = {
154 /* E.g. 0x00,0xC2,0x01,0x00 : 0x0001C200 is 115200 bits per second */
155 (LINE_CODING_DTERATE >> 0U) & 0x000000FFU,
156 (LINE_CODING_DTERATE >> 8U) & 0x000000FFU,
157 (LINE_CODING_DTERATE >> 16U) & 0x000000FFU,
158 (LINE_CODING_DTERATE >> 24U) & 0x000000FFU,
159 LINE_CODING_CHARFORMAT,
160 LINE_CODING_PARITYTYPE,
161 LINE_CODING_DATABITS};
162
163 /* Abstract state of cdc device */
164 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
165 static uint8_t s_abstractState[COMM_FEATURE_DATA_SIZE] = {(STATUS_ABSTRACT_STATE >> 0U) & 0x00FFU,
166 (STATUS_ABSTRACT_STATE >> 8U) & 0x00FFU};
167
168 /* Country code of cdc device */
169 USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE)
170 static uint8_t s_countryCode[COMM_FEATURE_DATA_SIZE] = {(COUNTRY_SETTING >> 0U) & 0x00FFU,
171 (COUNTRY_SETTING >> 8U) & 0x00FFU};
172
173 /* CDC ACM information */
174 USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static usb_cdc_acm_info_t s_usbCdcAcmInfo;
175 /* Data buffer for receiving and sending*/
176 USB_DMA_NONINIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) static uint8_t s_currRecvBuf[DATA_BUFF_SIZE];
177
178 /* USB device class information */
179 static usb_device_class_config_struct_t s_cdcAcmConfig[1] = {{
180 USB_DeviceCdcVcomCallback,
181 0,
182 &g_UsbDeviceCdcVcomConfig,
183 }};
184
185 /* USB device class configuration information */
186 static usb_device_class_config_list_struct_t s_cdcAcmConfigList = {
187 s_cdcAcmConfig,
188 USB_DeviceCallback,
189 1,
190 };
191
192 /*******************************************************************************
193 * Code
194 ******************************************************************************/
195
USB_DeviceGetInstanceFromDeviceHandle(serial_usb_cdc_state_t * head,usb_device_handle deviceHandle)196 static serial_usb_cdc_state_t *USB_DeviceGetInstanceFromDeviceHandle(serial_usb_cdc_state_t *head,
197 usb_device_handle deviceHandle)
198 {
199 while (NULL != head)
200 {
201 if (head->deviceHandle == deviceHandle)
202 {
203 return head;
204 }
205 head = head->next;
206 }
207 return NULL;
208 }
209
USB_DeviceGetInstanceFromClassHandle(serial_usb_cdc_state_t * head,class_handle_t ClassHandle)210 static serial_usb_cdc_state_t *USB_DeviceGetInstanceFromClassHandle(serial_usb_cdc_state_t *head,
211 class_handle_t ClassHandle)
212 {
213 while (NULL != head)
214 {
215 if (head->cdcAcmHandle == ClassHandle)
216 {
217 return head;
218 }
219 head = head->next;
220 }
221 return NULL;
222 }
223
USB_DeviceAddItem(serial_usb_cdc_state_t ** head,serial_usb_cdc_state_t * node)224 static usb_status_t USB_DeviceAddItem(serial_usb_cdc_state_t **head, serial_usb_cdc_state_t *node)
225 {
226 serial_usb_cdc_state_t *p = *head;
227 uint32_t regPrimask;
228
229 regPrimask = DisableGlobalIRQ();
230
231 if (NULL == p)
232 {
233 *head = node;
234 }
235 else
236 {
237 while (NULL != p->next)
238 {
239 if (p == node)
240 {
241 EnableGlobalIRQ(regPrimask);
242 return kStatus_USB_Error;
243 }
244 p = p->next;
245 }
246
247 p->next = node;
248 }
249 node->next = NULL;
250 EnableGlobalIRQ(regPrimask);
251 return kStatus_USB_Success;
252 }
253
USB_DeviceRemoveItem(serial_usb_cdc_state_t ** head,serial_usb_cdc_state_t * node)254 static usb_status_t USB_DeviceRemoveItem(serial_usb_cdc_state_t **head, serial_usb_cdc_state_t *node)
255 {
256 serial_usb_cdc_state_t *p = *head;
257 serial_usb_cdc_state_t *q = NULL;
258 uint32_t regPrimask;
259
260 regPrimask = DisableGlobalIRQ();
261 while (NULL != p)
262 {
263 if (p == node)
264 {
265 if (NULL == q)
266 {
267 *head = p->next;
268 }
269 else
270 {
271 q->next = p->next;
272 }
273 break;
274 }
275 else
276 {
277 q = p;
278 p = p->next;
279 }
280 }
281 EnableGlobalIRQ(regPrimask);
282 return kStatus_USB_Success;
283 }
284
285 /*!
286 * @brief CDC class specific callback function.
287 *
288 * This function handles the CDC class specific requests.
289 *
290 * @param handle The CDC ACM class handle.
291 * @param event The CDC ACM class event type.
292 * @param param The parameter of the class specific request.
293 *
294 * @return A USB error code or kStatus_USB_Success.
295 */
USB_DeviceCdcVcomCallback(class_handle_t handle,uint32_t event,void * param)296 static usb_status_t USB_DeviceCdcVcomCallback(class_handle_t handle, uint32_t event, void *param)
297 {
298 serial_usb_cdc_state_t *serialUsbCdc;
299 uint32_t len;
300 uint8_t *uartBitmap;
301 usb_device_cdc_acm_request_param_struct_t *acmReqParam;
302 usb_device_endpoint_callback_message_struct_t *epCbParam;
303 usb_cdc_acm_info_t *acmInfo = &s_usbCdcAcmInfo;
304 serial_manager_callback_message_t msg;
305 usb_status_t error = kStatus_USB_InvalidRequest;
306
307 serialUsbCdc = USB_DeviceGetInstanceFromClassHandle(s_UsbCdcHead, handle);
308 if (NULL == serialUsbCdc)
309 {
310 return kStatus_USB_InvalidRequest;
311 }
312 acmReqParam = (usb_device_cdc_acm_request_param_struct_t *)param;
313 epCbParam = (usb_device_endpoint_callback_message_struct_t *)param;
314 switch ((usb_device_cdc_acm_event_t)event)
315 {
316 case kUSB_DeviceCdcEventSendResponse:
317 {
318 if (1U == serialUsbCdc->attach)
319 {
320 if ((epCbParam->length != 0U) &&
321 (0U == (epCbParam->length % g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize)))
322 {
323 /* If the last packet is the size of endpoint, then send also zero-ended packet,
324 ** meaning that we want to inform the host that we do not have any additional
325 ** data, so it can flush the output.
326 */
327 error = USB_DeviceCdcAcmSend(handle, (uint8_t)USB_CDC_VCOM_BULK_IN_ENDPOINT, NULL, 0U);
328 }
329 else
330 {
331 serialUsbCdc->tx.busy = 0;
332
333 if ((NULL != serialUsbCdc->tx.callback))
334 {
335 serial_manager_status_t serialManagerStatus = kStatus_SerialManager_Success;
336 msg.buffer = serialUsbCdc->tx.buffer;
337 msg.length = serialUsbCdc->tx.length;
338 error = kStatus_USB_Success;
339 if (USB_UNINITIALIZED_VAL_32 == epCbParam->length)
340 {
341 serialManagerStatus = kStatus_SerialManager_Canceled;
342 }
343 serialUsbCdc->tx.callback(serialUsbCdc->tx.callbackParam, &msg, serialManagerStatus);
344 }
345 }
346 }
347 }
348 break;
349 case kUSB_DeviceCdcEventRecvResponse:
350 {
351 serialUsbCdc->rx.busy = 0U;
352 if ((1U == serialUsbCdc->startTransactions))
353 {
354 serial_manager_status_t callbackStatus = kStatus_SerialManager_Success;
355
356 if ((NULL != serialUsbCdc->rx.callback))
357 {
358 msg.buffer = epCbParam->buffer;
359 msg.length = epCbParam->length;
360 error = kStatus_USB_Success;
361 if (USB_UNINITIALIZED_VAL_32 == msg.length)
362 {
363 msg.length = 0U;
364 callbackStatus = kStatus_SerialManager_Canceled;
365 }
366 serialUsbCdc->rx.callback(serialUsbCdc->rx.callbackParam, &msg, callbackStatus);
367 }
368 }
369 }
370 break;
371 case kUSB_DeviceCdcEventSerialStateNotif:
372 ((usb_device_cdc_acm_struct_t *)handle)->hasSentState = 0;
373 if ((0U != serialUsbCdc->startTransactions) && (0U != serialUsbCdc->tx.waiting4Prime))
374 {
375 serialUsbCdc->tx.waiting4Prime = 0U;
376 serialUsbCdc->tx.busy = 1U;
377 if (kStatus_USB_Success != USB_DeviceCdcAcmSend(serialUsbCdc->cdcAcmHandle,
378 USB_CDC_VCOM_BULK_IN_ENDPOINT, serialUsbCdc->tx.buffer,
379 serialUsbCdc->tx.length))
380 {
381 serialUsbCdc->tx.busy = 0U;
382 }
383 }
384 error = kStatus_USB_Success;
385 break;
386 case kUSB_DeviceCdcEventSendEncapsulatedCommand:
387 break;
388 case kUSB_DeviceCdcEventGetEncapsulatedResponse:
389 break;
390 case kUSB_DeviceCdcEventSetCommFeature:
391 if ((uint16_t)USB_DEVICE_CDC_FEATURE_ABSTRACT_STATE == acmReqParam->setupValue)
392 {
393 if (1U == acmReqParam->isSetup)
394 {
395 *(acmReqParam->buffer) = s_abstractState;
396 *(acmReqParam->length) = sizeof(s_abstractState);
397 }
398 else
399 {
400 /* no action, data phase, s_abstractState has been assigned */
401 }
402 error = kStatus_USB_Success;
403 }
404 else if ((uint16_t)USB_DEVICE_CDC_FEATURE_COUNTRY_SETTING == acmReqParam->setupValue)
405 {
406 if (1U == acmReqParam->isSetup)
407 {
408 *(acmReqParam->buffer) = s_countryCode;
409 *(acmReqParam->length) = sizeof(s_countryCode);
410 }
411 else
412 {
413 /* no action, data phase, s_countryCode has been assigned */
414 }
415 error = kStatus_USB_Success;
416 }
417 else
418 {
419 /* MISRA C-2012 Rule 15.7 */
420 }
421 break;
422 case kUSB_DeviceCdcEventGetCommFeature:
423 if ((uint16_t)USB_DEVICE_CDC_FEATURE_ABSTRACT_STATE == acmReqParam->setupValue)
424 {
425 *(acmReqParam->buffer) = s_abstractState;
426 *(acmReqParam->length) = COMM_FEATURE_DATA_SIZE;
427 error = kStatus_USB_Success;
428 }
429 else if ((uint16_t)USB_DEVICE_CDC_FEATURE_COUNTRY_SETTING == acmReqParam->setupValue)
430 {
431 *(acmReqParam->buffer) = s_countryCode;
432 *(acmReqParam->length) = COMM_FEATURE_DATA_SIZE;
433 error = kStatus_USB_Success;
434 }
435 else
436 {
437 /* MISRA C-2012 Rule 15.7 */
438 }
439 break;
440 case kUSB_DeviceCdcEventClearCommFeature:
441 break;
442 case kUSB_DeviceCdcEventGetLineCoding:
443 *(acmReqParam->buffer) = s_lineCoding;
444 *(acmReqParam->length) = LINE_CODING_SIZE;
445 error = kStatus_USB_Success;
446 break;
447 case kUSB_DeviceCdcEventSetLineCoding:
448 {
449 if (1U == acmReqParam->isSetup)
450 {
451 *(acmReqParam->buffer) = s_lineCoding;
452 *(acmReqParam->length) = sizeof(s_lineCoding);
453 }
454 else
455 {
456 /* no action, data phase, s_lineCoding has been assigned */
457 }
458 }
459 error = kStatus_USB_Success;
460 break;
461 case kUSB_DeviceCdcEventSetControlLineState:
462 {
463 error = kStatus_USB_Success;
464 s_usbCdcAcmInfo.dteStatus = (uint8_t)acmReqParam->setupValue;
465 /* activate/deactivate Tx carrier */
466 if (0U != (acmInfo->dteStatus & (uint8_t)USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION))
467 {
468 acmInfo->uartState |= (uint16_t)USB_DEVICE_CDC_UART_STATE_TX_CARRIER;
469 }
470 else
471 {
472 acmInfo->uartState &= ~((uint16_t)USB_DEVICE_CDC_UART_STATE_TX_CARRIER);
473 }
474
475 /* activate carrier and DTE */
476 if (0U != (acmInfo->dteStatus & (uint8_t)USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE))
477 {
478 acmInfo->uartState |= (uint16_t)USB_DEVICE_CDC_UART_STATE_RX_CARRIER;
479 }
480 else
481 {
482 acmInfo->uartState &= ~((uint16_t)USB_DEVICE_CDC_UART_STATE_RX_CARRIER);
483 }
484
485 /* Indicates to DCE if DTE is present or not */
486 acmInfo->dtePresent =
487 (0U != (acmInfo->dteStatus & (uint8_t)USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE)) ? true : false;
488
489 /* Initialize the serial state buffer */
490 acmInfo->serialStateBuf[0] = NOTIF_REQUEST_TYPE; /* bmRequestType */
491 acmInfo->serialStateBuf[1] = USB_DEVICE_CDC_NOTIF_SERIAL_STATE; /* bNotification */
492 acmInfo->serialStateBuf[2] = 0x00; /* wValue */
493 acmInfo->serialStateBuf[3] = 0x00;
494 acmInfo->serialStateBuf[4] = 0x00; /* wIndex */
495 acmInfo->serialStateBuf[5] = 0x00;
496 acmInfo->serialStateBuf[6] = UART_BITMAP_SIZE; /* wLength */
497 acmInfo->serialStateBuf[7] = 0x00;
498 /* Notifiy to host the line state */
499 acmInfo->serialStateBuf[4] = (uint8_t)acmReqParam->interfaceIndex;
500 /* Lower byte of UART BITMAP */
501 uartBitmap = (uint8_t *)&acmInfo->serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE - 2];
502 uartBitmap[0] = (uint8_t)(acmInfo->uartState & 0xFFu);
503 uartBitmap[1] = (uint8_t)((acmInfo->uartState >> 8) & 0xFFu);
504 len = (uint32_t)NOTIF_PACKET_SIZE + (uint32_t)UART_BITMAP_SIZE;
505 if (0U == ((usb_device_cdc_acm_struct_t *)handle)->hasSentState)
506 {
507 error = USB_DeviceCdcAcmSend(handle, USB_CDC_VCOM_INTERRUPT_IN_ENDPOINT, acmInfo->serialStateBuf, len);
508 if (kStatus_USB_Success != error)
509 {
510 /* MISRA C-2012 Rule 17.2 */
511 /* (void)usb_echo("kUSB_DeviceCdcEventSetControlLineState error!"); */
512 }
513 ((usb_device_cdc_acm_struct_t *)handle)->hasSentState = 1;
514 }
515
516 /* Update status */
517 if (0U != (acmInfo->dteStatus & (uint8_t)USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION))
518 {
519 /* To do: CARRIER_ACTIVATED */
520 }
521 else
522 {
523 /* To do: CARRIER_DEACTIVATED */
524 }
525 if (0U != (acmInfo->dteStatus & (uint8_t)USB_DEVICE_CDC_CONTROL_SIG_BITMAP_DTE_PRESENCE))
526 {
527 /* DTE_ACTIVATED */
528 if (1U == serialUsbCdc->attach)
529 {
530 serialUsbCdc->startTransactions = 1U;
531 }
532 }
533 else
534 {
535 /* DTE_DEACTIVATED */
536 if (1U == serialUsbCdc->attach)
537 {
538 serialUsbCdc->startTransactions = 0U;
539 }
540 }
541 }
542 break;
543 case kUSB_DeviceCdcEventSendBreak:
544 break;
545 default:; /* MISRA C-2012 Rule 16.4 */
546 break;
547 }
548
549 return error;
550 }
551
552 /*!
553 * @brief USB device callback function.
554 *
555 * This function handles the usb device specific requests.
556 *
557 * @param handle The USB device handle.
558 * @param event The USB device event type.
559 * @param param The parameter of the device specific request.
560 *
561 * @return A USB error code or kStatus_USB_Success.
562 */
USB_DeviceCallback(usb_device_handle handle,uint32_t event,void * param)563 static usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param)
564 {
565 serial_usb_cdc_state_t *serialUsbCdc;
566 usb_status_t error = kStatus_USB_InvalidRequest;
567 uint16_t *temp16 = (uint16_t *)param;
568 uint8_t *temp8 = (uint8_t *)param;
569 #if (defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)) || \
570 (defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))
571 usb_status_t usbState;
572 #endif
573
574 serialUsbCdc = USB_DeviceGetInstanceFromDeviceHandle(s_UsbCdcHead, handle);
575 if (NULL == serialUsbCdc)
576 {
577 return kStatus_USB_InvalidRequest;
578 }
579
580 switch ((usb_device_event_t)event)
581 {
582 case kUSB_DeviceEventBusReset:
583 {
584 serialUsbCdc->attach = 0U;
585 serialUsbCdc->startTransactions = 0U;
586 error = kStatus_USB_Success;
587 #if (defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)) || \
588 (defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U))
589 /* Get USB speed to configure the device, including max packet size and interval of the endpoints. */
590 usbState = USB_DeviceClassGetSpeed(serialUsbCdc->instance, &serialUsbCdc->speed);
591 (void)usbState; /* Fix MISRA C-2012 Rule 2.2: declared but never referenced */
592 if (kStatus_USB_Success == usbState)
593 {
594 (void)USB_DeviceSetSpeed(handle, serialUsbCdc->speed);
595 }
596 #endif
597 }
598 break;
599 case kUSB_DeviceEventSetConfiguration:
600 if (NULL != param)
601 {
602 serialUsbCdc->attach = 1U;
603 serialUsbCdc->currentConfiguration = *temp8;
604 if ((uint8_t)USB_CDC_VCOM_CONFIGURE_INDEX == (*temp8))
605 {
606 /* Schedule buffer for receive */
607 (void)Serial_UsbCdcRead(serialUsbCdc, s_currRecvBuf,
608 g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize);
609 error = kStatus_USB_Success;
610 }
611 }
612 break;
613 case kUSB_DeviceEventSetInterface:
614 if (0U != serialUsbCdc->attach)
615 {
616 uint8_t interface = (uint8_t)((*temp16 & 0xFF00U) >> 0x08U);
617 uint8_t alternateSetting = (uint8_t)(*temp16 & 0x00FFU);
618 if (interface < (uint8_t)USB_CDC_VCOM_INTERFACE_COUNT)
619 {
620 serialUsbCdc->currentInterfaceAlternateSetting[interface] = alternateSetting;
621 error = kStatus_USB_Success;
622 }
623 }
624 break;
625 case kUSB_DeviceEventGetConfiguration:
626 break;
627 case kUSB_DeviceEventGetInterface:
628 break;
629 case kUSB_DeviceEventGetDeviceDescriptor:
630 if (NULL != param)
631 {
632 error = USB_DeviceGetDeviceDescriptor(handle, (usb_device_get_device_descriptor_struct_t *)param);
633 }
634 break;
635 case kUSB_DeviceEventGetConfigurationDescriptor:
636 if (NULL != param)
637 {
638 error = USB_DeviceGetConfigurationDescriptor(handle,
639 (usb_device_get_configuration_descriptor_struct_t *)param);
640 }
641 break;
642 case kUSB_DeviceEventGetStringDescriptor:
643 if (NULL != param)
644 {
645 /* Get device string descriptor request */
646 error = USB_DeviceGetStringDescriptor(handle, (usb_device_get_string_descriptor_struct_t *)param);
647 }
648 break;
649 default:
650 /* MISRA C-2012 Rule 16.4 */
651 break;
652 }
653
654 return error;
655 }
656
657 #if (defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U))
658 #ifndef SERIAL_PORT_USB_CDC_USB_OTG2_IRQ_HANDLER_DISABLE
659 void USB_OTG2_IRQHandler(void);
USB_OTG2_IRQHandler(void)660 void USB_OTG2_IRQHandler(void)
661 {
662 serial_usb_cdc_state_t *serialUsbCdc = s_UsbCdcHead;
663
664 while (NULL != serialUsbCdc)
665 {
666 if ((uint8_t)kSerialManager_UsbControllerEhci1 == serialUsbCdc->instance)
667 {
668 USB_DeviceEhciIsrFunction(serialUsbCdc->deviceHandle);
669 }
670 serialUsbCdc = serialUsbCdc->next;
671 }
672 }
673 #endif /* SERIAL_PORT_USB_CDC_USB_OTG2_IRQ_HANDLER_DISABLE */
674 #endif
675
676 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)
677 #ifndef SERIAL_PORT_USB_CDC_USBHS_IRQ_HANDLER_DISABLE
678 void USBHS_IRQHandler(void);
USBHS_IRQHandler(void)679 void USBHS_IRQHandler(void)
680 {
681 serial_usb_cdc_state_t *serialUsbCdc = s_UsbCdcHead;
682
683 while (NULL != serialUsbCdc)
684 {
685 if ((uint8_t)kSerialManager_UsbControllerEhci0 == serialUsbCdc->instance)
686 {
687 USB_DeviceEhciIsrFunction(serialUsbCdc->deviceHandle);
688 }
689 serialUsbCdc = serialUsbCdc->next;
690 }
691 SDK_ISR_EXIT_BARRIER;
692 }
693 #endif /* SERIAL_PORT_USB_CDC_USBHS_IRQ_HANDLER_DISABLE */
694 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 1U)
695 #if defined(FSL_FEATURE_USBHS_EHCI_COUNT) && (FSL_FEATURE_USBHS_EHCI_COUNT > 1U)
696 #ifndef SERIAL_PORT_USB_CDC_USB1_IRQ_HANDLER_DISABLE
697 void USB1_IRQHandler(void);
USB1_IRQHandler(void)698 void USB1_IRQHandler(void)
699 {
700 serial_usb_cdc_state_t *serialUsbCdc = s_UsbCdcHead;
701
702 while (serialUsbCdc)
703 {
704 if ((kSerialManager_UsbControllerEhci1 == serialUsbCdc->instance))
705 {
706 USB_DeviceEhciIsrFunction(serialUsbCdc->deviceHandle);
707 }
708 serialUsbCdc = serialUsbCdc->next;
709 }
710 SDK_ISR_EXIT_BARRIER;
711 }
712 #endif /* SERIAL_PORT_USB_CDC_USB1_IRQ_HANDLER_DISABLE */
713 #endif
714 #endif
715 #endif
716 #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0U)
717 #ifndef SERIAL_PORT_USB_CDC_USB0_IRQ_HANDLER_DISABLE
718 void USB0_IRQHandler(void);
USB0_IRQHandler(void)719 void USB0_IRQHandler(void)
720 {
721 serial_usb_cdc_state_t *serialUsbCdc = s_UsbCdcHead;
722
723 while (NULL != serialUsbCdc)
724 {
725 if (((uint8_t)kSerialManager_UsbControllerKhci0 == serialUsbCdc->instance))
726 {
727 USB_DeviceKhciIsrFunction(serialUsbCdc->deviceHandle);
728 }
729 serialUsbCdc = serialUsbCdc->next;
730 }
731 SDK_ISR_EXIT_BARRIER;
732 }
733 #endif /* SERIAL_PORT_USB_CDC_USB0_IRQ_HANDLER_DISABLE */
734 #endif
735 #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
736 #ifndef SERIAL_PORT_USB_CDC_USB0_IRQ_HANDLER_DISABLE
737 void USB0_IRQHandler(void);
USB0_IRQHandler(void)738 void USB0_IRQHandler(void)
739 {
740 serial_usb_cdc_state_t *serialUsbCdc = s_UsbCdcHead;
741
742 while (NULL != serialUsbCdc)
743 {
744 if (((uint8_t)kSerialManager_UsbControllerLpcIp3511Fs0 == serialUsbCdc->instance))
745 {
746 USB_DeviceLpcIp3511IsrFunction(serialUsbCdc->deviceHandle);
747 }
748 serialUsbCdc = serialUsbCdc->next;
749 }
750 SDK_ISR_EXIT_BARRIER;
751 }
752 #endif /* SERIAL_PORT_USB_CDC_USB0_IRQ_HANDLER_DISABLE */
753 #endif
754 #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
755 #ifndef SERIAL_PORT_USB_CDC_USB1_IRQ_HANDLER_DISABLE
756 void USB1_IRQHandler(void);
USB1_IRQHandler(void)757 void USB1_IRQHandler(void)
758 {
759 serial_usb_cdc_state_t *serialUsbCdc = s_UsbCdcHead;
760
761 while (NULL != serialUsbCdc)
762 {
763 if (((uint8_t)kSerialManager_UsbControllerLpcIp3511Hs0 == serialUsbCdc->instance))
764 {
765 USB_DeviceLpcIp3511IsrFunction(serialUsbCdc->deviceHandle);
766 }
767 serialUsbCdc = serialUsbCdc->next;
768 }
769 SDK_ISR_EXIT_BARRIER;
770 }
771 #endif /* SERIAL_PORT_USB_CDC_USB1_IRQ_HANDLER_DISABLE */
772 #ifndef SERIAL_PORT_USB_CDC_USB_IRQ_HANDLER_DISABLE
773 void USB_IRQHandler(void);
USB_IRQHandler(void)774 void USB_IRQHandler(void)
775 {
776 serial_usb_cdc_state_t *serialUsbCdc = s_UsbCdcHead;
777
778 while (NULL != serialUsbCdc)
779 {
780 if (((uint8_t)kSerialManager_UsbControllerLpcIp3511Hs0 == serialUsbCdc->instance))
781 {
782 USB_DeviceLpcIp3511IsrFunction(serialUsbCdc->deviceHandle);
783 }
784 serialUsbCdc = serialUsbCdc->next;
785 }
786 SDK_ISR_EXIT_BARRIER;
787 }
788 #endif /* SERIAL_PORT_USB_CDC_USB_IRQ_HANDLER_DISABLE */
789 #endif
790
USB_DeviceIsrEnable(serial_usb_cdc_state_t * serialUsbCdc)791 static void USB_DeviceIsrEnable(serial_usb_cdc_state_t *serialUsbCdc)
792 {
793 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U)
794 IRQn_Type usbDeviceEhciIrq[] = USBHS_IRQS;
795 serialUsbCdc->irqNumber =
796 (uint8_t)usbDeviceEhciIrq[serialUsbCdc->instance - (uint8_t)kSerialManager_UsbControllerEhci0];
797 #endif
798
799 #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0U)
800 IRQn_Type usbDeviceKhciIrq[] = USB_IRQS;
801 serialUsbCdc->irqNumber =
802 (uint8_t)usbDeviceKhciIrq[serialUsbCdc->instance - (uint8_t)kSerialManager_UsbControllerKhci0];
803 #endif
804
805 #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
806 IRQn_Type usbDeviceIP3511Irq[] = USB_IRQS;
807 serialUsbCdc->irqNumber =
808 (uint8_t)usbDeviceIP3511Irq[serialUsbCdc->instance - (uint8_t)kSerialManager_UsbControllerLpcIp3511Fs0];
809 #endif
810
811 #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
812 IRQn_Type usbDeviceIP3511Irq[] = USBHSD_IRQS;
813 serialUsbCdc->irqNumber =
814 (uint8_t)usbDeviceIP3511Irq[serialUsbCdc->instance - (uint8_t)kSerialManager_UsbControllerLpcIp3511Hs0];
815 #endif
816
817 /* Install isr, set priority, and enable IRQ. */
818 #if defined(__GIC_PRIO_BITS)
819 GIC_SetPriority((IRQn_Type)serialUsbCdc->irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
820 #else
821 NVIC_SetPriority((IRQn_Type)serialUsbCdc->irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
822 #endif
823 (void)EnableIRQ((IRQn_Type)serialUsbCdc->irqNumber);
824 }
825
Serial_UsbCdcInit(serial_handle_t serialHandle,void * config)826 serial_manager_status_t Serial_UsbCdcInit(serial_handle_t serialHandle, void *config)
827 {
828 serial_usb_cdc_state_t *serialUsbCdc;
829 serial_port_usb_cdc_config_t *usbCdcConfig;
830 usb_status_t usbState;
831
832 assert(config);
833 assert(serialHandle);
834 assert(SERIAL_PORT_USB_CDC_HANDLE_SIZE >= sizeof(serial_usb_cdc_state_t));
835
836 #if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
837 SYSMPU_Enable(SYSMPU, (bool)false);
838 #endif /* FSL_FEATURE_SOC_SYSMPU_COUNT */
839
840 usbCdcConfig = (serial_port_usb_cdc_config_t *)config;
841 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
842
843 serialUsbCdc->speed = USB_SPEED_FULL;
844 serialUsbCdc->instance = (uint8_t)usbCdcConfig->controllerIndex;
845
846 usbState = USB_DeviceClassInit(serialUsbCdc->instance, &s_cdcAcmConfigList, &serialUsbCdc->deviceHandle);
847 if (kStatus_USB_Success != usbState)
848 {
849 return kStatus_SerialManager_Error;
850 }
851 else
852 {
853 serialUsbCdc->cdcAcmHandle = s_cdcAcmConfigList.config->classHandle;
854 }
855
856 (void)USB_DeviceAddItem(&s_UsbCdcHead, serialUsbCdc);
857
858 USB_DeviceIsrEnable(serialUsbCdc);
859
860 /*Add one delay here to make the DP pull down long enough to allow host to detect the previous disconnection.*/
861 SDK_DelayAtLeastUs(5000, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
862 (void)USB_DeviceRun(serialUsbCdc->deviceHandle);
863
864 return kStatus_SerialManager_Success;
865 }
866
Serial_UsbCdcDeinit(serial_handle_t serialHandle)867 serial_manager_status_t Serial_UsbCdcDeinit(serial_handle_t serialHandle)
868 {
869 serial_usb_cdc_state_t *serialUsbCdc;
870 usb_status_t usbState;
871
872 assert(serialHandle);
873
874 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
875
876 usbState = USB_DeviceClassDeinit(serialUsbCdc->instance);
877 if (kStatus_USB_Success != usbState)
878 {
879 return kStatus_SerialManager_Error;
880 }
881 else
882 {
883 (void)USB_DeviceRemoveItem(&s_UsbCdcHead, serialUsbCdc);
884 }
885
886 return kStatus_SerialManager_Success;
887 }
888
Serial_UsbCdcWrite(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)889 serial_manager_status_t Serial_UsbCdcWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
890 {
891 serial_usb_cdc_state_t *serialUsbCdc;
892 uint32_t needToPrime = 0;
893
894 assert(serialHandle);
895
896 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
897
898 if (0U != serialUsbCdc->tx.busy)
899 {
900 return kStatus_SerialManager_Busy;
901 }
902
903 serialUsbCdc->tx.busy = 1U;
904 serialUsbCdc->tx.waiting4Prime = 0U;
905
906 serialUsbCdc->tx.buffer = buffer;
907 serialUsbCdc->tx.length = length;
908
909 if (0U != serialUsbCdc->attach)
910 {
911 needToPrime = 1U;
912 }
913
914 if (0U != needToPrime)
915 {
916 if (kStatus_USB_Success !=
917 USB_DeviceCdcAcmSend(serialUsbCdc->cdcAcmHandle, USB_CDC_VCOM_BULK_IN_ENDPOINT, buffer, length))
918 {
919 serialUsbCdc->tx.busy = 0U;
920 return kStatus_SerialManager_Error;
921 }
922 }
923 else
924 {
925 serialUsbCdc->tx.waiting4Prime = 1;
926 }
927
928 return kStatus_SerialManager_Success;
929 }
930
Serial_UsbCdcRead(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)931 serial_manager_status_t Serial_UsbCdcRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
932 {
933 serial_usb_cdc_state_t *serialUsbCdc;
934 uint8_t *primeBuffer;
935 uint32_t primeLength;
936 uint32_t regPrimask;
937
938 assert(serialHandle);
939
940 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
941
942 if (0U == serialUsbCdc->attach)
943 {
944 return kStatus_SerialManager_Error;
945 }
946
947 regPrimask = DisableGlobalIRQ();
948 if (0U != serialUsbCdc->rx.busy)
949 {
950 EnableGlobalIRQ(regPrimask);
951 return kStatus_SerialManager_Busy;
952 }
953 serialUsbCdc->rx.busy = 1U;
954 EnableGlobalIRQ(regPrimask);
955
956 if (length < g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize)
957 {
958 serialUsbCdc->rx.busy = 0U;
959 return kStatus_SerialManager_Error;
960 }
961
962 if (NULL == buffer)
963 {
964 primeBuffer = s_currRecvBuf;
965 primeLength = g_UsbDeviceCdcVcomDicEndpoints[0].maxPacketSize;
966 }
967 else
968 {
969 primeBuffer = buffer;
970 primeLength = length;
971 }
972 /* Schedule buffer for next receive event */
973
974 if (kStatus_USB_Success !=
975 USB_DeviceCdcAcmRecv(serialUsbCdc->cdcAcmHandle, USB_CDC_VCOM_BULK_OUT_ENDPOINT, primeBuffer, primeLength))
976 {
977 serialUsbCdc->rx.busy = 0U;
978 return kStatus_SerialManager_Error;
979 }
980
981 return kStatus_SerialManager_Success;
982 }
983
Serial_UsbCdcCancelWrite(serial_handle_t serialHandle)984 serial_manager_status_t Serial_UsbCdcCancelWrite(serial_handle_t serialHandle)
985 {
986 serial_usb_cdc_state_t *serialUsbCdc;
987
988 assert(serialHandle);
989
990 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
991 (void)USB_DeviceCancel(serialUsbCdc->deviceHandle, (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT) |
992 (uint8_t)USB_CDC_VCOM_BULK_IN_ENDPOINT);
993 return kStatus_SerialManager_Success;
994 }
995
Serial_UsbCdcInstallTxCallback(serial_handle_t serialHandle,serial_manager_callback_t callback,void * callbackParam)996 serial_manager_status_t Serial_UsbCdcInstallTxCallback(serial_handle_t serialHandle,
997 serial_manager_callback_t callback,
998 void *callbackParam)
999 {
1000 serial_usb_cdc_state_t *serialUsbCdc;
1001
1002 assert(serialHandle);
1003
1004 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
1005
1006 serialUsbCdc->tx.callback = callback;
1007 serialUsbCdc->tx.callbackParam = callbackParam;
1008
1009 return kStatus_SerialManager_Success;
1010 }
1011
Serial_UsbCdcInstallRxCallback(serial_handle_t serialHandle,serial_manager_callback_t callback,void * callbackParam)1012 serial_manager_status_t Serial_UsbCdcInstallRxCallback(serial_handle_t serialHandle,
1013 serial_manager_callback_t callback,
1014 void *callbackParam)
1015 {
1016 serial_usb_cdc_state_t *serialUsbCdc;
1017
1018 assert(serialHandle);
1019
1020 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
1021
1022 serialUsbCdc->rx.callback = callback;
1023 serialUsbCdc->rx.callbackParam = callbackParam;
1024
1025 return kStatus_SerialManager_Success;
1026 }
1027
Serial_UsbCdcGetConnectedStatus(serial_handle_t serialHandle)1028 serial_manager_status_t Serial_UsbCdcGetConnectedStatus(serial_handle_t serialHandle)
1029 {
1030 #if (defined(USB_CDC_SERIAL_MANAGER_RUN_NO_HOST) && (USB_CDC_SERIAL_MANAGER_RUN_NO_HOST == 1))
1031 serial_usb_cdc_state_t *serialUsbCdc;
1032 assert(serialHandle);
1033 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
1034 return ((serialUsbCdc->attach == 1U) && (serialUsbCdc->startTransactions == 1U)) ? kStatus_SerialManager_Success : kStatus_SerialManager_NotConnected;
1035 #else/* USB_CDC_SERIAL_MANAGER_RUN_NO_HOST == 1 */
1036 return kStatus_SerialManager_Success;
1037 #endif
1038 }
1039
Serial_UsbCdcIsrFunction(serial_handle_t serialHandle)1040 void Serial_UsbCdcIsrFunction(serial_handle_t serialHandle)
1041 {
1042 serial_usb_cdc_state_t *serialUsbCdc;
1043
1044 assert(serialHandle);
1045
1046 serialUsbCdc = (serial_usb_cdc_state_t *)serialHandle;
1047
1048 #if 0
1049 DisableIRQ((IRQn_Type)serialUsbCdc->irqNumber);
1050 #endif
1051 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
1052 if (((uint8_t)kSerialManager_UsbControllerEhci0 == serialUsbCdc->instance) ||
1053 ((uint8_t)kSerialManager_UsbControllerEhci1 == serialUsbCdc->instance))
1054 {
1055 USB_DeviceEhciIsrFunction(serialUsbCdc->deviceHandle);
1056 }
1057 #endif
1058 #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
1059 if (((uint8_t)kSerialManager_UsbControllerKhci0 == serialUsbCdc->instance) ||
1060 ((uint8_t)kSerialManager_UsbControllerKhci1 == serialUsbCdc->instance))
1061 {
1062 USB_DeviceKhciIsrFunction(serialUsbCdc->deviceHandle);
1063 }
1064 #endif
1065 #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
1066 if (((uint8_t)kSerialManager_UsbControllerLpcIp3511Fs0 == serialUsbCdc->instance) ||
1067 ((uint8_t)kSerialManager_UsbControllerLpcIp3511Fs1 == serialUsbCdc->instance))
1068 {
1069 USB_DeviceLpcIp3511IsrFunction(serialUsbCdc->deviceHandle);
1070 }
1071 #endif
1072
1073 #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
1074 if (((uint8_t)kSerialManager_UsbControllerLpcIp3511Hs0 == serialUsbCdc->instance) ||
1075 ((uint8_t)kSerialManager_UsbControllerLpcIp3511Hs1 == serialUsbCdc->instance))
1076 {
1077 USB_DeviceLpcIp3511IsrFunction(serialUsbCdc->deviceHandle);
1078 }
1079 #endif
1080 #if 0
1081 EnableIRQ((IRQn_Type)serialUsbCdc->irqNumber);
1082 #endif
1083 }
1084 #endif
1085