历史上的今天
返回首页

历史上的今天

今天是:2025年03月10日(星期一)

正在发生

2021年03月10日 | MSP430实现循环冗余算法

2021-03-10 来源:eefocus

/******************************************************************************

;   Code for application report slaa221 - "CRC Implementation with MSP430"

;

;   E.Lenchak

;   Texas Instruments, Inc

;   March 2004

;   Built with IAR Embedded Workbench Version: 3.20A

;******************************************************************************

; THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR

; REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,

; INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS

; FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR

; COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE.

; TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET

; POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY

; INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR

; YOUR USE OF THE PROGRAM.

;

; IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL,

; CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY

; THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED

; OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT

; OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM.

; EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF

; REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS

; OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF

; USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S

; AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF

; YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS

; (U.S.$500).

;

; Unless otherwise stated, the Program written and copyrighted

; by Texas Instruments is distributed as "freeware".  You may,

; only under TI's copyright in the Program, use and modify the

; Program without any charge or restriction.  You may

; distribute to third parties, provided that you transfer a

; copy of this license to the third party and the third party

; agrees to these terms by its first use of the Program. You

; must reproduce the copyright notice and any other legend of

; ownership on each copy or partial copy, of the Program.

;

; You acknowledge and agree that the Program contains

; copyrighted material, trade secrets and other TI proprietary

; information and is protected by copyright laws,

; international copyright treaties, and trade secret laws, as

; well as other intellectual property laws.  To protect TI's

; rights in the Program, you agree not to decompile, reverse

; engineer, disassemble or otherwise translate any object code

; versions of the Program to a human-readable form.  You agree

; that in no event will you alter, remove or destroy any

; copyright notice included in the Program.  TI reserves all

; rights not specifically granted under this license. Except

; as specifically provided herein, nothing in this agreement

; shall be construed as conferring by implication, estoppel,

; or otherwise, upon you, any license or other right under any

; TI patents, copyrights or trade secrets.

;

; You may not use the Program in non-TI devices.

;

;******************************************************************************/


/**********************************************************************************

FUNCTIONS: 16/32-bit CRC Algorithms, bitwsie and table methods

ARGUMENTS: "bitwise algorithm function signature"

   return: CRC

   arg1: CRC init value

   arg2: CRC generator polynomial

   arg3: pointer to the message

   arg4: size of message in bytes


  "table-based algorithm function signature"

   return: CRC

   arg1: CRC init value

   arg2: pointer to CRC table (specific to generator polynomial)

   arg3: pointer to the message

   arg4: size of message in bytes

***********************************************************************************/


#ifdef __ICC430__

#i nclude  "msp430x16x.h"

#endif


#i nclude "..inccrc.h"


/**************************************

 CRC MEMBERS (FUNCTIONS)

**************************************/


// this is an equivalent C implementation to the assembly implementation

unsigned short crc16MakeBitwise(unsigned short crc, unsigned short poly, 

      unsigned char *pmsg, unsigned int msg_size)

{

    unsigned int i, j, carry;

    unsigned char msg;

    unsigned short temp;


 temp = *pmsg++ << 8;

 temp |= *pmsg++;

 crc ^= temp;

    

    for(i = 0 ; i < msg_size-2 ; i ++)

    {

        msg = *pmsg++;

        

  for(j = 0 ; j < 8 ; j++)

        {

   carry = crc & 0x8000;

   crc = (crc << 1) | (msg >> 7);

   if(carry) crc ^= poly;

   msg <<= 1;

        }

    }


    for(i = 0 ; i < 2 ; i ++)

    {   

  for(j = 0 ; j < 8 ; j++)

        {

   carry = crc & 0x8000;

   crc <<= 1;

   if(carry) crc ^= poly;

        } 

    }

    return(crc ^ CRC16_FINAL_XOR);

}


// this is a C-optimized implementation

unsigned short crc16MakeBitwise2(unsigned short crc, unsigned short poly,

      unsigned char *pmsg, unsigned int msg_size)

{

    unsigned int i, j;

    unsigned short msg;

    

    for(i = 0 ; i < msg_size ; i ++)

    {

        msg = (*pmsg++ << 8);

        

  for(j = 0 ; j < 8 ; j++)

        {

            if((msg ^ crc) >> 15) crc = (crc << 1) ^ poly;

   else crc <<= 1; 

   msg <<= 1;

        }

    }

   

    return(crc ^ CRC16_FINAL_XOR);

}


// this is an equivalent C implementation to the assembly implementation

unsigned long crc32MakeBitwise(unsigned long crc, unsigned long poly, 

      unsigned char *pmsg, unsigned int msg_size)

{

    unsigned int i, j, carry;

    unsigned char msg;

    unsigned long temp;


 temp = (unsigned long)(*pmsg++) << 24;

 temp |= (unsigned long)(*pmsg++) << 16;

 temp |= (unsigned long)(*pmsg++) << 8;

 temp |= (unsigned long)(*pmsg++);

 crc ^= temp;


    for(i = 0 ; i < msg_size-4 ; i ++)

    {

        msg = *pmsg++;


  for(j = 0 ; j < 8 ; j++)

        {

   carry = crc >> 31;

   crc = (crc << 1) | (msg >> 7);

   if(carry) crc ^= poly;

   msg <<= 1;

        }

    }

    

    for(i = 0 ; i < 4 ; i ++)

    {   

  for(j = 0 ; j < 8 ; j++)

        {

   carry = crc >> 31;

   crc <<= 1;

   if(carry) crc ^= poly;

        } 

    }

 

    return(crc ^ CRC32_FINAL_XOR);

}


// this is a C-optimized implementation

unsigned long crc32MakeBitwise2(unsigned long crc, unsigned long poly, 

        unsigned char *pmsg, unsigned int msg_size)

{

    unsigned int i, j;

    unsigned long msg;

            

    for(i = 0 ; i < msg_size ; i++)

    {

        msg = *pmsg++;

        msg <<= 24;

        

        for(j = 0 ; j < 8 ; j++)

        {

            if((msg ^ crc) >> 31) crc = (crc << 1) ^ poly;

   else crc <<= 1;

   msg <<= 1;

        }

    }

    

    return(crc ^ CRC32_FINAL_XOR);

}


unsigned short crc16MakeTableMethod(unsigned short crc, TBL_MEM unsigned short *table,

         unsigned char *pbuffer, unsigned int length)

{

    while(length--) 

        crc = table[((crc >> 8) ^ *pbuffer++)] ^ (crc << 8); // normal


    return(crc ^ CRC16_FINAL_XOR);

}


unsigned short crc16rMakeTableMethod(unsigned short crc, TBL_MEM unsigned short *table,

         unsigned char *pbuffer, unsigned int length)

{

    while(length--) 

        crc = table[(crc & 0xFF) ^ *pbuffer++] ^ (crc >> 8); // reflected


    return(crc ^ CRC16R_FINAL_XOR);

}


unsigned long crc32MakeTableMethod(unsigned long crc, TBL_MEM unsigned long *table, 

           unsigned char *pbuffer, unsigned int length)

{

    while(length--) 

        crc = table[((crc >> 24) ^ *pbuffer++)] ^ (crc << 8); // normal


    return(crc ^ CRC32_FINAL_XOR);

}


unsigned long crc32rMakeTableMethod(unsigned long crc, TBL_MEM unsigned long *table, 

           unsigned char *pbuffer, unsigned int length)

{

    while(length--) 

        crc = table[(crc ^ *pbuffer++) & 0xFFL] ^ (crc >> 8); // reflected


    return(crc ^ CRC32R_FINAL_XOR);

}


/************************************

 CRC UTILITIES

************************************/


void crc16BuildTable(unsigned short *ptable, unsigned short poly)

{

 unsigned int i, j;


    for(i = 0; i <= 255; i++)

    {

        ptable[i] = i << 8;

        for(j = 0; j < 8; j++)

            ptable[i] = (ptable[i] << 1) ^ (ptable[i] & 0x8000 ? poly : 0);

    }

}


void crc32BuildTable(unsigned long *ptable, unsigned long poly)

推荐阅读

史海拾趣

飞虹(FeiHong)公司的发展小趣事

随着业务规模的不断扩大,苏州锋驰开始积极拓展国内外市场。公司不仅在国内市场取得了显著的成绩,还逐步将产品和服务推向国际市场。在品牌建设方面,苏州锋驰注重提升品牌知名度和美誉度,通过参加行业展会、举办技术交流会等多种方式,加强与客户的沟通和交流,赢得了广泛的关注和认可。同时,公司还不断优化产品和服务质量,提升客户满意度和忠诚度。

这五个故事共同勾勒出了苏州锋驰微电子有限公司在电子行业中的发展历程和成就,展现了其作为一家科技型中小企业的蓬勃生机和广阔前景。

台湾义隆电子(ELAN)公司的发展小趣事

义隆电子在多个技术领域保持领先地位,如数字模拟混合技术、高阶设计流程等。这些技术优势使得公司能够迅速掌握市场脉动,开发出具有实用性的新产品。同时,义隆电子还注重将先进技术应用于实际产品中,如高性能的触摸屏控制器、触摸板模块等,这些产品广泛应用于智能手机、平板电脑等消费电子产品中,赢得了市场的广泛认可。

Electric Imp Inc.公司的发展小趣事

在电子行业的浪潮中,Electric Imp Inc.公司以其独特的物联网(IoT)解决方案崭露头角。公司创始人是一位资深的电子工程师,他敏锐地捕捉到了物联网市场的巨大潜力。在创业初期,公司面临资金短缺、技术瓶颈等挑战,但创始人带领团队夜以继日地研发,终于推出了第一款基于云计算的物联网设备管理平台。这款产品凭借其易用性、稳定性和可扩展性,迅速获得了市场的认可。

DAQ Electronics LLC公司的发展小趣事

在DAQ Electronics LLC公司的发展历程中,质量一直是其坚守的核心原则。公司建立了严格的质量控制体系,从原材料采购到产品生产、检测、包装等各个环节都进行严格把控。这种对质量的坚持,使得DAQ Electronics LLC公司的产品在市场上获得了良好的口碑和信誉。客户对公司的产品和服务给予了高度评价,也为公司的持续发展提供了有力保障。

Delock公司的发展小趣事

Delock公司自创立之初,就致力于电子连接技术的研发。公司创始人李先生敏锐地洞察到市场对高性能、稳定可靠的电子连接设备的需求,于是带领团队投入大量资源进行技术研发。经过数年的努力,Delock公司成功开发出一种具有革命性意义的电子连接器,不仅传输速度快,而且耐用性高,迅速在市场上获得了认可。这一创新不仅为Delock公司带来了可观的利润,也为公司在电子行业树立了技术领先的形象。

BLT Circuit Services公司的发展小趣事

随着公司实力的不断增强,BLT Circuit Services开始积极拓展国内外市场。公司积极参加各类行业展会,与国内外同行进行深入交流与合作,不断提升公司的知名度和影响力。同时,公司还根据市场需求调整产品策略,推出了一系列符合市场需求的新产品,进一步扩大了市场份额。

问答坊 | AI 解惑

请教非门的作用??

请教一下:信号从光耦接收出来,到达两个四个并联的非门再与两个非门串联来驱动三极管,其中这些非门的作用是为了增强驱动能力的作用吗? [ 本帖最后由 qmchen 于 2009-3-18 10:16 编辑 ]…

查看全部问答>

IGBT 损坏后结果情况

IGBT损坏后,有哪些结果情况?比如IGBT开路,但开路后IGBT的续流二极管还继续有用吗?…

查看全部问答>

波特率一高 串口传输就出錯

用串口收发数据,只要提高波特率,传输数据就出错,尤其是接收方,不知道是什么原因。 代码是C写的,查询方式。 比如红外用2400bps是好的,发01,02,03。。。20共20个数,接收都对,收到01,02,03,04,05,06一直到20. 但是改成4800bps之 ...…

查看全部问答>

"已失去对设备的远程连接。请验证设备连接并重新启动调试 "????

PDA上从电脑上pull入一个数据表,然后PDA自己存入数据时出现 \"已失去对设备的远程连接。请验证设备连接并重新启动调试 \",程序会自动退出,没有出现其它异常报告。 PDA重启程序后,再往刚才的数据表里存储数据一切正常。每次都是刚从电脑上pull入 ...…

查看全部问答>

cpu风扇转速

如何设置cpu风扇的转速呢,我的生音太大…

查看全部问答>

将要进入嵌入软件开发 的人

各位大哥们,我还是一个大一的学生,现在听说嵌入开发还可以,所以就有一点想向这一方面发展,但是现在在我面前的一个问题就是 我不知道要学那些东西,我也是一个计算机班的学生,这是不是有很大的优点. 所以就想问一下大哥们的应该出什么方向入手好一 ...…

查看全部问答>

tShell重定向到pty后,一直被PEND(内详)

将shell定向到2个pty上,分别是    数据写--> pty1 -->shell读取    数据读…

查看全部问答>

EE_FPGA 硬件手册 V1.0

部分页面预览   下载链接: …

查看全部问答>

请教小数的处理,和小数的输出!

我AD采样的范围是0 - 2.5 V , 采样肯定是小数, 其类型应该是 float 型吧? 假如其采样点储存在float型数组内, 经过一系列运算后 如何使其转换成十进制数据 输出? 是有固定程序么? 比如将其转换成BCD码! 还请高手指点!…

查看全部问答>