MCPcopy Create free account
hub / github.com/DanielOgorchock/ST_Anything / crc16

Method crc16

Arduino/libraries/OneWire/OneWire.cpp:567–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565}
566
567uint16_t OneWire::crc16(const uint8_t* input, uint16_t len, uint16_t crc)
568{
569#if defined(__AVR__)
570 for (uint16_t i = 0 ; i < len ; i++) {
571 crc = _crc16_update(crc, input[i]);
572 }
573#else
574 static const uint8_t oddparity[16] =
575 { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
576
577 for (uint16_t i = 0 ; i < len ; i++) {
578 // Even though we're just copying a byte from the input,
579 // we'll be doing 16-bit computation with it.
580 uint16_t cdata = input[i];
581 cdata = (cdata ^ crc) & 0xff;
582 crc >>= 8;
583
584 if (oddparity[cdata & 0x0F] ^ oddparity[cdata >> 4])
585 crc ^= 0xC001;
586
587 cdata <<= 6;
588 crc ^= cdata;
589 cdata <<= 1;
590 crc ^= cdata;
591 }
592#endif
593 return crc;
594}
595#endif
596
597#endif

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected