Cleanup, apply standards to debug_frmwrk.c

Although this is an external contribution, clean up anyway to stop seeing it in global searches for typical flaws.
This commit is contained in:
Scott Lahteine 2017-10-25 02:35:43 -05:00
parent 55653dce63
commit 203f2923a1

View file

@ -1,11 +1,11 @@
/********************************************************************** /**********************************************************************
* $Id$ debug_frmwrk.c 2010-05-21 * $Id$ debug_frmwrk.c 2010-05-21
*//** *
* @file debug_frmwrk.c * @file debug_frmwrk.c
* @brief Contains some utilities that used for debugging through UART * @brief Contains some utilities that used for debugging through UART
* @version 2.0 * @version 2.0
* @date 21. May. 2010 * @date 21. May. 2010
* @author NXP MCU SW Application Team * @author NXP MCU SW Application Team
* *
* Copyright(C) 2010, NXP Semiconductor * Copyright(C) 2010, NXP Semiconductor
* All rights reserved. * All rights reserved.
@ -37,12 +37,13 @@
* otherwise the default FW library configuration file must be included instead * otherwise the default FW library configuration file must be included instead
*/ */
#ifdef __BUILD_WITH_EXAMPLE__ #ifdef __BUILD_WITH_EXAMPLE__
#include "lpc17xx_libcfg.h" #include "lpc17xx_libcfg.h"
#else #else
#include "lpc17xx_libcfg_default.h" #include "lpc17xx_libcfg_default.h"
#endif /* __BUILD_WITH_EXAMPLE__ */ #endif
#ifdef _DBGFWK #ifdef _DBGFWK
/* Debug framework */ /* Debug framework */
static Bool debug_frmwrk_initialized = FALSE; static Bool debug_frmwrk_initialized = FALSE;
@ -59,284 +60,247 @@ uint8_t (*_db_get_char)(LPC_UART_TypeDef *UARTx) = UARTGetChar;
/*********************************************************************//** /*********************************************************************//**
* @brief Puts a character to UART port * @brief Puts a character to UART port
* @param[in] UARTx Pointer to UART peripheral * @param[in] UARTx Pointer to UART peripheral
* @param[in] ch Character to put * @param[in] ch Character to put
* @return None * @return None
**********************************************************************/ **********************************************************************/
void UARTPutChar (LPC_UART_TypeDef *UARTx, uint8_t ch) void UARTPutChar(LPC_UART_TypeDef *UARTx, uint8_t ch) {
{
if (debug_frmwrk_initialized) if (debug_frmwrk_initialized)
UART_Send(UARTx, &ch, 1, BLOCKING); UART_Send(UARTx, &ch, 1, BLOCKING);
} }
/*********************************************************************//** /*********************************************************************//**
* @brief Get a character to UART port * @brief Get a character to UART port
* @param[in] UARTx Pointer to UART peripheral * @param[in] UARTx Pointer to UART peripheral
* @return character value that returned * @return character value that returned
**********************************************************************/ **********************************************************************/
uint8_t UARTGetChar (LPC_UART_TypeDef *UARTx) uint8_t UARTGetChar(LPC_UART_TypeDef *UARTx) {
{
uint8_t tmp = 0; uint8_t tmp = 0;
if (debug_frmwrk_initialized) if (debug_frmwrk_initialized)
UART_Receive(UARTx, &tmp, 1, BLOCKING); UART_Receive(UARTx, &tmp, 1, BLOCKING);
return(tmp);
}
return(tmp);
/*********************************************************************//**
* @brief Puts a string to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] str string to put
* @return None
**********************************************************************/
void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)
{
uint8_t *s = (uint8_t *) str;
if (!debug_frmwrk_initialized)
return;
while (*s)
{
UARTPutChar(UARTx, *s++);
}
}
/*********************************************************************//**
* @brief Puts a string to UART port and print new line
* @param[in] UARTx Pointer to UART peripheral
* @param[in] str String to put
* @return None
**********************************************************************/
void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str)
{
if (!debug_frmwrk_initialized)
return;
UARTPuts (UARTx, str);
UARTPuts (UARTx, "\n\r");
}
/*********************************************************************//**
* @brief Puts a decimal number to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] decnum Decimal number (8-bit long)
* @return None
**********************************************************************/
void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum)
{
if (!debug_frmwrk_initialized)
return;
uint8_t c1=decnum%10;
uint8_t c2=(decnum/10)%10;
uint8_t c3=(decnum/100)%10;
UARTPutChar(UARTx, '0'+c3);
UARTPutChar(UARTx, '0'+c2);
UARTPutChar(UARTx, '0'+c1);
} }
/*********************************************************************//** /*********************************************************************//**
* @brief Puts a decimal number to UART port * @brief Puts a string to UART port
* @param[in] UARTx Pointer to UART peripheral * @param[in] UARTx Pointer to UART peripheral
* @param[in] decnum Decimal number (8-bit long) * @param[in] str string to put
* @return None * @return None
**********************************************************************/ **********************************************************************/
void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum) void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str) {
{ if (!debug_frmwrk_initialized) return;
if (!debug_frmwrk_initialized)
return;
uint8_t c1=decnum%10; uint8_t *s = (uint8_t*)str;
uint8_t c2=(decnum/10)%10; while (*s) UARTPutChar(UARTx, *s++);
uint8_t c3=(decnum/100)%10;
uint8_t c4=(decnum/1000)%10;
uint8_t c5=(decnum/10000)%10;
UARTPutChar(UARTx, '0'+c5);
UARTPutChar(UARTx, '0'+c4);
UARTPutChar(UARTx, '0'+c3);
UARTPutChar(UARTx, '0'+c2);
UARTPutChar(UARTx, '0'+c1);
} }
/*********************************************************************//** /*********************************************************************//**
* @brief Puts a decimal number to UART port * @brief Puts a string to UART port and print new line
* @param[in] UARTx Pointer to UART peripheral * @param[in] UARTx Pointer to UART peripheral
* @param[in] decnum Decimal number (8-bit long) * @param[in] str String to put
* @return None * @return None
**********************************************************************/ **********************************************************************/
void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum) void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str) {
{ if (!debug_frmwrk_initialized) return;
if (!debug_frmwrk_initialized)
return;
uint8_t c1=decnum%10; UARTPuts (UARTx, str);
uint8_t c2=(decnum/10)%10; UARTPuts (UARTx, "\n\r");
uint8_t c3=(decnum/100)%10;
uint8_t c4=(decnum/1000)%10;
uint8_t c5=(decnum/10000)%10;
uint8_t c6=(decnum/100000)%10;
uint8_t c7=(decnum/1000000)%10;
uint8_t c8=(decnum/10000000)%10;
uint8_t c9=(decnum/100000000)%10;
uint8_t c10=(decnum/1000000000)%10;
UARTPutChar(UARTx, '0'+c10);
UARTPutChar(UARTx, '0'+c9);
UARTPutChar(UARTx, '0'+c8);
UARTPutChar(UARTx, '0'+c7);
UARTPutChar(UARTx, '0'+c6);
UARTPutChar(UARTx, '0'+c5);
UARTPutChar(UARTx, '0'+c4);
UARTPutChar(UARTx, '0'+c3);
UARTPutChar(UARTx, '0'+c2);
UARTPutChar(UARTx, '0'+c1);
} }
/*********************************************************************//** /*********************************************************************//**
* @brief Puts a hex number to UART port * @brief Puts a decimal number to UART port
* @param[in] UARTx Pointer to UART peripheral * @param[in] UARTx Pointer to UART peripheral
* @param[in] hexnum Hex number (8-bit long) * @param[in] decnum Decimal number (8-bit long)
* @return None * @return None
**********************************************************************/ **********************************************************************/
void UARTPutHex (LPC_UART_TypeDef *UARTx, uint8_t hexnum) void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum) {
{ if (!debug_frmwrk_initialized) return;
uint8_t nibble, i;
if (!debug_frmwrk_initialized)
return;
UARTPuts(UARTx, "0x"); uint8_t c1 = decnum%10;
i = 1; uint8_t c2 = (decnum / 10) % 10;
do { uint8_t c3 = (decnum / 100) % 10;
nibble = (hexnum >> (4*i)) & 0x0F; UARTPutChar(UARTx, '0'+c3);
UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble)); UARTPutChar(UARTx, '0'+c2);
} while (i--); UARTPutChar(UARTx, '0'+c1);
}
/*********************************************************************//**
* @brief Puts a hex number to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] hexnum Hex number (16-bit long)
* @return None
**********************************************************************/
void UARTPutHex16 (LPC_UART_TypeDef *UARTx, uint16_t hexnum)
{
uint8_t nibble, i;
if (!debug_frmwrk_initialized)
return;
UARTPuts(UARTx, "0x");
i = 3;
do {
nibble = (hexnum >> (4*i)) & 0x0F;
UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
} while (i--);
} }
/*********************************************************************//** /*********************************************************************//**
* @brief Puts a hex number to UART port * @brief Puts a decimal number to UART port
* @param[in] UARTx Pointer to UART peripheral * @param[in] UARTx Pointer to UART peripheral
* @param[in] hexnum Hex number (32-bit long) * @param[in] decnum Decimal number (8-bit long)
* @return None * @return None
**********************************************************************/ **********************************************************************/
void UARTPutHex32 (LPC_UART_TypeDef *UARTx, uint32_t hexnum) void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum) {
{ if (!debug_frmwrk_initialized) return;
uint8_t nibble, i;
if (!debug_frmwrk_initialized)
return;
UARTPuts(UARTx, "0x"); uint8_t c1 = decnum%10;
i = 7; uint8_t c2 = (decnum / 10) % 10;
do { uint8_t c3 = (decnum / 100) % 10;
nibble = (hexnum >> (4*i)) & 0x0F; uint8_t c4 = (decnum / 1000) % 10;
UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble)); uint8_t c5 = (decnum / 10000) % 10;
} while (i--); UARTPutChar(UARTx, '0'+c5);
UARTPutChar(UARTx, '0'+c4);
UARTPutChar(UARTx, '0'+c3);
UARTPutChar(UARTx, '0'+c2);
UARTPutChar(UARTx, '0'+c1);
} }
///*********************************************************************//** /*********************************************************************//**
// * @brief print function that supports format as same as printf() * @brief Puts a decimal number to UART port
// * function of <stdio.h> library * @param[in] UARTx Pointer to UART peripheral
// * @param[in] None * @param[in] decnum Decimal number (8-bit long)
// * @return None * @return None
// **********************************************************************/ **********************************************************************/
//void _printf (const char *format, ...) void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum) {
//{ if (!debug_frmwrk_initialized) return;
// static char buffer[512 + 1];
// va_list vArgs; const uint8_t c1 = decnum % 10,
// char *tmp; c2 = (decnum / 10) % 10,
// va_start(vArgs, format); c3 = (decnum / 100) % 10,
// vsprintf((char *)buffer, (char const *)format, vArgs); c4 = (decnum / 1000) % 10,
// va_end(vArgs); c5 = (decnum / 10000) % 10,
c6 = (decnum / 100000) % 10,
c7 = (decnum / 1000000) % 10,
c8 = (decnum / 10000000) % 10,
c9 = (decnum / 100000000) % 10,
c10 = (decnum / 1000000000) % 10;
UARTPutChar(UARTx, '0' + c10);
UARTPutChar(UARTx, '0' + c9);
UARTPutChar(UARTx, '0' + c8);
UARTPutChar(UARTx, '0' + c7);
UARTPutChar(UARTx, '0' + c6);
UARTPutChar(UARTx, '0' + c5);
UARTPutChar(UARTx, '0' + c4);
UARTPutChar(UARTx, '0' + c3);
UARTPutChar(UARTx, '0' + c2);
UARTPutChar(UARTx, '0' + c1);
}
/*********************************************************************//**
* @brief Puts a hex number to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] hexnum Hex number (8-bit long)
* @return None
**********************************************************************/
void UARTPutHex(LPC_UART_TypeDef *UARTx, uint8_t hexnum) {
if (!debug_frmwrk_initialized) return;
UARTPuts(UARTx, "0x");
uint8_t nibble, i = 1;
do {
nibble = (hexnum >> (4 * i)) & 0x0F;
UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
} while (i--);
}
/*********************************************************************//**
* @brief Puts a hex number to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] hexnum Hex number (16-bit long)
* @return None
**********************************************************************/
void UARTPutHex16(LPC_UART_TypeDef *UARTx, uint16_t hexnum) {
if (!debug_frmwrk_initialized) return;
UARTPuts(UARTx, "0x");
uint8_t nibble, i = 3;
do {
nibble = (hexnum >> (4 * i)) & 0x0F;
UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
} while (i--);
}
/*********************************************************************//**
* @brief Puts a hex number to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] hexnum Hex number (32-bit long)
* @return None
**********************************************************************/
void UARTPutHex32(LPC_UART_TypeDef *UARTx, uint32_t hexnum) {
if (!debug_frmwrk_initialized) return;
UARTPuts(UARTx, "0x");
uint8_t nibble, i = 7;
do {
nibble = (hexnum >> (4 * i)) & 0x0F;
UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
} while (i--);
}
/*********************************************************************//**
* @brief print function that supports format as same as printf()
* function of <stdio.h> library
* @param[in] None
* @return None
**********************************************************************/
//void _printf (const char *format, ...) {
// static char buffer[512 + 1];
// va_list vArgs;
// char *tmp;
// va_start(vArgs, format);
// vsprintf((char *)buffer, (char const *)format, vArgs);
// va_end(vArgs);
// //
// _DBG(buffer); // _DBG(buffer);
//} //}
/*********************************************************************//** /*********************************************************************//**
* @brief Initialize Debug frame work through initializing UART port * @brief Initialize Debug frame work through initializing UART port
* @param[in] None * @param[in] None
* @return None * @return None
**********************************************************************/ **********************************************************************/
void debug_frmwrk_init(void) void debug_frmwrk_init(void) {
{ UART_CFG_Type UARTConfigStruct;
UART_CFG_Type UARTConfigStruct; PINSEL_CFG_Type PinCfg;
PINSEL_CFG_Type PinCfg;
#if (USED_UART_DEBUG_PORT==0) #if (USED_UART_DEBUG_PORT==0)
/* /*
* Initialize UART0 pin connect * Initialize UART0 pin connect
*/ */
PinCfg.Funcnum = 1; PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0; PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0; PinCfg.Pinmode = 0;
PinCfg.Pinnum = 2; PinCfg.Pinnum = 2;
PinCfg.Portnum = 0; PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg); PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 3; PinCfg.Pinnum = 3;
PINSEL_ConfigPin(&PinCfg); PINSEL_ConfigPin(&PinCfg);
#elif (USED_UART_DEBUG_PORT==1) #elif (USED_UART_DEBUG_PORT==1)
/* /*
* Initialize UART1 pin connect * Initialize UART1 pin connect
*/ */
PinCfg.Funcnum = 1; PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0; PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0; PinCfg.Pinmode = 0;
PinCfg.Pinnum = 15; PinCfg.Pinnum = 15;
PinCfg.Portnum = 0; PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg); PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 16; PinCfg.Pinnum = 16;
PINSEL_ConfigPin(&PinCfg); PINSEL_ConfigPin(&PinCfg);
#endif #endif
/* Initialize UART Configuration parameter structure to default state: /* Initialize UART Configuration parameter structure to default state:
* Baudrate = 9600bps * Baudrate = 9600bps
* 8 data bit * 8 data bit
* 1 Stop bit * 1 Stop bit
* None parity * None parity
*/ */
UART_ConfigStructInit(&UARTConfigStruct); UART_ConfigStructInit(&UARTConfigStruct);
// Re-configure baudrate to 115200bps // Re-configure baudrate to 115200bps
UARTConfigStruct.Baud_rate = 115200; UARTConfigStruct.Baud_rate = 115200;
// Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter // Initialize DEBUG_UART_PORT peripheral with given to corresponding parameter
UART_Init((LPC_UART_TypeDef *)DEBUG_UART_PORT, &UARTConfigStruct); UART_Init((LPC_UART_TypeDef *)DEBUG_UART_PORT, &UARTConfigStruct);
// Enable UART Transmit // Enable UART Transmit
UART_TxCmd((LPC_UART_TypeDef *)DEBUG_UART_PORT, ENABLE); UART_TxCmd((LPC_UART_TypeDef *)DEBUG_UART_PORT, ENABLE);
debug_frmwrk_initialized = TRUE; debug_frmwrk_initialized = TRUE;
} }
#endif /*_DBGFWK */
#endif // _DBGFWK
/* --------------------------------- End Of File ------------------------------ */