]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/NXP_Code/utilities/fsl_debug_console.h
2528343558e0c12ac55b3fa01f91d4f7195e612f
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso / NXP_Code / utilities / fsl_debug_console.h
1 /*\r
2  * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.\r
3  * Copyright 2016-2018 NXP\r
4  * All rights reserved.\r
5  *\r
6  * SPDX-License-Identifier: BSD-3-Clause\r
7  *\r
8  * Debug console shall provide input and output functions to scan and print formatted data.\r
9  * o Support a format specifier for PRINTF follows this prototype "%[flags][width][.precision][length]specifier"\r
10  *   - [flags] :'-', '+', '#', ' ', '0'\r
11  *   - [width]:  number (0,1...)\r
12  *   - [.precision]: number (0,1...)\r
13  *   - [length]: do not support\r
14  *   - [specifier]: 'd', 'i', 'f', 'F', 'x', 'X', 'o', 'p', 'u', 'c', 's', 'n'\r
15  * o Support a format specifier for SCANF follows this prototype " %[*][width][length]specifier"\r
16  *   - [*]: is supported.\r
17  *   - [width]: number (0,1...)\r
18  *   - [length]: 'h', 'hh', 'l','ll','L'. ignore ('j','z','t')\r
19  *   - [specifier]: 'd', 'i', 'u', 'f', 'F', 'e', 'E', 'g', 'G', 'a', 'A', 'o', 'c', 's'\r
20  */\r
21 \r
22 #ifndef _FSL_DEBUGCONSOLE_H_\r
23 #define _FSL_DEBUGCONSOLE_H_\r
24 \r
25 #include "fsl_common.h"\r
26 #include "serial_manager.h"\r
27 \r
28 /*!\r
29  * @addtogroup debugconsole\r
30  * @{\r
31  */\r
32 \r
33 /*******************************************************************************\r
34  * Definitions\r
35  ******************************************************************************/\r
36 \r
37 /*! @brief Definition select redirect toolchain printf, scanf to uart or not. */\r
38 #define DEBUGCONSOLE_REDIRECT_TO_TOOLCHAIN 0U /*!< Select toolchain printf and scanf. */\r
39 #define DEBUGCONSOLE_REDIRECT_TO_SDK 1U       /*!< Select SDK version printf, scanf. */\r
40 #define DEBUGCONSOLE_DISABLE 2U               /*!< Disable debugconsole function. */\r
41 \r
42 /*! @brief Definition to select sdk or toolchain printf, scanf. */\r
43 #ifndef SDK_DEBUGCONSOLE\r
44 #define SDK_DEBUGCONSOLE 1U\r
45 #endif\r
46 \r
47 /*! @brief Definition to select redirect toolchain printf, scanf to uart or not. */\r
48 #ifndef SDK_DEBUGCONSOLE_UART\r
49 /* mcux will handle this macro, not define it here */\r
50 #if (!defined(__MCUXPRESSO))\r
51 #define SDK_DEBUGCONSOLE_UART\r
52 #endif\r
53 #endif\r
54 \r
55 #if defined(SDK_DEBUGCONSOLE) && !(SDK_DEBUGCONSOLE)\r
56 #include <stdio.h>\r
57 #endif\r
58 \r
59 /*! @brief Definition to select redirect toolchain printf, scanf to uart or not.\r
60  *\r
61  *  if SDK_DEBUGCONSOLE defined to 0,it represents select toolchain printf, scanf.\r
62  *  if SDK_DEBUGCONSOLE defined to 1,it represents select SDK version printf, scanf.\r
63  *  if SDK_DEBUGCONSOLE defined to 2,it represents disable debugconsole function.\r
64 */\r
65 #if SDK_DEBUGCONSOLE == DEBUGCONSOLE_DISABLE /* Disable debug console */\r
66 #define PRINTF\r
67 #define SCANF\r
68 #define PUTCHAR\r
69 #define GETCHAR\r
70 #elif SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK /* Select printf, scanf, putchar, getchar of SDK version. */\r
71 #define PRINTF DbgConsole_Printf\r
72 #define SCANF DbgConsole_Scanf\r
73 #define PUTCHAR DbgConsole_Putchar\r
74 #define GETCHAR DbgConsole_Getchar\r
75 #elif SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_TOOLCHAIN /* Select printf, scanf, putchar, getchar of toolchain. \ \\r
76                                                                 */\r
77 #define PRINTF printf\r
78 #define SCANF scanf\r
79 #define PUTCHAR putchar\r
80 #define GETCHAR getchar\r
81 #endif /* SDK_DEBUGCONSOLE */\r
82 \r
83 /*******************************************************************************\r
84  * Prototypes\r
85  ******************************************************************************/\r
86 \r
87 #if defined(__cplusplus)\r
88 extern "C" {\r
89 #endif /* __cplusplus */\r
90 \r
91 /*! @name Initialization*/\r
92 /* @{ */\r
93 \r
94 /*!\r
95  * @brief Initializes the peripheral used for debug messages.\r
96  *\r
97  * Call this function to enable debug log messages to be output via the specified peripheral\r
98  * initialized by the serial manager module.\r
99  * After this function has returned, stdout and stdin are connected to the selected peripheral.\r
100  *\r
101  * @param instance      The instance of the module.\r
102  * @param baudRate      The desired baud rate in bits per second.\r
103  * @param device        Low level device type for the debug console, can be one of the following.\r
104  *                      @arg kSerialPort_Uart,\r
105  *                      @arg kSerialPort_UsbCdc.\r
106  * @param clkSrcFreq    Frequency of peripheral source clock.\r
107  *\r
108  * @return              Indicates whether initialization was successful or not.\r
109  * @retval kStatus_Success          Execution successfully\r
110  */\r
111 status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq);\r
112 \r
113 /*!\r
114  * @brief De-initializes the peripheral used for debug messages.\r
115  *\r
116  * Call this function to disable debug log messages to be output via the specified peripheral\r
117  * initialized by the serial manager module.\r
118  *\r
119  * @return Indicates whether de-initialization was successful or not.\r
120  */\r
121 status_t DbgConsole_Deinit(void);\r
122 \r
123 #if SDK_DEBUGCONSOLE\r
124 /*!\r
125  * @brief Writes formatted output to the standard output stream.\r
126  *\r
127  * Call this function to write a formatted output to the standard output stream.\r
128  *\r
129  * @param   formatString Format control string.\r
130  * @return  Returns the number of characters printed or a negative value if an error occurs.\r
131  */\r
132 int DbgConsole_Printf(const char *formatString, ...);\r
133 \r
134 /*!\r
135  * @brief Writes a character to stdout.\r
136  *\r
137  * Call this function to write a character to stdout.\r
138  *\r
139  * @param   ch Character to be written.\r
140  * @return  Returns the character written.\r
141  */\r
142 int DbgConsole_Putchar(int ch);\r
143 \r
144 /*!\r
145  * @brief Reads formatted data from the standard input stream.\r
146  *\r
147  * Call this function to read formatted data from the standard input stream.\r
148  *\r
149  * @note Due the limitation in the BM OSA environment (CPU is blocked in the function,\r
150  * other tasks will not be scheduled), the function cannot be used when the\r
151  * DEBUG_CONSOLE_TRANSFER_NON_BLOCKING is set in the BM OSA environment.\r
152  * And an error is returned when the function called in this case. The suggestion\r
153  * is that polling the non-blocking function DbgConsole_TryGetchar to get the input char.\r
154  *\r
155  * @param   formatString Format control string.\r
156  * @return  Returns the number of fields successfully converted and assigned.\r
157  */\r
158 int DbgConsole_Scanf(char *formatString, ...);\r
159 \r
160 /*!\r
161  * @brief Reads a character from standard input.\r
162  *\r
163  * Call this function to read a character from standard input.\r
164  *\r
165  * @note Due the limitation in the BM OSA environment (CPU is blocked in the function,\r
166  * other tasks will not be scheduled), the function cannot be used when the\r
167  * DEBUG_CONSOLE_TRANSFER_NON_BLOCKING is set in the BM OSA environment.\r
168  * And an error is returned when the function called in this case. The suggestion\r
169  * is that polling the non-blocking function DbgConsole_TryGetchar to get the input char.\r
170  *\r
171  * @return Returns the character read.\r
172  */\r
173 int DbgConsole_Getchar(void);\r
174 \r
175 /*!\r
176  * @brief Debug console flush.\r
177  *\r
178  * Call this function to wait the tx buffer empty.\r
179  * If interrupt transfer is using, make sure the global IRQ is enable before call this function\r
180  * This function should be called when\r
181  * 1, before enter power down mode\r
182  * 2, log is required to print to terminal immediately\r
183  * @return Indicates whether wait idle was successful or not.\r
184  */\r
185 status_t DbgConsole_Flush(void);\r
186 \r
187 #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING\r
188 /*!\r
189  * @brief Debug console try to get char\r
190  * This function provides a API which will not block current task, if character is\r
191  * available return it, otherwise return fail.\r
192  * @param ch the address of char to receive\r
193  * @return Indicates get char was successful or not.\r
194  */\r
195 status_t DbgConsole_TryGetchar(char *ch);\r
196 #endif\r
197 \r
198 #endif /* SDK_DEBUGCONSOLE */\r
199 \r
200 /*! @} */\r
201 \r
202 #if defined(__cplusplus)\r
203 }\r
204 #endif /* __cplusplus */\r
205 \r
206 /*! @} */\r
207 \r
208 #endif /* _FSL_DEBUGCONSOLE_H_ */\r