📄 debug_frmwrk.c
字号:
/**********************************************************************
* $Id$ debug_frmwrk.c 2011-06-02
*//**
* @file debug_frmwrk.c
* @brief Contains some utilities that used for debugging through UART
* @version 1.0
* @date 02. June. 2011
* @author NXP MCU SW Application Team
*
* Copyright(C) 2011, NXP Semiconductor
* All rights reserved.
*
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors'
* relevant copyright in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers. This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
**********************************************************************/
#ifdef __BUILD_WITH_EXAMPLE__
#include "lpc177x_8x_libcfg.h"
#else
#include "lpc177x_8x_libcfg_default.h"
#endif /* __BUILD_WITH_EXAMPLE__ */
#ifdef _DBGFWK
#include "debug_frmwrk.h"
#include "lpc177x_8x_pinsel.h"
/* Debug framework */
void (*_db_msg)(UART_ID_Type UartID, const void *s);
void (*_db_msg_)(UART_ID_Type UartID, const void *s);
void (*_db_char)(UART_ID_Type UartID, uint8_t ch);
void (*_db_dec)(UART_ID_Type UartID, uint8_t decn);
void (*_db_dec_16)(UART_ID_Type UartID, uint16_t decn);
void (*_db_dec_32)(UART_ID_Type UartID, uint32_t decn);
void (*_db_hex)(UART_ID_Type UartID, uint8_t hexn);
void (*_db_hex_16)(UART_ID_Type UartID, uint16_t hexn);
void (*_db_hex_32)(UART_ID_Type UartID, uint32_t hexn);
void (*_db_hex_)(UART_ID_Type UartID, uint8_t hexn);
void (*_db_hex_16_)(UART_ID_Type UartID, uint16_t hexn);
void (*_db_hex_32_)(UART_ID_Type UartID, uint32_t hexn);
uint8_t (*_db_get_char)(UART_ID_Type UartID);
Bool (*_db_get_char_nonblocking)(UART_ID_Type UartID, uint8_t* c);
uint8_t (*_db_get_val)(UART_ID_Type UartID, uint8_t option, uint8_t numCh, uint32_t * val);
/*********************************************************************//**
* @brief Puts a character to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] ch Character to put
* @return None
**********************************************************************/
void UARTPutChar (UART_ID_Type UartID, uint8_t ch)
{
UART_Send(UartID, &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 (UART_ID_Type UartID)
{
uint8_t tmp = 0;
UART_Receive(UartID, &tmp, 1, BLOCKING);
return(tmp);
}
/*********************************************************************//**
* @brief Get a character to UART port in non-blocking mode
* @param[in] UARTx Pointer to UART peripheral
* @param[out] c character value that returned
* @return TRUE (there is a character for procesisng)/FALSE
**********************************************************************/
Bool UARTGetCharInNonBlock(UART_ID_Type UartID, uint8_t* c)
{
if(c == NULL)
return FALSE;
if(UART_Receive(UartID, c, 1, NONE_BLOCKING))
return TRUE;
return FALSE;
}
/*********************************************************************//**
* @brief Get a character to UART port
* @param[in] UARTx Pointer to UART peripheral
* @return character value that returned
**********************************************************************/
uint8_t UARTGetValue (UART_ID_Type UartID, uint8_t option,
uint8_t numCh, uint32_t* val)
{
uint8_t tmpCh = 0, cnt, factor, isValidCh = FALSE;
uint32_t tmpVal, rVal, cntFailed, multiplier;
//it does not get any value
if(numCh <= 0)
{
*val = 0;
return 0;
}
cntFailed = 0;
// To store the multiplier of Decimal (10) or Heximal (16)
factor = (option == DBG_GETVAL_IN_HEX) ? 16 : ((option == DBG_GETVAL_IN_DEC) ? 10 : 0);
if (factor == 0)
{
*val = 0;
return 0;
}
rVal = 0;
while (numCh > 0)
{
isValidCh = TRUE;
UART_Receive(UartID, &tmpCh, 1, BLOCKING);
if((tmpCh >= '0') && (tmpCh<= '9'))
{
tmpVal = (uint32_t) (tmpCh - '0');
}
else if (option == DBG_GETVAL_IN_HEX)
{
factor = 16;
switch (tmpCh)
{
case 'a':
case 'A':
tmpVal = 10;
break;
case 'b':
case 'B':
tmpVal = 11;
break;
case 'c':
case 'C':
tmpVal = 12;
break;
case 'd':
case 'D':
tmpVal = 13;
break;
case 'e':
case 'E':
tmpVal = 14;
break;
case 'f':
case 'F':
tmpVal = 15;
break;
default:
isValidCh = FALSE;
break;
}
}
else
{
isValidCh = FALSE;
}
multiplier = 1;
if(isValidCh == FALSE)
{
if(option == DBG_GETVAL_IN_DEC)
{
UARTPuts(UartID, "Please enter a char from '0' to '9'!!!\r\n");
}
else if (option == DBG_GETVAL_IN_HEX)
{
UARTPuts(UartID, "Please enter a char from '0' to '9', and 'a/A', 'b/B', c/C', 'd/D', 'e/E' and 'f/F'!!!\r\n");
}
cntFailed ++;
if(cntFailed >= NUM_SKIPPED_ALLOWED)
{
UARTPuts(UartID, "Reach limitation of re-tries. Return FAILED\r\n");
//it's failed, should return
return 0;
}
}
else
{
//Echo the character to the terminal
UARTPutChar(UartID, tmpCh);
if(numCh == 1)
{
factor = 1;
multiplier = 1;
}
else
{
for(cnt = 1; cnt < numCh; cnt++)
{
multiplier *= factor;
}
}
tmpVal *= multiplier;
//Update the value return
rVal += tmpVal;
numCh --;
}
}
*val = rVal;
return(1);
}
/*********************************************************************//**
* @brief Puts a string to UART port
* @param[in] UARTx Pointer to UART peripheral
* @param[in] str string to put
* @return None
**********************************************************************/
void UARTPuts(UART_ID_Type UartID, const void *str)
{
uint8_t *s = (uint8_t *) str;
while (*s)
{
UARTPutChar(UartID, *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_(UART_ID_Type UartID, const void *str)
{
UARTPuts (UartID, str);
UARTPuts (UartID, "\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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -