|
crc16 1.0
CRC calcualtion library
|
Implements the CRC16 utility functions. More...
#include "crc16.h"
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. | |
Implements the CRC16 utility functions.
This file provides the implementation of the CRC16 utility functions declared in crc16.h. It manages a software-based CRC16 calculation, supporting configurable initial values and polynomials.
| 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.
| initial | The initial CRC16 value (e.g. CRC16_INITIAL_VALUE or a protocol-specific seed). |
| data | Pointer to the data buffer to compute the CRC for. |
| length | Number of bytes in the data buffer. |

| 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.
| value | The initial value to load into the CRC register (e.g. CRC16_INITIAL_VALUE or a custom seed). |

| 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().

| 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.
| crc | Pointer to a two-byte buffer that receives the CRC16 result. The array must have space for at least two bytes. |

| 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.
| data | The 8-bit data value to include in the CRC16 computation. |
