]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_MPU_LPC54018_MCUXpresso/NXP_Code/utilities/fsl_debug_console.h
Add MPU demo project for LPC54018 board.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_LPC54018_MCUXpresso / NXP_Code / utilities / fsl_debug_console.h
diff --git a/FreeRTOS/Demo/CORTEX_MPU_LPC54018_MCUXpresso/NXP_Code/utilities/fsl_debug_console.h b/FreeRTOS/Demo/CORTEX_MPU_LPC54018_MCUXpresso/NXP_Code/utilities/fsl_debug_console.h
new file mode 100644 (file)
index 0000000..ec50606
--- /dev/null
@@ -0,0 +1,244 @@
+/*\r
+ * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.\r
+ * Copyright 2016-2018 NXP\r
+ * All rights reserved.\r
+ *\r
+ * SPDX-License-Identifier: BSD-3-Clause\r
+ *\r
+ * Debug console shall provide input and output functions to scan and print formatted data.\r
+ * o Support a format specifier for PRINTF follows this prototype "%[flags][width][.precision][length]specifier"\r
+ *   - [flags] :'-', '+', '#', ' ', '0'\r
+ *   - [width]:  number (0,1...)\r
+ *   - [.precision]: number (0,1...)\r
+ *   - [length]: do not support\r
+ *   - [specifier]: 'd', 'i', 'f', 'F', 'x', 'X', 'o', 'p', 'u', 'c', 's', 'n'\r
+ * o Support a format specifier for SCANF follows this prototype " %[*][width][length]specifier"\r
+ *   - [*]: is supported.\r
+ *   - [width]: number (0,1...)\r
+ *   - [length]: 'h', 'hh', 'l','ll','L'. ignore ('j','z','t')\r
+ *   - [specifier]: 'd', 'i', 'u', 'f', 'F', 'e', 'E', 'g', 'G', 'a', 'A', 'o', 'c', 's'\r
+ */\r
+\r
+#ifndef _FSL_DEBUGCONSOLE_H_\r
+#define _FSL_DEBUGCONSOLE_H_\r
+\r
+#include "fsl_common.h"\r
+#include "serial_manager.h"\r
+\r
+/*!\r
+ * @addtogroup debugconsole\r
+ * @{\r
+ */\r
+\r
+/*******************************************************************************\r
+ * Definitions\r
+ ******************************************************************************/\r
+\r
+extern serial_handle_t g_serialHandle; /*!< serial manager handle */\r
+\r
+/*! @brief Definition select redirect toolchain printf, scanf to uart or not. */\r
+#define DEBUGCONSOLE_REDIRECT_TO_TOOLCHAIN 0U /*!< Select toolchain printf and scanf. */\r
+#define DEBUGCONSOLE_REDIRECT_TO_SDK 1U       /*!< Select SDK version printf, scanf. */\r
+#define DEBUGCONSOLE_DISABLE 2U               /*!< Disable debugconsole function. */\r
+\r
+/*! @brief Definition to select sdk or toolchain printf, scanf. The macro only support\r
+ * to be redefined in project setting.\r
+ */\r
+#ifndef SDK_DEBUGCONSOLE\r
+#define SDK_DEBUGCONSOLE 1U\r
+#endif\r
+\r
+#if defined(SDK_DEBUGCONSOLE) && !(SDK_DEBUGCONSOLE)\r
+#include <stdio.h>\r
+#endif\r
+\r
+/*! @brief Definition to select redirect toolchain printf, scanf to uart or not.\r
+ *\r
+ *  if SDK_DEBUGCONSOLE defined to 0,it represents select toolchain printf, scanf.\r
+ *  if SDK_DEBUGCONSOLE defined to 1,it represents select SDK version printf, scanf.\r
+ *  if SDK_DEBUGCONSOLE defined to 2,it represents disable debugconsole function.\r
+ */\r
+#if SDK_DEBUGCONSOLE == DEBUGCONSOLE_DISABLE /* Disable debug console */\r
+#define PRINTF\r
+#define SCANF\r
+#define PUTCHAR\r
+#define GETCHAR\r
+#elif SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK /* Select printf, scanf, putchar, getchar of SDK version. */\r
+#define PRINTF DbgConsole_Printf\r
+#define SCANF DbgConsole_Scanf\r
+#define PUTCHAR DbgConsole_Putchar\r
+#define GETCHAR DbgConsole_Getchar\r
+#elif SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_TOOLCHAIN /* Select printf, scanf, putchar, getchar of toolchain. \ \\r
+                                                              */\r
+#define PRINTF printf\r
+#define SCANF scanf\r
+#define PUTCHAR putchar\r
+#define GETCHAR getchar\r
+#endif /* SDK_DEBUGCONSOLE */\r
+\r
+/*******************************************************************************\r
+ * Prototypes\r
+ ******************************************************************************/\r
+\r
+#if defined(__cplusplus)\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+/*! @name Initialization*/\r
+/* @{ */\r
+\r
+#if ((SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK) || defined(SDK_DEBUGCONSOLE_UART))\r
+/*!\r
+ * @brief Initializes the peripheral used for debug messages.\r
+ *\r
+ * Call this function to enable debug log messages to be output via the specified peripheral\r
+ * initialized by the serial manager module.\r
+ * After this function has returned, stdout and stdin are connected to the selected peripheral.\r
+ *\r
+ * @param instance      The instance of the module.\r
+ * @param baudRate      The desired baud rate in bits per second.\r
+ * @param device        Low level device type for the debug console, can be one of the following.\r
+ *                      @arg kSerialPort_Uart,\r
+ *                      @arg kSerialPort_UsbCdc\r
+ *                      @arg kSerialPort_UsbCdcVirtual.\r
+ * @param clkSrcFreq    Frequency of peripheral source clock.\r
+ *\r
+ * @return              Indicates whether initialization was successful or not.\r
+ * @retval kStatus_Success          Execution successfully\r
+ */\r
+status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq);\r
+\r
+/*!\r
+ * @brief De-initializes the peripheral used for debug messages.\r
+ *\r
+ * Call this function to disable debug log messages to be output via the specified peripheral\r
+ * initialized by the serial manager module.\r
+ *\r
+ * @return Indicates whether de-initialization was successful or not.\r
+ */\r
+status_t DbgConsole_Deinit(void);\r
+#else\r
+/*!\r
+ * Use an error to replace the DbgConsole_Init when SDK_DEBUGCONSOLE is not DEBUGCONSOLE_REDIRECT_TO_SDK and\r
+ * SDK_DEBUGCONSOLE_UART is not defined.\r
+ */\r
+static inline status_t DbgConsole_Init(uint8_t instance,\r
+                                       uint32_t baudRate,\r
+                                       serial_port_type_t device,\r
+                                       uint32_t clkSrcFreq)\r
+{\r
+    (void)instance;\r
+    (void)baudRate;\r
+    (void)device;\r
+    (void)clkSrcFreq;\r
+    return (status_t)kStatus_Fail;\r
+}\r
+/*!\r
+ * Use an error to replace the DbgConsole_Deinit when SDK_DEBUGCONSOLE is not DEBUGCONSOLE_REDIRECT_TO_SDK and\r
+ * SDK_DEBUGCONSOLE_UART is not defined.\r
+ */\r
+static inline status_t DbgConsole_Deinit(void)\r
+{\r
+    return (status_t)kStatus_Fail;\r
+}\r
+#endif /* ((SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK) || defined(SDK_DEBUGCONSOLE_UART)) */\r
+\r
+#if SDK_DEBUGCONSOLE\r
+/*!\r
+ * @brief Writes formatted output to the standard output stream.\r
+ *\r
+ * Call this function to write a formatted output to the standard output stream.\r
+ *\r
+ * @param   formatString Format control string.\r
+ * @return  Returns the number of characters printed or a negative value if an error occurs.\r
+ */\r
+int DbgConsole_Printf(const char *formatString, ...);\r
+\r
+/*!\r
+ * @brief Writes a character to stdout.\r
+ *\r
+ * Call this function to write a character to stdout.\r
+ *\r
+ * @param   ch Character to be written.\r
+ * @return  Returns the character written.\r
+ */\r
+int DbgConsole_Putchar(int ch);\r
+\r
+/*!\r
+ * @brief Reads formatted data from the standard input stream.\r
+ *\r
+ * Call this function to read formatted data from the standard input stream.\r
+ *\r
+ * @note Due the limitation in the BM OSA environment (CPU is blocked in the function,\r
+ * other tasks will not be scheduled), the function cannot be used when the\r
+ * DEBUG_CONSOLE_TRANSFER_NON_BLOCKING is set in the BM OSA environment.\r
+ * And an error is returned when the function called in this case. The suggestion\r
+ * is that polling the non-blocking function DbgConsole_TryGetchar to get the input char.\r
+ *\r
+ * @param   formatString Format control string.\r
+ * @return  Returns the number of fields successfully converted and assigned.\r
+ */\r
+int DbgConsole_Scanf(char *formatString, ...);\r
+\r
+/*!\r
+ * @brief Reads a character from standard input.\r
+ *\r
+ * Call this function to read a character from standard input.\r
+ *\r
+ * @note Due the limitation in the BM OSA environment (CPU is blocked in the function,\r
+ * other tasks will not be scheduled), the function cannot be used when the\r
+ * DEBUG_CONSOLE_TRANSFER_NON_BLOCKING is set in the BM OSA environment.\r
+ * And an error is returned when the function called in this case. The suggestion\r
+ * is that polling the non-blocking function DbgConsole_TryGetchar to get the input char.\r
+ *\r
+ * @return Returns the character read.\r
+ */\r
+int DbgConsole_Getchar(void);\r
+\r
+/*!\r
+ * @brief Writes formatted output to the standard output stream with the blocking mode.\r
+ *\r
+ * Call this function to write a formatted output to the standard output stream with the blocking mode.\r
+ * The function will send data with blocking mode no matter the DEBUG_CONSOLE_TRANSFER_NON_BLOCKING set\r
+ * or not.\r
+ * The function could be used in system ISR mode with DEBUG_CONSOLE_TRANSFER_NON_BLOCKING set.\r
+ *\r
+ * @param   formatString Format control string.\r
+ * @return  Returns the number of characters printed or a negative value if an error occurs.\r
+ */\r
+int DbgConsole_BlockingPrintf(const char *formatString, ...);\r
+\r
+/*!\r
+ * @brief Debug console flush.\r
+ *\r
+ * Call this function to wait the tx buffer empty.\r
+ * If interrupt transfer is using, make sure the global IRQ is enable before call this function\r
+ * This function should be called when\r
+ * 1, before enter power down mode\r
+ * 2, log is required to print to terminal immediately\r
+ * @return Indicates whether wait idle was successful or not.\r
+ */\r
+status_t DbgConsole_Flush(void);\r
+\r
+#ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING\r
+/*!\r
+ * @brief Debug console try to get char\r
+ * This function provides a API which will not block current task, if character is\r
+ * available return it, otherwise return fail.\r
+ * @param ch the address of char to receive\r
+ * @return Indicates get char was successful or not.\r
+ */\r
+status_t DbgConsole_TryGetchar(char *ch);\r
+#endif\r
+\r
+#endif /* SDK_DEBUGCONSOLE */\r
+\r
+/*! @} */\r
+\r
+#if defined(__cplusplus)\r
+}\r
+#endif /* __cplusplus */\r
+\r
+/*! @} */\r
+\r
+#endif /* _FSL_DEBUGCONSOLE_H_ */\r