serial_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2020 NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __SERIAL_MANAGER_H__
10 #define __SERIAL_MANAGER_H__
11 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
21 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
22 #ifndef SERIAL_MANAGER_NON_BLOCKING_MODE
23 #define SERIAL_MANAGER_NON_BLOCKING_MODE (1U)
24 #endif
25 #else
26 #ifndef SERIAL_MANAGER_NON_BLOCKING_MODE
27 #define SERIAL_MANAGER_NON_BLOCKING_MODE (0U)
28 #endif
29 #endif
30 
32 #ifndef SERIAL_PORT_TYPE_UART
33 #define SERIAL_PORT_TYPE_UART (0U)
34 #endif
35 
37 #ifndef SERIAL_PORT_TYPE_USBCDC
38 #define SERIAL_PORT_TYPE_USBCDC (0U)
39 #endif
40 
42 #ifndef SERIAL_PORT_TYPE_SWO
43 #define SERIAL_PORT_TYPE_SWO (0U)
44 #endif
45 
47 #ifndef SERIAL_PORT_TYPE_USBCDC_VIRTUAL
48 #define SERIAL_PORT_TYPE_USBCDC_VIRTUAL (0U)
49 #endif
50 
52 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
53 #define SERIAL_MANAGER_WRITE_HANDLE_SIZE (44U)
54 #define SERIAL_MANAGER_READ_HANDLE_SIZE (44U)
55 #else
56 #define SERIAL_MANAGER_WRITE_HANDLE_SIZE (4U)
57 #define SERIAL_MANAGER_READ_HANDLE_SIZE (4U)
58 #endif
59 
60 #if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
61 #include "serial_port_uart.h"
62 #endif
63 
64 #if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
65 
66 #if !(defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
67 #error The serial manager blocking mode cannot be supported for USB CDC.
68 #endif
69 
70 #include "serial_port_usb.h"
71 #endif
72 
73 #if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
74 #include "serial_port_swo.h"
75 #endif
76 
77 #if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
78 
79 #if !(defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
80 #error The serial manager blocking mode cannot be supported for USB CDC.
81 #endif
82 
83 #include "serial_port_usb_virtual.h"
84 #endif
85 
86 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP 0U
87 #if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
88 
89 #if (SERIAL_PORT_UART_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
90 #undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
91 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_UART_HANDLE_SIZE
92 #endif
93 
94 #endif
95 
96 #if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
97 
98 #if (SERIAL_PORT_USB_CDC_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
99 #undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
100 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_USB_CDC_HANDLE_SIZE
101 #endif
102 
103 #endif
104 
105 #if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
106 
107 #if (SERIAL_PORT_SWO_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
108 #undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
109 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_SWO_HANDLE_SIZE
110 #endif
111 
112 #endif
113 
114 #if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
115 
116 #if (SERIAL_PORT_USB_VIRTUAL_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
117 #undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
118 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_USB_VIRTUAL_HANDLE_SIZE
119 #endif
120 
121 #endif
122 
124 #if ((defined(SERIAL_MANAGER_HANDLE_SIZE_TEMP) && (SERIAL_MANAGER_HANDLE_SIZE_TEMP > 0U)))
125 #else
126 #error SERIAL_PORT_TYPE_UART, SERIAL_PORT_TYPE_USBCDC, SERIAL_PORT_TYPE_SWO and SERIAL_PORT_TYPE_USBCDC_VIRTUAL should not be cleared at same time.
127 #endif
128 
130 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
131 #define SERIAL_MANAGER_HANDLE_SIZE (SERIAL_MANAGER_HANDLE_SIZE_TEMP + 120U)
132 #else
133 #define SERIAL_MANAGER_HANDLE_SIZE (SERIAL_MANAGER_HANDLE_SIZE_TEMP + 12U)
134 #endif
135 
151 #define SERIAL_MANAGER_HANDLE_DEFINE(name) \
152  uint32_t name[((SERIAL_MANAGER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
153 
169 #define SERIAL_MANAGER_WRITE_HANDLE_DEFINE(name) \
170  uint32_t name[((SERIAL_MANAGER_WRITE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
171 
187 #define SERIAL_MANAGER_READ_HANDLE_DEFINE(name) \
188  uint32_t name[((SERIAL_MANAGER_READ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
189 
191 #ifndef SERIAL_MANAGER_USE_COMMON_TASK
192 #define SERIAL_MANAGER_USE_COMMON_TASK (1U)
193 #endif
194 
196 #ifndef SERIAL_MANAGER_TASK_PRIORITY
197 #define SERIAL_MANAGER_TASK_PRIORITY (2U)
198 #endif
199 
201 #ifndef SERIAL_MANAGER_TASK_STACK_SIZE
202 #define SERIAL_MANAGER_TASK_STACK_SIZE (1000U)
203 #endif
204 
206 typedef void *serial_handle_t;
207 
209 typedef void *serial_write_handle_t;
210 
212 typedef void *serial_read_handle_t;
213 
215 typedef enum _serial_port_type
216 {
222 
225 {
226 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
227  uint8_t *ringBuffer;
230  uint32_t ringBufferSize;
231 #endif
233  void *portConfig;
235 
238 {
250 
253 {
254  uint8_t *buffer;
255  uint32_t length;
257 
259 typedef void (*serial_manager_callback_t)(void *callbackParam,
261  serial_manager_status_t status);
262 
263 /*******************************************************************************
264  * API
265  ******************************************************************************/
266 
267 #if defined(__cplusplus)
268 extern "C" {
269 #endif /* _cplusplus */
270 
332 
344 
393 
403 
438 
448 
468  uint8_t *buffer,
469  uint32_t length);
470 
489 serial_manager_status_t SerialManager_ReadBlocking(serial_read_handle_t readHandle, uint8_t *buffer, uint32_t length);
490 
491 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
492 
511 serial_manager_status_t SerialManager_WriteNonBlocking(serial_write_handle_t writeHandle,
512  uint8_t *buffer,
513  uint32_t length);
514 
534 serial_manager_status_t SerialManager_ReadNonBlocking(serial_read_handle_t readHandle,
535  uint8_t *buffer,
536  uint32_t length);
537 
554 serial_manager_status_t SerialManager_TryRead(serial_read_handle_t readHandle,
555  uint8_t *buffer,
556  uint32_t length,
557  uint32_t *receivedLength);
558 
572 serial_manager_status_t SerialManager_CancelWriting(serial_write_handle_t writeHandle);
573 
588 serial_manager_status_t SerialManager_CancelReading(serial_read_handle_t readHandle);
589 
602 serial_manager_status_t SerialManager_InstallTxCallback(serial_write_handle_t writeHandle,
603  serial_manager_callback_t callback,
604  void *callbackParam);
605 
618 serial_manager_status_t SerialManager_InstallRxCallback(serial_read_handle_t readHandle,
619  serial_manager_callback_t callback,
620  void *callbackParam);
621 
622 #endif
623 
633 
643 
644 #if defined(__cplusplus)
645 }
646 #endif
647 
648 #endif /* __SERIAL_MANAGER_H__ */
_serial_manager_config::portConfig
void * portConfig
Definition: serial_manager.h:233
serial_manager_callback_message_t
struct _serial_manager_callback_message serial_manager_callback_message_t
Callback message structure.
SerialManager_Init
serial_manager_status_t SerialManager_Init(serial_handle_t serialHandle, serial_manager_config_t *config)
Initializes a serial manager module with the serial manager handle and the user configuration structu...
Definition: serial_manager.c:823
serial_manager_status_t
enum _serial_manager_status serial_manager_status_t
serial manager error code
_serial_manager_callback_message::length
uint32_t length
Definition: serial_manager.h:255
kStatus_SerialManager_HandleConflict
@ kStatus_SerialManager_HandleConflict
Definition: serial_manager.h:245
serial_port_type_t
enum _serial_port_type serial_port_type_t
serial port type
kSerialPort_UsbCdcVirtual
@ kSerialPort_UsbCdcVirtual
Definition: serial_manager.h:220
kStatus_SerialManager_NotConnected
@ kStatus_SerialManager_NotConnected
Definition: serial_manager.h:248
_serial_manager_config
serial manager config structure
Definition: serial_manager.h:224
_serial_manager_callback_message::buffer
uint8_t * buffer
Definition: serial_manager.h:254
kStatus_SerialManager_Canceled
@ kStatus_SerialManager_Canceled
Definition: serial_manager.h:243
serial_handle_t
void * serial_handle_t
The handle of the serial manager module.
Definition: serial_manager.h:206
kStatus_SerialManager_Error
@ kStatus_SerialManager_Error
Definition: serial_manager.h:240
kStatus_SerialManager_RingBufferOverflow
@ kStatus_SerialManager_RingBufferOverflow
Definition: serial_manager.h:246
kStatus_SerialManager_Notify
@ kStatus_SerialManager_Notify
Definition: serial_manager.h:242
SerialManager_CloseWriteHandle
serial_manager_status_t SerialManager_CloseWriteHandle(serial_write_handle_t writeHandle)
Closes a writing handle for the serial manager module.
Definition: serial_manager.c:1031
MAKE_STATUS
#define MAKE_STATUS(group, code)
Construct a status code value from a group and code number.
Definition: fsl_common.h:43
kSerialPort_Swo
@ kSerialPort_Swo
Definition: serial_manager.h:219
kStatus_SerialManager_Success
@ kStatus_SerialManager_Success
Definition: serial_manager.h:239
serial_read_handle_t
void * serial_read_handle_t
The read handle of the serial manager module.
Definition: serial_manager.h:212
_serial_manager_callback_message
Callback message structure.
Definition: serial_manager.h:252
SerialManager_ReadBlocking
serial_manager_status_t SerialManager_ReadBlocking(serial_read_handle_t readHandle, uint8_t *buffer, uint32_t length)
Reads data with the blocking mode.
Definition: serial_manager.c:1132
_serial_manager_config::type
serial_port_type_t type
Definition: serial_manager.h:232
SerialManager_OpenWriteHandle
serial_manager_status_t SerialManager_OpenWriteHandle(serial_handle_t serialHandle, serial_write_handle_t writeHandle)
Opens a writing handle for the serial manager module.
Definition: serial_manager.c:1004
kSerialPort_Uart
@ kSerialPort_Uart
Definition: serial_manager.h:217
kStatusGroup_SERIALMANAGER
@ kStatusGroup_SERIALMANAGER
Definition: fsl_common.h:155
serial_port_uart.h
_serial_port_type
_serial_port_type
serial port type
Definition: serial_manager.h:215
SerialManager_EnterLowpower
serial_manager_status_t SerialManager_EnterLowpower(serial_handle_t serialHandle)
Prepares to enter low power consumption.
Definition: serial_manager.c:1325
SerialManager_OpenReadHandle
serial_manager_status_t SerialManager_OpenReadHandle(serial_handle_t serialHandle, serial_read_handle_t readHandle)
Opens a reading handle for the serial manager module.
Definition: serial_manager.c:1062
kStatus_SerialManager_Busy
@ kStatus_SerialManager_Busy
Definition: serial_manager.h:241
kSerialPort_UsbCdc
@ kSerialPort_UsbCdc
Definition: serial_manager.h:218
serial_write_handle_t
void * serial_write_handle_t
The write handle of the serial manager module.
Definition: serial_manager.h:209
serial_manager_callback_t
void(* serial_manager_callback_t)(void *callbackParam, serial_manager_callback_message_t *message, serial_manager_status_t status)
callback function
Definition: serial_manager.h:259
_serial_manager_status
_serial_manager_status
serial manager error code
Definition: serial_manager.h:237
SerialManager_Deinit
serial_manager_status_t SerialManager_Deinit(serial_handle_t serialHandle)
De-initializes the serial manager module instance.
Definition: serial_manager.c:944
SerialManager_WriteBlocking
serial_manager_status_t SerialManager_WriteBlocking(serial_write_handle_t writeHandle, uint8_t *buffer, uint32_t length)
Transmits data with the blocking mode.
Definition: serial_manager.c:1123
SerialManager_CloseReadHandle
serial_manager_status_t SerialManager_CloseReadHandle(serial_read_handle_t readHandle)
Closes a reading for the serial manager module.
Definition: serial_manager.c:1094
config
static sai_transceiver_t config
Definition: imxrt1050/imxrt1050-evkb/source/pv_audio_rec.c:75
serial_manager_config_t
struct _serial_manager_config serial_manager_config_t
serial manager config structure
SerialManager_ExitLowpower
serial_manager_status_t SerialManager_ExitLowpower(serial_handle_t serialHandle)
Restores from low power consumption.
Definition: serial_manager.c:1360
kStatus_Success
@ kStatus_Success
Definition: fsl_common.h:179


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:50