Mike Fruge / OneWire

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Fri May 13 07:48:35 2016 -0500
Revision:
74:23be10c32fa3
Parent:
73:2cecc1372acc
Child:
75:8b627804927c
Assimilated indentation and braces.

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