Mike Fruge / OneWire

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Thu May 12 14:38:16 2016 -0500
Revision:
73:2cecc1372acc
Parent:
49:36954b62f503
Child:
74:23be10c32fa3
Added namespaces. Renamed files and directories for consistency. Use <stdint.h> instead of <cstdint> since it is not supported by C++98.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 17:b646b1e3970b 1 /******************************************************************//**
j3 17:b646b1e3970b 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 17:b646b1e3970b 3 *
j3 17:b646b1e3970b 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 17:b646b1e3970b 5 * copy of this software and associated documentation files (the "Software"),
j3 17:b646b1e3970b 6 * to deal in the Software without restriction, including without limitation
j3 17:b646b1e3970b 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 17:b646b1e3970b 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 17:b646b1e3970b 9 * Software is furnished to do so, subject to the following conditions:
j3 17:b646b1e3970b 10 *
j3 17:b646b1e3970b 11 * The above copyright notice and this permission notice shall be included
j3 17:b646b1e3970b 12 * in all copies or substantial portions of the Software.
j3 17:b646b1e3970b 13 *
j3 17:b646b1e3970b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 17:b646b1e3970b 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 17:b646b1e3970b 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 17:b646b1e3970b 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 17:b646b1e3970b 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 17:b646b1e3970b 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 17:b646b1e3970b 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 17:b646b1e3970b 21 *
j3 17:b646b1e3970b 22 * Except as contained in this notice, the name of Maxim Integrated
j3 17:b646b1e3970b 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 17:b646b1e3970b 24 * Products, Inc. Branding Policy.
j3 17:b646b1e3970b 25 *
j3 17:b646b1e3970b 26 * The mere transfer of this software does not imply any licenses
j3 17:b646b1e3970b 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 17:b646b1e3970b 28 * trademarks, maskwork rights, or any other form of intellectual
j3 17:b646b1e3970b 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 17:b646b1e3970b 30 * ownership rights.
j3 17:b646b1e3970b 31 **********************************************************************/
j3 17:b646b1e3970b 32
IanBenzMaxim 73:2cecc1372acc 33 #include "RomId.h"
j3 17:b646b1e3970b 34
IanBenzMaxim 73:2cecc1372acc 35 using OneWire::RomId;
IanBenzMaxim 73:2cecc1372acc 36
IanBenzMaxim 73:2cecc1372acc 37 uint8_t RomId::calculateCRC8(uint8_t crc8, uint8_t data)
j3 17:b646b1e3970b 38 {
j3 17:b646b1e3970b 39 int i;
j3 17:b646b1e3970b 40
j3 17:b646b1e3970b 41 // See Application Note 27
j3 17:b646b1e3970b 42 crc8 = crc8 ^ data;
j3 17:b646b1e3970b 43 for (i = 0; i < 8; ++i)
j3 17:b646b1e3970b 44 {
j3 17:b646b1e3970b 45 if (crc8 & 1)
j3 17:b646b1e3970b 46 crc8 = (crc8 >> 1) ^ 0x8c;
j3 17:b646b1e3970b 47 else
j3 17:b646b1e3970b 48 crc8 = (crc8 >> 1);
j3 17:b646b1e3970b 49 }
j3 17:b646b1e3970b 50
j3 17:b646b1e3970b 51 return crc8;
j3 17:b646b1e3970b 52 }
j3 17:b646b1e3970b 53
IanBenzMaxim 73:2cecc1372acc 54 uint8_t RomId::calculateCRC8(const uint8_t * data, size_t data_len, uint8_t crc)
j3 17:b646b1e3970b 55 {
IanBenzMaxim 73:2cecc1372acc 56 for (size_t i = 0; i < data_len; i++)
j3 17:b646b1e3970b 57 crc = calculateCRC8(crc, data[i]);
j3 17:b646b1e3970b 58 return crc;
j3 17:b646b1e3970b 59 }