SPRU513Z August 2001 – October 2023 SM320F28335-EP
#include <stdio.h>
#include "crc_tbl.h"
/****************************************************************************/
/* gen_crc() - computes the CRC value of data using the CRC algorithm ID */
/* specified. Found in ref_crc.c */
/****************************************************************************/
unsigned long gen_crc(int id, const unsigned char *data, size_t len);
/****************************************************************************/
/* my_check_CRC() - verify the CRC values for all records stored in the */
/* given CRC table. Print diagnostic information also. */
/****************************************************************************/
unsigned int my_check_CRC(CRC_TABLE *tp)
{
int i;
unsigned int ret_val = 1;
uint32_t my_crc;
printf("\n\tTABLE INFO: rec size=%d, num_rec=%d.",
tp->rec_size, tp->num_recs);
for (i = 0; i < tp->num_recs; i++)
{
CRC_RECORD crc_rec = tp->recs[i];
/**************************************************/
/* COMPUTE CRC OF DATA STARTING AT crc_rec.addr */
/* FOR crc_rec.size UNITS. USE */
/* crc_rec.crc_alg_ID to select algorithm. */
/* COMPARE COMPUTED VALUE TO crc_rec.crc_value. */
/**************************************************/
my_crc = gen_crc(crc_rec.crc_alg_ID, (unsigned char *)crc_rec.addr,
crc_rec.size);
printf("\n\tCRC record: page=%x, alg=%x, addr = %lx, size=%lx, "
"\n\t\tcrc=%lx, my_crc=%lx.",
crc_rec.page_id, crc_rec.crc_alg_ID,
crc_rec.addr, crc_rec.size, crc_rec.crc_value, my_crc);
if (my_crc == crc_rec.crc_value)
printf("\n\tCRCs match for record %d.\n", i);
else
{
ret_val = 0;
printf("\n\tCRCs DO NOT match for record %d.\n", i);
}
}
return ret_val;
}