| Author | AI Assistant |
| Adapted-by | |
| Compiler | >=2.4q3 |
This library provides CRC7 and CRC16 calculations for SD card
communication in SPI mode. CRC7 is used for command frames,
CRC16 is used for data blocks.
SD Card Physical Layer Simplified Specification Version 2.00 SanDisk Secure Digital Card - http://www.cs.ucr.edu/~amitra/sdcard/ProdManualSDCardv1.9.pdf
- CRC7 polynomial: x^7 + x^3 + 1 (0x89) - CRC16 polynomial: x^16 + x^12 + x^5 + 1 (0x1021) - CRC7 is used for SD card command frames - CRC16 is used for SD card data blocks
No dependency found
const byte CRC_ERROR_VERIFICATION_FAILED = 3
const byte CRC_ERROR_NONE = 0
var bit crc_has_error = FALSE
const byte crc7_table[128] = {
const byte CRC_ERROR_INVALID_PARAMETER = 1
var byte crc_error_code = 0
const byte CRC_ERROR_CALCULATION_FAILED = 2
const bit CRC_USE_CONSTANT_TABLES = TRUE
const word CRC16_POLYNOMIAL = 0x1021
const byte CRC_ERROR_OVERFLOW = 5
const word crc16_table[256] = {
const bit CRC_USE_LOOKUP_TABLES = TRUE
const byte CRC_ERROR_TABLE_NOT_INITIALIZED = 4
const byte CRC7_POLYNOMIAL = 0x09
crc_print_error(volatile byte out device)
crc_init()
crc_set_error(byte in error_code)
crc_test()
crc_clear_error()
crc_get_error() return byte
crc7_sd_command(byte in cmd, dword in arg) return byte
crc7_sd_calculate_bitwise(byte in data[], byte in length) return byte
crc7_sd_verify(byte in data[], byte in length) return bit
crc_has_error_status() return bit
crc16_sd_verify(byte in data[], word in length, word in received_crc) return bit
crc16_sd_calculate_bitwise(byte in data[], word in length) return word
crc16_sd_calculate_byte(word in current_crc, byte in data) return word
crc7_sd_cmd8() return byte
crc7_sd_calculate(byte in data[], byte in length) return byte
crc16_sd_calculate(byte in data[], word in length) return word
crc7_sd_cmd0() return byte
const byte CRC_ERROR_VERIFICATION_FAILED = 3
No documentation found
const byte CRC_ERROR_NONE = 0
CRC error codes
var bit crc_has_error = FALSE
CRC error handling
const byte crc7_table[128] = {
CRC7 constant lookup table (stored in program memory)
const byte CRC_ERROR_INVALID_PARAMETER = 1
No documentation found
var byte crc_error_code = 0
No documentation found
const byte CRC_ERROR_CALCULATION_FAILED = 2
No documentation found
const bit CRC_USE_CONSTANT_TABLES = TRUE
No documentation found
const word CRC16_POLYNOMIAL = 0x1021
CRC16 polynomial: x^16 + x^12 + x^5 + 1 (0x1021) - SD card standard
const byte CRC_ERROR_OVERFLOW = 5
No documentation found
const word crc16_table[256] = {
CRC16 constant lookup table (stored in program memory)
const bit CRC_USE_LOOKUP_TABLES = TRUE
Memory-constrained mode: use constant lookup tables stored in program memory This saves RAM by storing tables in Flash memory instead of data memory
const byte CRC_ERROR_TABLE_NOT_INITIALIZED = 4
No documentation found
const byte CRC7_POLYNOMIAL = 0x09
CRC7 polynomial: x^7 + x^3 + 1 (0x09) - SD card standard
crc_print_error(volatile byte out device)
Print CRC error message
crc_init()
Initialize CRC lookup tables for faster calculation
crc_set_error(byte in error_code)
Set CRC error
crc_test()
Test CRC functions with known test vectors This procedure can be used for debugging and verification
crc_clear_error()
Clear CRC error
crc_get_error() return byte
Get CRC error status
crc7_sd_command(byte in cmd, dword in arg) return byte
Calculate CRC7 for a single command frame (6 bytes: command + argument + crc) Input: command byte, 32-bit argument Output: 7-bit CRC value
crc7_sd_calculate_bitwise(byte in data[], byte in length) return byte
Calculate CRC7 for SD card command frames (bit-by-bit method) Input: data array and length Output: 7-bit CRC value
crc7_sd_verify(byte in data[], byte in length) return bit
Verify CRC7 for a received command response Input: response data array and length Output: TRUE if CRC is valid, FALSE otherwise
crc_has_error_status() return bit
Check if CRC has error
crc16_sd_verify(byte in data[], word in length, word in received_crc) return bit
Verify CRC16 for a received data block Input: data array, length, and received CRC Output: TRUE if CRC is valid, FALSE otherwise
crc16_sd_calculate_bitwise(byte in data[], word in length) return word
Calculate CRC16 for SD card data blocks (bit-by-bit method) Input: data array and length Output: 16-bit CRC value
crc16_sd_calculate_byte(word in current_crc, byte in data) return word
Calculate CRC16 for a single byte (for incremental calculation) Input: current CRC value and new byte Output: updated CRC value
crc7_sd_cmd8() return byte
Calculate CRC7 for CMD8 (SEND_IF_COND) command CMD8 has a special CRC value of 0x87
crc7_sd_calculate(byte in data[], byte in length) return byte
Calculate CRC7 for SD card command frames Input: data array and length Output: 7-bit CRC value
crc16_sd_calculate(byte in data[], word in length) return word
Calculate CRC16 for SD card data blocks Input: data array and length Output: 16-bit CRC value
crc7_sd_cmd0() return byte
Calculate CRC7 for CMD0 (GO_IDLE_STATE) command CMD0 has a special CRC value of 0x95
| 18f67j50 | 18f67j50_sd_card_crc_test.jal |