code wiki / (root) / crc16.nx

crc16.nx

buildroot/runtime/crc16.nx

3182 B109 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

crc16.nx -- CRC-16 variants (CCITT, IBM, MODBUS). Used by serial / wire protocols where 16-bit checksums are adequate (link-layer error detection). Three common variants shipped: CCITT-FALSE (poly 0x1021, init 0xFFFF, no reflection) Used by: XMODEM, MAVLink, DNP3, Bluetooth HCI IBM (poly 0x8005, init 0x0000, reflected) Used by: Modbus RTU, USB token CRC, ISO/IEC 13239 MODBUS (poly 0x8005, init 0xFFFF, reflected) Used by: Modbus serial framing All NOT cryptographic. Burst-error detection only. Invariants: CR1 Pure functions; no global state; deterministic. CR2 Result fits in low 16 bits of i64. CR3 Bit-by-bit implementation (no 256-entry table) -- slower than tabulated variants but ~50 LoC instead of 50 LoC + 256-byte data + per-variant table.

dependencies 1 imports · 0 importers

syscalls.nx crc16.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main crc16_ccitt crc16_modbus

structs

none

consts

25const CR_POLY_CCITT: i64 = 0x1021
26const CR_POLY_IBM: i64 = 0x8005
27const CR_INIT_FFFF: i64 = 0xFFFF
28const CR_INIT_0000: i64 = 0x0000
29const CR_U16_MASK: i64 = 0xFFFF

functions

32func crc16_reflect8(b: i64) -> i64 {
45func crc16_reflect16(x: i64) -> i64 {
59func crc16_ccitt(bytes: *u8, n: i64) -> i64 {
called by 1: main
81func crc16_modbus(bytes: *u8, n: i64) -> i64 {
called by 1: main
102func main() -> i64 {