Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: Utilities/crc.h
- Revision:
- 86:2ce08ca58b9e
- Parent:
- 80:83b0d879cc32
- Child:
- 104:3f48daed532b
diff -r 708b7be59fb2 -r 2ce08ca58b9e Utilities/crc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Utilities/crc.h Wed Jun 15 15:00:06 2016 -0500 @@ -0,0 +1,40 @@ +#ifndef OneWire_CRC +#define OneWire_CRC + +#include <stdint.h> +#include <stddef.h> + +namespace OneWire +{ + namespace crc + { + /// Perform a CRC8 calculation. + /// @param crc8 Beginning state of the CRC generator. + /// @param data Data to pass though the CRC generator. + /// @returns The calculated CRC8. + uint8_t calculateCrc8(uint8_t crc8, uint8_t data); + + /// Perform a CRC8 calculation with variable length data. + /// @param[in] data Data array to pass through the CRC generator. + /// @param dataLen Length of the data array to process. + /// @param crc Beginning state of the CRC generator. + /// @returns The calculated CRC8. + uint8_t calculateCrc8(const uint8_t * data, size_t dataLen, uint8_t crc = 0); + + /// Perform a CRC16 calculation. + /// @param crc16 Beginning state of the CRC generator. + /// @param data Data to pass though the CRC generator. + /// @returns The calculated CRC16. + uint16_t calculateCrc16(uint16_t crc16, uint16_t data); + + /// Perform a CRC16 calculation with variable length data. + /// @param[in] data Data array to pass through the CRC generator. + /// @param data_offset Offset of the data array to begin processing. + /// @param data_len Length of the data array to process. + /// @param crc Beginning state of the CRC generator. + /// @returns The calculated CRC16. + uint16_t calculateCrc16(const uint8_t * data, size_t dataOffset, size_t dataLen, uint16_t crc = 0); + } +} + +#endif