# crc7_sd_card

Library for communicating with SD memory cards

Author | Matthew Schinkel, copyright © 2009..2022, all rights reserved.
Adapted-by |
Compiler | 2.5r9

Description

    this library provides functions for SD memory cards.

Sources

    SanDisk Secure Digital Card - http://www.cs.ucr.edu/~amitra/sdcard/ProdManualSDCardv1.9.pdf
    How to use MMC/SDC - http://forums.parallax.com/forums/attach.aspx?a=32012
    http://www.rjhcoding.com/avrc-sd-interface-3.php

Notes

    SD card SPI mode is 1,1

Dependencies

No dependency found

## Summary

### Global variables/contants

- `var byte _crc7_accumulator_crc = 0`
- `var byte _crc_error_type_crc = CRC_ERROR_SUCCESS`
- `var bit _crc7_calculation_complete_crc = FALSE`
- `var bit _crc_error_occurred_crc = FALSE`
- `const byte CRC7_POLYNOMIAL = 0x89`
- `var word _crc7_bytes_processed_crc = 0`
- `var byte _crc7_final_result_crc = 0`
- `var word _crc7_total_bytes_expected_crc = 0`

### Procedures

- `crc7_calculate_bytes(byte in data)`
- `crc7_start(word in expected_bytes)`
- `crc7_reset()`

### Functions

- `crc7_verify_large_array_dwords(word in length, byte in expected) return bit`
- `crc7_calculate_large_array_dwords(word in length) return byte`
- `crc7_verify_data(byte in data[], word in length, byte in expected) return bit`
- `crc7_calculate_large_array_words(word in length) return byte`
- `crc7_verify_large_array_words(word in length, byte in expected) return bit`
- `crc7_verify(byte in calculated, byte in expected) return bit`
- `crc7_get_result() return byte`
- `crc7_calculate_array_bytes(byte in data[], word in length) return byte`
- `crc7_get_error_type() return byte`
- `crc7_has_error() return bit`
- `crc7_verify_large_array(word in length, byte in expected) return bit`
- `crc7_calculate_large_array_bytes(word in length) return byte`
- `crc7_is_complete() return bit`

## API details

### Global variables/contants

- `var byte _crc7_accumulator_crc = 0`

  No documentation found

- `var byte _crc_error_type_crc = CRC_ERROR_SUCCESS`

  No documentation found

- `var bit _crc7_calculation_complete_crc = FALSE`

      CRC7 state variables

- `var bit _crc_error_occurred_crc = FALSE`

  No documentation found

- `const byte CRC7_POLYNOMIAL = 0x89`

  No documentation found

- `var word _crc7_bytes_processed_crc = 0`

  No documentation found

- `var byte _crc7_final_result_crc = 0`

  No documentation found

- `var word _crc7_total_bytes_expected_crc = 0`

  No documentation found

### Procedures

- `crc7_calculate_bytes(byte in data)`

      Calculate CRC7 for a single byte (incremental processing)
      Parameters: data - single byte to process
      Updates internal CRC state with new data byte

- `crc7_start(word in expected_bytes)`

      Start CRC7 calculation with expected byte count
      Parameters: expected_bytes - total number of bytes to be processed
      Initializes CRC calculation state and sets up for incremental processing

- `crc7_reset()`

      Reset CRC7 calculation state
      Clears all internal state and error flags
      Call this to start fresh after an error or to reuse the library

### Functions

- `crc7_verify_large_array_dwords(word in length, byte in expected) return bit`

      Verify CRC7 for large array (dwords)
      Parameters: length - number of dwords to verify, expected - expected CRC
      Returns: TRUE if calculated CRC matches expected, FALSE otherwise
      Calculates CRC for dwords from large_array_6 and compares with expected value

- `crc7_calculate_large_array_dwords(word in length) return byte`

      Calculate CRC7 for large array (dwords)
      Parameters: length - number of dwords to process from large_array_6
      Returns: calculated CRC7 value
      Processes dwords from large_array_6 alias (MSB first)

- `crc7_verify_data(byte in data[], word in length, byte in expected) return bit`

      Verify CRC7 for data array
      Parameters: data[] - array to verify, length - number of bytes, expected - expected CRC
      Returns: TRUE if calculated CRC matches expected, FALSE otherwise
      Calculates CRC for array and compares with expected value

- `crc7_calculate_large_array_words(word in length) return byte`

      Calculate CRC7 for large array (words)
      Parameters: length - number of words to process from large_array_5
      Returns: calculated CRC7 value
      Processes words from large_array_5 alias (MSB first)

- `crc7_verify_large_array_words(word in length, byte in expected) return bit`

      Verify CRC7 for large array (words)
      Parameters: length - number of words to verify, expected - expected CRC
      Returns: TRUE if calculated CRC matches expected, FALSE otherwise
      Calculates CRC for words from large_array_5 and compares with expected value

- `crc7_verify(byte in calculated, byte in expected) return bit`

      Verify CRC7 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

- `crc7_get_result() return byte`

      Get final CRC7 result
      Returns: calculated CRC7 value
      Marks calculation as complete and returns the final CRC result

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

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

- `crc7_get_error_type() return byte`

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

- `crc7_has_error() return bit`

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

- `crc7_verify_large_array(word in length, byte in expected) return bit`

      Verify CRC7 for large array (bytes)
      Parameters: length - number of bytes to verify, expected - expected CRC
      Returns: TRUE if calculated CRC matches expected, FALSE otherwise
      Calculates CRC for bytes from large_array_4 and compares with expected value

- `crc7_calculate_large_array_bytes(word in length) return byte`

      Calculate CRC7 for large array (bytes)
      Parameters: length - number of bytes to process from large_array_4
      Returns: calculated CRC7 value
      Processes bytes from large_array_4 alias

- `crc7_is_complete() return bit`

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

## Related samples

Here are the list of samples which use this library:

18f67j50 | 18f67j50_crc7_bitwise.jal