Tool/software: TI C/C++ Compiler
Hi,
I've tried to use the crc_table function in the linker command file, but in the application I'm not able the calculate the same value as the Linker.
My development enviroment looks like:
Operating System: Windows 10 64Bit
CCS: 6.6.2
Compiler: TI MSP430 16.9.3 LTS
MCU: MSP430F2274
A snippet from the linker command file:
.TI.crctab : > FLASH .cinit : {} > FLASH,PAGE=0,crc_table(_crc_table_cinit ) .const : {} > FLASH,PAGE=0,crc_table(_crc_table_const ) .text : {} > FLASH,PAGE=0,crc_table(_crc_table_text )
In the application I'm using the crc functions which are described in the document slaa221.pdf :
// CRC16 g(x) = x^16+ x^12 + x^5 + 1 (CCITT-Polynom). // CCITT = CRC16_802_15_4 #define CRC16_802_15_4 1 #define CRC16_POLY 0x1021 #define CRC16_INIT_REM 0x0 #define CRC16_FINAL_XOR 0x0 unsigned int CRC_CheckROM(CRC_TABLE *tp) { int i; unsigned int uiResult = 0; for (i = 0; i < tp->num_recs; i++) { CRC_RECORD crc_rec = tp->recs[i]; if (crc_rec.crc_alg_ID == CRC16_802_15_4 ) // CRC_CCITT, CRC16_802_15_4 = 1 { uint16_t uiCrc = 0; uint16_t uiExpCrc = (uint16_t)crc_rec.crc_value; // expected checksum unsigned char * pData = (unsigned char *) crc_rec.addr; // start address // calculate the current checksum uiCrc = CRC_CalcCRC16(CRC16_INIT_REM, CRC16_POLY, pData , crc_rec.size); // Validate CRC Sum if (uiCrc == uiExpCrc) { uiResult = 1; // pass } else { uiResult = 0; // fail } } } return uiResult; } unsigned short CRC_CalcCRC16(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); }
I've implemted a table based crc function as well.
Here are my results:
.text section:
Linker: crc_value 0x00005A9E
Linker: crc_alg_ID 0x0001
Linker: addr 0x8000
Linker: size 0x1000
application:
16 Bit calculation bitwise: 0x1CBC
16 Bit table calculation: 0x1CBC
Where is my fault?
Kind regards,
Arne