Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
OneWire_Masters/OneWireMaster.h@17:b646b1e3970b, 2016-03-18 (annotated)
- Committer:
- j3
- Date:
- Fri Mar 18 20:21:05 2016 +0000
- Revision:
- 17:b646b1e3970b
- Parent:
- 15:f6cb0d906fb6
- Child:
- 21:00c94aeb533e
Updated library with error codes on return statements
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 5:ce108eeb878d | 1 | /******************************************************************//** |
j3 | 5:ce108eeb878d | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 5:ce108eeb878d | 3 | * |
j3 | 5:ce108eeb878d | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 5:ce108eeb878d | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 5:ce108eeb878d | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 5:ce108eeb878d | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 5:ce108eeb878d | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 5:ce108eeb878d | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 5:ce108eeb878d | 10 | * |
j3 | 5:ce108eeb878d | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 5:ce108eeb878d | 12 | * in all copies or substantial portions of the Software. |
j3 | 5:ce108eeb878d | 13 | * |
j3 | 5:ce108eeb878d | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 5:ce108eeb878d | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 5:ce108eeb878d | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 5:ce108eeb878d | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 5:ce108eeb878d | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 5:ce108eeb878d | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 5:ce108eeb878d | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 5:ce108eeb878d | 21 | * |
j3 | 5:ce108eeb878d | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 5:ce108eeb878d | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 5:ce108eeb878d | 24 | * Products, Inc. Branding Policy. |
j3 | 5:ce108eeb878d | 25 | * |
j3 | 5:ce108eeb878d | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 5:ce108eeb878d | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 5:ce108eeb878d | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 5:ce108eeb878d | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 5:ce108eeb878d | 30 | * ownership rights. |
j3 | 5:ce108eeb878d | 31 | **********************************************************************/ |
j3 | 5:ce108eeb878d | 32 | |
j3 | 5:ce108eeb878d | 33 | |
j3 | 15:f6cb0d906fb6 | 34 | #ifndef ONEWIREMASTER_H |
j3 | 15:f6cb0d906fb6 | 35 | #define ONEWIREMASTER_H |
j3 | 5:ce108eeb878d | 36 | |
j3 | 5:ce108eeb878d | 37 | |
j3 | 5:ce108eeb878d | 38 | #include "mbed.h" |
j3 | 15:f6cb0d906fb6 | 39 | #include "OneWireInterface.h" |
j3 | 5:ce108eeb878d | 40 | |
j3 | 5:ce108eeb878d | 41 | |
j3 | 17:b646b1e3970b | 42 | //This class is an abstract class type that can not be instaniated |
j3 | 17:b646b1e3970b | 43 | |
j3 | 17:b646b1e3970b | 44 | //OneWireMaster is the first derived class of OneWireInterface that |
j3 | 17:b646b1e3970b | 45 | //defines implementations of common functions between masters and adds |
j3 | 17:b646b1e3970b | 46 | //support for CRC16. |
j3 | 17:b646b1e3970b | 47 | |
j3 | 17:b646b1e3970b | 48 | //OneWireMaster should be inherited by your OW master declaration |
j3 | 17:b646b1e3970b | 49 | |
j3 | 17:b646b1e3970b | 50 | |
j3 | 15:f6cb0d906fb6 | 51 | class OneWireMaster: public OneWireInterface |
j3 | 15:f6cb0d906fb6 | 52 | { |
j3 | 15:f6cb0d906fb6 | 53 | public: |
j3 | 15:f6cb0d906fb6 | 54 | |
j3 | 17:b646b1e3970b | 55 | static uint16_t calculateCRC16(uint16_t CRC16, uint16_t data); |
j3 | 17:b646b1e3970b | 56 | |
j3 | 17:b646b1e3970b | 57 | static uint16_t calculateCRC16(const uint8_t * data, size_t data_offset, size_t data_len, uint16_t crc); |
j3 | 17:b646b1e3970b | 58 | |
j3 | 15:f6cb0d906fb6 | 59 | //Part of OneWireInterface that should only be implemented once |
j3 | 15:f6cb0d906fb6 | 60 | //See OneWireInterface.h for documentation |
j3 | 15:f6cb0d906fb6 | 61 | |
j3 | 17:b646b1e3970b | 62 | virtual OneWireInterface::CmdResult OWWriteBit(uint8_t sendbit); |
j3 | 15:f6cb0d906fb6 | 63 | |
j3 | 17:b646b1e3970b | 64 | virtual OneWireInterface::CmdResult OWReadBit(uint8_t & recvbit); |
j3 | 15:f6cb0d906fb6 | 65 | |
j3 | 17:b646b1e3970b | 66 | virtual OneWireInterface::CmdResult OWTouchByte(uint8_t & sendrecvbyte); |
j3 | 17:b646b1e3970b | 67 | |
j3 | 17:b646b1e3970b | 68 | virtual OneWireInterface::CmdResult OWBlock(uint8_t *tran_buf, uint8_t tran_len); |
j3 | 15:f6cb0d906fb6 | 69 | |
j3 | 17:b646b1e3970b | 70 | virtual OneWireInterface::CmdResult OWFirst(RomId & romId); |
j3 | 17:b646b1e3970b | 71 | |
j3 | 17:b646b1e3970b | 72 | virtual OneWireInterface::CmdResult OWNext(RomId & romId); |
j3 | 15:f6cb0d906fb6 | 73 | |
j3 | 17:b646b1e3970b | 74 | virtual OneWireInterface::CmdResult OWVerify(const RomId & romId); |
j3 | 15:f6cb0d906fb6 | 75 | |
j3 | 17:b646b1e3970b | 76 | virtual void OWTargetSetup(RomId & romId); |
j3 | 15:f6cb0d906fb6 | 77 | |
j3 | 15:f6cb0d906fb6 | 78 | virtual void OWFamilySkipSetup(void); |
j3 | 15:f6cb0d906fb6 | 79 | |
j3 | 17:b646b1e3970b | 80 | virtual OneWireInterface::CmdResult OWReadROM(RomId & romId); |
j3 | 15:f6cb0d906fb6 | 81 | |
j3 | 17:b646b1e3970b | 82 | virtual OneWireInterface::CmdResult OWSkipROM(void); |
j3 | 15:f6cb0d906fb6 | 83 | |
j3 | 17:b646b1e3970b | 84 | virtual OneWireInterface::CmdResult OWMatchROM(const RomId & romId); |
j3 | 15:f6cb0d906fb6 | 85 | |
j3 | 17:b646b1e3970b | 86 | virtual OneWireInterface::CmdResult OWOverdriveSkipROM(void); |
j3 | 15:f6cb0d906fb6 | 87 | |
j3 | 17:b646b1e3970b | 88 | virtual OneWireInterface::CmdResult OWOverdriveMatchROM(const RomId & romId); |
j3 | 15:f6cb0d906fb6 | 89 | |
j3 | 17:b646b1e3970b | 90 | virtual OneWireInterface::CmdResult OWResume(void); |
j3 | 15:f6cb0d906fb6 | 91 | |
j3 | 15:f6cb0d906fb6 | 92 | protected: |
j3 | 15:f6cb0d906fb6 | 93 | |
j3 | 15:f6cb0d906fb6 | 94 | // Search state |
j3 | 15:f6cb0d906fb6 | 95 | uint8_t _last_discrepancy; |
j3 | 15:f6cb0d906fb6 | 96 | uint8_t _last_family_discrepancy; |
j3 | 15:f6cb0d906fb6 | 97 | uint8_t _last_device_flag; |
j3 | 15:f6cb0d906fb6 | 98 | uint8_t _crc8; |
j3 | 17:b646b1e3970b | 99 | |
j3 | 17:b646b1e3970b | 100 | static const uint16_t _oddparity[16]; |
j3 | 15:f6cb0d906fb6 | 101 | }; |
j3 | 15:f6cb0d906fb6 | 102 | |
j3 | 15:f6cb0d906fb6 | 103 | |
j3 | 15:f6cb0d906fb6 | 104 | |
j3 | 5:ce108eeb878d | 105 | |
j3 | 5:ce108eeb878d | 106 | |
j3 | 5:ce108eeb878d | 107 | #endif /*ONEWIREMASTERSSHARED_H*/ |