友情推荐网上购书渠道:
EDN网(ednchina)购书入口   >>>
互动出版网(china-pub)购书入口   >>>
当当网(dangdang)购书入口   >>>
淘宝网(taobao)购书入口   >>>
更多购书渠道……   >>> 

设为首页加入收藏联系匠人管理入口21IC首页21IC博客21IC社区侃单片机回复的贴参与的贴

天气预报
百宝日历

百宝专栏

  • 首页 相册 标签
  • 电脑应用(65)
  • 供需信息(22)
  • 写书近况(82)
  • 匠人文集(115)
  • 硬件技术(171)
  • 匠人公告(86)
  • 与非门专栏(545)
  • 匠人笔记(115)
  • 团队撰写(96)
  • 汽车电子(52)
  • 编程技巧(465)
  • 程序宝典(476)
  • 网络酷文(472)
  • 开发工具(19)
  • 资料宝藏(274)
  • 项目管理(11)
  • 藏经宝阁(42)
  • 趣味设计(5)
  • 社区热贴(2)
  • 比尔盖茨熊专栏(0) 
  • 百宝信息

    载入中...

    百宝流量

    (2006-07-01开始)



    匠人手记

    芯片专题

    器件专题

    软件专题

    硬件专题

    综合专题

    项目专题

    原创专题

    器件检测
    LCD LED
    按键 触摸键
    E2PROM
    电池 电机
    电阻 电容 电感

    指令系统
    软件算法
    编程规范
    滤波算法
    串行通讯

    PCB设计
    I2C PWM
    红外遥控
    充电技术
    中断 ADC 

    匠人手记
    匠人夜话
    网络心路
    一周热点串烧
    从零开始玩PIC
    DIY旋转时钟

    MSP430实现循环冗余算法
    程序匠人 发表于 2006-6-18 21:48:00  阅读全文 | 回复(0) | 引用通告 | 编辑

    MSP430实现循环冗余算法
    [ 2006-6-18 14:54:59 | By: 超越梦想 ]
    /******************************************************************************
    ;   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 "..\inc\crc.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)
    {
     unsigned int i, j;

        for(i = 0; i <= 255; i++)
        {
            ptable[i] = (long)i << 24;       
            for(j = 0; j < 8; j++)
                ptable[i] = (ptable[i] << 1) ^ (ptable[i] & 0x80000000 ? poly : 0);
        }
    }

    unsigned long bitReflect(unsigned long data, unsigned int width)
    {
        unsigned long result = 0;
     unsigned int i;

        for (i = 1; i < (width + 1); i++)
        {
            if(data & 1) result |= 0x1L << (width - i);
            data >>= 1;
        } 

        return result;
    }

    /************************************ END ***************************************/

    看《匠人手记》,与匠人同行!北航出版,正在热卖!

    发表评论:
    载入中...

    广告5号位 [投放]


    学习板、开发板、编程器、下载器、仿真器(查看详情……)

    站内搜索


    站外搜索


    百度  google
    mp3  歌词 
    图片  FLASH 
    知道  文档
    新闻  词典 
    地图  mp3 
    软件  天网 
    雅虎  爱问 
    搜狗  讯雷 
    网讯  华军 
    天空 

    21IC器件搜索
    百宝箱分站
  • 《匠人的百宝箱》21IC站
  • 《匠人的百宝箱》21IC笔记团队
  • 《匠人的百宝箱》MCUBLOG站
  • 《匠人的百宝箱》MCUBLOG笔记团队
  • 《匠人的百宝箱》EDN站
  • 《匠人手记》EDN书友会
  • 《匠人的百宝箱》与非网站
  • 《匠人的百宝箱》新浪站
  • 《匠人的百宝箱》百度站
  • 《匠人的百宝箱》网易126站
  • 《匠人的百宝箱》网易163站
  • 《匠人的百宝箱》互动出版网站
  • 广告4号位 [投放]

     
     
     

    新鲜货色

    匠人手记

    近期动态

    载入中...

      《匠人手记》购书全攻略 
     书友近况:淘书手记答疑与讨论:什么是散转程序 
     《匠人手记》新书艳照
     EDN《匠人手记》签名售书优惠活动开始报名啦!
     欢迎加入《匠人手记》EDN书友会
     欢迎加入《匠人手记》书友会Q群
     《匠人手记》终稿目录
     《匠人手记》封面,请大家先睹为快
     上周六收到了北航寄来的《匠人手记》清样,让大家先睹为快

    匠人原创

    粉丝评论

    往日酷贴

    载入中...

    载入中...



     网络酷文:博客,改变的不仅仅是图书 
     网络酷文:C语言宏定义技巧C语言 条件编译详解

      21IC上海2008-04聚会报名进行中。。。 
     两分钟让你明白什么是ERP![转]
      神奇的Duff's Device 算法
      实用一线通讯电路及软件设计方法
      程序员的“七年之痒”
      史上最短但最精彩的武侠小说
      网络无厘头文学《缺钙水浒》(爆笑)

     你的博客还能持续多久(转贴)
     电动车无刷电机控制器软件设计要点(作者:谢渊斌)

    大千八卦

    友情连接

    新浪新闻:
    新浪财经:
    AK58新闻:
    新浪股票:
    新浪股票:
    证券之星:

     [更多酷站连接]

     

     

    [欢迎交换连接]

    [百宝箱之与非门分舵]

    [电脑圈圈的家当]

    [IC921的博客]

    [柔月阁]

    [八楼的呼吸]

    [hotpower 的水潭]

    [xwj的文君阁]

    [所长的BLOG]

    [阿摆手记]

    [电子伙伴]

    [unaided的笔记]

    [小飞的笔记]

    [单片机开发联盟]

    [网址之家]

    [好东西网址大全]

    [美萍中文精选]

    [数字电视之家]

    [SMARTCODE电子书斋]

    [软件开发之窗]

    [Armoric]

    [我爱研发网]

    [infernal的笔记]

    [雄鹰的空中加油站]

    [SunK]

    [逍遥电子]

    [ningpanda的博客]

    [C-Design]

    [一网见天下]

    [海边淘沙]

    [嵌入式365]

    [水牛的仓库]

    [股剩是怎样炼成的]

    [PIC论坛]

    [ICC AVR开发网]

    [中国高校自动化网]

     

     

     

    MCU博客-中国电子工程师博客网 

    大学生电子网 

     

     

     

     

     

    !!! 《匠人的百宝箱》 !!!