]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/NXP_Code/component/serial_manager/serial_manager.h
539864d8ea7fc3945ca03c2de6c424b6dfabb776
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso / NXP_Code / component / serial_manager / serial_manager.h
1 /*\r
2  * Copyright 2018 NXP\r
3  * All rights reserved.\r
4  *\r
5  *\r
6  * SPDX-License-Identifier: BSD-3-Clause\r
7  */\r
8 \r
9 #ifndef __SERIAL_MANAGER_H__\r
10 #define __SERIAL_MANAGER_H__\r
11 \r
12 /*******************************************************************************\r
13  * Definitions\r
14  ******************************************************************************/\r
15 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING\r
16 #define SERIAL_MANAGER_NON_BLOCKING_MODE \\r
17     (1U) /* Enable or disable serial manager non-blocking mode (1 - enable, 0 - disable) */\r
18 #else\r
19 #ifndef SERIAL_MANAGER_NON_BLOCKING_MODE\r
20 #define SERIAL_MANAGER_NON_BLOCKING_MODE \\r
21     (0U) /* Enable or disable serial manager non-blocking mode (1 - enable, 0 - disable) */\r
22 #endif\r
23 #endif\r
24 \r
25 #ifndef SERIAL_PORT_TYPE_UART\r
26 #define SERIAL_PORT_TYPE_UART (1U) /* Enable or disable uart port (1 - enable, 0 - disable) */\r
27 #endif\r
28 \r
29 #ifndef SERIAL_PORT_TYPE_USBCDC\r
30 #define SERIAL_PORT_TYPE_USBCDC (0U) /* Enable or disable USB CDC port (1 - enable, 0 - disable) */\r
31 #endif\r
32 \r
33 #ifndef SERIAL_PORT_TYPE_SWO\r
34 #define SERIAL_PORT_TYPE_SWO (0U) /* Enable or disable SWO port (1 - enable, 0 - disable) */\r
35 #endif\r
36 \r
37 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))\r
38 #define SERIAL_MANAGER_WRITE_HANDLE_SIZE (44U)\r
39 #define SERIAL_MANAGER_READ_HANDLE_SIZE (44U)\r
40 #else\r
41 #define SERIAL_MANAGER_WRITE_HANDLE_SIZE (4U)\r
42 #define SERIAL_MANAGER_READ_HANDLE_SIZE (4U)\r
43 #endif\r
44 \r
45 #if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))\r
46 #include "serial_port_uart.h"\r
47 #endif\r
48 \r
49 #if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))\r
50 \r
51 #if !(defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))\r
52 #error The serial manager blocking mode cannot be supported for USB CDC.\r
53 #endif\r
54 \r
55 #include "serial_port_usb.h"\r
56 #endif\r
57 \r
58 #if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))\r
59 #include "serial_port_swo.h"\r
60 #endif\r
61 \r
62 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP 0U\r
63 #if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))\r
64 \r
65 #if (SERIAL_PORT_UART_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)\r
66 #undef SERIAL_MANAGER_HANDLE_SIZE_TEMP\r
67 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_UART_HANDLE_SIZE\r
68 #endif\r
69 \r
70 #endif\r
71 \r
72 #if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))\r
73 \r
74 #if (SERIAL_PORT_USB_CDC_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)\r
75 #undef SERIAL_MANAGER_HANDLE_SIZE_TEMP\r
76 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_USB_CDC_HANDLE_SIZE\r
77 #endif\r
78 \r
79 #endif\r
80 \r
81 #if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))\r
82 \r
83 #if (SERIAL_PORT_SWO_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)\r
84 #undef SERIAL_MANAGER_HANDLE_SIZE_TEMP\r
85 #define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_SWO_HANDLE_SIZE\r
86 #endif\r
87 \r
88 #endif\r
89 \r
90 /* SERIAL_PORT_UART_HANDLE_SIZE/SERIAL_PORT_USB_CDC_HANDLE_SIZE + serial manager dedicated size */\r
91 #if ((defined(SERIAL_MANAGER_HANDLE_SIZE_TEMP) && (SERIAL_MANAGER_HANDLE_SIZE_TEMP > 0U)))\r
92 #else\r
93 #error SERIAL_PORT_TYPE_UART, SERIAL_PORT_TYPE_USBCDC and SERIAL_PORT_TYPE_SWO should not be cleared at same time.\r
94 #endif\r
95 \r
96 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))\r
97 #define SERIAL_MANAGER_HANDLE_SIZE (SERIAL_MANAGER_HANDLE_SIZE_TEMP + 120U)\r
98 #else\r
99 #define SERIAL_MANAGER_HANDLE_SIZE (SERIAL_MANAGER_HANDLE_SIZE_TEMP + 12U)\r
100 #endif\r
101 \r
102 #define SERIAL_MANAGER_USE_COMMON_TASK (1U)\r
103 #define SERIAL_MANAGER_TASK_PRIORITY (2U)\r
104 #define SERIAL_MANAGER_TASK_STACK_SIZE (1000U)\r
105 \r
106 typedef void *serial_handle_t;\r
107 typedef void *serial_write_handle_t;\r
108 typedef void *serial_read_handle_t;\r
109 \r
110 typedef enum _serial_port_type\r
111 {\r
112     kSerialPort_Uart = 1U, /*!< Serial port UART */\r
113     kSerialPort_UsbCdc,    /*!< Serial port USB CDC */\r
114     kSerialPort_Swo,       /*!< Serial port SWO */\r
115 } serial_port_type_t;\r
116 \r
117 typedef struct _serial_manager_config\r
118 {\r
119     uint8_t *ringBuffer;     /*!< Ring buffer address, it is used to buffer data received by the hardware.\r
120                                   Besides, the memory space cannot be free during the lifetime of the serial\r
121                                   manager module. */\r
122     uint32_t ringBufferSize; /*!< The size of the ring buffer */\r
123     serial_port_type_t type; /*!< Serial port type */\r
124     void *portConfig;        /*!< Serial port configuration */\r
125 } serial_manager_config_t;\r
126 \r
127 typedef enum _serial_manager_status\r
128 {\r
129     kStatus_SerialManager_Success = kStatus_Success,                           /*!< Success */\r
130     kStatus_SerialManager_Error = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 1),  /*!< Failed */\r
131     kStatus_SerialManager_Busy = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 2),   /*!< Busy */\r
132     kStatus_SerialManager_Notify = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 3), /*!< Ring buffer is not empty */\r
133     kStatus_SerialManager_Canceled =\r
134         MAKE_STATUS(kStatusGroup_SERIALMANAGER, 4), /*!< the non-blocking request is canceled */\r
135     kStatus_SerialManager_HandleConflict = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 5), /*!< The handle is opened */\r
136     kStatus_SerialManager_RingBufferOverflow =\r
137         MAKE_STATUS(kStatusGroup_SERIALMANAGER, 6), /*!< The ring buffer is overflowed */\r
138 } serial_manager_status_t;\r
139 \r
140 /*! @brief Callback message structure */\r
141 typedef struct _serial_manager_callback_message\r
142 {\r
143     uint8_t *buffer; /*!< Transferred buffer */\r
144     uint32_t length; /*!< Transferred data length */\r
145 } serial_manager_callback_message_t;\r
146 \r
147 /*! @brief callback function */\r
148 typedef void (*serial_manager_callback_t)(void *callbackParam,\r
149                                           serial_manager_callback_message_t *message,\r
150                                           serial_manager_status_t status);\r
151 \r
152 /*******************************************************************************\r
153  * API\r
154  ******************************************************************************/\r
155 \r
156 #if defined(__cplusplus)\r
157 extern "C" {\r
158 #endif /* _cplusplus */\r
159 \r
160 /*!\r
161  * @brief Initializes a serial manager module with the serial manager handle and the user configuration structure.\r
162  *\r
163  * This function configures the serial manager module with user-defined settings. The user can configure the\r
164  * configuration\r
165  * structure. The parameter serialHandle is a pointer to point to a memory space of size #SERIAL_MANAGER_HANDLE_SIZE\r
166  * allocated by the caller.\r
167  * The serial manager module supports two types serial port, uart (includes UART, USART, LPSCI, LPUART, etc) and USB\r
168  * CDC.\r
169  * Please refer to #serial_port_type_t for serial port setting. These two types can be set by using\r
170  * #serial_manager_config_t.\r
171  *\r
172  * Example below shows how to use this API to configure the serial manager.\r
173  * For UART,\r
174  *  @code\r
175  *   #define SERIAL_MANAGER_RING_BUFFER_SIZE          (256U)\r
176  *   static uint8_t s_serialHandleBuffer[SERIAL_MANAGER_HANDLE_SIZE];\r
177  *   static serial_handle_t s_serialHandle = &s_serialHandleBuffer[0];\r
178  *   static uint8_t s_ringBuffer[SERIAL_MANAGER_RING_BUFFER_SIZE];\r
179  *\r
180  *   serial_manager_config_t config;\r
181  *   serial_port_uart_config_t uartConfig;\r
182  *   config.type = kSerialPort_Uart;\r
183  *   config.ringBuffer = &s_ringBuffer[0];\r
184  *   config.ringBufferSize = SERIAL_MANAGER_RING_BUFFER_SIZE;\r
185  *   uartConfig.instance = 0;\r
186  *   uartConfig.clockRate = 24000000;\r
187  *   uartConfig.baudRate = 115200;\r
188  *   uartConfig.parityMode = kSerialManager_UartParityDisabled;\r
189  *   uartConfig.stopBitCount = kSerialManager_UartOneStopBit;\r
190  *   uartConfig.enableRx = 1;\r
191  *   uartConfig.enableTx = 1;\r
192  *   config.portConfig = &uartConfig;\r
193  *   SerialManager_Init(s_serialHandle, &config);\r
194  *  @endcode\r
195  * For USB CDC,\r
196  *  @code\r
197  *   #define SERIAL_MANAGER_RING_BUFFER_SIZE          (256U)\r
198  *   static uint8_t s_serialHandleBuffer[SERIAL_MANAGER_HANDLE_SIZE];\r
199  *   static serial_handle_t s_serialHandle = &s_serialHandleBuffer[0];\r
200  *   static uint8_t s_ringBuffer[SERIAL_MANAGER_RING_BUFFER_SIZE];\r
201  *\r
202  *   serial_manager_config_t config;\r
203  *   serial_port_usb_cdc_config_t usbCdcConfig;\r
204  *   config.type = kSerialPort_UsbCdc;\r
205  *   config.ringBuffer = &s_ringBuffer[0];\r
206  *   config.ringBufferSize = SERIAL_MANAGER_RING_BUFFER_SIZE;\r
207  *   usbCdcConfig.controllerIndex = kSerialManager_UsbControllerKhci0;\r
208  *   config.portConfig = &usbCdcConfig;\r
209  *   SerialManager_Init(s_serialHandle, &config);\r
210  *  @endcode\r
211  *\r
212  * @param serialHandle Pointer to point to a memory space of size #SERIAL_MANAGER_HANDLE_SIZE allocated by the caller.\r
213  * @param config Pointer to user-defined configuration structure.\r
214  * @retval kStatus_SerialManager_Error An error occurred.\r
215  * @retval kStatus_SerialManager_Success The serial manager module initialization succeed.\r
216  */\r
217 serial_manager_status_t SerialManager_Init(serial_handle_t serialHandle, serial_manager_config_t *config);\r
218 \r
219 /*!\r
220  * @brief De-initializes the serial manager module instance.\r
221  *\r
222  * This function de-initializes the serial manager module instance. If the opened writing or\r
223  * reading handle is not closed, the function will return kStatus_SerialManager_Busy.\r
224  *\r
225  * @param serialHandle The serial manager module handle pointer.\r
226  * @retval kStatus_SerialManager_Success The serial manager de-initialization succeed.\r
227  * @retval kStatus_SerialManager_Busy Opened reading or writing handle is not closed.\r
228  */\r
229 serial_manager_status_t SerialManager_Deinit(serial_handle_t serialHandle);\r
230 \r
231 /*!\r
232  * @brief Opens a writing handle for the serial manager module.\r
233  *\r
234  * This function Opens a writing handle for the serial manager module. If the serial manager needs to\r
235  * be used in different tasks, the task should open a dedicated write handle for itself by calling\r
236  * #SerialManager_OpenWriteHandle. Since there can only one buffer for transmission for the writing\r
237  * handle at the same time, multiple writing handles need to be opened when the multiple transmission\r
238  * is needed for a task.\r
239  *\r
240  * @param serialHandle The serial manager module handle pointer.\r
241  * @param writeHandle The serial manager module writing handle pointer.\r
242  * @retval kStatus_SerialManager_Error An error occurred.\r
243  * @retval kStatus_SerialManager_HandleConflict The writing handle was opened.\r
244  * @retval kStatus_SerialManager_Success The writing handle is opened.\r
245  *\r
246  * Example below shows how to use this API to write data.\r
247  * For task 1,\r
248  *  @code\r
249  *   static uint8_t s_serialWriteHandleBuffer1[SERIAL_MANAGER_WRITE_HANDLE_SIZE];\r
250  *   static serial_write_handle_t s_serialWriteHandle1 = &s_serialWriteHandleBuffer1[0];\r
251  *   static uint8_t s_nonBlockingWelcome1[] = "This is non-blocking writing log for task1!\r\n";\r
252  *   SerialManager_OpenWriteHandle(serialHandle, s_serialWriteHandle1);\r
253  *   SerialManager_InstallTxCallback(s_serialWriteHandle1, Task1_SerialManagerTxCallback, s_serialWriteHandle1);\r
254  *   SerialManager_WriteNonBlocking(s_serialWriteHandle1, s_nonBlockingWelcome1, sizeof(s_nonBlockingWelcome1) - 1);\r
255  *  @endcode\r
256  * For task 2,\r
257  *  @code\r
258  *   static uint8_t s_serialWriteHandleBuffer2[SERIAL_MANAGER_WRITE_HANDLE_SIZE];\r
259  *   static serial_write_handle_t s_serialWriteHandle2 = &s_serialWriteHandleBuffer2[0];\r
260  *   static uint8_t s_nonBlockingWelcome2[] = "This is non-blocking writing log for task2!\r\n";\r
261  *   SerialManager_OpenWriteHandle(serialHandle, s_serialWriteHandle2);\r
262  *   SerialManager_InstallTxCallback(s_serialWriteHandle2, Task2_SerialManagerTxCallback, s_serialWriteHandle2);\r
263  *   SerialManager_WriteNonBlocking(s_serialWriteHandle2, s_nonBlockingWelcome2, sizeof(s_nonBlockingWelcome2) - 1);\r
264  *  @endcode\r
265  */\r
266 serial_manager_status_t SerialManager_OpenWriteHandle(serial_handle_t serialHandle, serial_write_handle_t writeHandle);\r
267 \r
268 /*!\r
269  * @brief Closes a writing handle for the serial manager module.\r
270  *\r
271  * This function Closes a writing handle for the serial manager module.\r
272  *\r
273  * @param writeHandle The serial manager module writing handle pointer.\r
274  * @retval kStatus_SerialManager_Success The writing handle is closed.\r
275  */\r
276 serial_manager_status_t SerialManager_CloseWriteHandle(serial_write_handle_t writeHandle);\r
277 \r
278 /*!\r
279  * @brief Opens a reading handle for the serial manager module.\r
280  *\r
281  * This function Opens a reading handle for the serial manager module. The reading handle can not be\r
282  * opened multiple at the same time. The error code kStatus_SerialManager_Busy would be returned when\r
283  * the previous reading handle is not closed. And There can only one buffer for receiving for the\r
284  * reading handle at the same time.\r
285  *\r
286  * @param serialHandle The serial manager module handle pointer.\r
287  * @param readHandle The serial manager module reading handle pointer.\r
288  * @retval kStatus_SerialManager_Error An error occurred.\r
289  * @retval kStatus_SerialManager_Success The reading handle is opened.\r
290  * @retval kStatus_SerialManager_Busy Previous reading handle is not closed.\r
291  *\r
292  * Example below shows how to use this API to read data.\r
293  *  @code\r
294  *   static uint8_t s_serialReadHandleBuffer[SERIAL_MANAGER_READ_HANDLE_SIZE];\r
295  *   static serial_read_handle_t s_serialReadHandle = &s_serialReadHandleBuffer[0];\r
296  *   SerialManager_OpenReadHandle(serialHandle, s_serialReadHandle);\r
297  *   static uint8_t s_nonBlockingBuffer[64];\r
298  *   SerialManager_InstallRxCallback(s_serialReadHandle, APP_SerialManagerRxCallback, s_serialReadHandle);\r
299  *   SerialManager_ReadNonBlocking(s_serialReadHandle, s_nonBlockingBuffer, sizeof(s_nonBlockingBuffer));\r
300  *  @endcode\r
301  */\r
302 serial_manager_status_t SerialManager_OpenReadHandle(serial_handle_t serialHandle, serial_read_handle_t readHandle);\r
303 \r
304 /*!\r
305  * @brief Closes a reading for the serial manager module.\r
306  *\r
307  * This function Closes a reading for the serial manager module.\r
308  *\r
309  * @param readHandle The serial manager module reading handle pointer.\r
310  * @retval kStatus_SerialManager_Success The reading handle is closed.\r
311  */\r
312 serial_manager_status_t SerialManager_CloseReadHandle(serial_read_handle_t readHandle);\r
313 \r
314 /*!\r
315  * @brief Transmits data with the blocking mode.\r
316  *\r
317  * This is a blocking function, which polls the sending queue, waits for the sending queue to be empty.\r
318  * This function sends data using an interrupt method. The interrupt of the hardware could not be disabled.\r
319  * And There can only one buffer for transmission for the writing handle at the same time.\r
320  *\r
321  * @note The function #SerialManager_WriteBlocking and the function #SerialManager_WriteNonBlocking\r
322  * cannot be used at the same time.\r
323  * And, the function #SerialManager_CancelWriting cannot be used to abort the transmission of this function.\r
324  *\r
325  * @param writeHandle The serial manager module handle pointer.\r
326  * @param buffer Start address of the data to write.\r
327  * @param length Length of the data to write.\r
328  * @retval kStatus_SerialManager_Success Successfully sent all data.\r
329  * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all sent yet.\r
330  * @retval kStatus_SerialManager_Error An error occurred.\r
331  */\r
332 serial_manager_status_t SerialManager_WriteBlocking(serial_write_handle_t writeHandle,\r
333                                                     uint8_t *buffer,\r
334                                                     uint32_t length);\r
335 \r
336 /*!\r
337  * @brief Reads data with the blocking mode.\r
338  *\r
339  * This is a blocking function, which polls the receiving buffer, waits for the receiving buffer to be full.\r
340  * This function receives data using an interrupt method. The interrupt of the hardware could not be disabled.\r
341  * And There can only one buffer for receiving for the reading handle at the same time.\r
342  *\r
343  * @note The function #SerialManager_ReadBlocking and the function #SerialManager_ReadNonBlocking\r
344  * cannot be used at the same time.\r
345  * And, the function #SerialManager_CancelReading cannot be used to abort the transmission of this function.\r
346  *\r
347  * @param readHandle The serial manager module handle pointer.\r
348  * @param buffer Start address of the data to store the received data.\r
349  * @param length The length of the data to be received.\r
350  * @retval kStatus_SerialManager_Success Successfully received all data.\r
351  * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all received yet.\r
352  * @retval kStatus_SerialManager_Error An error occurred.\r
353  */\r
354 serial_manager_status_t SerialManager_ReadBlocking(serial_read_handle_t readHandle, uint8_t *buffer, uint32_t length);\r
355 \r
356 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))\r
357 /*!\r
358  * @brief Transmits data with the non-blocking mode.\r
359  *\r
360  * This is a non-blocking function, which returns directly without waiting for all data to be sent.\r
361  * When all data is sent, the module notifies the upper layer through a TX callback function and passes\r
362  * the status parameter @ref kStatus_SerialManager_Success.\r
363  * This function sends data using an interrupt method. The interrupt of the hardware could not be disabled.\r
364  * And There can only one buffer for transmission for the writing handle at the same time.\r
365  *\r
366  * @note The function #SerialManager_WriteBlocking and the function #SerialManager_WriteNonBlocking\r
367  * cannot be used at the same time. And, the TX callback is mandatory before the function could be used.\r
368  *\r
369  * @param writeHandle The serial manager module handle pointer.\r
370  * @param buffer Start address of the data to write.\r
371  * @param length Length of the data to write.\r
372  * @retval kStatus_SerialManager_Success Successfully sent all data.\r
373  * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all sent yet.\r
374  * @retval kStatus_SerialManager_Error An error occurred.\r
375  */\r
376 serial_manager_status_t SerialManager_WriteNonBlocking(serial_write_handle_t writeHandle,\r
377                                                        uint8_t *buffer,\r
378                                                        uint32_t length);\r
379 \r
380 /*!\r
381  * @brief Reads data with the non-blocking mode.\r
382  *\r
383  * This is a non-blocking function, which returns directly without waiting for all data to be received.\r
384  * When all data is received, the module driver notifies the upper layer\r
385  * through a RX callback function and passes the status parameter @ref kStatus_SerialManager_Success.\r
386  * This function receives data using an interrupt method. The interrupt of the hardware could not be disabled.\r
387  * And There can only one buffer for receiving for the reading handle at the same time.\r
388  *\r
389  * @note The function #SerialManager_ReadBlocking and the function #SerialManager_ReadNonBlocking\r
390  * cannot be used at the same time. And, the RX callback is mandatory before the function could be used.\r
391  *\r
392  * @param readHandle The serial manager module handle pointer.\r
393  * @param buffer Start address of the data to store the received data.\r
394  * @param length The length of the data to be received.\r
395  * @retval kStatus_SerialManager_Success Successfully received all data.\r
396  * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all received yet.\r
397  * @retval kStatus_SerialManager_Error An error occurred.\r
398  */\r
399 serial_manager_status_t SerialManager_ReadNonBlocking(serial_read_handle_t readHandle,\r
400                                                       uint8_t *buffer,\r
401                                                       uint32_t length);\r
402 \r
403 /*!\r
404  * @brief Tries to read data.\r
405  *\r
406  * The function tries to read data from internal ring buffer. If the ring buffer is not empty, the data will be\r
407  * copied from ring buffer to up layer buffer. The copied length is the minimum of the ring buffer and up layer length.\r
408  * After the data is copied, the actual data length is passed by the parameter length.\r
409  * And There can only one buffer for receiving for the reading handle at the same time.\r
410  *\r
411  * @param readHandle The serial manager module handle pointer.\r
412  * @param buffer Start address of the data to store the received data.\r
413  * @param length The length of the data to be received.\r
414  * @param receivedLength Length received from the ring buffer directly.\r
415  * @retval kStatus_SerialManager_Success Successfully received all data.\r
416  * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all received yet.\r
417  * @retval kStatus_SerialManager_Error An error occurred.\r
418  */\r
419 serial_manager_status_t SerialManager_TryRead(serial_read_handle_t readHandle,\r
420                                               uint8_t *buffer,\r
421                                               uint32_t length,\r
422                                               uint32_t *receivedLength);\r
423 \r
424 /*!\r
425  * @brief Cancels unfinished send transmission.\r
426  *\r
427  * The function cancels unfinished send transmission. When the transfer is canceled, the module notifies the upper layer\r
428  * through a TX callback function and passes the status parameter @ref kStatus_SerialManager_Canceled.\r
429  *\r
430  * @note The function #SerialManager_CancelWriting cannot be used to abort the transmission of\r
431  * the function #SerialManager_WriteBlocking.\r
432  *\r
433  * @param writeHandle The serial manager module handle pointer.\r
434  * @retval kStatus_SerialManager_Success Get successfully abort the sending.\r
435  * @retval kStatus_SerialManager_Error An error occurred.\r
436  */\r
437 serial_manager_status_t SerialManager_CancelWriting(serial_write_handle_t writeHandle);\r
438 \r
439 /*!\r
440  * @brief Cancels unfinished receive transmission.\r
441  *\r
442  * The function cancels unfinished receive transmission. When the transfer is canceled, the module notifies the upper\r
443  * layer\r
444  * through a RX callback function and passes the status parameter @ref kStatus_SerialManager_Canceled.\r
445  *\r
446  * @note The function #SerialManager_CancelReading cannot be used to abort the transmission of\r
447  * the function #SerialManager_ReadBlocking.\r
448  *\r
449  * @param readHandle The serial manager module handle pointer.\r
450  * @retval kStatus_SerialManager_Success Get successfully abort the receiving.\r
451  * @retval kStatus_SerialManager_Error An error occurred.\r
452  */\r
453 serial_manager_status_t SerialManager_CancelReading(serial_read_handle_t readHandle);\r
454 \r
455 /*!\r
456  * @brief Installs a TX callback and callback parameter.\r
457  *\r
458  * This function is used to install the TX callback and callback parameter for the serial manager module.\r
459  * When any status of TX transmission changed, the driver will notify the upper layer by the installed callback\r
460  * function. And the status is also passed as status parameter when the callback is called.\r
461  *\r
462  * @param writeHandle The serial manager module handle pointer.\r
463  * @param callback The callback function.\r
464  * @param callbackParam The parameter of the callback function.\r
465  * @retval kStatus_SerialManager_Success Successfully install the callback.\r
466  */\r
467 serial_manager_status_t SerialManager_InstallTxCallback(serial_write_handle_t writeHandle,\r
468                                                         serial_manager_callback_t callback,\r
469                                                         void *callbackParam);\r
470 \r
471 /*!\r
472  * @brief Installs a RX callback and callback parameter.\r
473  *\r
474  * This function is used to install the RX callback and callback parameter for the serial manager module.\r
475  * When any status of RX transmission changed, the driver will notify the upper layer by the installed callback\r
476  * function. And the status is also passed as status parameter when the callback is called.\r
477  *\r
478  * @param readHandle The serial manager module handle pointer.\r
479  * @param callback The callback function.\r
480  * @param callbackParam The parameter of the callback function.\r
481  * @retval kStatus_SerialManager_Success Successfully install the callback.\r
482  */\r
483 serial_manager_status_t SerialManager_InstallRxCallback(serial_read_handle_t readHandle,\r
484                                                         serial_manager_callback_t callback,\r
485                                                         void *callbackParam);\r
486 \r
487 #endif\r
488 \r
489 /*!\r
490  * @brief Prepares to enter low power consumption.\r
491  *\r
492  * This function is used to prepare to enter low power consumption.\r
493  *\r
494  * @param serialHandle The serial manager module handle pointer.\r
495  * @retval kStatus_SerialManager_Success Successful operation.\r
496  */\r
497 serial_manager_status_t SerialManager_EnterLowpower(serial_handle_t serialHandle);\r
498 \r
499 /*!\r
500  * @brief Restores from low power consumption.\r
501  *\r
502  * This function is used to restore from low power consumption.\r
503  *\r
504  * @param serialHandle The serial manager module handle pointer.\r
505  * @retval kStatus_SerialManager_Success Successful operation.\r
506  */\r
507 serial_manager_status_t SerialManager_ExitLowpower(serial_handle_t serialHandle);\r
508 \r
509 #if defined(__cplusplus)\r
510 }\r
511 #endif\r
512 \r
513 #endif /* __SERIAL_MANAGER_H__ */\r