📄 sum_check.c
字号:
/* Follow is the introducation for the file in Chinese.
* 版权和版本声明中文模式
*
* 文件名称:sum_check.c
* 文件标识:xx.yy.zz 参见配置管理计划书
* 摘 要:定义校验和相关函数
*
*/
#include "sum_check.h"
//-----------------------------------------------------------------------------
// compute the data sum,and return the sum's patch-code(not a professiona glossary)
// the function only use in functions append_sum_check and verify_sum_check_ok
// so the function is a local function.
//-----------------------------------------------------------------------------
/*
* Function name : compute_sum_check
* Function describe : compute the datas sum result and the sum's patch-code
*
* Input : p:the datas point
* : length:the data length,length < 0xff
* Output : the sum's patch-code
* Ram be effected : none
* global variable : none
* Called module : none
*
*/
unsigned char compute_sum_check(unsigned char xdata *p,unsigned char length)
{
unsigned char sum,i;
sum = 0;
for(i=0;i<length;i++)
{
sum += *(p+i);
}
sum = 0x100-sum;
return sum;
}
/*
* Function name : append_sum_check
* Function describe : append the sum-check's patch-code follow the datas
*
* Input : p:the datas point
* : length:the data length,length < 0xff
* Output : none
* Ram be effected : none
* global variable : none
* Called module : compute_sum_check
*
*/
void append_sum_check(unsigned char xdata *p,unsigned char length)
{
*(p + length) = compute_sum_check(p,length);
}
/*
* Function name : verify_sum_check_ok
* Function describe : verify the datas's sum-check are correct
*
* Input : p:the datas point
* : length:the data length,length <= 0xff
* Output : SUM_CORRECT: the datas sum check result are correct.
* SUM_INCORRECT :the datas sum check result are false.
* global variable : none
* Called module : compute_sum_check
*
*/
#define SUM_CORRECT 1
#define SUM_INCORRECT 0
bit verify_sum_check_ok(unsigned char xdata *p,unsigned char length)
{
if(compute_sum_check(p,length) == 0x00)
{
return SUM_CORRECT;
}
else
{
return SUM_INCORRECT;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -