ADS124S08 Example C Code  1.0.0
Functions | Variables
crc.c File Reference

Library of functions for CRC implementations. More...

#include "crc.h"
Include dependency graph for crc.c:

Functions

static uint8_t calculateCRC (const uint8_t dataBytes[], uint8_t numberBytes, uint8_t initialValue)
 calculateCRC() Calculates the CRC for the selected CRC polynomial More...
 
static void initTable (void)
 initTable() Creates lookup table in memory using byte wide computation in a 256 element array More...
 
static uint8_t lookupCRC (const uint8_t dataBytes[], uint8_t numberBytes, uint8_t initialValue)
 lookupCRC(() Performs CRC lookup operation in byte increments More...
 
void initCRC (void)
 initCRC() Initializes CRC module and creates lookup table (if using lookup method) More...
 
uint8_t getCRC (const uint8_t dataBytes[], uint8_t numberBytes, uint8_t initialValue)
 getCRC() Performs CRC lookup or calculation More...
 

Variables

static bool initialized = false
 
static uint8_t crcLookupTable [256]
 

Detailed Description

Library of functions for CRC implementations.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

static uint8_t calculateCRC ( const uint8_t  dataBytes[],
uint8_t  numberBytes,
uint8_t  initialValue 
)
static

calculateCRC() Calculates the CRC for the selected CRC polynomial

Parameters
[in]dataBytespointer to first element in the data byte array
[in]numberBytesnumber of bytes to be used in CRC calculation
[in]initialValuethe seed value (or partial crc calculation), use CRC_INITIAL_SEED when beginning a new CRC computation
Returns
CRCWORD of the calculation
uint8_t getCRC ( const uint8_t  dataBytes[],
uint8_t  numberBytes,
uint8_t  initialValue 
)

getCRC() Performs CRC lookup or calculation

Parameters
[in]dataBytespointer to the data array
[in]numberBytesnumber of bytes in array to process
[in]initialValueCRC initial seed value or partial result of previous CRC calculation
Returns
CRCWORD of the calculation
1 // To calculate the CRC of a 3-byte message call:
2 CRCWORD crc = getCRC(data, 3, CRC_INITIAL_SEED);
3 
4 // To test a 4-byte message with a CRC byte call:
5 bool error = (bool) getCRC(data, 4, CRC_INITIAL_SEED);

Here is the call graph for this function:

void initCRC ( void  )

initCRC() Initializes CRC module and creates lookup table (if using lookup method)

Returns
None

Here is the call graph for this function:

static void initTable ( void  )
static

initTable() Creates lookup table in memory using byte wide computation in a 256 element array

Returns
None

Here is the call graph for this function:

static uint8_t lookupCRC ( const uint8_t  dataBytes[],
uint8_t  numberBytes,
uint8_t  initialValue 
)
static

lookupCRC(() Performs CRC lookup operation in byte increments

Parameters
[in]dataBytespointer to the data array (little endian)
[in]numberBytesnumber of bytes in array to process
[in]initialValueCRC initial seed value or partial result of previous CRC calculation
Returns
CRCWORD of the calculation

Variable Documentation

uint8_t crcLookupTable[256]
static
bool initialized = false
static