📄 util.c
字号:
/***********************************************************************************
Filename: util.c
Description: Utility library
***********************************************************************************/
/***********************************************************************************
* INCLUDES
*/
#include "util.h"
#include "hal_defs.h"
/***********************************************************************************
* GLOBAL FUNCTIONS
*/
/***********************************************************************************
* @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
/***********************************************************************************
Copyright 2007 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -