Diff: OneWireCRC.h
- Revision:
- 1:7218c076189b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/OneWireCRC.h Sun Apr 17 17:26:52 2011 +0000
@@ -0,0 +1,163 @@
+/*
+* OneWireCRC. This is a port to mbed of Jim Studt's Adruino One Wire
+* library. Please see additional copyrights below this one, including
+* references to other copyrights.
+*
+* Copyright (C) <2011> Version 1.2 Wim De Roeve
+* <2009> Petras Saduikis <petras@petras.co.uk>
+*
+* This file is part of OneWireCRC.
+*
+* OneWireCRC is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* OneWireCRC is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with OneWireCRC. If not, see <http://www.gnu.org/licenses/>.
+*/
+/*
+Copyright (c) 2007, Jim Studt
+
+Version 2.0: Modifications by Paul Stoffregen, January 2010:
+http://www.pjrc.com/teensy/td_libs_OneWire.html
+ Search fix from Robin James
+ http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238032295/27#27
+ Use direct optimized I/O in all cases
+ Disable interrupts during timing critical sections
+ (this solves many random communication errors)
+ Disable interrupts during read-modify-write I/O
+ Reduce RAM consumption by eliminating unnecessary
+ variables and trimming many to 8 bits
+ Optimize both crc8 - table version moved to flash
+
+Modified to work with larger numbers of devices - avoids loop.
+Tested in Arduino 11 alpha with 12 sensors.
+26 Sept 2008 -- Robin James
+http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238032295/27#27
+
+
+Updated to work with arduino-0008 and to include skip() as of
+2007/07/06. --RJL20
+
+Modified to calculate the 8-bit CRC directly, avoiding the need for
+the 256-byte lookup table to be loaded in RAM. Tested in arduino-0010
+-- Tom Pollard, Jan 23, 2008
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Much of the code was inspired by Derek Yerger's code, though I don't
+think much of that remains. In any event that was..
+ (copyleft) 2006 by Derek Yerger - Free to distribute freely.
+
+The CRC code was excerpted and inspired by the Dallas Semiconductor
+sample code bearing this copyright.
+*/
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//--------------------------------------------------------------------------
+
+#ifndef SNATCH59_ONEWIRECRC_H
+#define SNATCH59_ONEWIRECRC_H
+
+#include <mbed.h>
+
+// Select the table-lookup method of computing the 8-bit CRC by setting this to 1
+#ifndef ONEWIRE_CRC8_TABLE
+#define ONEWIRE_CRC8_TABLE 1
+#endif
+
+typedef unsigned char BYTE; // used to be uint8_t : something a byte wide, whatever ....
+
+enum eSpeed {OVERDRIVE, STANDARD};
+
+class OneWireCRC {
+public:
+ OneWireCRC(PinName oneWire, eSpeed);
+
+ // reset, read, write functions
+ int reset();
+ void writeByte(int data);
+ int readByte();
+ int touchByte(int data);
+ void block(BYTE* data, int data_len);
+ int overdriveSkip(BYTE* data, int data_len);
+
+ // address functions
+ void matchROM(BYTE rom[8]);
+ void skipROM();
+
+ // address search functions
+ void resetSearch();
+ BYTE search(BYTE* newAddr);
+
+ // CRC check functions
+ static BYTE crc8(BYTE* addr, BYTE len);
+ static unsigned short crc16(unsigned short* data, unsigned short len);
+
+ BYTE ROMCode[8];
+private:
+ const int* timing;
+
+ /*int searchJunction; // so we can set to it -1 somewhere
+ bool searchExhausted;
+ BYTE _address[8];*/
+
+ BYTE ROM_NO[8];
+ uint8_t LastDiscrepancy;
+ uint8_t LastFamilyDiscrepancy;
+ uint8_t LastDeviceFlag;
+
+
+ DigitalInOut oneWirePort;
+
+ // read/write bit functions
+ void writeBit(int bit);
+ int readBit();
+};
+
+#endif