# crc16_ccitt_lookup

CRC16-CCITT Lookup Table Implementation Library

Author | Matthew Schinkel
Adapted-by |
Compiler | >=2.4r9

Description

    CRC16-CCITT implementation using lookup table for maximum speed.
    This version splits the large table into smaller chunks to avoid 8-bit PIC memory issues.
    Provides identical results to the bitwise implementation but with better performance.

Dependencies

No dependency found

## Summary

### Global variables/contants

- `var byte _crc16_error_type_crc = CRC_ERROR_SUCCESS`
- `var word _crc16_final_result_crc`
- `var word _crc16_total_bytes_expected_crc`
- `const word CRC16_POLYNOMIAL = 0x1021`
- `var word _crc16_current_crc_crc`
- `var bit _crc16_error_occurred_crc`
- `const word CRC16_TABLE_1[64] = {`
- `const word CRC16_TABLE_3[64] = {`
- `var word _crc16_bytes_processed_crc`
- `const word CRC16_TABLE_0[64] = {`
- `const word CRC16_TABLE_2[64] = {`
- `var bit _crc16_calculation_complete_crc`

### Procedures

- `crc16_init(byte in total_bytes)`
- `crc16_calculate_bytes(byte in data)`

### Functions

- `crc16_has_error() return bit`
- `crc16_get_error_type() return byte`
- `crc16_get_table_value(byte in index) return word`
- `crc16_is_complete() return bit`
- `crc16_verify(word in calculated, word in expected) return bit`
- `crc16_get_result() return word`

## API details

### Global variables/contants

- `var byte _crc16_error_type_crc = CRC_ERROR_SUCCESS`

  No documentation found

- `var word _crc16_final_result_crc`

  No documentation found

- `var word _crc16_total_bytes_expected_crc`

  No documentation found

- `const word CRC16_POLYNOMIAL = 0x1021`

      CRC16-CCITT constants

- `var word _crc16_current_crc_crc`

      CRC16 lookup table state variables

- `var bit _crc16_error_occurred_crc`

  No documentation found

- `const word CRC16_TABLE_1[64] = {`

      Table 1: indices 0x40-0x7F (64-127)

- `const word CRC16_TABLE_3[64] = {`

      Table 3: indices 0xC0-0xFF (192-255)

- `var word _crc16_bytes_processed_crc`

  No documentation found

- `const word CRC16_TABLE_0[64] = {`

      CRC16 lookup table split into smaller chunks to avoid memory issues
      Table 0: indices 0x00-0x3F (0-63)

- `const word CRC16_TABLE_2[64] = {`

      Table 2: indices 0x80-0xBF (128-191)

- `var bit _crc16_calculation_complete_crc`

  No documentation found

### Procedures

- `crc16_init(byte in total_bytes)`

      Initialize CRC16 calculation
      Parameters: total_bytes - expected number of bytes to process
      Initializes CRC calculation state and sets up for incremental processing

- `crc16_calculate_bytes(byte in data)`

      Calculate CRC16 for a single byte using lookup table
      Parameters: data - single byte to process
      Updates internal CRC state with new data byte using lookup table algorithm

### Functions

- `crc16_has_error() return bit`

      Check if error occurred
      Returns: TRUE if error occurred, FALSE otherwise
      Indicates whether an error was detected during CRC calculation

- `crc16_get_error_type() return byte`

      Get error type
      Returns: error type code
      Returns the specific type of error that occurred during calculation

- `crc16_get_table_value(byte in index) return word`

      Get lookup table value based on index
      Parameters: index - table index (0-255)
      Returns: CRC16 table value for the given index
      Retrieves the appropriate CRC16 table value from one of four 64-entry tables

- `crc16_is_complete() return bit`

      Check if calculation is complete
      Returns: TRUE if calculation is complete, FALSE otherwise
      Indicates whether the CRC calculation has been finalized

- `crc16_verify(word in calculated, word in expected) return bit`

      Verify CRC16 result
      Parameters: calculated - computed CRC value, expected - expected CRC value
      Returns: TRUE if CRC values match, FALSE otherwise
      Compares calculated CRC against expected value for validation

- `crc16_get_result() return word`

      Get CRC16 result
      Returns: calculated CRC16 value
      Returns the current CRC16 value (intermediate or final)

## Related samples

Here are the list of samples which use this library:

18f67j50 | 18f67j50_crc16_ccitt_lookup.jal