📄 util.c
字号:
/*******************************************************************************
Filename: util.c
Description: Utility library
*******************************************************************************/
/*******************************************************************************
* INCLUDES
*/
#include "util.h"
#include "hal_defs.h"
#include "hal_rf.h"
/*******************************************************************************
* GLOBAL FUNCTIONS
*/
/*******************************************************************************
* @fn utilChipIdToStr
*
* @brief Converts a chip ID to a text string.
*
* @param uint8 chipID
*
* @return none
*/
const char* utilChipIdToStr(uint8 chipID)
{
const char* szId;
switch(chipID) {
case HAL_RF_CHIP_ID_CC2420:
szId= "2420";
break;
case HAL_RF_CHIP_ID_CC2430:
szId= "2430";
break;
case HAL_RF_CHIP_ID_CC2431:
szId= "2431";
break;
case HAL_RF_CHIP_ID_CC2520:
szId= "2520";
break;
case HAL_RF_CHIP_ID_CC2530:
szId= "2530";
break;
case HAL_RF_CHIP_ID_CC2531:
szId= "2531";
break;
case HAL_RF_CHIP_ID_CC2510:
szId= "2510";
break;
default:
szId= "";
};
return szId;
}
/*******************************************************************************
* @fn convInt32ToText
*
* @brief Converts 32 bit int to text
*
* @param int32 value
*
* @return char* - pointer to text buffer which is a file scope allocated array
*/
char* convInt32ToText(int32 value)
{
static char pValueToTextBuffer[12];
char *pLast;
char *pFirst;
char last;
uint8 negative;
pLast = pValueToTextBuffer;
// Record the sign of the value
negative = (value < 0);
value = ABS(value);
// Print the value in the reverse order
do {
*(pLast++) = '0' + (uint8)(value % 10);
value /= 10;
} while (value);
// Add the '-' when the number is negative, and terminate the string
if (negative) *(pLast++) = '-';
*(pLast--) = 0x00;
// Now reverse the string
pFirst = pValueToTextBuffer;
while (pLast > pFirst) {
last = *pLast;
*(pLast--) = *pFirst;
*(pFirst++) = last;
}
return pValueToTextBuffer;
}
#ifndef WIN32
/*******************************************************************************
* @fn min
*
* @brief Return minimum of two values
*
* @param uint8 v1 - value 1
* uint8 v2 - value 2
*
* @return uint8 - minimum of two values
*/
uint8 min(uint8 v1, uint8 v2)
{
if(v1 < v2)
return v1;
else return v2;
}
/*******************************************************************************
* @fn utilReverseBuf
*
* @brief reverse buffer
*
* @param uint8 pBuf - pointer to buffer
* uint8 length - length of buffer
*
* @return void
*/
void utilReverseBuf(uint8* pBuf, uint8 length)
{
uint8 temp;
uint8* pBufLast = (pBuf + length - 1);
while(pBufLast > pBuf){
temp = *pBuf;
*pBuf++ = *pBufLast;
*pBufLast-- = temp;
}
}
#endif
/*------------------------------------------------------------------------------
0ooo
ooo0 ( )
( ) ) /
\ ( (_/
\_) Modify By:cuiqingwei [gary]
------------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -