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,6 +1,6 @@
/**********************************************************************
* $Id$ debug_frmwrk.c 2010-05-21
*//**
*
* @file debug_frmwrk.c
* @brief Contains some utilities that used for debugging through UART
* @version 2.0
@ -40,9 +40,10 @@
#include "lpc17xx_libcfg.h"
#else
#include "lpc17xx_libcfg_default.h"
#endif /* __BUILD_WITH_EXAMPLE__ */
#endif
#ifdef _DBGFWK
/* Debug framework */
static Bool debug_frmwrk_initialized = FALSE;
@ -64,20 +65,17 @@ uint8_t (*_db_get_char)(LPC_UART_TypeDef *UARTx) = UARTGetChar;
* @param[in] ch Character to put
* @return None
**********************************************************************/
void UARTPutChar (LPC_UART_TypeDef *UARTx, uint8_t ch)
{
void UARTPutChar(LPC_UART_TypeDef *UARTx, uint8_t ch) {
if (debug_frmwrk_initialized)
UART_Send(UARTx, &ch, 1, BLOCKING);
}
/*********************************************************************//**
* @brief Get a character to UART port
* @param[in] UARTx Pointer to UART peripheral
* @return character value that returned
**********************************************************************/
uint8_t UARTGetChar (LPC_UART_TypeDef *UARTx)
{
uint8_t UARTGetChar(LPC_UART_TypeDef *UARTx) {
uint8_t tmp = 0;
if (debug_frmwrk_initialized)
@ -86,26 +84,18 @@ uint8_t UARTGetChar (LPC_UART_TypeDef *UARTx)
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)
{
void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str) {
if (!debug_frmwrk_initialized) return;
uint8_t *s = (uint8_t*)str;
if (!debug_frmwrk_initialized)
return;
while (*s)
{
UARTPutChar(UARTx, *s++);
while (*s) UARTPutChar(UARTx, *s++);
}
}
/*********************************************************************//**
* @brief Puts a string to UART port and print new line
@ -113,26 +103,21 @@ void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)
* @param[in] str String to put
* @return None
**********************************************************************/
void UARTPuts_(LPC_UART_TypeDef *UARTx, const void *str)
{
if (!debug_frmwrk_initialized)
return;
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;
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;
@ -148,10 +133,8 @@ void UARTPutDec(LPC_UART_TypeDef *UARTx, uint8_t decnum)
* @param[in] decnum Decimal number (8-bit long)
* @return None
**********************************************************************/
void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum)
{
if (!debug_frmwrk_initialized)
return;
void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum) {
if (!debug_frmwrk_initialized) return;
uint8_t c1 = decnum%10;
uint8_t c2 = (decnum / 10) % 10;
@ -171,21 +154,19 @@ void UARTPutDec16(LPC_UART_TypeDef *UARTx, uint16_t decnum)
* @param[in] decnum Decimal number (8-bit long)
* @return None
**********************************************************************/
void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum)
{
if (!debug_frmwrk_initialized)
return;
void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum) {
if (!debug_frmwrk_initialized) return;
uint8_t c1=decnum%10;
uint8_t c2=(decnum/10)%10;
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;
const uint8_t c1 = decnum % 10,
c2 = (decnum / 10) % 10,
c3 = (decnum / 100) % 10,
c4 = (decnum / 1000) % 10,
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);
@ -204,37 +185,28 @@ void UARTPutDec32(LPC_UART_TypeDef *UARTx, uint32_t decnum)
* @param[in] hexnum Hex number (8-bit long)
* @return None
**********************************************************************/
void UARTPutHex (LPC_UART_TypeDef *UARTx, uint8_t hexnum)
{
uint8_t nibble, i;
if (!debug_frmwrk_initialized)
return;
void UARTPutHex(LPC_UART_TypeDef *UARTx, uint8_t hexnum) {
if (!debug_frmwrk_initialized) return;
UARTPuts(UARTx, "0x");
i = 1;
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)
{
uint8_t nibble, i;
if (!debug_frmwrk_initialized)
return;
void UARTPutHex16(LPC_UART_TypeDef *UARTx, uint16_t hexnum) {
if (!debug_frmwrk_initialized) return;
UARTPuts(UARTx, "0x");
i = 3;
uint8_t nibble, i = 3;
do {
nibble = (hexnum >> (4 * i)) & 0x0F;
UARTPutChar(UARTx, (nibble > 9) ? ('A' + nibble - 10) : ('0' + nibble));
@ -247,29 +219,24 @@ void UARTPutHex16 (LPC_UART_TypeDef *UARTx, uint16_t hexnum)
* @param[in] hexnum Hex number (32-bit long)
* @return None
**********************************************************************/
void UARTPutHex32 (LPC_UART_TypeDef *UARTx, uint32_t hexnum)
{
uint8_t nibble, i;
if (!debug_frmwrk_initialized)
return;
void UARTPutHex32(LPC_UART_TypeDef *UARTx, uint32_t hexnum) {
if (!debug_frmwrk_initialized) return;
UARTPuts(UARTx, "0x");
i = 7;
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, ...)
//{
/*********************************************************************//**
* @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;
@ -285,8 +252,7 @@ void UARTPutHex32 (LPC_UART_TypeDef *UARTx, uint32_t hexnum)
* @param[in] None
* @return None
**********************************************************************/
void debug_frmwrk_init(void)
{
void debug_frmwrk_init(void) {
UART_CFG_Type UARTConfigStruct;
PINSEL_CFG_Type PinCfg;
@ -336,7 +302,5 @@ void debug_frmwrk_init(void)
debug_frmwrk_initialized = TRUE;
}
#endif /*_DBGFWK */
/* --------------------------------- End Of File ------------------------------ */
#endif // _DBGFWK