⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sum_xa.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
字号:
/* sum_xa.c

   Copyright 2000 by InterNIche Technologies Inc. All rights reserved.
   Copyright 1990-1996 by NetPort Software.

*/

#include "ipport.h"

/* cksum(buf, len) performs an Internet type checksum. buf points to where
 	the checksumming should begin, len is the number of 16 bit words
	to be summed.

   This version for philips XA CPUs in 16 bit mode
*/

//#pragma optimize 1
#pragma O0
/*typedef union {
   unsigned long m_long;
   struct {
      unsigned int lint;
      unsigned int hint;
   } m_int;
} LONG_UNION;
*/
typedef union{
   unsigned int m_long;
   struct{
      unsigned short lint;
      unsigned short hint;
   }m_int;
}LONG_UNION;

unsigned short cksum(void* buf, unsigned short word_count)
{
   LONG_UNION sum;
   unsigned short *ptr;
   
   ptr = (unsigned short *)buf;
   sum.m_long = 0;
   for (; word_count > 0; word_count--) {
      sum.m_long += *ptr++;
      if (sum.m_int.hint > 0) {
          sum.m_int.lint += sum.m_int.hint;
          sum.m_int.hint  = 0;
      }
   }
   
   return sum.m_int.lint;
}
//#pragma endoptimize

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -