Mike Fruge / OneWire

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Fri May 13 14:52:50 2016 -0500
Revision:
75:8b627804927c
Parent:
74:23be10c32fa3
Code cleanup.

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 75:8b627804927c 37 uint8_t RomId::calculateCrc8(uint8_t crc8, uint8_t data)
j3 17:b646b1e3970b 38 {
IanBenzMaxim 74:23be10c32fa3 39 // See Application Note 27
IanBenzMaxim 74:23be10c32fa3 40 crc8 = crc8 ^ data;
IanBenzMaxim 75:8b627804927c 41 for (int i = 0; i < 8; i++)
IanBenzMaxim 74:23be10c32fa3 42 {
IanBenzMaxim 74:23be10c32fa3 43 if (crc8 & 1)
IanBenzMaxim 74:23be10c32fa3 44 {
IanBenzMaxim 74:23be10c32fa3 45 crc8 = (crc8 >> 1) ^ 0x8c;
IanBenzMaxim 74:23be10c32fa3 46 }
IanBenzMaxim 74:23be10c32fa3 47 else
IanBenzMaxim 74:23be10c32fa3 48 {
IanBenzMaxim 74:23be10c32fa3 49 crc8 = (crc8 >> 1);
IanBenzMaxim 74:23be10c32fa3 50 }
IanBenzMaxim 74:23be10c32fa3 51 }
j3 17:b646b1e3970b 52
IanBenzMaxim 74:23be10c32fa3 53 return crc8;
j3 17:b646b1e3970b 54 }
j3 17:b646b1e3970b 55
IanBenzMaxim 75:8b627804927c 56 uint8_t RomId::calculateCrc8(const uint8_t * data, size_t dataLen, uint8_t crc)
j3 17:b646b1e3970b 57 {
IanBenzMaxim 75:8b627804927c 58 for (size_t i = 0; i < dataLen; i++)
IanBenzMaxim 74:23be10c32fa3 59 {
IanBenzMaxim 75:8b627804927c 60 crc = calculateCrc8(crc, data[i]);
IanBenzMaxim 74:23be10c32fa3 61 }
IanBenzMaxim 74:23be10c32fa3 62 return crc;
j3 17:b646b1e3970b 63 }