Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Utilities/crc.h@104:3f48daed532b, 2016-08-02 (annotated)
- Committer:
- j3
- Date:
- Tue Aug 02 18:21:09 2016 +0000
- Revision:
- 104:3f48daed532b
- Parent:
- 86:2ce08ca58b9e
- Child:
- 139:f0e0a7976846
removed "OneWire" from absolute paths
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 104:3f48daed532b | 1 | /******************************************************************//** |
j3 | 104:3f48daed532b | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 104:3f48daed532b | 3 | * |
j3 | 104:3f48daed532b | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 104:3f48daed532b | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 104:3f48daed532b | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 104:3f48daed532b | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 104:3f48daed532b | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 104:3f48daed532b | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 104:3f48daed532b | 10 | * |
j3 | 104:3f48daed532b | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 104:3f48daed532b | 12 | * in all copies or substantial portions of the Software. |
j3 | 104:3f48daed532b | 13 | * |
j3 | 104:3f48daed532b | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 104:3f48daed532b | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 104:3f48daed532b | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 104:3f48daed532b | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 104:3f48daed532b | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 104:3f48daed532b | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 104:3f48daed532b | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 104:3f48daed532b | 21 | * |
j3 | 104:3f48daed532b | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 104:3f48daed532b | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 104:3f48daed532b | 24 | * Products, Inc. Branding Policy. |
j3 | 104:3f48daed532b | 25 | * |
j3 | 104:3f48daed532b | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 104:3f48daed532b | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 104:3f48daed532b | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 104:3f48daed532b | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 104:3f48daed532b | 30 | * ownership rights. |
j3 | 104:3f48daed532b | 31 | **********************************************************************/ |
j3 | 104:3f48daed532b | 32 | |
IanBenzMaxim | 78:0cbbac7f2016 | 33 | #ifndef OneWire_CRC |
IanBenzMaxim | 78:0cbbac7f2016 | 34 | #define OneWire_CRC |
IanBenzMaxim | 78:0cbbac7f2016 | 35 | |
IanBenzMaxim | 78:0cbbac7f2016 | 36 | #include <stdint.h> |
IanBenzMaxim | 78:0cbbac7f2016 | 37 | #include <stddef.h> |
IanBenzMaxim | 78:0cbbac7f2016 | 38 | |
IanBenzMaxim | 78:0cbbac7f2016 | 39 | namespace OneWire |
IanBenzMaxim | 78:0cbbac7f2016 | 40 | { |
IanBenzMaxim | 78:0cbbac7f2016 | 41 | namespace crc |
IanBenzMaxim | 78:0cbbac7f2016 | 42 | { |
j3 | 80:83b0d879cc32 | 43 | /// Perform a CRC8 calculation. |
j3 | 80:83b0d879cc32 | 44 | /// @param crc8 Beginning state of the CRC generator. |
j3 | 80:83b0d879cc32 | 45 | /// @param data Data to pass though the CRC generator. |
j3 | 80:83b0d879cc32 | 46 | /// @returns The calculated CRC8. |
j3 | 80:83b0d879cc32 | 47 | uint8_t calculateCrc8(uint8_t crc8, uint8_t data); |
j3 | 80:83b0d879cc32 | 48 | |
j3 | 80:83b0d879cc32 | 49 | /// Perform a CRC8 calculation with variable length data. |
j3 | 80:83b0d879cc32 | 50 | /// @param[in] data Data array to pass through the CRC generator. |
j3 | 80:83b0d879cc32 | 51 | /// @param dataLen Length of the data array to process. |
j3 | 80:83b0d879cc32 | 52 | /// @param crc Beginning state of the CRC generator. |
j3 | 80:83b0d879cc32 | 53 | /// @returns The calculated CRC8. |
j3 | 80:83b0d879cc32 | 54 | uint8_t calculateCrc8(const uint8_t * data, size_t dataLen, uint8_t crc = 0); |
j3 | 80:83b0d879cc32 | 55 | |
IanBenzMaxim | 78:0cbbac7f2016 | 56 | /// Perform a CRC16 calculation. |
IanBenzMaxim | 78:0cbbac7f2016 | 57 | /// @param crc16 Beginning state of the CRC generator. |
IanBenzMaxim | 78:0cbbac7f2016 | 58 | /// @param data Data to pass though the CRC generator. |
IanBenzMaxim | 78:0cbbac7f2016 | 59 | /// @returns The calculated CRC16. |
IanBenzMaxim | 78:0cbbac7f2016 | 60 | uint16_t calculateCrc16(uint16_t crc16, uint16_t data); |
IanBenzMaxim | 78:0cbbac7f2016 | 61 | |
IanBenzMaxim | 78:0cbbac7f2016 | 62 | /// Perform a CRC16 calculation with variable length data. |
IanBenzMaxim | 78:0cbbac7f2016 | 63 | /// @param[in] data Data array to pass through the CRC generator. |
IanBenzMaxim | 78:0cbbac7f2016 | 64 | /// @param data_offset Offset of the data array to begin processing. |
IanBenzMaxim | 78:0cbbac7f2016 | 65 | /// @param data_len Length of the data array to process. |
IanBenzMaxim | 78:0cbbac7f2016 | 66 | /// @param crc Beginning state of the CRC generator. |
IanBenzMaxim | 78:0cbbac7f2016 | 67 | /// @returns The calculated CRC16. |
IanBenzMaxim | 78:0cbbac7f2016 | 68 | uint16_t calculateCrc16(const uint8_t * data, size_t dataOffset, size_t dataLen, uint16_t crc = 0); |
IanBenzMaxim | 78:0cbbac7f2016 | 69 | } |
IanBenzMaxim | 78:0cbbac7f2016 | 70 | } |
IanBenzMaxim | 78:0cbbac7f2016 | 71 | |
IanBenzMaxim | 78:0cbbac7f2016 | 72 | #endif |