Other Parts Discussed in Thread: C2000WARE
The linker generated symbol name for my CRC table user_specified_table_name allocates a different/new address and the programe uses this new address for the run time code to calculate the CRC. Hence the CRC does not work.
Below is the CRC generated data after building and linking
LINKER GENERATED CRC TABLES
page0_crc_table @ 00085938 records: 8, size/record: 8, table size: 66
.cinit: algorithm=CRC32_PRIME(ID=0), page=0, load addr=000815e8, size=00000154, CRC=de66b93b
.pinit: algorithm=CRC32_PRIME(ID=0), page=0, load addr=0008173c, size=00000006, CRC=3c6ee8ab
.text.1: algorithm=CRC32_PRIME(ID=0), page=0, load addr=00081744, size=000008bc, CRC=6e143b1b
.text.2: algorithm=CRC32_PRIME(ID=0), page=0, load addr=00082000, size=00001000, CRC=ecbb58db
.text.3: algorithm=CRC32_PRIME(ID=0), page=0, load addr=00083000, size=00001000, CRC=81cf7677
.econst: algorithm=CRC32_PRIME(ID=0), page=0, load addr=00084000, size=00000614, CRC=3bc27337
.text.4: algorithm=CRC32_PRIME(ID=0), page=0, load addr=00084614, size=000009ec, CRC=5571944b
.text.5: algorithm=CRC32_PRIME(ID=0), page=0, load addr=00085000, size=00000938, CRC=7a0e9afe
Below is the linker generated symbol names and the allocated address. This was gotten from the .map file of the build and liking of code
Line 342: 00085938 00000042 (.TI.crctab:page0_crc_table)
Line 1407: page0_crc_table @ 00085938 records: 8, size/record: 8, table size: 66
Line 1600: 0000ae02 2b8 (0000ae00) _page0_crc_table
Line 1934: 0 00085938 __TI_CRC_page0_crc_table
Line 2054: 1 0000ae02 _page0_crc_table
Line 2094: 0 00085938 page0_crc_table
Line 2345: 0 00085938 __TI_CRC_page0_crc_table
Line 2346: 0 00085938 page0_crc_table
Line 2458: 1 0000ae02 _page0_crc_table
The address has been changed from 0x00085938 to 0x0000ae02 and the code uses the new (0x0000ae02, which is wrong) to do the run time CRC calculation.
My CRC code is below
in the .h file
extern CRC_TABLE page0_crc_table; // linker generated object (crc table)
extern uint32 crc32_table[256]; //Lookup table for the CRC32 polynomial 0x04C11DB7
.cpp file
/**< private variable definition for file */
CRC_TABLE page0_crc_table; // linker generated object (crc table)
CRC_TABLE *saf_crc::pLinker_crc_table = (CRC_TABLE*)&page0_crc_table;
//CRC_TABLE *saf_crc::pLinker_crc_table = (CRC_TABLE*)0x00085938; //work around
uint32 crc32_table[256]; //Lookup table for the CRC32 polynomial 0x04C11DB7
void saf_crc::InitCRC(void)
{
CRC_reset ();
genCRC32Table();
}
void saf_crc::CRCCalPage0(CRC_TABLE *p_crc_table)
{
uint16_t cou = 0;
uint32_t crc_cal_val;
for (cou = 0; cou < p_crc_table->num_recs; cou++ )
{
crc_cal_val = getCRC32_cpu(INIT_CRC32, (uint16*)(p_crc_table->recs[cou].addr), (CRC_parity_e)CRC_parity_even, ((p_crc_table->recs[cou].size) << 1));
if (crc_cal_val != p_crc_table->recs[cou].crc_value)
{
//TODO
//crc value not correct error
uint16_t abc;
if (crc_cal_val ==888)
{
abc = 0;
}
}
}
}
void saf_crc::CRCCal(void)
{
saf_crc::CRCCalPage0(saf_crc::pLinker_crc_table );
}
This work around works just fine
//CRC_TABLE *saf_crc::pLinker_crc_table = (CRC_TABLE*)0x00085938; //work around
But of course i am not to use this in the final code.
Please what can the problem be. I have read the entire compiler and assembler documentation and checked the pointer usage in the code but i could not solve it. Does it have to do with the mixing of c++ and c code or some compiler settings.
Thanks.