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

📄 crc_algs.lst

📁 用TI单片机MSP430系列写的CRC检验程序
💻 LST
字号:
##############################################################################
#                                                                            #
# IAR MSP430 C Compiler V2.21B/W32  [Kickstart]        17/Aug/2004  19:23:25 #
# Copyright 1996-2003 IAR Systems. All rights reserved.                      #
#                                                                            #
#    __rt_version  =  1                                                      #
#    __double_size =  32                                                     #
#    __reg_r4      =  free                                                   #
#    __reg_r5      =  free                                                   #
#    __pic         =  no                                                     #
#    Source file   =  C:\Program Files\IAR Systems\Embedded Workbench        #
#                     3.2\myProjects\CRC\src\crc_algs.c                      #
#    Command line  =  -I "C:\Program Files\IAR Systems\Embedded Workbench    #
#                     3.2\430\INC\" -I "C:\Program Files\IAR                 #
#                     Systems\Embedded Workbench 3.2\430\INC\CLIB\" -lc      #
#                     "C:\Program Files\IAR Systems\Embedded Workbench       #
#                     3.2\myProjects\CRC\MSP430\Debug\List\" -o "C:\Program  #
#                     Files\IAR Systems\Embedded Workbench                   #
#                     3.2\myProjects\CRC\MSP430\Debug\Obj\" -s9 --no_cse     #
#                     --no_unroll --no_inline --no_code_motion --debug -e    #
#                     --double=32 "C:\Program Files\IAR Systems\Embedded     #
#                     Workbench 3.2\myProjects\CRC\src\crc_algs.c"           #
#    List file     =  C:\Program Files\IAR Systems\Embedded Workbench        #
#                     3.2\myProjects\CRC\MSP430\Debug\List\crc_algs.lst      #
#    Object file   =  C:\Program Files\IAR Systems\Embedded Workbench        #
#                     3.2\myProjects\CRC\MSP430\Debug\Obj\crc_algs.r43       #
#                                                                            #
#                                                                            #
##############################################################################

C:\Program Files\IAR Systems\Embedded Workbench 3.2\myProjects\CRC\src\crc_algs.c
      1          
      2          /**********************************************************************************
      3          FUNCTIONS:	16/32-bit CRC Algorithms, bitwsie and table methods
      4          ARGUMENTS:	"bitwise algorithm function signature"
      5          			return: CRC
      6          			arg1: CRC init value
      7          			arg2: CRC generator polynomial
      8          			arg3: pointer to the message
      9          			arg4: size of message in bytes
     10          			"table-based algorithm function signature"
     11          			return: CRC
     12          			arg1: CRC init value
     13          			arg2: pointer to CRC table (specific to generator polynomial)
     14          			arg3: pointer to the message
     15          			arg4: size of message in bytes
     16          AUTHOR:		Emil Lenchak
     17          DATE:		March, 2004
     18          COPYRIGHT:	Texas Instruments, 2004
     19          TOOLS:		Built with IAR Kickstart V2/MS Visual C++ 6.0
     20          ***********************************************************************************/
     21          
     22          #ifdef __ICC430__
     23          #include  "msp430x16x.h"
     24          #endif
     25          
     26          #include "..\inc\crc.h"
     27          
     28          /**************************************
     29          	CRC MEMBERS (FUNCTIONS)
     30          **************************************/
     31          
     32          // this is an equivalent C implementation to the assembly implementation
     33          unsigned short crc16MakeBitwise(unsigned short crc, unsigned short poly, 
     34          						unsigned char *pmsg, unsigned int msg_size)
     35          {
     36              unsigned int i, j, carry;
     37              unsigned char msg;
     38              unsigned short temp;
     39          
     40          	temp = *pmsg++ << 8;
     41          	temp |= *pmsg++;
     42          	crc ^= temp;
     43              
     44              for(i = 0 ; i < msg_size ; i ++)
     45              {
     46                  msg = *pmsg++;
     47                  
     48          		for(j = 0 ; j < 8 ; j++)
     49                  {
     50          			carry = crc & 0x8000;
     51          			crc = (crc << 1) | (msg >> 7);
     52          			if(carry) crc ^= poly;
     53          			msg <<= 1;
     54                  }
     55              }
     56             
     57              return(crc ^ CRC16_FINAL_XOR);
     58          }
     59          
     60          // this is a C-optimized implementation
     61          unsigned short crc16MakeBitwise2(unsigned short crc, unsigned short poly,
     62          						unsigned char *pmsg, unsigned int msg_size)
     63          {
     64              unsigned int i, j;
     65              unsigned short msg;
     66              
     67              for(i = 0 ; i < msg_size ; i ++)
     68              {
     69                  msg = (*pmsg++ << 8);
     70                  
     71          		for(j = 0 ; j < 8 ; j++)
     72                  {
     73                      if((msg ^ crc) >> 15) crc = (crc << 1) ^ poly;
     74          			else crc <<= 1;
     75          	
     76          			msg <<= 1;
     77                  }
     78              }
     79             
     80              return(crc ^ CRC16R_FINAL_XOR);
     81          }
     82          
     83          // this is an equivalent C implementation to the assembly implementation
     84          unsigned long crc32MakeBitwise(unsigned long crc, unsigned long poly, 
     85          						unsigned char *pmsg, unsigned int msg_size)
     86          {
     87              unsigned int i, j, carry;
     88              unsigned char msg;
     89              unsigned long temp;
     90          
     91          	temp = (unsigned long)(*pmsg++) << 24;
     92          	temp |= (unsigned long)(*pmsg++) << 16;
     93          	temp |= (unsigned long)(*pmsg++) << 8;
     94          	temp |= (unsigned long)(*pmsg++);
     95          	crc ^= temp;
     96          
     97              for(i = 0 ; i < msg_size ; i ++)
     98              {
     99                  msg = *pmsg++;
    100          
    101          		for(j = 0 ; j < 8 ; j++)
    102                  {
    103          			carry = crc >> 31;
    104          			crc = (crc << 1) | (msg >> 7);
    105          			if(carry) crc ^= poly;
    106          			msg <<= 1;
    107                  }
    108              }
    109             
    110              return(crc ^ CRC32_FINAL_XOR);
    111          }
    112          
    113          // this is a C-optimized implementation
    114          unsigned long crc32MakeBitwise2(unsigned long crc, unsigned long poly, 
    115          								unsigned char *pmsg, unsigned int msg_size)
    116          {
    117              unsigned int i, j;
    118              unsigned long msg;
    119                      
    120              for(i = 0 ; i < msg_size ; i++)
    121              {
    122                  msg = *pmsg++;
    123                  msg <<= 24;
    124                  
    125                  for(j = 0 ; j < 8 ; j++)
    126                  {
    127                      if((msg ^ crc) >> 31) crc = (crc << 1) ^ poly;
    128          			else crc <<= 1;
    129          	
    130          	    msg <<= 1;
    131                  }
    132              }
    133              
    134              return(crc ^ CRC32R_FINAL_XOR);
    135          }
    136          
    137          unsigned short crc16MakeTableMethod(unsigned short crc, TBL_MEM unsigned short *table,
    138          									unsigned char *pbuffer, unsigned int length)
    139          {
    140              while(length--) 
    141                  crc = table[((crc >> 8) ^ *pbuffer++)] ^ (crc << 8);	// normal
    142          
    143              return(crc ^ CRC16_FINAL_XOR);
    144          }
    145          
    146          unsigned short crc16rMakeTableMethod(unsigned short crc, TBL_MEM unsigned short *table,
    147          									unsigned char *pbuffer, unsigned int length)
    148          {
    149              while(length--) 
    150                  crc = table[(crc & 0xFF) ^ *pbuffer++] ^ (crc >> 8);	// reflected
    151          
    152              return(crc ^ CRC16R_FINAL_XOR);
    153          }
    154          
    155          unsigned long crc32MakeTableMethod(unsigned long crc, TBL_MEM unsigned long *table, 
    156          								   unsigned char *pbuffer, unsigned int length)
    157          {
    158              while(length--) 
    159                  crc = table[((crc >> 24) ^ *pbuffer++)] ^ (crc << 8);		// normal
    160          
    161              return(crc ^ CRC32_FINAL_XOR);
    162          }
    163          
    164          unsigned long crc32rMakeTableMethod(unsigned long crc, TBL_MEM unsigned long *table, 
    165          								   unsigned char *pbuffer, unsigned int length)
    166          {
    167              while(length--) 
    168                  crc = table[(crc ^ *pbuffer++) & 0xFFL] ^ (crc >> 8);
    169          
    170              return(crc ^ CRC32R_FINAL_XOR);
    171          }
    172          
    173          /************************************
    174          	CRC UTILITIES
    175          ************************************/
    176          
    177          void crc16BuildTable(unsigned short *ptable, unsigned short poly)
    178          {
    179          	unsigned int i, j;
    180          
    181              for(i = 0; i <= 255; i++)
    182              {
    183                  ptable[i] = i << 8;
    184                  for(j = 0; j < 8; j++)
    185                      ptable[i] = (ptable[i] << 1) ^ (ptable[i] & 0x8000 ? poly : 0);
    186              }
    187          }
    188          
    189          void crc32BuildTable(unsigned long *ptable, unsigned long poly)
    190          {
    191          	unsigned int i, j;
    192          
    193              for(i = 0; i <= 255; i++)
    194              {
    195                  ptable[i] = (long)i << 24;        
    196                  for(j = 0; j < 8; j++)
    197                      ptable[i] = (ptable[i] << 1) ^ (ptable[i] & 0x80000000 ? poly : 0);
    198              }
    199          }
    200          
    201          unsigned long bitReflect(unsigned long data, unsigned int width)
    202          {
    203              unsigned long result = 0;
    204          	unsigned int i;
    205          
    206              for (i = 1; i < (width + 1); i++)
    207              {
    208                  if(data & 1) result |= 0x1L << (width - i);
    209                  data >>= 1;
    210              } 	
    211          
    212              return result;
    213          }
    214          
    215          /************************************ END ***************************************/

   Maximum stack usage in bytes:

     Function              CSTACK
     --------              ------
     bitReflect               14
     crc16BuildTable           6
     crc16MakeBitwise         10
     crc16MakeBitwise2         8
     crc16MakeTableMethod      6
     crc16rMakeTableMethod     6
     crc32BuildTable          12
     crc32MakeBitwise         16
     crc32MakeBitwise2        16
     crc32MakeTableMethod     10
     crc32rMakeTableMethod     8


   Segment part sizes:

     Function/Label        Bytes
     --------------        -----
     crc16MakeBitwise        74
     crc16MakeBitwise2       58
     crc32MakeBitwise       110
     crc32MakeBitwise2       82
     crc16MakeTableMethod    50
     crc16rMakeTableMethod   48
     crc32MakeTableMethod    68
     crc32rMakeTableMethod   64
     crc16BuildTable         64
     crc32BuildTable         96
     bitReflect              78

 
 792 bytes in segment CODE
 
 792 bytes of CODE memory

Errors: none
Warnings: none

⌨️ 快捷键说明

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