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