CRC → C Code Generator
embedcalc_crc_to_cGenerate a compilable C CRC-8/16/32 implementation with 256-entry lookup table and built-in check value. Supports common presets or custom Rocksoft parameters.
Instructions
Generate a complete, compilable C implementation (256-entry lookup table + compute function) for any CRC-8/16/32, plus its standard check value.
Use a preset for common CRCs, or specify the Rocksoft model parameters (width/poly/init/reflect-in/reflect-out/xor-out) for a custom CRC. The generated code embeds check("123456789") so the result can be verified on target.
Args:
preset (optional): one of CRC-8, CRC-8/MAXIM, CRC-16/CCITT, CRC-16/ARC, CRC-16/MODBUS, CRC-32, CRC-32/BZIP2. Overrides all other args.
bits (8|16|32), poly_hex (e.g. '0x1021'): required for a custom CRC.
init_hex, reflect_in, reflect_out, xor_out_hex: optional custom parameters (defaults: 0x0, false, false, 0x0).
Returns (structured): { check_hex, config, c_code }. The text content is the C source itself.
Examples:
"MODBUS RTU CRC in C" -> preset='CRC-16/MODBUS'
"CRC-16 poly 0x1021 init 0xFFFF, no reflection" -> bits=16, poly_hex='0x1021', init_hex='0xFFFF' Check values are exact (e.g. CRC-16/CCITT -> 0x29B1, CRC-32 -> 0xCBF43926); do not estimate CRCs — call this tool.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bits | No | CRC width in bits (8, 16, or 32). Required when no preset is given. | |
| preset | No | Standard CRC preset. If given, all other parameters are ignored. One of: CRC-8, CRC-8/MAXIM, CRC-16/CCITT, CRC-16/ARC, CRC-16/MODBUS, CRC-32, CRC-32/BZIP2 | |
| init_hex | No | Initial CRC register value in hex (default 0x0). | |
| poly_hex | No | Generator polynomial in normal (non-reflected) hex form, e.g. '0x1021'. Required when no preset is given. | |
| reflect_in | No | Reflect each input byte (LSB-first processing). Default false. | |
| reflect_out | No | Reflect the final CRC before XOR-out. Default false. | |
| xor_out_hex | No | Final XOR value in hex (default 0x0). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| c_code | Yes | Complete, compilable C source: 256-entry lookup table + crcN_compute() function | |
| config | Yes | ||
| check_hex | Yes | CRC of the ASCII string "123456789" — the standard check value for verifying the parameters |