Example 31. The CRC Table Header, crc_tbl.h

/*****************************************************************************/ /* crc_tbl.h */ /* */ /* PRELIMINARY - SUBJECT TO CHANGE */ /* */ /* Specification of CRC table data structures which can be automatically */ /* generated by the linker (using the crc_table() operator in the linker */ /* command file). */ /*****************************************************************************/ /*****************************************************************************/ /* */ /* The CRC generator used by the linker is based on concepts from the */ /* document: */ /* "A Painless Guide to CRC Error Detection Algorithms" */ /* */ /* Author : Ross Williams (ross@guest.adelaide.edu.au.). */ /* Date : 3 June 1993. */ /* Status : Public domain (C code). */ /* */ /* Description : For more information on the Rocksoft^tm Model CRC */ /* Algorithm, see the document titled "A Painless Guide to CRC Error */ /* Detection Algorithms" by Ross Williams (ross@guest.adelaide.edu.au.). */ /* This document is likely to be in "ftp.adelaide.edu.au/pub/rocksoft" or */ /* at http:www.ross.net/crc/download/crc_v3.txt. */ /* */ /* Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia. */ /*****************************************************************************/ #include <stdint.h> /* For uintXX_t */ /*****************************************************************************/ /* CRC Algorithm Specifiers */ /* */ /* The following specifications, based on the above cited document, are used */ /* by the linker to generate CRC values. */ /* */ /* */ /* ID Name Order Polynomial Initial Ref Ref CRC XOR Zero */ /* Value In Out Value Pad */ /*-------------------------------------------------------------------------- */ /* 0, "CRC32_PRIME", 32, 0x04c11db7, 0x00000000, 0, 0, 0x00000000, 1 */ /* 1, "CRC16_802_15_4", 16, 0x00001021, 0x00000000, 0, 0, 0x00000000, 1 */ /* 2, "CRC16_ALT", 16, 0x00008005, 0x00000000, 0, 0, 0x00000000, 1 */ /* 3, "CRC8_PRIME", 8, 0x00000007, 0x00000000, 0, 0, 0x00000000, 1 */ /* */ /* */ /* Users should specify the name, such as CRC32_PRIME, in the linker command */ /* file. The resulting CRC_RECORD structure will contain the corresponding */ /* ID value in the crc_alg_ID field. */ /*****************************************************************************/ #define CRC32_PRIME 0 /* Poly = 0x04c11db7 */ /* DEFAULT ALGORITHM */ #define CRC16_802_15_4 1 /* Poly = 0x00001021 */ #define CRC16_ALT 2 /* Poly = 0x00008005 */ #define CRC8_PRIME 3 /* Poly = 0x00000007 */ /*********************************************************/ /* CRC Record Data Structure */ /* NOTE: The list of fields and the size of each field */ /* varies by target and memory model. */ /*********************************************************/ typedef struct crc_record { uint16_t crc_alg_ID; /* CRC algorithm ID */ uint16_t page_id; /* page number of data */ uint32_t addr; /* Starting address */ uint32_t size; /* size of data in 16-bit units */ uint32_t crc_value; } CRC_RECORD; /*********************************************************/ /* CRC Table Data Structure */ /*********************************************************/ typedef struct crc_table { uint16_t rec_size; uint16_t num_recs; CRC_RECORD recs[1]; } CRC_TABLE;

In the CRC_TABLE struct, the array recs[1] is dynamically sized by the linker to accommodate the number of records contained in the table (num_recs). A user-supplied routine to verify CRC values should take a table name and check the CRC values for all entries in the table. An outline of such a routine is shown in Section C.