# crc16_ccitt_bitwise

CRC16-CCITT Bitwise Implementation Library

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

Description

    CRC16-CCITT implementation using optimized bitwise algorithm.
    Provides incremental and one-shot calculation over bytes using direct bit manipulation.
    This is the reference implementation for CRC16-CCITT with polynomial 0x1021.

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`
- `var word _crc16_current_crc_crc`
- `var bit _crc16_error_occurred_crc`
- `var word _crc16_bytes_processed_crc`
- `const word CRC16_TABLE[256] = {`
- `const word CRC16_POLYNOMIAL = 0x1021`
- `var bit _crc16_calculation_complete_crc`

### Procedures

- `crc16_calculate_bytes(byte in data)`
- `crc16_start(word in expected_bytes)`
- `crc16_verify(word in calculated, word in expected)`

### Functions

- `crc16_is_complete() return bit`
- `crc16_error_occurred() return bit`
- `crc16_get_result() return word`
- `crc16_calculate_array_bytes(byte in data[], word in length) return word`
- `crc16_get_error_type() return byte`

## 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

- `var word _crc16_current_crc_crc`

      CRC16 state variables (matching working library)

- `var bit _crc16_error_occurred_crc`

  No documentation found

- `var word _crc16_bytes_processed_crc`

  No documentation found

- `const word CRC16_TABLE[256] = {`

      CRC16 lookup table for polynomial 0x1021 (CCITT)

- `const word CRC16_POLYNOMIAL = 0x1021`

  No documentation found

- `var bit _crc16_calculation_complete_crc`

  No documentation found

### Procedures

- `crc16_calculate_bytes(byte in data)`

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

- `crc16_start(word in expected_bytes)`

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

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

      Verify CRC16 result
      Parameters: calculated - computed CRC value, expected - expected CRC value
      Compares calculated CRC against expected value for validation

### Functions

- `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_error_occurred() return bit`

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

- `crc16_get_result() return word`

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

- `crc16_calculate_array_bytes(byte in data[], word in length) return word`

      Calculate CRC16 for a byte array (one-shot calculation)
      Parameters: data[] - array of bytes to process, length - number of bytes
      Returns: calculated CRC16 value
      Processes entire array in one operation

- `crc16_get_error_type() return byte`

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

## Related samples

Here are the list of samples which use this library:

18f67j50 | 18f67j50_crc16_ccitt_bitwise.jal