rng90 1.0
rng90 driver library
Loading...
Searching...
No Matches
crc16.c File Reference
#include "crc16.h"
Include dependency graph for crc16.c:

Functions

void crc16_init (unsigned int value)
 Initializes the CRC16 calculation with a specified starting value.
void crc16_update (unsigned char data)
 Updates the CRC16 value with a single data byte.
void crc16_calculate (unsigned char initial, unsigned char *data, unsigned char length)
 Calculates a complete CRC16 checksum over a data buffer.
unsigned int crc16_result (void)
 Returns the current CRC16 result.
void crc16_result_array (unsigned char *crc)
 Stores the CRC16 result as a two-byte array.

Function Documentation

◆ crc16_calculate()

void crc16_calculate ( unsigned char initial,
unsigned char * data,
unsigned char length )

Calculates a complete CRC16 checksum over a data buffer.

This function initializes the CRC register with the given start value and processes each byte in the provided data buffer using the CRC16 update routine. It performs a full CRC16 computation over a contiguous block of data.

Parameters
initialThe initial CRC16 value (e.g. CRC16_INITIAL_VALUE or a protocol-specific seed).
dataPointer to the data buffer to compute the CRC for.
lengthNumber of bytes in the data buffer.
Note
This function combines crc16_init() and repeated calls to crc16_update() for each byte. After completion, the CRC result can be retrieved with crc16_result() or crc16_result_array().
See also
crc16_init(), crc16_update(), crc16_result(), crc16_result_array()
Here is the call graph for this function:

◆ crc16_init()

void crc16_init ( unsigned int value)

Initializes the CRC16 calculation with a specified starting value.

This function sets the internal CRC register to the given initial value. It is typically called before starting a new CRC calculation sequence.

Parameters
valueThe initial value to load into the CRC register (e.g. CRC16_INITIAL_VALUE or a custom seed).
Note
This function must be called before any calls to crc16_update().
See also
crc16_update(), crc16_result(), CRC16_INITIAL_VALUE
Here is the caller graph for this function:

◆ crc16_result()

unsigned int crc16_result ( void )

Returns the current CRC16 result.

This function returns the 16-bit value currently stored in the internal CRC register. It can be called after one or more calls to crc16_update() or after a complete block calculation using crc16_calculate().

Returns
The 16-bit CRC result as an unsigned integer.
Note
The result reflects the current CRC state and is not reset automatically. To start a new calculation, call crc16_init() again.
See also
crc16_calculate(), crc16_result_array(), crc16_init()
Here is the caller graph for this function:

◆ crc16_result_array()

void crc16_result_array ( unsigned char * crc)

Stores the CRC16 result as a two-byte array.

This function retrieves the current 16-bit CRC value (via crc16_result()) and writes it into a two-byte array in little-endian order — the least significant byte first, followed by the most significant byte.

Parameters
crcPointer to a two-byte buffer that receives the CRC16 result. The array must have space for at least two bytes.
Note
Useful when communicating CRC values as byte streams over serial interfaces or storing them in data packets. The byte order follows the convention used in common embedded CRC protocols.
See also
crc16_result(), crc16_calculate(), crc16_update()
Here is the call graph for this function:

◆ crc16_update()

void crc16_update ( unsigned char data)

Updates the CRC16 value with a single data byte.

This function processes one byte of data and updates the internal CRC register according to the CRC16 algorithm defined by CRC16_POLYNOM. The implementation follows the method described in the Microchip application note: Atmel-8936 – CryptoAuth Data Zone CRC Calculation.

Each bit of the input byte is processed sequentially. If the current data bit differs from the most significant bit of the CRC register, the polynomial is applied via XOR to update the remainder.

Parameters
dataThe 8-bit data value to include in the CRC16 computation.
Note
Call crc16_init() before using this function to ensure a valid initial state. Subsequent calls to this function extend the CRC over multi-byte data.
See also
crc16_init(), crc16_result(), CRC16_POLYNOM
Here is the caller graph for this function: