diff options
author | Bhuvanchandra DV <bhuvanchandra.dv@toradex.com> | 2016-07-08 16:41:50 +0530 |
---|---|---|
committer | Bhuvanchandra DV <bhuvanchandra.dv@gmail.com> | 2016-07-22 14:37:31 +0530 |
commit | 72dd5f6900c5af5f5ce1cd750aa1aacabb2c00e0 (patch) | |
tree | 36126c7bba9c4252e1ff31992371596c731756d4 | |
parent | b2140e7ea49c4e38341d9ae5d922b6e9c474eabd (diff) |
platform: utilities: debug_console: split platform independent code
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
-rw-r--r-- | platform/utilities/inc/debug_console.h | 142 | ||||
-rw-r--r-- | platform/utilities/inc/debug_console_imx.h | 116 | ||||
-rw-r--r-- | platform/utilities/src/debug_console.c | 312 | ||||
-rw-r--r-- | platform/utilities/src/debug_console_imx.c | 336 |
4 files changed, 479 insertions, 427 deletions
diff --git a/platform/utilities/inc/debug_console.h b/platform/utilities/inc/debug_console.h new file mode 100644 index 0000000..74fd462 --- /dev/null +++ b/platform/utilities/inc/debug_console.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * o Neither the name of Freescale Semiconductor, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __DEBUG_CONSOLE_H__ +#define __DEBUG_CONSOLE_H__ + +#include <stdbool.h> +#include <stdint.h> + +/*! + * @addtogroup debug_console + * @{ + */ + +/******************************************************************************* + * Definitions + ******************************************************************************/ + +/*! @brief Operation functions definitions for debug console. */ +typedef struct DebugConsoleOperationFunctions { + void (* Send)(void *base, const uint8_t *buf, uint32_t count); + void (* Receive)(void *base, uint8_t *buf, uint32_t count); +} debug_console_ops_t; + +/*! @brief State structure storing debug console. */ +typedef struct DebugConsoleState { + bool inited; /*<! Identify debug console inited or not. */ + void* base; /*<! Base of the IP register. */ + debug_console_ops_t ops; /*<! Operation function pointers for debug uart operations. */ +} debug_console_state_t; + +#define IO_MAXLINE 20 + +/*! @brief Configuration for toolchain's printf/scanf or Freescale version printf/scanf */ +#define PRINTF debug_printf +//#define PRINTF printf +#define SCANF debug_scanf +//#define SCANF scanf +#define PUTCHAR debug_putchar +//#define PUTCHAR putchar +#define GETCHAR debug_getchar +//#define GETCHAR getchar + +/*! @brief Error code for the debug console driver. */ +typedef enum _debug_console_status { + status_DEBUGCONSOLE_Success = 0U, + status_DEBUGCONSOLE_InvalidDevice, + status_DEBUGCONSOLE_AllocateMemoryFailed, + status_DEBUGCONSOLE_Failed +} debug_console_status_t; + +/******************************************************************************* + * API + ******************************************************************************/ + +#if defined(__cplusplus) +extern "C" { +#endif + +/*! + * @name Initialization + * @{ + */ + +debug_console_status_t DbgConsole_Init(debug_console_state_t *prv_debugConsole); + +/*! + * @brief Prints formatted output to the standard output stream. + * + * Call this function to print formatted output to the standard output stream. + * + * @param fmt_s Format control string. + * @return Returns the number of characters printed, or a negative value if an error occurs. + */ +int debug_printf(const char *fmt_s, ...); + +/*! + * @brief Writes a character to stdout. + * + * Call this function to write a character to stdout. + * + * @param ch Character to be written. + * @return Returns the character written. + */ +int debug_putchar(int ch); + +/*! + * @brief Reads formatted data from the standard input stream. + * + * Call this function to read formatted data from the standard input stream. + * + * @param fmt_ptr Format control string. + * @return Returns the number of fields successfully converted and assigned. + */ +int debug_scanf(const char *fmt_ptr, ...); + +/*! + * @brief Reads a character from standard input. + * + * Call this function to read a character from standard input. + * + * @return Returns the character read. + */ +int debug_getchar(void); + +#if defined(__cplusplus) +} +#endif + +/*! @}*/ + +#endif /* __DEBUG_CONSOLE_H__ */ +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/platform/utilities/inc/debug_console_imx.h b/platform/utilities/inc/debug_console_imx.h index 21069b8..dd4bd06 100644 --- a/platform/utilities/inc/debug_console_imx.h +++ b/platform/utilities/inc/debug_console_imx.h @@ -31,122 +31,14 @@ #ifndef __DEBUG_CONSOLE_IMX_H__ #define __DEBUG_CONSOLE_IMX_H__ +#include <stdbool.h> #include <stdint.h> #include "device_imx.h" +#include "debug_console.h" -/*! - * @addtogroup debug_console - * @{ - */ - -/******************************************************************************* - * Definitions - ******************************************************************************/ -#define IO_MAXLINE 20 - -/*! @brief Configuration for toolchain's printf/scanf or Freescale version printf/scanf */ -#define PRINTF debug_printf -//#define PRINTF printf -#define SCANF debug_scanf -//#define SCANF scanf -#define PUTCHAR debug_putchar -//#define PUTCHAR putchar -#define GETCHAR debug_getchar -//#define GETCHAR getchar - -/*! @brief Error code for the debug console driver. */ -typedef enum _debug_console_status { - status_DEBUGCONSOLE_Success = 0U, - status_DEBUGCONSOLE_InvalidDevice, - status_DEBUGCONSOLE_AllocateMemoryFailed, - status_DEBUGCONSOLE_Failed -} debug_console_status_t; - -/******************************************************************************* - * API - ******************************************************************************/ - -#if defined(__cplusplus) -extern "C" { -#endif - -/*! - * @name Initialization - * @{ - */ - -/*! - * @brief Init the UART_IMX used for debug messages. - * - * Call this function to enable debug log messages to be output via the specified UART_IMX - * base address and at the specified baud rate. Just initializes the UART_IMX to the given baud - * rate and 8N1. After this function has returned, stdout and stdin will be connected to the - * selected UART_IMX. The debug_printf() function also uses this UART_IMX. - * - * @param base Which UART_IMX instance is used to send debug messages. - * @param clockRate The input clock of UART_IMX module. - * @param baudRate The desired baud rate in bits per second. - * @param mode The Modem mode (DTE/DCE), (see _uart_modem_mode enumeration). - * @return Whether initialization was successful or not. - */ -debug_console_status_t DbgConsole_Init(UART_Type* base, - uint32_t clockRate, - uint32_t baudRate, +void imx_DbgConsole_Init(UART_Type* base, uint32_t clockRate, uint32_t baudRate, uint32_t mode); - -/*! - * @brief Deinit the UART/LPUART used for debug messages. - * - * Call this function to disable debug log messages to be output via the specified UART/LPUART - * base address and at the specified baud rate. - * @return Whether de-initialization was successful or not. - */ -debug_console_status_t DbgConsole_DeInit(void); - -/*! - * @brief Prints formatted output to the standard output stream. - * - * Call this function to print formatted output to the standard output stream. - * - * @param fmt_s Format control string. - * @return Returns the number of characters printed, or a negative value if an error occurs. - */ -int debug_printf(const char *fmt_s, ...); - -/*! - * @brief Writes a character to stdout. - * - * Call this function to write a character to stdout. - * - * @param ch Character to be written. - * @return Returns the character written. - */ -int debug_putchar(int ch); - -/*! - * @brief Reads formatted data from the standard input stream. - * - * Call this function to read formatted data from the standard input stream. - * - * @param fmt_ptr Format control string. - * @return Returns the number of fields successfully converted and assigned. - */ -int debug_scanf(const char *fmt_ptr, ...); - -/*! - * @brief Reads a character from standard input. - * - * Call this function to read a character from standard input. - * - * @return Returns the character read. - */ -int debug_getchar(void); - -#if defined(__cplusplus) -} -#endif - -/*! @}*/ +void imx_DbgConsole_DeInit(void); #endif /* __DEBUG_CONSOLE_IMX_H__ */ /******************************************************************************* diff --git a/platform/utilities/src/debug_console.c b/platform/utilities/src/debug_console.c new file mode 100644 index 0000000..6a0366a --- /dev/null +++ b/platform/utilities/src/debug_console.c @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2015, Freescale Semiconductor, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * o Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * + * o Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * o Neither the name of Freescale Semiconductor, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include "debug_console.h" +#include "print_scan.h" + +#if __ICCARM__ +#include <yfuns.h> +#endif + +static int debug_putc(int ch, void* stream); + +/******************************************************************************* + * Variables + ******************************************************************************/ +/*! @brief Debug UART state information.*/ +static debug_console_state_t s_debugConsole; + +/******************************************************************************* + * Code + ******************************************************************************/ +debug_console_status_t DbgConsole_Init(debug_console_state_t *prv_debugConsole) +{ + if (s_debugConsole.inited) + { + return status_DEBUGCONSOLE_Failed; + } + + s_debugConsole.base = prv_debugConsole->base; + /* Set the function pointer for send and receive for this kind of device. */ + s_debugConsole.ops.Send = prv_debugConsole->ops.Send; + s_debugConsole.ops.Receive = prv_debugConsole->ops.Receive; + + s_debugConsole.inited = true; + return status_DEBUGCONSOLE_Success; +} + +#if __ICCARM__ +#pragma weak __write +size_t __write(int handle, const unsigned char * buffer, size_t size) +{ + if (buffer == 0) + { + /* This means that we should flush internal buffers. Since we*/ + /* don't we just return. (Remember, "handle" == -1 means that all*/ + /* handles should be flushed.)*/ + return 0; + } + + /* This function only writes to "standard out" and "standard err",*/ + /* for all other file handles it returns failure.*/ + if ((handle != _LLIO_STDOUT) && (handle != _LLIO_STDERR)) + { + return _LLIO_ERROR; + } + + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return _LLIO_ERROR; + } + + /* Send data.*/ + s_debugConsole.ops.Send(s_debugConsole.base, (uint8_t const *)buffer, size); + return size; +} + +#pragma weak __read +size_t __read(int handle, unsigned char * buffer, size_t size) +{ + /* This function only reads from "standard in", for all other file*/ + /* handles it returns failure.*/ + if (handle != _LLIO_STDIN) + { + return _LLIO_ERROR; + } + + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return _LLIO_ERROR; + } + + /* Receive data.*/ + s_debugConsole.ops.Receive(s_debugConsole.base, buffer, size); + + return size; +} + +#elif (defined(__GNUC__)) +#pragma weak _write +int _write (int handle, char *buffer, int size) +{ + if (buffer == 0) + { + /* return -1 if error */ + return -1; + } + + /* This function only writes to "standard out" and "standard err",*/ + /* for all other file handles it returns failure.*/ + if ((handle != 1) && (handle != 2)) + { + return -1; + } + + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + + /* Send data.*/ + s_debugConsole.ops.Send(s_debugConsole.base, (uint8_t *)buffer, size); + return size; +} + +#pragma weak _read +int _read(int handle, char *buffer, int size) +{ + /* This function only reads from "standard in", for all other file*/ + /* handles it returns failure.*/ + if (handle != 0) + { + return -1; + } + + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + + /* Receive data.*/ + s_debugConsole.ops.Receive(s_debugConsole.base, (uint8_t *)buffer, size); + return size; +} +#elif defined(__CC_ARM) +struct __FILE +{ + int handle; + /* Whatever you require here. If the only file you are using is */ + /* standard output using printf() for debugging, no file handling */ + /* is required. */ +}; + +/* FILE is typedef in stdio.h. */ +#pragma weak __stdout +FILE __stdout; +FILE __stdin; + +#pragma weak fputc +int fputc(int ch, FILE *f) +{ + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + + /* Send data.*/ + s_debugConsole.ops.Send(s_debugConsole.base, (const uint8_t*)&ch, 1); + return 1; +} + +#pragma weak fgetc +int fgetc(FILE *f) +{ + uint8_t temp; + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + + /* Receive data.*/ + s_debugConsole.ops.Receive(s_debugConsole.base, &temp, 1); + return temp; +} +#endif + +/*************Code for debug_printf/scanf/assert*******************************/ +int debug_printf(const char *fmt_s, ...) +{ + va_list ap; + int result; + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + + va_start(ap, fmt_s); + result = _doprint(NULL, debug_putc, -1, (char *)fmt_s, ap); + va_end(ap); + + return result; +} + +static int debug_putc(int ch, void* stream) +{ + const unsigned char c = (unsigned char) ch; + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + s_debugConsole.ops.Send(s_debugConsole.base, &c, 1); + + return 0; +} + +int debug_putchar(int ch) +{ + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + debug_putc(ch, NULL); + + return 1; +} + +int debug_scanf(const char *fmt_ptr, ...) +{ + char temp_buf[IO_MAXLINE]; + va_list ap; + uint32_t i; + char result; + + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + va_start(ap, fmt_ptr); + temp_buf[0] = '\0'; + + for (i = 0; i < IO_MAXLINE; i++) + { + temp_buf[i] = result = debug_getchar(); + + if ((result == '\r') || (result == '\n')) + { + /* End of Line */ + if (i == 0) + { + i = (uint32_t)-1; + } + else + { + break; + } + } + + temp_buf[i + 1] = '\0'; + } + + result = scan_prv(temp_buf, (char *)fmt_ptr, ap); + va_end(ap); + + return result; +} + +int debug_getchar(void) +{ + unsigned char c; + + /* Do nothing if the debug uart is not initialized.*/ + if (!s_debugConsole.inited) + { + return -1; + } + s_debugConsole.ops.Receive(s_debugConsole.base, &c, 1); + + return c; +} + +/******************************************************************************* + * EOF + ******************************************************************************/ diff --git a/platform/utilities/src/debug_console_imx.c b/platform/utilities/src/debug_console_imx.c index 93c9a3c..7d53b82 100644 --- a/platform/utilities/src/debug_console_imx.c +++ b/platform/utilities/src/debug_console_imx.c @@ -28,337 +28,43 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <stdbool.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include "device_imx.h" #include "debug_console_imx.h" #include "uart_imx.h" -#include "print_scan.h" -#if __ICCARM__ -#include <yfuns.h> -#endif - -static int debug_putc(int ch, void* stream); static void UART_SendDataPolling(void *base, const uint8_t *txBuff, uint32_t txSize); static void UART_ReceiveDataPolling(void *base, uint8_t *rxBuff, uint32_t rxSize); -/******************************************************************************* - * Definitions - ******************************************************************************/ - -/*! @brief Operation functions definitions for debug console. */ -typedef struct DebugConsoleOperationFunctions { - void (* Send)(void *base, const uint8_t *buf, uint32_t count); - void (* Receive)(void *base, uint8_t *buf, uint32_t count); -} debug_console_ops_t; - -/*! @brief State structure storing debug console. */ -typedef struct DebugConsoleState { - bool inited; /*<! Identify debug console inited or not. */ - void* base; /*<! Base of the IP register. */ - debug_console_ops_t ops; /*<! Operation function pointers for debug uart operations. */ -} debug_console_state_t; - -/******************************************************************************* - * Variables - ******************************************************************************/ -/*! @brief Debug UART state information.*/ -static debug_console_state_t s_debugConsole; +debug_console_state_t prv_debugConsole; -/******************************************************************************* - * Code - ******************************************************************************/ -/* See fsl_debug_console_imx.h for documentation of this function.*/ -debug_console_status_t DbgConsole_Init(UART_Type* base, - uint32_t clockRate, +void imx_DbgConsole_Init(UART_Type* base, uint32_t clockRate, uint32_t baudRate, uint32_t mode) { - if (s_debugConsole.inited) - { - return status_DEBUGCONSOLE_Failed; - } - - s_debugConsole.base = base; - /* Setup UART init structure. */ - uart_init_config_t uart_init_str = {.clockRate = clockRate, - .baudRate = baudRate, - .wordLength = uartWordLength8Bits, - .stopBitNum = uartStopBitNumOne, - .parity = uartParityDisable, - .direction = uartDirectionTxRx}; - /* UART Init operation */ - UART_Init(s_debugConsole.base, &uart_init_str); - UART_Enable(s_debugConsole.base); - UART_SetModemMode(s_debugConsole.base, mode); - /* Set the function pointer for send and receive for this kind of device. */ - s_debugConsole.ops.Send = UART_SendDataPolling; - s_debugConsole.ops.Receive = UART_ReceiveDataPolling; - - s_debugConsole.inited = true; - return status_DEBUGCONSOLE_Success; -} - -/* See fsl_debug_console.h for documentation of this function.*/ -debug_console_status_t DbgConsole_DeInit(void) -{ - if (!s_debugConsole.inited) - { - return status_DEBUGCONSOLE_Success; - } - - /* UART Deinit operation */ - UART_Disable(s_debugConsole.base); - UART_Deinit(s_debugConsole.base); - - s_debugConsole.inited = false; - - return status_DEBUGCONSOLE_Success; -} - -#if __ICCARM__ -#pragma weak __write -size_t __write(int handle, const unsigned char * buffer, size_t size) -{ - if (buffer == 0) - { - /* This means that we should flush internal buffers. Since we*/ - /* don't we just return. (Remember, "handle" == -1 means that all*/ - /* handles should be flushed.)*/ - return 0; - } - - /* This function only writes to "standard out" and "standard err",*/ - /* for all other file handles it returns failure.*/ - if ((handle != _LLIO_STDOUT) && (handle != _LLIO_STDERR)) - { - return _LLIO_ERROR; - } - - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return _LLIO_ERROR; - } - - /* Send data.*/ - s_debugConsole.ops.Send(s_debugConsole.base, (uint8_t const *)buffer, size); - return size; -} - -#pragma weak __read -size_t __read(int handle, unsigned char * buffer, size_t size) -{ - /* This function only reads from "standard in", for all other file*/ - /* handles it returns failure.*/ - if (handle != _LLIO_STDIN) - { - return _LLIO_ERROR; - } - - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return _LLIO_ERROR; - } - - /* Receive data.*/ - s_debugConsole.ops.Receive(s_debugConsole.base, buffer, size); - - return size; -} - -#elif (defined(__GNUC__)) -#pragma weak _write -int _write (int handle, char *buffer, int size) -{ - if (buffer == 0) - { - /* return -1 if error */ - return -1; - } - - /* This function only writes to "standard out" and "standard err",*/ - /* for all other file handles it returns failure.*/ - if ((handle != 1) && (handle != 2)) - { - return -1; - } - - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - - /* Send data.*/ - s_debugConsole.ops.Send(s_debugConsole.base, (uint8_t *)buffer, size); - return size; -} - -#pragma weak _read -int _read(int handle, char *buffer, int size) -{ - /* This function only reads from "standard in", for all other file*/ - /* handles it returns failure.*/ - if (handle != 0) - { - return -1; - } - - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - - /* Receive data.*/ - s_debugConsole.ops.Receive(s_debugConsole.base, (uint8_t *)buffer, size); - return size; -} -#elif defined(__CC_ARM) -struct __FILE -{ - int handle; - /* Whatever you require here. If the only file you are using is */ - /* standard output using printf() for debugging, no file handling */ - /* is required. */ -}; - -/* FILE is typedef in stdio.h. */ -#pragma weak __stdout -FILE __stdout; -FILE __stdin; - -#pragma weak fputc -int fputc(int ch, FILE *f) -{ - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - - /* Send data.*/ - s_debugConsole.ops.Send(s_debugConsole.base, (const uint8_t*)&ch, 1); - return 1; -} - -#pragma weak fgetc -int fgetc(FILE *f) -{ - uint8_t temp; - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - - /* Receive data.*/ - s_debugConsole.ops.Receive(s_debugConsole.base, &temp, 1); - return temp; -} -#endif - -/*************Code for debug_printf/scanf/assert*******************************/ -int debug_printf(const char *fmt_s, ...) -{ - va_list ap; - int result; - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - - va_start(ap, fmt_s); - result = _doprint(NULL, debug_putc, -1, (char *)fmt_s, ap); - va_end(ap); - - return result; -} - -static int debug_putc(int ch, void* stream) -{ - const unsigned char c = (unsigned char) ch; - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - s_debugConsole.ops.Send(s_debugConsole.base, &c, 1); - - return 0; -} - -int debug_putchar(int ch) -{ - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - debug_putc(ch, NULL); - - return 1; -} - -int debug_scanf(const char *fmt_ptr, ...) -{ - char temp_buf[IO_MAXLINE]; - va_list ap; - uint32_t i; - char result; - - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - va_start(ap, fmt_ptr); - temp_buf[0] = '\0'; - - for (i = 0; i < IO_MAXLINE; i++) - { - temp_buf[i] = result = debug_getchar(); + prv_debugConsole.base = base; - if ((result == '\r') || (result == '\n')) - { - /* End of Line */ - if (i == 0) - { - i = (uint32_t)-1; - } - else - { - break; - } - } + /* Setup UART init structure. */ + uart_init_config_t uart_init_str = {.clockRate = clockRate, + .baudRate = baudRate, + .wordLength = uartWordLength8Bits, + .stopBitNum = uartStopBitNumOne, + .parity = uartParityDisable, + .direction = uartDirectionTxRx}; + /* UART Init operation */ + UART_Init(prv_debugConsole.base, &uart_init_str); + UART_Enable(prv_debugConsole.base); + UART_SetModemMode(prv_debugConsole.base, mode); - temp_buf[i + 1] = '\0'; - } - - result = scan_prv(temp_buf, (char *)fmt_ptr, ap); - va_end(ap); + prv_debugConsole.ops.Send = UART_SendDataPolling; + prv_debugConsole.ops.Receive = UART_ReceiveDataPolling; - return result; + DbgConsole_Init(&prv_debugConsole); } -int debug_getchar(void) +void imx_DbgConsole_DeInit(void) { - unsigned char c; - - /* Do nothing if the debug uart is not initialized.*/ - if (!s_debugConsole.inited) - { - return -1; - } - s_debugConsole.ops.Receive(s_debugConsole.base, &c, 1); - - return c; + /* UART Deinit operation */ + UART_Disable(prv_debugConsole.base); + UART_Deinit(prv_debugConsole.base); } void UART_SendDataPolling(void *base, const uint8_t *txBuff, uint32_t txSize) |