展开全部
/* Check sum calulation. data in buff, size, InSum is initial sum */
WORD CheckSum(WORD DT_XDATA * buff,WORD size,DWORD InSum) REENTRANT_SIG
{
/* TO DO:in packet memory high part of short is in low memory. add all data in
form of 16 bits get a result of 32 bits, add high 16 bits to low 16 bits two
times. get a 16 bits result then complement it. */
DWORD cksum = InSum;
/* sum all word except the last odd byte(if size is a odd num) */
WORD DT_XDATA * EndBuf = buff + size/2;
while(buff < EndBuf)
{
/* net order is equeal as host order in mirochip, so no need to change */
cksum += *(buff++);
}
/**((WORD xdata *)CheckSumInParam) = size;
*((WORD xdata *)(CheckSumInParam+2)) = buff;
asmAddCheckSum();
cksum = CheckSumOutParm;
*/
/* if has last odd byte. use this byte as the high part of 16 bits, and add. */
if((size & 0x0001) != 0)
cksum += (*buff) & 0xff00;
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (WORD)(~cksum);
}
WORD CheckSum(WORD DT_XDATA * buff,WORD size,DWORD InSum) REENTRANT_SIG
{
/* TO DO:in packet memory high part of short is in low memory. add all data in
form of 16 bits get a result of 32 bits, add high 16 bits to low 16 bits two
times. get a 16 bits result then complement it. */
DWORD cksum = InSum;
/* sum all word except the last odd byte(if size is a odd num) */
WORD DT_XDATA * EndBuf = buff + size/2;
while(buff < EndBuf)
{
/* net order is equeal as host order in mirochip, so no need to change */
cksum += *(buff++);
}
/**((WORD xdata *)CheckSumInParam) = size;
*((WORD xdata *)(CheckSumInParam+2)) = buff;
asmAddCheckSum();
cksum = CheckSumOutParm;
*/
/* if has last odd byte. use this byte as the high part of 16 bits, and add. */
if((size & 0x0001) != 0)
cksum += (*buff) & 0xff00;
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (WORD)(~cksum);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-08-29 广告
2023-08-29 广告
"StormProxies是全球大数据IP资源服务商,其住宅代理网络由真实的家庭住宅IP组成,可为企业或个人提供满足各种场景的代理产品。点击免费测试(注册即送1G流量)StormProxies有哪些优势?1、IP+端口提取形式,不限带宽,I...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询