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