fsl_debug_console.c
Go to the documentation of this file.
1 /*
2  * This is a modified version of the file printf.c, which was distributed
3  * by Motorola as part of the M5407C3BOOT.zip package used to initialize
4  * the M5407C3 evaluation board.
5  *
6  * Copyright:
7  * 1999-2000 MOTOROLA, INC. All Rights Reserved.
8  * You are hereby granted a copyright license to use, modify, and
9  * distribute the SOFTWARE so long as this entire notice is
10  * retained without alteration in any modified and/or redistributed
11  * versions, and that such modified versions are clearly identified
12  * as such. No licenses are granted by implication, estoppel or
13  * otherwise under any patents or trademarks of Motorola, Inc. This
14  * software is provided on an "AS IS" basis and without warranty.
15  *
16  * To the maximum extent permitted by applicable law, MOTOROLA
17  * DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED, INCLUDING
18  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
19  * PURPOSE AND ANY WARRANTY AGAINST INFRINGEMENT WITH REGARD TO THE
20  * SOFTWARE (INCLUDING ANY MODIFIED VERSIONS THEREOF) AND ANY
21  * ACCOMPANYING WRITTEN MATERIALS.
22  *
23  * To the maximum extent permitted by applicable law, IN NO EVENT
24  * SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING
25  * WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS
26  * INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY
27  * LOSS) ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
28  *
29  * Motorola assumes no responsibility for the maintenance and support
30  * of this software
31 
32  * Copyright (c) 2015, Freescale Semiconductor, Inc.
33  * Copyright 2016-2019 NXP
34  *
35  * SPDX-License-Identifier: BSD-3-Clause
36  */
37 
38 #include <stdarg.h>
39 #include <stdlib.h>
40 #if defined(__CC_ARM) || defined(__ARMCC_VERSION)
41 #include <stdio.h>
42 #endif
43 
44 #ifdef FSL_RTOS_FREE_RTOS
45 #include "FreeRTOS.h"
46 #include "semphr.h"
47 #include "task.h"
48 #endif
49 
50 #include "fsl_debug_console_conf.h"
51 #include "fsl_str.h"
52 
53 #include "fsl_common.h"
54 #include "serial_manager.h"
55 
56 #include "fsl_debug_console.h"
57 
58 /*******************************************************************************
59  * Definitions
60  ******************************************************************************/
61 #ifndef NDEBUG
62 #if (defined(DEBUG_CONSOLE_ASSERT_DISABLE) && (DEBUG_CONSOLE_ASSERT_DISABLE > 0U))
63 #undef assert
64 #define assert(n)
65 #endif
66 #endif
67 
68 #if SDK_DEBUGCONSOLE
69 #define DEBUG_CONSOLE_FUNCTION_PREFIX
70 #else
71 #define DEBUG_CONSOLE_FUNCTION_PREFIX static
72 #endif
73 
75 #define DEBUG_CONSOLE_BACKSPACE 127U
76 
77 /* lock definition */
78 #if (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_FREERTOS)
79 
80 static SemaphoreHandle_t s_debugConsoleReadSemaphore;
81 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
82 static SemaphoreHandle_t s_debugConsoleReadWaitSemaphore;
83 #endif
84 
85 #elif (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_BM)
86 
87 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
88 static volatile uint8_t s_debugConsoleReadWaitSemaphore;
89 #endif
90 
91 #else
92 
93 #endif /* DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_FREERTOS */
94 
96 #ifdef __CA7_REV
97 #define IS_RUNNING_IN_ISR() SystemGetIRQNestingLevel()
98 #else
99 #define IS_RUNNING_IN_ISR() __get_IPSR()
100 #endif /* __CA7_REV */
101 
102 /* semaphore definition */
103 #if (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_FREERTOS)
104 
105 /* mutex semaphore */
106 /* clang-format off */
107 #define DEBUG_CONSOLE_CREATE_MUTEX_SEMAPHORE(mutex) ((mutex) = xSemaphoreCreateMutex())
108 #define DEBUG_CONSOLE_DESTROY_MUTEX_SEMAPHORE(mutex) \
109  do \
110  { \
111  if(NULL != mutex) \
112  { \
113  vSemaphoreDelete(mutex); \
114  mutex = NULL; \
115  } \
116  } while(0)
117 
118 #define DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE(mutex) \
119 { \
120  if (IS_RUNNING_IN_ISR() == 0U) \
121  { \
122  (void)xSemaphoreGive(mutex); \
123  } \
124 }
125 
126 #define DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_BLOCKING(mutex) \
127 { \
128  if (IS_RUNNING_IN_ISR() == 0U) \
129  { \
130  (void)xSemaphoreTake(mutex, portMAX_DELAY); \
131  } \
132 }
133 
134 #define DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_NONBLOCKING(mutex, result) \
135 { \
136  if (IS_RUNNING_IN_ISR() == 0U) \
137  { \
138  result = xSemaphoreTake(mutex, 0U); \
139  } \
140  else \
141  { \
142  result = 1U; \
143  } \
144 }
145 
146 /* Binary semaphore */
147 #define DEBUG_CONSOLE_CREATE_BINARY_SEMAPHORE(binary) ((binary) = xSemaphoreCreateBinary())
148 #define DEBUG_CONSOLE_DESTROY_BINARY_SEMAPHORE(binary) \
149  do \
150  { \
151  if(NULL != binary) \
152  { \
153  vSemaphoreDelete(binary); \
154  binary = NULL; \
155  } \
156  } while(0)
157 #define DEBUG_CONSOLE_TAKE_BINARY_SEMAPHORE_BLOCKING(binary) ((void)xSemaphoreTake(binary, portMAX_DELAY))
158 #define DEBUG_CONSOLE_GIVE_BINARY_SEMAPHORE_FROM_ISR(binary) ((void)xSemaphoreGiveFromISR(binary, NULL))
159 
160 #elif (DEBUG_CONSOLE_SYNCHRONIZATION_BM == DEBUG_CONSOLE_SYNCHRONIZATION_MODE)
161 
162 #define DEBUG_CONSOLE_CREATE_MUTEX_SEMAPHORE(mutex)
163 #define DEBUG_CONSOLE_DESTROY_MUTEX_SEMAPHORE(mutex)
164 #define DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_BLOCKING(mutex)
165 #define DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE(mutex)
166 #define DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_NONBLOCKING(mutex, result) (result = 1U)
167 
168 #define DEBUG_CONSOLE_CREATE_BINARY_SEMAPHORE(binary)
169 #define DEBUG_CONSOLE_DESTROY_BINARY_SEMAPHORE(binary)
170 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
171 #define DEBUG_CONSOLE_TAKE_BINARY_SEMAPHORE_BLOCKING(binary) \
172  { \
173  while (!binary) \
174  { \
175  } \
176  binary = false; \
177  }
178 #define DEBUG_CONSOLE_GIVE_BINARY_SEMAPHORE_FROM_ISR(binary) (binary = true)
179 #else
180 #define DEBUG_CONSOLE_TAKE_BINARY_SEMAPHORE_BLOCKING(binary)
181 #define DEBUG_CONSOLE_GIVE_BINARY_SEMAPHORE_FROM_ISR(binary)
182 #endif /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */
183 /* clang-format on */
184 
185 /* add other implementation here
186  *such as :
187  * #elif(DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DDEBUG_CONSOLE_SYNCHRONIZATION_xxx)
188  */
189 
190 #else
191 
192 #error RTOS type is not defined by DEBUG_CONSOLE_SYNCHRONIZATION_MODE.
193 
194 #endif /* DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_FREERTOS */
195 
196 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
197 /* receive state structure */
198 typedef struct _debug_console_write_ring_buffer
199 {
200  uint32_t ringBufferSize;
201  volatile uint32_t ringHead;
202  volatile uint32_t ringTail;
203  uint8_t ringBuffer[DEBUG_CONSOLE_TRANSMIT_BUFFER_LEN];
204 } debug_console_write_ring_buffer_t;
205 #endif
206 
208 {
209  SERIAL_MANAGER_HANDLE_DEFINE(serialHandleBuffer);
211 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
212  debug_console_write_ring_buffer_t writeRingBuffer;
213  uint8_t readRingBuffer[DEBUG_CONSOLE_RECEIVE_BUFFER_LEN];
214 #endif
215  SERIAL_MANAGER_WRITE_HANDLE_DEFINE(serialWriteHandleBuffer);
216  SERIAL_MANAGER_READ_HANDLE_DEFINE(serialReadHandleBuffer);
218 
219 /*******************************************************************************
220  * Variables
221  ******************************************************************************/
222 
224 #if (defined(DATA_SECTION_IS_CACHEABLE) && (DATA_SECTION_IS_CACHEABLE > 0))
226 #else
228 #endif
231 /*******************************************************************************
232  * Prototypes
233  ******************************************************************************/
244 #if SDK_DEBUGCONSOLE
245 static void DbgConsole_PrintCallback(char *buf, int32_t *indicator, char dbgVal, int len);
246 #endif
247 
249 int DbgConsole_SendData(uint8_t *ch, size_t size);
250 int DbgConsole_SendDataReliable(uint8_t *ch, size_t size);
251 int DbgConsole_ReadLine(uint8_t *buf, size_t size);
252 int DbgConsole_ReadCharacter(uint8_t *ch);
253 
254 #if ((SDK_DEBUGCONSOLE == 0U) && defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING) && \
255  (defined(DEBUG_CONSOLE_TX_RELIABLE_ENABLE) && (DEBUG_CONSOLE_TX_RELIABLE_ENABLE > 0U)))
257 #endif
258 /*******************************************************************************
259  * Code
260  ******************************************************************************/
261 
262 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
263 
264 static void DbgConsole_SerialManagerTxCallback(void *callbackParam,
267 {
269  uint32_t sendDataLength;
270 
271  if ((NULL == callbackParam) || (NULL == message))
272  {
273  return;
274  }
275 
276  ioState = (debug_console_state_struct_t *)callbackParam;
277 
278  ioState->writeRingBuffer.ringTail += message->length;
279  if (ioState->writeRingBuffer.ringTail >= ioState->writeRingBuffer.ringBufferSize)
280  {
281  ioState->writeRingBuffer.ringTail = 0U;
282  }
283 
284  if (kStatus_SerialManager_Success == status)
285  {
286  if (ioState->writeRingBuffer.ringTail != ioState->writeRingBuffer.ringHead)
287  {
288  if (ioState->writeRingBuffer.ringHead > ioState->writeRingBuffer.ringTail)
289  {
290  sendDataLength = ioState->writeRingBuffer.ringHead - ioState->writeRingBuffer.ringTail;
291  }
292  else
293  {
294  sendDataLength = ioState->writeRingBuffer.ringBufferSize - ioState->writeRingBuffer.ringTail;
295  }
296 
297  (void)SerialManager_WriteNonBlocking(
298  ((serial_write_handle_t)&ioState->serialWriteHandleBuffer[0]),
299  &ioState->writeRingBuffer.ringBuffer[ioState->writeRingBuffer.ringTail], sendDataLength);
300  }
301  }
302  else if (kStatus_SerialManager_Canceled == status)
303  {
304  ioState->writeRingBuffer.ringTail = 0U;
305  ioState->writeRingBuffer.ringHead = 0U;
306  }
307  else
308  {
309  /*MISRA rule 16.4*/
310  }
311 }
312 
313 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
314 
315 static void DbgConsole_SerialManagerRxCallback(void *callbackParam,
318 {
319  if ((NULL == callbackParam) || (NULL == message))
320  {
321  return;
322  }
323 
324  if (kStatus_SerialManager_Notify == status)
325  {
326  }
327  else if (kStatus_SerialManager_Success == status)
328  {
329  /* release s_debugConsoleReadWaitSemaphore from RX callback */
331  }
332  else
333  {
334  /*MISRA rule 16.4*/
335  }
336 }
337 #endif
338 
339 #endif
340 
342 {
343 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
344 
345 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING) && \
346  (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_BM) && defined(OSA_USED)
347  return (status_t)kStatus_Fail;
348 #else /*defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING) && (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == \
349  DEBUG_CONSOLE_SYNCHRONIZATION_BM) && defined(OSA_USED)*/
351 
352 /* recieve one char every time */
353 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
354  status =
355  SerialManager_ReadNonBlocking(((serial_read_handle_t)&s_debugConsoleState.serialReadHandleBuffer[0]), ch, 1);
356 #else /*defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)*/
357  status = SerialManager_ReadBlocking(((serial_read_handle_t)&s_debugConsoleState.serialReadHandleBuffer[0]), ch, 1);
358 #endif /*defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)*/
359  if (kStatus_SerialManager_Success != status)
360  {
362  }
363  else
364  {
365  /* wait s_debugConsoleReadWaitSemaphore from RX callback */
368  }
369  return (status_t)status;
370 #endif /*defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING) && (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == \
371  DEBUG_CONSOLE_SYNCHRONIZATION_BM) && defined(OSA_USED)*/
372 
373 #else /*(defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))*/
374 
375  return (status_t)kStatus_Fail;
376 
377 #endif /*(defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))*/
378 }
379 
380 #if DEBUG_CONSOLE_ENABLE_ECHO_FUNCTION
381 static status_t DbgConsole_EchoCharacter(uint8_t *ch, bool isGetChar, int *index)
382 {
383  /* Due to scanf take \n and \r as end of string,should not echo */
384  if (((*ch != (uint8_t)'\r') && (*ch != (uint8_t)'\n')) || (isGetChar))
385  {
386  /* recieve one char every time */
387  if (1 != DbgConsole_SendDataReliable(ch, 1U))
388  {
389  return (status_t)kStatus_Fail;
390  }
391  }
392 
393  if ((!isGetChar) && (index != NULL))
394  {
395  if (DEBUG_CONSOLE_BACKSPACE == *ch)
396  {
397  if ((*index >= 2))
398  {
399  *index -= 2;
400  }
401  else
402  {
403  *index = 0;
404  }
405  }
406  }
407 
408  return (status_t)kStatus_Success;
409 }
410 #endif
411 
412 int DbgConsole_SendData(uint8_t *ch, size_t size)
413 {
414  status_t status;
415 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
416  uint32_t sendDataLength;
417  int txBusy = 0;
418 #endif
419  assert(NULL != ch);
420  assert(0U != size);
421 
422 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
423  uint32_t regPrimask = DisableGlobalIRQ();
424  if (s_debugConsoleState.writeRingBuffer.ringHead != s_debugConsoleState.writeRingBuffer.ringTail)
425  {
426  txBusy = 1;
427  sendDataLength =
428  (s_debugConsoleState.writeRingBuffer.ringHead + s_debugConsoleState.writeRingBuffer.ringBufferSize -
429  s_debugConsoleState.writeRingBuffer.ringTail) %
430  s_debugConsoleState.writeRingBuffer.ringBufferSize;
431  }
432  else
433  {
434  sendDataLength = 0U;
435  }
436  sendDataLength = s_debugConsoleState.writeRingBuffer.ringBufferSize - sendDataLength - 1;
437  if (sendDataLength < size)
438  {
439  EnableGlobalIRQ(regPrimask);
440  return -1;
441  }
442  for (int i = 0; i < (int)size; i++)
443  {
444  s_debugConsoleState.writeRingBuffer.ringBuffer[s_debugConsoleState.writeRingBuffer.ringHead++] = ch[i];
445  if (s_debugConsoleState.writeRingBuffer.ringHead >= s_debugConsoleState.writeRingBuffer.ringBufferSize)
446  {
447  s_debugConsoleState.writeRingBuffer.ringHead = 0U;
448  }
449  }
450 
452 
453  if (txBusy == 0)
454  {
455  if (s_debugConsoleState.writeRingBuffer.ringHead > s_debugConsoleState.writeRingBuffer.ringTail)
456  {
457  sendDataLength =
458  s_debugConsoleState.writeRingBuffer.ringHead - s_debugConsoleState.writeRingBuffer.ringTail;
459  }
460  else
461  {
462  sendDataLength =
463  s_debugConsoleState.writeRingBuffer.ringBufferSize - s_debugConsoleState.writeRingBuffer.ringTail;
464  }
465 
466  status = (status_t)SerialManager_WriteNonBlocking(
467  ((serial_write_handle_t)&s_debugConsoleState.serialWriteHandleBuffer[0]),
468  &s_debugConsoleState.writeRingBuffer.ringBuffer[s_debugConsoleState.writeRingBuffer.ringTail],
469  sendDataLength);
470  }
471  EnableGlobalIRQ(regPrimask);
472 #else
474  ((serial_write_handle_t)&s_debugConsoleState.serialWriteHandleBuffer[0]), ch, size);
475 #endif
476  return (((status_t)kStatus_Success == status) ? (int)size : -1);
477 }
478 
479 int DbgConsole_SendDataReliable(uint8_t *ch, size_t size)
480 {
481 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
482 #if (defined(DEBUG_CONSOLE_TX_RELIABLE_ENABLE) && (DEBUG_CONSOLE_TX_RELIABLE_ENABLE > 0U))
484  uint32_t sendDataLength;
485  uint32_t totalLength = size;
486  int sentLength;
487 #endif /* DEBUG_CONSOLE_TX_RELIABLE_ENABLE */
488 #else /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */
490 #endif /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */
491 
492  assert(NULL != ch);
493  assert(0U != size);
494 
495  if (NULL == g_serialHandle)
496  {
497  return 0;
498  }
499 
500 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
501 
502 #if (defined(DEBUG_CONSOLE_TX_RELIABLE_ENABLE) && (DEBUG_CONSOLE_TX_RELIABLE_ENABLE > 0U))
503  do
504  {
505  uint32_t regPrimask = DisableGlobalIRQ();
506  if (s_debugConsoleState.writeRingBuffer.ringHead != s_debugConsoleState.writeRingBuffer.ringTail)
507  {
508  sendDataLength =
509  (s_debugConsoleState.writeRingBuffer.ringHead + s_debugConsoleState.writeRingBuffer.ringBufferSize -
510  s_debugConsoleState.writeRingBuffer.ringTail) %
511  s_debugConsoleState.writeRingBuffer.ringBufferSize;
512  }
513  else
514  {
515  sendDataLength = 0U;
516  }
517  sendDataLength = s_debugConsoleState.writeRingBuffer.ringBufferSize - sendDataLength - 1U;
518 
519  if (sendDataLength > 0U)
520  {
521  if (sendDataLength > totalLength)
522  {
523  sendDataLength = totalLength;
524  }
525 
526  sentLength = DbgConsole_SendData(&ch[size - totalLength], sendDataLength);
527  if (sentLength > 0)
528  {
529  totalLength = totalLength - (uint32_t)sentLength;
530  }
531  }
532  EnableGlobalIRQ(regPrimask);
533 
534  if (totalLength != 0U)
535  {
537  if (kStatus_SerialManager_Success != status)
538  {
539  break;
540  }
541  }
542  } while (totalLength != 0U);
543  return ((int)size - (int)totalLength);
544 #else /* DEBUG_CONSOLE_TX_RELIABLE_ENABLE */
545  return DbgConsole_SendData(ch, size);
546 #endif /* DEBUG_CONSOLE_TX_RELIABLE_ENABLE */
547 
548 #else /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */
549  status =
550  SerialManager_WriteBlocking(((serial_write_handle_t)&s_debugConsoleState.serialWriteHandleBuffer[0]), ch, size);
551  return ((kStatus_SerialManager_Success == status) ? (int)size : -1);
552 #endif /* DEBUG_CONSOLE_TRANSFER_NON_BLOCKING */
553 }
554 
555 int DbgConsole_ReadLine(uint8_t *buf, size_t size)
556 {
557  int i = 0;
558 
559  assert(buf != NULL);
560 
561  if (NULL == g_serialHandle)
562  {
563  return -1;
564  }
565 
566  /* take mutex lock function */
567  DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_BLOCKING(s_debugConsoleReadSemaphore);
568 
569  do
570  {
571  /* recieve one char every time */
573  {
574  /* release mutex lock function */
575  DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE(s_debugConsoleReadSemaphore);
576  i = -1;
577  break;
578  }
579 #if DEBUG_CONSOLE_ENABLE_ECHO_FUNCTION
580  (void)DbgConsole_EchoCharacter(&buf[i], false, &i);
581 #endif
582  /* analysis data */
583  if (((uint8_t)'\r' == buf[i]) || ((uint8_t)'\n' == buf[i]))
584  {
585  /* End of Line. */
586  if (0 == i)
587  {
588  buf[i] = (uint8_t)'\0';
589  continue;
590  }
591  else
592  {
593  break;
594  }
595  }
596  i++;
597  } while (i < (int)size);
598 
599  /* get char should not add '\0'*/
600  if (i == (int)size)
601  {
602  buf[i] = (uint8_t)'\0';
603  }
604  else
605  {
606  buf[i + 1] = (uint8_t)'\0';
607  }
608 
609  /* release mutex lock function */
610  DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE(s_debugConsoleReadSemaphore);
611 
612  return i;
613 }
614 
615 int DbgConsole_ReadCharacter(uint8_t *ch)
616 {
617  int ret;
618 
619  assert(ch);
620 
621  if (NULL == g_serialHandle)
622  {
623  return -1;
624  }
625 
626  /* take mutex lock function */
627  DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_BLOCKING(s_debugConsoleReadSemaphore);
628  /* read one character */
630  {
631  ret = 1;
632 #if DEBUG_CONSOLE_ENABLE_ECHO_FUNCTION
633  (void)DbgConsole_EchoCharacter(ch, true, NULL);
634 #endif
635  }
636  else
637  {
638  ret = -1;
639  }
640 
641  /* release mutex lock function */
642  DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE(s_debugConsoleReadSemaphore);
643 
644  return ret;
645 }
646 
647 #if SDK_DEBUGCONSOLE
648 static void DbgConsole_PrintCallback(char *buf, int32_t *indicator, char dbgVal, int len)
649 {
650  int i = 0;
651 
652  for (i = 0; i < len; i++)
653  {
654  if (((uint32_t)*indicator + 1UL) >= DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN)
655  {
656  (void)DbgConsole_SendDataReliable((uint8_t *)buf, (uint32_t)(*indicator));
657  *indicator = 0;
658  }
659 
660  buf[*indicator] = dbgVal;
661  (*indicator)++;
662  }
663 }
664 #endif
665 
666 /*************Code for DbgConsole Init, Deinit, Printf, Scanf *******************************/
667 
668 #if ((SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK) || defined(SDK_DEBUGCONSOLE_UART))
669 /* See fsl_debug_console.h for documentation of this function. */
670 status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq)
671 {
672  serial_manager_config_t serialConfig;
674 
675 #if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
676  serial_port_uart_config_t uartConfig = {
677  .instance = instance,
678  .clockRate = clkSrcFreq,
679  .baudRate = baudRate,
680  .parityMode = kSerialManager_UartParityDisabled,
681  .stopBitCount = kSerialManager_UartOneStopBit,
682  .enableRx = 1,
683  .enableTx = 1,
684  };
685 #endif
686 
687 #if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
688  serial_port_usb_cdc_config_t usbCdcConfig = {
689  .controllerIndex = (serial_port_usb_cdc_controller_index_t)instance,
690  };
691 #endif
692 
693 #if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
694  serial_port_swo_config_t swoConfig = {
695  .clockRate = clkSrcFreq,
696  .baudRate = baudRate,
697  .port = instance,
698  .protocol = kSerialManager_SwoProtocolNrz,
699  };
700 #endif
701 
702 #if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
703  serial_port_usb_cdc_virtual_config_t usbCdcVirtualConfig = {
704  .controllerIndex = (serial_port_usb_cdc_virtual_controller_index_t)instance,
705  };
706 #endif
707 
708  serialConfig.type = device;
709 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
710  serialConfig.ringBuffer = &s_debugConsoleState.readRingBuffer[0];
711  serialConfig.ringBufferSize = DEBUG_CONSOLE_RECEIVE_BUFFER_LEN;
712 #endif
713 
714  if (kSerialPort_Uart == device)
715  {
716 #if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
717  serialConfig.portConfig = &uartConfig;
718 #else
720 #endif
721  }
722  else if (kSerialPort_UsbCdc == device)
723  {
724 #if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
725  serialConfig.portConfig = &usbCdcConfig;
726 #else
728 #endif
729  }
730  else if (kSerialPort_Swo == device)
731  {
732 #if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
733  serialConfig.portConfig = &swoConfig;
734 #else
736 #endif
737  }
738  else if (kSerialPort_UsbCdcVirtual == device)
739  {
740 #if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
741  serialConfig.portConfig = &usbCdcVirtualConfig;
742 #else
744 #endif
745  }
746  else
747  {
749  }
750 
751  if (kStatus_SerialManager_Error != status)
752  {
753  (void)memset(&s_debugConsoleState, 0, sizeof(s_debugConsoleState));
754 
755 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
756  s_debugConsoleState.writeRingBuffer.ringBufferSize = DEBUG_CONSOLE_TRANSMIT_BUFFER_LEN;
757 #endif
758 
760  status = SerialManager_Init(s_debugConsoleState.serialHandle, &serialConfig);
761 
762  assert(kStatus_SerialManager_Success == status);
763 
764  DEBUG_CONSOLE_CREATE_MUTEX_SEMAPHORE(s_debugConsoleReadSemaphore);
765 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
767 #endif
768 
769  {
770  status =
772  ((serial_write_handle_t)&s_debugConsoleState.serialWriteHandleBuffer[0]));
773  assert(kStatus_SerialManager_Success == status);
774 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
775  (void)SerialManager_InstallTxCallback(
776  ((serial_write_handle_t)&s_debugConsoleState.serialWriteHandleBuffer[0]),
777  DbgConsole_SerialManagerTxCallback, &s_debugConsoleState);
778 #endif
779  }
780 
781 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
782  {
783  status =
785  ((serial_read_handle_t)&s_debugConsoleState.serialReadHandleBuffer[0]));
786  assert(kStatus_SerialManager_Success == status);
787 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
788  (void)SerialManager_InstallRxCallback(
789  ((serial_read_handle_t)&s_debugConsoleState.serialReadHandleBuffer[0]),
790  DbgConsole_SerialManagerRxCallback, &s_debugConsoleState);
791 #endif
792  }
793 #endif
794 
796  }
797  return (status_t)status;
798 }
799 
800 /* See fsl_debug_console.h for documentation of this function. */
802 {
803  {
805  {
807  ((serial_write_handle_t)&s_debugConsoleState.serialWriteHandleBuffer[0]));
808  }
809  }
810 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
811  {
813  {
814  (void)SerialManager_CloseReadHandle(((serial_read_handle_t)&s_debugConsoleState.serialReadHandleBuffer[0]));
815  }
816  }
817 #endif
819  {
821  {
824  }
825  }
826 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
828 #endif
829  DEBUG_CONSOLE_DESTROY_MUTEX_SEMAPHORE(s_debugConsoleReadSemaphore);
830 
831  return (status_t)kStatus_Success;
832 }
833 #endif /* ((SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK) || defined(SDK_DEBUGCONSOLE_UART)) */
834 
835 #if ((SDK_DEBUGCONSOLE > 0U) || \
836  ((SDK_DEBUGCONSOLE == 0U) && defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING) && \
837  (defined(DEBUG_CONSOLE_TX_RELIABLE_ENABLE) && (DEBUG_CONSOLE_TX_RELIABLE_ENABLE > 0U))))
839 {
840 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
841 
842 #if (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_BM) && defined(OSA_USED)
843 
844  if (s_debugConsoleState.writeRingBuffer.ringHead != s_debugConsoleState.writeRingBuffer.ringTail)
845  {
846  return (status_t)kStatus_Fail;
847  }
848 
849 #else
850 
851  while (s_debugConsoleState.writeRingBuffer.ringHead != s_debugConsoleState.writeRingBuffer.ringTail)
852  {
853 #if (DEBUG_CONSOLE_SYNCHRONIZATION_MODE == DEBUG_CONSOLE_SYNCHRONIZATION_FREERTOS)
854  if (0U == IS_RUNNING_IN_ISR())
855  {
856  if (taskSCHEDULER_RUNNING == xTaskGetSchedulerState())
857  {
858  vTaskDelay(1);
859  }
860  }
861  else
862  {
863  return (status_t)kStatus_Fail;
864  }
865 #endif
866  }
867 
868 #endif
869 
870 #endif
871  return (status_t)kStatus_Success;
872 }
873 #endif
874 
875 #if SDK_DEBUGCONSOLE
876 /* See fsl_debug_console.h for documentation of this function. */
877 int DbgConsole_Printf(const char *formatString, ...)
878 {
879  va_list ap;
880  int logLength = 0, dbgResult = 0;
881  char printBuf[DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN] = {'\0'};
882 
883  if (NULL != g_serialHandle)
884  {
885  va_start(ap, formatString);
886  /* format print log first */
887  logLength = StrFormatPrintf(formatString, ap, printBuf, DbgConsole_PrintCallback);
888  /* print log */
889  dbgResult = DbgConsole_SendDataReliable((uint8_t *)printBuf, (size_t)logLength);
890 
891  va_end(ap);
892  }
893  return dbgResult;
894 }
895 
896 /* See fsl_debug_console.h for documentation of this function. */
898 {
899  /* print char */
900  return DbgConsole_SendDataReliable((uint8_t *)&ch, 1U);
901 }
902 
903 /* See fsl_debug_console.h for documentation of this function. */
904 int DbgConsole_Scanf(char *formatString, ...)
905 {
906  va_list ap;
907  int formatResult;
908  char scanfBuf[DEBUG_CONSOLE_SCANF_MAX_LOG_LEN + 1U] = {'\0'};
909 
910  /* scanf log */
911  (void)DbgConsole_ReadLine((uint8_t *)scanfBuf, DEBUG_CONSOLE_SCANF_MAX_LOG_LEN);
912  /* get va_list */
913  va_start(ap, formatString);
914  /* format scanf log */
915  formatResult = StrFormatScanf(scanfBuf, formatString, ap);
916 
917  va_end(ap);
918 
919  return formatResult;
920 }
921 /* See fsl_debug_console.h for documentation of this function. */
922 int DbgConsole_BlockingPrintf(const char *formatString, ...)
923 {
924  va_list ap;
925  status_t status;
926  int logLength = 0, dbgResult = 0;
927  char printBuf[DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN] = {'\0'};
928 
929  if (NULL == g_serialHandle)
930  {
931  return 0;
932  }
933 
934  va_start(ap, formatString);
935  /* format print log first */
936  logLength = StrFormatPrintf(formatString, ap, printBuf, DbgConsole_PrintCallback);
937 
938 #if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
939  SerialManager_CancelWriting(((serial_write_handle_t)&s_debugConsoleState.serialWriteHandleBuffer[0]));
940 #endif
941  /* print log */
942  status =
944  (uint8_t *)printBuf, (size_t)logLength);
945  dbgResult = (((status_t)kStatus_Success == status) ? (int)logLength : -1);
946  va_end(ap);
947 
948  return dbgResult;
949 }
950 
951 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
952 status_t DbgConsole_TryGetchar(char *ch)
953 {
954 #if (defined(DEBUG_CONSOLE_RX_ENABLE) && (DEBUG_CONSOLE_RX_ENABLE > 0U))
955  uint32_t length = 0;
956  status_t status = (status_t)kStatus_Fail;
957 
958  assert(ch);
959 
960  if (NULL == g_serialHandle)
961  {
962  return kStatus_Fail;
963  }
964 
965  /* take mutex lock function */
966  DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_BLOCKING(s_debugConsoleReadSemaphore);
967 
969  SerialManager_TryRead(((serial_read_handle_t)&s_debugConsoleState.serialReadHandleBuffer[0]), (uint8_t *)ch, 1,
970  &length))
971  {
972  if (length != 0U)
973  {
974 #if DEBUG_CONSOLE_ENABLE_ECHO_FUNCTION
975  (void)DbgConsole_EchoCharacter((uint8_t *)ch, true, NULL);
976 #endif
977  status = (status_t)kStatus_Success;
978  }
979  }
980  /* release mutex lock function */
981  DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE(s_debugConsoleReadSemaphore);
982  return status;
983 #else
984  return (status_t)kStatus_Fail;
985 #endif
986 }
987 #endif
988 
989 /* See fsl_debug_console.h for documentation of this function. */
991 {
992  uint8_t ch = 0U;
993 
994  /* Get char */
995  (void)DbgConsole_ReadCharacter(&ch);
996 
997  return (int)ch;
998 }
999 
1000 #endif /* SDK_DEBUGCONSOLE */
1001 
1002 /*************Code to support toolchain's printf, scanf *******************************/
1003 /* These function __write and __read is used to support IAR toolchain to printf and scanf*/
1004 #if (defined(__ICCARM__))
1005 #if defined(SDK_DEBUGCONSOLE_UART)
1006 #pragma weak __write
1007 size_t __write(int handle, const unsigned char *buffer, size_t size);
1008 size_t __write(int handle, const unsigned char *buffer, size_t size)
1009 {
1010  size_t ret;
1011  if (0 == buffer)
1012  {
1013  /*
1014  * This means that we should flush internal buffers. Since we don't we just return.
1015  * (Remember, "handle" == -1 means that all handles should be flushed.)
1016  */
1017  ret = 0U;
1018  }
1019  else if ((handle != 1) && (handle != 2))
1020  {
1021  /* This function only writes to "standard out" and "standard err" for all other file handles it returns failure.
1022  */
1023  ret = (uint32_t)0xff;
1024  }
1025  else
1026  {
1027  /* Send data. */
1028  uint8_t buff[512];
1029  (void)memcpy(buff, buffer, size);
1030  (void)DbgConsole_SendDataReliable((uint8_t *)buff, size);
1031 
1032  ret = size;
1033  }
1034  return ret;
1035 }
1036 
1037 #pragma weak __read
1038 size_t __read(int handle, unsigned char *buffer, size_t size);
1039 size_t __read(int handle, unsigned char *buffer, size_t size)
1040 {
1041  uint8_t ch = 0U;
1042  int actualSize = 0;
1043 
1044  /* This function only reads from "standard in", for all other file handles it returns failure. */
1045  if (0 != handle)
1046  {
1047  actualSize = -1;
1048  }
1049  else
1050  {
1051  /* Receive data.*/
1052  for (; size > 0U; size--)
1053  {
1054  (void)DbgConsole_ReadCharacter(&ch);
1055  if (0U == ch)
1056  {
1057  break;
1058  }
1059 
1060  *buffer++ = ch;
1061  actualSize++;
1062  }
1063  }
1064  return (size_t)actualSize;
1065 }
1066 #endif /* SDK_DEBUGCONSOLE_UART */
1067 
1068 /* support LPC Xpresso with RedLib */
1069 #elif (defined(__REDLIB__))
1070 
1071 #if (defined(SDK_DEBUGCONSOLE_UART))
1072 int __attribute__((weak)) __sys_write(int handle, char *buffer, int size)
1073 {
1074  if (buffer == 0)
1075  {
1076  /* return -1 if error. */
1077  return -1;
1078  }
1079 
1080  /* This function only writes to "standard out" and "standard err" for all other file handles it returns failure. */
1081  if ((handle != 1) && (handle != 2))
1082  {
1083  return -1;
1084  }
1085 
1086  /* Send data. */
1087  DbgConsole_SendDataReliable((uint8_t *)buffer, size);
1088 
1089  return 0;
1090 }
1091 
1092 int __attribute__((weak)) __sys_readc(void)
1093 {
1094  char tmp;
1095 
1096  /* Receive data. */
1097  DbgConsole_ReadCharacter((uint8_t *)&tmp);
1098 
1099  return tmp;
1100 }
1101 #endif
1102 
1103 /* These function fputc and fgetc is used to support KEIL toolchain to printf and scanf*/
1104 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
1105 #if defined(SDK_DEBUGCONSOLE_UART)
1106 #if defined(__CC_ARM)
1107 struct __FILE
1108 {
1109  int handle;
1110  /*
1111  * Whatever you require here. If the only file you are using is standard output using printf() for debugging,
1112  * no file handling is required.
1113  */
1114 };
1115 #endif
1116 
1117 /* FILE is typedef in stdio.h. */
1118 #pragma weak __stdout
1119 #pragma weak __stdin
1120 FILE __stdout;
1121 FILE __stdin;
1122 
1123 #pragma weak fputc
1124 int fputc(int ch, FILE *f)
1125 {
1126  /* Send data. */
1127  return DbgConsole_SendDataReliable((uint8_t *)(&ch), 1);
1128 }
1129 
1130 #pragma weak fgetc
1131 int fgetc(FILE *f)
1132 {
1133  char ch;
1134 
1135  /* Receive data. */
1136  DbgConsole_ReadCharacter((uint8_t *)&ch);
1137 
1138  return ch;
1139 }
1140 
1141 /*
1142  * Terminate the program, passing a return code back to the user.
1143  * This function may not return.
1144  */
1145 void _sys_exit(int returncode)
1146 {
1147  while (1)
1148  {
1149  }
1150 }
1151 
1152 /*
1153  * Writes a character to the output channel. This function is used
1154  * for last-resort error message output.
1155  */
1156 void _ttywrch(int ch)
1157 {
1158  char ench = ch;
1159  DbgConsole_SendDataReliable((uint8_t *)(&ench), 1);
1160 }
1161 
1162 char *_sys_command_string(char *cmd, int len)
1163 {
1164  return (cmd);
1165 }
1166 #endif /* SDK_DEBUGCONSOLE_UART */
1167 
1168 /* These function __write and __read is used to support ARM_GCC, KDS, Atollic toolchains to printf and scanf*/
1169 #elif (defined(__GNUC__))
1170 
1171 #if ((defined(__GNUC__) && (!defined(__MCUXPRESSO)) && (defined(SDK_DEBUGCONSOLE_UART))) || \
1172  (defined(__MCUXPRESSO) && (defined(SDK_DEBUGCONSOLE_UART))))
1173 int __attribute__((weak)) _write(int handle, char *buffer, int size);
1174 int __attribute__((weak)) _write(int handle, char *buffer, int size)
1175 {
1176  if (buffer == NULL)
1177  {
1178  /* return -1 if error. */
1179  return -1;
1180  }
1181 
1182  /* This function only writes to "standard out" and "standard err" for all other file handles it returns failure. */
1183  if ((handle != 1) && (handle != 2))
1184  {
1185  return -1;
1186  }
1187 
1188  /* Send data. */
1189  (void)DbgConsole_SendDataReliable((uint8_t *)buffer, (size_t)size);
1190 
1191  return size;
1192 }
1193 
1194 int __attribute__((weak)) _read(int handle, char *buffer, int size);
1195 int __attribute__((weak)) _read(int handle, char *buffer, int size)
1196 {
1197  uint8_t ch = 0U;
1198  int actualSize = 0;
1199 
1200  /* This function only reads from "standard in", for all other file handles it returns failure. */
1201  if (handle != 0)
1202  {
1203  return -1;
1204  }
1205 
1206  /* Receive data. */
1207  for (; size > 0; size--)
1208  {
1209  if (DbgConsole_ReadCharacter(&ch) < 0)
1210  {
1211  break;
1212  }
1213 
1214  *buffer++ = (char)ch;
1215  actualSize++;
1216 
1217  if ((ch == 0U) || (ch == (uint8_t)'\n') || (ch == (uint8_t)'\r'))
1218  {
1219  break;
1220  }
1221  }
1222 
1223  return (actualSize > 0) ? actualSize : -1;
1224 }
1225 #endif
1226 
1227 #endif /* __ICCARM__ */
_serial_manager_config::portConfig
void * portConfig
Definition: serial_manager.h:233
fsl_common.h
DbgConsole_Flush
DEBUG_CONSOLE_FUNCTION_PREFIX status_t DbgConsole_Flush(void)
Debug console flush.
Definition: fsl_debug_console.c:838
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
kSerialManager_UartOneStopBit
@ kSerialManager_UartOneStopBit
Definition: serial_port_uart.h:40
serial_port_type_t
enum _serial_port_type serial_port_type_t
serial port type
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
kSerialPort_UsbCdcVirtual
@ kSerialPort_UsbCdcVirtual
Definition: serial_manager.h:220
_debug_console_state_struct
Definition: fsl_debug_console.c:207
_serial_manager_config
serial manager config structure
Definition: serial_manager.h:224
DEBUG_CONSOLE_DESTROY_MUTEX_SEMAPHORE
#define DEBUG_CONSOLE_DESTROY_MUTEX_SEMAPHORE(mutex)
Definition: fsl_debug_console.c:163
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
fsl_str.h
kStatus_SerialManager_Error
@ kStatus_SerialManager_Error
Definition: serial_manager.h:240
DbgConsole_Getchar
int DbgConsole_Getchar(void)
Reads a character from standard input.
Definition: fsl_debug_console.c:990
DbgConsole_Printf
int DbgConsole_Printf(const char *formatString,...)
Writes formatted output to the standard output stream.
Definition: fsl_debug_console.c:877
s_debugConsoleReadWaitSemaphore
static volatile uint8_t s_debugConsoleReadWaitSemaphore
Definition: fsl_debug_console.c:88
fsl_debug_console_conf.h
DEBUG_CONSOLE_DESTROY_BINARY_SEMAPHORE
#define DEBUG_CONSOLE_DESTROY_BINARY_SEMAPHORE(binary)
Definition: fsl_debug_console.c:169
DbgConsole_Deinit
status_t DbgConsole_Deinit(void)
De-initializes the peripheral used for debug messages.
Definition: fsl_debug_console.c:801
g_serialHandle
serial_handle_t g_serialHandle
Definition: fsl_debug_console.c:229
DbgConsole_SendData
int DbgConsole_SendData(uint8_t *ch, size_t size)
Definition: fsl_debug_console.c:412
DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_BLOCKING
#define DEBUG_CONSOLE_TAKE_MUTEX_SEMAPHORE_BLOCKING(mutex)
Definition: fsl_debug_console.c:164
device
ma_device device
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/tests/test_deviceio/ma_test_deviceio.c:57
IS_RUNNING_IN_ISR
#define IS_RUNNING_IN_ISR()
get current runing environment is ISR or not
Definition: fsl_debug_console.c:99
serial_manager.h
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
DEBUG_CONSOLE_SCANF_MAX_LOG_LEN
#define DEBUG_CONSOLE_SCANF_MAX_LOG_LEN
Definition: fsl_debug_console_conf.h:88
kSerialManager_UartParityDisabled
@ kSerialManager_UartParityDisabled
Definition: serial_port_uart.h:32
kSerialPort_Swo
@ kSerialPort_Swo
Definition: serial_manager.h:219
_write
int _write(int file, char *ptr, int len)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:101
DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE
#define DEBUG_CONSOLE_GIVE_MUTEX_SEMAPHORE(mutex)
Definition: fsl_debug_console.c:165
_debug_console_state_struct::SERIAL_MANAGER_WRITE_HANDLE_DEFINE
SERIAL_MANAGER_WRITE_HANDLE_DEFINE(serialWriteHandleBuffer)
_read
int _read(int file, char *ptr, int len)
Definition: stm32f407/stm32f407g-disc1/Src/syscalls.c:133
DbgConsole_Putchar
int DbgConsole_Putchar(int ch)
Writes a character to stdout.
Definition: fsl_debug_console.c:897
kStatus_SerialManager_Success
@ kStatus_SerialManager_Success
Definition: serial_manager.h:239
StrFormatScanf
int StrFormatScanf(const char *line_ptr, char *format, va_list args_ptr)
Converts an input line of ASCII characters based upon a provided string format.
Definition: fsl_str.c:1317
_serial_port_uart_config
serial port uart config struct
Definition: serial_port_uart.h:45
serial_read_handle_t
void * serial_read_handle_t
The read handle of the serial manager module.
Definition: serial_manager.h:212
s_debugConsoleState
static debug_console_state_struct_t s_debugConsoleState
Debug console state information.
Definition: fsl_debug_console.c:227
_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
DbgConsole_Init
status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq)
Initializes the peripheral used for debug messages.
Definition: fsl_debug_console.c:670
DEBUG_CONSOLE_CREATE_MUTEX_SEMAPHORE
#define DEBUG_CONSOLE_CREATE_MUTEX_SEMAPHORE(mutex)
Definition: fsl_debug_console.c:162
_serial_manager_config::type
serial_port_type_t type
Definition: serial_manager.h:232
DEBUG_CONSOLE_BACKSPACE
#define DEBUG_CONSOLE_BACKSPACE
character backspace ASCII value
Definition: fsl_debug_console.c:75
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
kStatus_Fail
@ kStatus_Fail
Definition: fsl_common.h:180
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
DbgConsole_SendDataReliable
int DbgConsole_SendDataReliable(uint8_t *ch, size_t size)
Definition: fsl_debug_console.c:479
DbgConsole_ReadOneCharacter
status_t DbgConsole_ReadOneCharacter(uint8_t *ch)
Definition: fsl_debug_console.c:341
fsl_debug_console.h
kSerialPort_UsbCdc
@ kSerialPort_UsbCdc
Definition: serial_manager.h:218
_serial_port_uart_config::instance
uint8_t instance
Definition: serial_port_uart.h:51
DEBUG_CONSOLE_GIVE_BINARY_SEMAPHORE_FROM_ISR
#define DEBUG_CONSOLE_GIVE_BINARY_SEMAPHORE_FROM_ISR(binary)
Definition: fsl_debug_console.c:181
DisableGlobalIRQ
static uint32_t DisableGlobalIRQ(void)
Disable the global IRQ.
Definition: fsl_common.h:552
DbgConsole_ReadCharacter
int DbgConsole_ReadCharacter(uint8_t *ch)
Definition: fsl_debug_console.c:615
DbgConsole_ReadLine
int DbgConsole_ReadLine(uint8_t *buf, size_t size)
Definition: fsl_debug_console.c:555
_debug_console_state_struct::SERIAL_MANAGER_HANDLE_DEFINE
SERIAL_MANAGER_HANDLE_DEFINE(serialHandleBuffer)
serial_write_handle_t
void * serial_write_handle_t
The write handle of the serial manager module.
Definition: serial_manager.h:209
DEBUG_CONSOLE_CREATE_BINARY_SEMAPHORE
#define DEBUG_CONSOLE_CREATE_BINARY_SEMAPHORE(binary)
Definition: fsl_debug_console.c:168
DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN
#define DEBUG_CONSOLE_PRINTF_MAX_LOG_LEN
Definition: fsl_debug_console_conf.h:80
SerialManager_Deinit
serial_manager_status_t SerialManager_Deinit(serial_handle_t serialHandle)
De-initializes the serial manager module instance.
Definition: serial_manager.c:944
debug_console_state_struct_t
struct _debug_console_state_struct debug_console_state_struct_t
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
DbgConsole_BlockingPrintf
int DbgConsole_BlockingPrintf(const char *formatString,...)
Writes formatted output to the standard output stream with the blocking mode.
Definition: fsl_debug_console.c:922
_debug_console_state_struct::SERIAL_MANAGER_READ_HANDLE_DEFINE
SERIAL_MANAGER_READ_HANDLE_DEFINE(serialReadHandleBuffer)
DEBUG_CONSOLE_TAKE_BINARY_SEMAPHORE_BLOCKING
#define DEBUG_CONSOLE_TAKE_BINARY_SEMAPHORE_BLOCKING(binary)
Definition: fsl_debug_console.c:180
_debug_console_state_struct::serialHandle
serial_handle_t serialHandle
Definition: fsl_debug_console.c:210
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
DbgConsole_Scanf
int DbgConsole_Scanf(char *formatString,...)
Reads formatted data from the standard input stream.
Definition: fsl_debug_console.c:904
__attribute__
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
Reverse byte order (16 bit)
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_armcc.h:492
DbgConsole_PrintCallback
static void DbgConsole_PrintCallback(char *buf, int32_t *indicator, char dbgVal, int len)
This is a printf call back function which is used to relocate the log to buffer or print the log imme...
Definition: fsl_debug_console.c:648
StrFormatPrintf
int StrFormatPrintf(const char *fmt, va_list ap, char *buf, printfCb cb)
This function outputs its parameters according to a formatted string.
Definition: fsl_str.c:737
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:189
kStatus_Success
@ kStatus_Success
Definition: fsl_common.h:179
AT_NONCACHEABLE_SECTION
#define AT_NONCACHEABLE_SECTION(var)
Definition: fsl_common.h:378
DEBUG_CONSOLE_FUNCTION_PREFIX
#define DEBUG_CONSOLE_FUNCTION_PREFIX
Definition: fsl_debug_console.c:69
EnableGlobalIRQ
static void EnableGlobalIRQ(uint32_t primask)
Enable the global IRQ.
Definition: fsl_common.h:583


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:56