![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First Publish
Dependencies: BridgeDriver2 FrontPanelButtons MAX31855 MCP23017 SDFileSystem TextLCD mbed
OneWireCRC.h@0:20e78c9d2ea9, 2014-11-10 (annotated)
- Committer:
- mehatfie
- Date:
- Mon Nov 10 22:56:20 2014 +0000
- Revision:
- 0:20e78c9d2ea9
First Commit of Falcon Wing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mehatfie | 0:20e78c9d2ea9 | 1 | /* |
mehatfie | 0:20e78c9d2ea9 | 2 | * OneWireCRC. This is a port to mbed of Jim Studt's Adruino One Wire |
mehatfie | 0:20e78c9d2ea9 | 3 | * library. Please see additional copyrights below this one, including |
mehatfie | 0:20e78c9d2ea9 | 4 | * references to other copyrights. |
mehatfie | 0:20e78c9d2ea9 | 5 | * |
mehatfie | 0:20e78c9d2ea9 | 6 | * Copyright (C) <2009> Petras Saduikis <petras@petras.co.uk> |
mehatfie | 0:20e78c9d2ea9 | 7 | * |
mehatfie | 0:20e78c9d2ea9 | 8 | * This file is part of OneWireCRC. |
mehatfie | 0:20e78c9d2ea9 | 9 | * |
mehatfie | 0:20e78c9d2ea9 | 10 | * OneWireCRC is free software: you can redistribute it and/or modify |
mehatfie | 0:20e78c9d2ea9 | 11 | * it under the terms of the GNU General Public License as published by |
mehatfie | 0:20e78c9d2ea9 | 12 | * the Free Software Foundation, either version 3 of the License, or |
mehatfie | 0:20e78c9d2ea9 | 13 | * (at your option) any later version. |
mehatfie | 0:20e78c9d2ea9 | 14 | * |
mehatfie | 0:20e78c9d2ea9 | 15 | * OneWireCRC is distributed in the hope that it will be useful, |
mehatfie | 0:20e78c9d2ea9 | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
mehatfie | 0:20e78c9d2ea9 | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
mehatfie | 0:20e78c9d2ea9 | 18 | * GNU General Public License for more details. |
mehatfie | 0:20e78c9d2ea9 | 19 | * |
mehatfie | 0:20e78c9d2ea9 | 20 | * You should have received a copy of the GNU General Public License |
mehatfie | 0:20e78c9d2ea9 | 21 | * along with OneWireCRC. If not, see <http://www.gnu.org/licenses/>. |
mehatfie | 0:20e78c9d2ea9 | 22 | */ |
mehatfie | 0:20e78c9d2ea9 | 23 | /* |
mehatfie | 0:20e78c9d2ea9 | 24 | Copyright (c) 2007, Jim Studt |
mehatfie | 0:20e78c9d2ea9 | 25 | |
mehatfie | 0:20e78c9d2ea9 | 26 | Updated to work with arduino-0008 and to include skip() as of |
mehatfie | 0:20e78c9d2ea9 | 27 | 2007/07/06. --RJL20 |
mehatfie | 0:20e78c9d2ea9 | 28 | |
mehatfie | 0:20e78c9d2ea9 | 29 | Modified to calculate the 8-bit CRC directly, avoiding the need for |
mehatfie | 0:20e78c9d2ea9 | 30 | the 256-byte lookup table to be loaded in RAM. Tested in arduino-0010 |
mehatfie | 0:20e78c9d2ea9 | 31 | -- Tom Pollard, Jan 23, 2008 |
mehatfie | 0:20e78c9d2ea9 | 32 | |
mehatfie | 0:20e78c9d2ea9 | 33 | Permission is hereby granted, free of charge, to any person obtaining |
mehatfie | 0:20e78c9d2ea9 | 34 | a copy of this software and associated documentation files (the |
mehatfie | 0:20e78c9d2ea9 | 35 | "Software"), to deal in the Software without restriction, including |
mehatfie | 0:20e78c9d2ea9 | 36 | without limitation the rights to use, copy, modify, merge, publish, |
mehatfie | 0:20e78c9d2ea9 | 37 | distribute, sublicense, and/or sell copies of the Software, and to |
mehatfie | 0:20e78c9d2ea9 | 38 | permit persons to whom the Software is furnished to do so, subject to |
mehatfie | 0:20e78c9d2ea9 | 39 | the following conditions: |
mehatfie | 0:20e78c9d2ea9 | 40 | |
mehatfie | 0:20e78c9d2ea9 | 41 | The above copyright notice and this permission notice shall be |
mehatfie | 0:20e78c9d2ea9 | 42 | included in all copies or substantial portions of the Software. |
mehatfie | 0:20e78c9d2ea9 | 43 | |
mehatfie | 0:20e78c9d2ea9 | 44 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
mehatfie | 0:20e78c9d2ea9 | 45 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
mehatfie | 0:20e78c9d2ea9 | 46 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
mehatfie | 0:20e78c9d2ea9 | 47 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
mehatfie | 0:20e78c9d2ea9 | 48 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
mehatfie | 0:20e78c9d2ea9 | 49 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
mehatfie | 0:20e78c9d2ea9 | 50 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
mehatfie | 0:20e78c9d2ea9 | 51 | |
mehatfie | 0:20e78c9d2ea9 | 52 | Much of the code was inspired by Derek Yerger's code, though I don't |
mehatfie | 0:20e78c9d2ea9 | 53 | think much of that remains. In any event that was.. |
mehatfie | 0:20e78c9d2ea9 | 54 | (copyleft) 2006 by Derek Yerger - Free to distribute freely. |
mehatfie | 0:20e78c9d2ea9 | 55 | |
mehatfie | 0:20e78c9d2ea9 | 56 | The CRC code was excerpted and inspired by the Dallas Semiconductor |
mehatfie | 0:20e78c9d2ea9 | 57 | sample code bearing this copyright. |
mehatfie | 0:20e78c9d2ea9 | 58 | */ |
mehatfie | 0:20e78c9d2ea9 | 59 | //--------------------------------------------------------------------------- |
mehatfie | 0:20e78c9d2ea9 | 60 | // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved. |
mehatfie | 0:20e78c9d2ea9 | 61 | // |
mehatfie | 0:20e78c9d2ea9 | 62 | // Permission is hereby granted, free of charge, to any person obtaining a |
mehatfie | 0:20e78c9d2ea9 | 63 | // copy of this software and associated documentation files (the "Software"), |
mehatfie | 0:20e78c9d2ea9 | 64 | // to deal in the Software without restriction, including without limitation |
mehatfie | 0:20e78c9d2ea9 | 65 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
mehatfie | 0:20e78c9d2ea9 | 66 | // and/or sell copies of the Software, and to permit persons to whom the |
mehatfie | 0:20e78c9d2ea9 | 67 | // Software is furnished to do so, subject to the following conditions: |
mehatfie | 0:20e78c9d2ea9 | 68 | // |
mehatfie | 0:20e78c9d2ea9 | 69 | // The above copyright notice and this permission notice shall be included |
mehatfie | 0:20e78c9d2ea9 | 70 | // in all copies or substantial portions of the Software. |
mehatfie | 0:20e78c9d2ea9 | 71 | // |
mehatfie | 0:20e78c9d2ea9 | 72 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
mehatfie | 0:20e78c9d2ea9 | 73 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
mehatfie | 0:20e78c9d2ea9 | 74 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
mehatfie | 0:20e78c9d2ea9 | 75 | // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES |
mehatfie | 0:20e78c9d2ea9 | 76 | // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
mehatfie | 0:20e78c9d2ea9 | 77 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
mehatfie | 0:20e78c9d2ea9 | 78 | // OTHER DEALINGS IN THE SOFTWARE. |
mehatfie | 0:20e78c9d2ea9 | 79 | // |
mehatfie | 0:20e78c9d2ea9 | 80 | // Except as contained in this notice, the name of Dallas Semiconductor |
mehatfie | 0:20e78c9d2ea9 | 81 | // shall not be used except as stated in the Dallas Semiconductor |
mehatfie | 0:20e78c9d2ea9 | 82 | // Branding Policy. |
mehatfie | 0:20e78c9d2ea9 | 83 | //-------------------------------------------------------------------------- |
mehatfie | 0:20e78c9d2ea9 | 84 | |
mehatfie | 0:20e78c9d2ea9 | 85 | #ifndef SNATCH59_ONEWIRECRC_H |
mehatfie | 0:20e78c9d2ea9 | 86 | #define SNATCH59_ONEWIRECRC_H |
mehatfie | 0:20e78c9d2ea9 | 87 | |
mehatfie | 0:20e78c9d2ea9 | 88 | #include <mbed.h> |
mehatfie | 0:20e78c9d2ea9 | 89 | |
mehatfie | 0:20e78c9d2ea9 | 90 | // Select the table-lookup method of computing the 8-bit CRC by setting this to 1 |
mehatfie | 0:20e78c9d2ea9 | 91 | #ifndef ONEWIRE_CRC8_TABLE |
mehatfie | 0:20e78c9d2ea9 | 92 | #define ONEWIRE_CRC8_TABLE 1 |
mehatfie | 0:20e78c9d2ea9 | 93 | #endif |
mehatfie | 0:20e78c9d2ea9 | 94 | |
mehatfie | 0:20e78c9d2ea9 | 95 | typedef unsigned char BYTE; // used to be uint8_t : something a byte wide, whatever .... |
mehatfie | 0:20e78c9d2ea9 | 96 | |
mehatfie | 0:20e78c9d2ea9 | 97 | enum eSpeed {OVERDRIVE, STANDARD}; |
mehatfie | 0:20e78c9d2ea9 | 98 | |
mehatfie | 0:20e78c9d2ea9 | 99 | class OneWireCRC |
mehatfie | 0:20e78c9d2ea9 | 100 | { |
mehatfie | 0:20e78c9d2ea9 | 101 | public: |
mehatfie | 0:20e78c9d2ea9 | 102 | OneWireCRC(PinName oneWire, eSpeed); |
mehatfie | 0:20e78c9d2ea9 | 103 | |
mehatfie | 0:20e78c9d2ea9 | 104 | // reset, read, write functions |
mehatfie | 0:20e78c9d2ea9 | 105 | int reset(); |
mehatfie | 0:20e78c9d2ea9 | 106 | void writeByte(int data); |
mehatfie | 0:20e78c9d2ea9 | 107 | int readByte(); |
mehatfie | 0:20e78c9d2ea9 | 108 | int touchByte(int data); |
mehatfie | 0:20e78c9d2ea9 | 109 | void block(BYTE* data, int data_len); |
mehatfie | 0:20e78c9d2ea9 | 110 | int overdriveSkip(BYTE* data, int data_len); |
mehatfie | 0:20e78c9d2ea9 | 111 | |
mehatfie | 0:20e78c9d2ea9 | 112 | // address functions |
mehatfie | 0:20e78c9d2ea9 | 113 | void matchROM(BYTE rom[8]); |
mehatfie | 0:20e78c9d2ea9 | 114 | void skipROM(); |
mehatfie | 0:20e78c9d2ea9 | 115 | |
mehatfie | 0:20e78c9d2ea9 | 116 | // address search functions |
mehatfie | 0:20e78c9d2ea9 | 117 | void resetSearch(); |
mehatfie | 0:20e78c9d2ea9 | 118 | BYTE search(BYTE* newAddr); |
mehatfie | 0:20e78c9d2ea9 | 119 | |
mehatfie | 0:20e78c9d2ea9 | 120 | // CRC check functions |
mehatfie | 0:20e78c9d2ea9 | 121 | static BYTE crc8(BYTE* addr, BYTE len); |
mehatfie | 0:20e78c9d2ea9 | 122 | static unsigned short crc16(unsigned short* data, unsigned short len); |
mehatfie | 0:20e78c9d2ea9 | 123 | |
mehatfie | 0:20e78c9d2ea9 | 124 | private: |
mehatfie | 0:20e78c9d2ea9 | 125 | const int* timing; |
mehatfie | 0:20e78c9d2ea9 | 126 | |
mehatfie | 0:20e78c9d2ea9 | 127 | BYTE address[8]; |
mehatfie | 0:20e78c9d2ea9 | 128 | int searchJunction; // so we can set to it -1 somewhere |
mehatfie | 0:20e78c9d2ea9 | 129 | bool searchExhausted; |
mehatfie | 0:20e78c9d2ea9 | 130 | |
mehatfie | 0:20e78c9d2ea9 | 131 | DigitalInOut oneWirePort; |
mehatfie | 0:20e78c9d2ea9 | 132 | |
mehatfie | 0:20e78c9d2ea9 | 133 | // read/write bit functions |
mehatfie | 0:20e78c9d2ea9 | 134 | void writeBit(int bit); |
mehatfie | 0:20e78c9d2ea9 | 135 | int readBit(); |
mehatfie | 0:20e78c9d2ea9 | 136 | }; |
mehatfie | 0:20e78c9d2ea9 | 137 | |
mehatfie | 0:20e78c9d2ea9 | 138 | #endif |