Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
OneWire_Masters/OneWireMaster.h@32:bce180b544ed, 2016-03-30 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Wed Mar 30 16:50:29 2016 -0500
- Revision:
- 32:bce180b544ed
- Parent:
- 27:d5aaefa252f1
- Child:
- 43:23017dcd2ec3
1. Move the implementation of OWSearch() into OneWireMaster since it is a fairly complex algorithm that shouldn?t be implemented over and over. It will also match all other ROM function that are implemented there.
2. Create a new member function, OWTriplet(), in OneWireMaster to handle the virtual section of OWSearch(). Create a default implementation of OWTriplet() that uses OWReadByte() and OWWriteByte(). Masters only need to implement this function if they have a search accelerator of some sort.
3. Create type SearchState that will encapsulate all persistent data used by the search ROM functions. This will also make it easy to not have the search state part of the permanent OneWireMaster class data.
4. Rename OWSpeed() to OWSetSpeed() and OWLevel() to OWSetLevel() for naming consistency.
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 | |
IanBenzMaxim | 27:d5aaefa252f1 | 37 | #include <cstdint> |
IanBenzMaxim | 27:d5aaefa252f1 | 38 | #include <cstddef> |
j3 | 5:ce108eeb878d | 39 | |
IanBenzMaxim | 32:bce180b544ed | 40 | #include "RomId.hpp" |
j3 | 5:ce108eeb878d | 41 | |
j3 | 23:e8e403d61359 | 42 | class OneWireMaster |
IanBenzMaxim | 27:d5aaefa252f1 | 43 | { |
IanBenzMaxim | 24:8942d8478d68 | 44 | public: |
j3 | 23:e8e403d61359 | 45 | |
IanBenzMaxim | 32:bce180b544ed | 46 | enum OWSpeed |
j3 | 23:e8e403d61359 | 47 | { |
j3 | 23:e8e403d61359 | 48 | SPEED_STANDARD = 0x00, |
j3 | 23:e8e403d61359 | 49 | SPEED_OVERDRIVE = 0x01 |
j3 | 23:e8e403d61359 | 50 | }; |
j3 | 23:e8e403d61359 | 51 | |
IanBenzMaxim | 32:bce180b544ed | 52 | enum OWLevel |
j3 | 23:e8e403d61359 | 53 | { |
j3 | 23:e8e403d61359 | 54 | LEVEL_NORMAL = 0x00, |
j3 | 23:e8e403d61359 | 55 | LEVEL_STRONG = 0x02 |
j3 | 23:e8e403d61359 | 56 | }; |
j3 | 23:e8e403d61359 | 57 | |
IanBenzMaxim | 32:bce180b544ed | 58 | enum SearchDirection |
IanBenzMaxim | 32:bce180b544ed | 59 | { |
IanBenzMaxim | 32:bce180b544ed | 60 | DIRECTION_WRITE_ZERO = 0, |
IanBenzMaxim | 32:bce180b544ed | 61 | DIRECTION_WRITE_ONE = 1 |
IanBenzMaxim | 32:bce180b544ed | 62 | }; |
IanBenzMaxim | 32:bce180b544ed | 63 | |
j3 | 23:e8e403d61359 | 64 | enum CmdResult |
j3 | 23:e8e403d61359 | 65 | { |
j3 | 23:e8e403d61359 | 66 | Success, |
j3 | 23:e8e403d61359 | 67 | CommunicationWriteError, |
j3 | 23:e8e403d61359 | 68 | CommunicationReadError, |
j3 | 23:e8e403d61359 | 69 | TimeoutError, |
j3 | 23:e8e403d61359 | 70 | OperationFailure |
j3 | 23:e8e403d61359 | 71 | }; |
j3 | 23:e8e403d61359 | 72 | |
IanBenzMaxim | 32:bce180b544ed | 73 | struct SearchState |
IanBenzMaxim | 32:bce180b544ed | 74 | { |
IanBenzMaxim | 32:bce180b544ed | 75 | RomId romId; |
IanBenzMaxim | 32:bce180b544ed | 76 | std::uint8_t last_discrepancy; |
IanBenzMaxim | 32:bce180b544ed | 77 | std::uint8_t last_family_discrepancy; |
IanBenzMaxim | 32:bce180b544ed | 78 | bool last_device_flag; |
IanBenzMaxim | 32:bce180b544ed | 79 | |
IanBenzMaxim | 32:bce180b544ed | 80 | void reset() |
IanBenzMaxim | 32:bce180b544ed | 81 | { |
IanBenzMaxim | 32:bce180b544ed | 82 | last_discrepancy = 0; |
IanBenzMaxim | 32:bce180b544ed | 83 | last_device_flag = false; |
IanBenzMaxim | 32:bce180b544ed | 84 | last_family_discrepancy = 0; |
IanBenzMaxim | 32:bce180b544ed | 85 | romId.reset(); |
IanBenzMaxim | 32:bce180b544ed | 86 | } |
IanBenzMaxim | 32:bce180b544ed | 87 | |
IanBenzMaxim | 32:bce180b544ed | 88 | SearchState() { reset(); } |
IanBenzMaxim | 32:bce180b544ed | 89 | }; |
IanBenzMaxim | 32:bce180b544ed | 90 | |
IanBenzMaxim | 27:d5aaefa252f1 | 91 | static std::uint16_t calculateCRC16(std::uint16_t CRC16, std::uint16_t data); |
j3 | 17:b646b1e3970b | 92 | |
IanBenzMaxim | 27:d5aaefa252f1 | 93 | static std::uint16_t calculateCRC16(const std::uint8_t * data, std::size_t data_offset, std::size_t data_len, std::uint16_t crc = 0); |
j3 | 17:b646b1e3970b | 94 | |
IanBenzMaxim | 26:a361e3f42ba5 | 95 | virtual ~OneWireMaster() { } |
IanBenzMaxim | 26:a361e3f42ba5 | 96 | |
j3 | 23:e8e403d61359 | 97 | |
j3 | 23:e8e403d61359 | 98 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 99 | * @brief OWInitMaster() |
j3 | 23:e8e403d61359 | 100 | * |
j3 | 23:e8e403d61359 | 101 | * @details Initiializes particular master being instaniated. |
j3 | 23:e8e403d61359 | 102 | * Added to interface to provide a common 'init' function between |
j3 | 23:e8e403d61359 | 103 | * all masters |
j3 | 23:e8e403d61359 | 104 | * |
j3 | 23:e8e403d61359 | 105 | * On Entry: |
j3 | 23:e8e403d61359 | 106 | * |
j3 | 23:e8e403d61359 | 107 | * On Exit: |
j3 | 23:e8e403d61359 | 108 | * |
j3 | 23:e8e403d61359 | 109 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 110 | **************************************************************/ |
j3 | 23:e8e403d61359 | 111 | virtual CmdResult OWInitMaster(void) = 0; |
j3 | 23:e8e403d61359 | 112 | |
j3 | 23:e8e403d61359 | 113 | |
j3 | 23:e8e403d61359 | 114 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 115 | * @brief OWReset() |
j3 | 23:e8e403d61359 | 116 | * |
j3 | 23:e8e403d61359 | 117 | * @details Reset all of the devices on the 1-Wire Net and return |
j3 | 23:e8e403d61359 | 118 | * the result. |
j3 | 23:e8e403d61359 | 119 | * |
j3 | 23:e8e403d61359 | 120 | * On Entry: |
j3 | 23:e8e403d61359 | 121 | * |
j3 | 23:e8e403d61359 | 122 | * On Exit: |
j3 | 23:e8e403d61359 | 123 | * |
j3 | 23:e8e403d61359 | 124 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 125 | **************************************************************/ |
j3 | 23:e8e403d61359 | 126 | virtual CmdResult OWReset(void) = 0; |
j3 | 23:e8e403d61359 | 127 | |
j3 | 23:e8e403d61359 | 128 | |
j3 | 23:e8e403d61359 | 129 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 130 | * @brief OWTouchBit() |
j3 | 23:e8e403d61359 | 131 | * |
j3 | 23:e8e403d61359 | 132 | * @details Send 1 bit of communication to the 1-Wire Net and return |
j3 | 23:e8e403d61359 | 133 | * the result 1 bit read from the 1-Wire Net. The |
j3 | 23:e8e403d61359 | 134 | * parameter 'sendbit' least significant bit is used and |
j3 | 23:e8e403d61359 | 135 | * the least significant bit of the result is the return |
j3 | 23:e8e403d61359 | 136 | * bit. |
j3 | 23:e8e403d61359 | 137 | * |
j3 | 23:e8e403d61359 | 138 | * On Entry: |
j3 | 23:e8e403d61359 | 139 | * @param[in] 'sendbit' - the least significant bit is the bit to send |
j3 | 23:e8e403d61359 | 140 | * |
j3 | 23:e8e403d61359 | 141 | * On Exit: |
j3 | 23:e8e403d61359 | 142 | * |
j3 | 23:e8e403d61359 | 143 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 144 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 145 | virtual CmdResult OWTouchBit(std::uint8_t & sendrecvbit, OWLevel after_level) = 0; |
j3 | 23:e8e403d61359 | 146 | |
j3 | 23:e8e403d61359 | 147 | |
j3 | 23:e8e403d61359 | 148 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 149 | * @brief OWWRiteByte() |
j3 | 23:e8e403d61359 | 150 | * |
j3 | 23:e8e403d61359 | 151 | * @details Send 8 bits of communication to the 1-Wire Net and |
j3 | 23:e8e403d61359 | 152 | * verify that the 8 bits read from the 1-Wire Net is the |
j3 | 23:e8e403d61359 | 153 | * same (write operation).The parameter 'sendbyte' least |
j3 | 23:e8e403d61359 | 154 | * significant 8 bits are used. |
j3 | 23:e8e403d61359 | 155 | * |
j3 | 23:e8e403d61359 | 156 | * On Entry: |
j3 | 23:e8e403d61359 | 157 | * @param[in] 'sendbyte' - 8 bits to send (least significant byte) |
j3 | 23:e8e403d61359 | 158 | * |
j3 | 23:e8e403d61359 | 159 | * On Exit: |
j3 | 23:e8e403d61359 | 160 | * |
j3 | 23:e8e403d61359 | 161 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 162 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 163 | virtual CmdResult OWWriteByte(std::uint8_t sendbyte, OWLevel after_level) = 0; |
j3 | 23:e8e403d61359 | 164 | |
j3 | 23:e8e403d61359 | 165 | |
j3 | 23:e8e403d61359 | 166 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 167 | * @brief OWReadByte() |
j3 | 23:e8e403d61359 | 168 | * |
j3 | 23:e8e403d61359 | 169 | * @details Send 8 bits of read communication to the 1-Wire Net |
j3 | 23:e8e403d61359 | 170 | * and return the result 8 bits read from the 1-Wire Net. |
j3 | 23:e8e403d61359 | 171 | * |
j3 | 23:e8e403d61359 | 172 | * On Entry: |
j3 | 23:e8e403d61359 | 173 | * |
j3 | 23:e8e403d61359 | 174 | * On Exit: |
j3 | 23:e8e403d61359 | 175 | * |
j3 | 23:e8e403d61359 | 176 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 177 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 178 | virtual CmdResult OWReadByte(std::uint8_t & recvbyte, OWLevel after_level) = 0; |
j3 | 23:e8e403d61359 | 179 | |
j3 | 23:e8e403d61359 | 180 | |
j3 | 23:e8e403d61359 | 181 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 182 | * @brief OWWriteBlock() |
j3 | 23:e8e403d61359 | 183 | * |
j3 | 23:e8e403d61359 | 184 | * @details complements OWBlock, writes 'tran_len' bytes from |
j3 | 23:e8e403d61359 | 185 | * 'tran_buf' to 1-wire Net. |
j3 | 23:e8e403d61359 | 186 | * |
j3 | 23:e8e403d61359 | 187 | * On Entry: |
j3 | 23:e8e403d61359 | 188 | * @param[in] tran_buf - pointer to data to write |
j3 | 23:e8e403d61359 | 189 | * @param[in] tran_len - number of bytes to write |
j3 | 23:e8e403d61359 | 190 | * |
j3 | 23:e8e403d61359 | 191 | * On Exit: |
j3 | 23:e8e403d61359 | 192 | * |
j3 | 23:e8e403d61359 | 193 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 194 | **************************************************************/ |
IanBenzMaxim | 27:d5aaefa252f1 | 195 | virtual CmdResult OWWriteBlock(const std::uint8_t *tran_buf, std::uint8_t tran_len) = 0; |
j3 | 23:e8e403d61359 | 196 | |
j3 | 15:f6cb0d906fb6 | 197 | |
j3 | 23:e8e403d61359 | 198 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 199 | * @brief OWReadBlock() |
j3 | 23:e8e403d61359 | 200 | * |
j3 | 23:e8e403d61359 | 201 | * @details complements OWBlock, reads 'recv_len' bytes from |
j3 | 23:e8e403d61359 | 202 | * 1-wire Net and puts them in 'recv_buf'. |
j3 | 23:e8e403d61359 | 203 | * |
j3 | 23:e8e403d61359 | 204 | * On Entry: |
j3 | 23:e8e403d61359 | 205 | * @param[in] recv_buf - pointer to receive buffer |
j3 | 23:e8e403d61359 | 206 | * @param[in] recv_len - number of bytes to read |
j3 | 23:e8e403d61359 | 207 | * |
j3 | 23:e8e403d61359 | 208 | * On Exit: |
j3 | 23:e8e403d61359 | 209 | * |
j3 | 23:e8e403d61359 | 210 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 211 | **************************************************************/ |
IanBenzMaxim | 27:d5aaefa252f1 | 212 | virtual CmdResult OWReadBlock(std::uint8_t *rx_buf, std::uint8_t rx_len) = 0; |
j3 | 23:e8e403d61359 | 213 | |
j3 | 23:e8e403d61359 | 214 | |
j3 | 23:e8e403d61359 | 215 | /**********************************************************//** |
IanBenzMaxim | 32:bce180b544ed | 216 | * @brief OWSetSpeed() |
j3 | 23:e8e403d61359 | 217 | * |
j3 | 23:e8e403d61359 | 218 | * @details Set the 1-Wire Net communication speed. |
j3 | 23:e8e403d61359 | 219 | * |
j3 | 23:e8e403d61359 | 220 | * On Entry: |
j3 | 23:e8e403d61359 | 221 | * @param[in] 'new_speed' - new speed defined as |
j3 | 23:e8e403d61359 | 222 | * MODE_STANDARD 0x00 |
j3 | 23:e8e403d61359 | 223 | * MODE_OVERDRIVE 0x01 |
j3 | 23:e8e403d61359 | 224 | * |
j3 | 23:e8e403d61359 | 225 | * On Exit: |
j3 | 23:e8e403d61359 | 226 | * |
j3 | 23:e8e403d61359 | 227 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 228 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 229 | virtual CmdResult OWSetSpeed(OWSpeed new_speed) = 0; |
IanBenzMaxim | 32:bce180b544ed | 230 | |
j3 | 15:f6cb0d906fb6 | 231 | |
j3 | 23:e8e403d61359 | 232 | /**********************************************************//** |
IanBenzMaxim | 32:bce180b544ed | 233 | * @brief OWSetLevel() |
j3 | 23:e8e403d61359 | 234 | * |
j3 | 23:e8e403d61359 | 235 | * @details Set the 1-Wire Net line level pull-up to normal. The |
j3 | 23:e8e403d61359 | 236 | * ds2484 does only allows enabling strong pull-up on a |
j3 | 23:e8e403d61359 | 237 | * bit or byte event. Consequently this function only |
j3 | 23:e8e403d61359 | 238 | * allows the MODE_STANDARD argument. To enable strong |
j3 | 23:e8e403d61359 | 239 | * pull-up use OWWriteBytePower or OWReadBitPower. |
j3 | 23:e8e403d61359 | 240 | * |
j3 | 23:e8e403d61359 | 241 | * On Entry: |
j3 | 23:e8e403d61359 | 242 | * @param[in] 'new_level' - new level defined as |
j3 | 23:e8e403d61359 | 243 | * MODE_STANDARD 0x00 |
j3 | 23:e8e403d61359 | 244 | * |
j3 | 23:e8e403d61359 | 245 | * On Exit: |
j3 | 23:e8e403d61359 | 246 | * |
j3 | 23:e8e403d61359 | 247 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 248 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 249 | virtual CmdResult OWSetLevel(OWLevel new_level) = 0; |
IanBenzMaxim | 32:bce180b544ed | 250 | |
IanBenzMaxim | 32:bce180b544ed | 251 | |
IanBenzMaxim | 32:bce180b544ed | 252 | |
j3 | 23:e8e403d61359 | 253 | |
IanBenzMaxim | 32:bce180b544ed | 254 | virtual CmdResult OWTriplet(SearchDirection & search_direction, std::uint8_t & sbr, std::uint8_t & tsb); |
IanBenzMaxim | 32:bce180b544ed | 255 | |
IanBenzMaxim | 32:bce180b544ed | 256 | |
IanBenzMaxim | 32:bce180b544ed | 257 | CmdResult OWWriteBit(std::uint8_t sendbit, OWLevel after_level) { return OWTouchBit(sendbit, after_level); } |
IanBenzMaxim | 32:bce180b544ed | 258 | CmdResult OWReadBit(std::uint8_t & recvbit, OWLevel after_level) { recvbit = 0x01; return OWTouchBit(recvbit, after_level); } |
j3 | 23:e8e403d61359 | 259 | |
IanBenzMaxim | 27:d5aaefa252f1 | 260 | CmdResult OWWriteBit(std::uint8_t sendbit) { return OWWriteBit(sendbit, LEVEL_NORMAL); } |
IanBenzMaxim | 27:d5aaefa252f1 | 261 | CmdResult OWReadBit(std::uint8_t & recvbit) { return OWReadBit(recvbit, LEVEL_NORMAL); } |
IanBenzMaxim | 27:d5aaefa252f1 | 262 | CmdResult OWWriteBitPower(std::uint8_t sendbit) { return OWWriteBit(sendbit, LEVEL_STRONG); } |
IanBenzMaxim | 27:d5aaefa252f1 | 263 | CmdResult OWReadBitPower(std::uint8_t & recvbit) { return OWReadBit(recvbit, LEVEL_STRONG); } |
IanBenzMaxim | 27:d5aaefa252f1 | 264 | CmdResult OWWriteByte(std::uint8_t sendbyte) { return OWWriteByte(sendbyte, LEVEL_NORMAL); } |
IanBenzMaxim | 27:d5aaefa252f1 | 265 | CmdResult OWReadByte(std::uint8_t & recvbyte) { return OWReadByte(recvbyte, LEVEL_NORMAL); } |
IanBenzMaxim | 27:d5aaefa252f1 | 266 | CmdResult OWWriteBytePower(std::uint8_t sendbyte) { return OWWriteByte(sendbyte, LEVEL_STRONG); } |
IanBenzMaxim | 27:d5aaefa252f1 | 267 | CmdResult OWReadBytePower(std::uint8_t & recvbyte) { return OWReadByte(recvbyte, LEVEL_STRONG); } |
j3 | 23:e8e403d61359 | 268 | |
j3 | 23:e8e403d61359 | 269 | |
j3 | 23:e8e403d61359 | 270 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 271 | * @brief OWFirst() |
j3 | 23:e8e403d61359 | 272 | * |
j3 | 23:e8e403d61359 | 273 | * @details Find the 'first' devices on the 1-Wire network |
j3 | 23:e8e403d61359 | 274 | * |
j3 | 23:e8e403d61359 | 275 | * On Entry: |
j3 | 23:e8e403d61359 | 276 | * |
j3 | 23:e8e403d61359 | 277 | * On Exit: |
j3 | 23:e8e403d61359 | 278 | * |
j3 | 23:e8e403d61359 | 279 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 280 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 281 | CmdResult OWFirst(SearchState & searchState); |
j3 | 23:e8e403d61359 | 282 | |
j3 | 23:e8e403d61359 | 283 | |
j3 | 23:e8e403d61359 | 284 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 285 | * @brief OWNext() |
j3 | 23:e8e403d61359 | 286 | * |
j3 | 23:e8e403d61359 | 287 | * @details Find the 'next' devices on the 1-Wire network |
j3 | 23:e8e403d61359 | 288 | * |
j3 | 23:e8e403d61359 | 289 | * On Entry: |
j3 | 23:e8e403d61359 | 290 | * |
j3 | 23:e8e403d61359 | 291 | * On Exit: |
j3 | 23:e8e403d61359 | 292 | * |
j3 | 23:e8e403d61359 | 293 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 294 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 295 | CmdResult OWNext(SearchState & searchState); |
j3 | 23:e8e403d61359 | 296 | |
j3 | 23:e8e403d61359 | 297 | |
j3 | 23:e8e403d61359 | 298 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 299 | * @brief OWVerify() |
j3 | 23:e8e403d61359 | 300 | * |
j3 | 23:e8e403d61359 | 301 | * @details Verify the device with the ROM number in ROM_NO buffer |
j3 | 23:e8e403d61359 | 302 | * is present. |
j3 | 23:e8e403d61359 | 303 | * |
j3 | 23:e8e403d61359 | 304 | * On Entry: |
j3 | 23:e8e403d61359 | 305 | * |
j3 | 23:e8e403d61359 | 306 | * On Exit: |
j3 | 23:e8e403d61359 | 307 | * |
j3 | 23:e8e403d61359 | 308 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 309 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 310 | CmdResult OWVerify(const RomId & romId); |
j3 | 23:e8e403d61359 | 311 | |
j3 | 23:e8e403d61359 | 312 | |
j3 | 23:e8e403d61359 | 313 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 314 | * @brief OWTargetSetup() |
j3 | 23:e8e403d61359 | 315 | * |
j3 | 23:e8e403d61359 | 316 | * @details Setup the search to find the device type 'family_code' |
j3 | 23:e8e403d61359 | 317 | * on the next call to OWNext() if it is present. |
j3 | 23:e8e403d61359 | 318 | * |
j3 | 23:e8e403d61359 | 319 | * On Entry: |
j3 | 23:e8e403d61359 | 320 | * @param[in] family_code - family code of device |
j3 | 23:e8e403d61359 | 321 | * |
j3 | 23:e8e403d61359 | 322 | * On Exit: |
j3 | 23:e8e403d61359 | 323 | * |
j3 | 23:e8e403d61359 | 324 | * @return |
j3 | 23:e8e403d61359 | 325 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 326 | void OWTargetSetup(SearchState & searchState); |
j3 | 23:e8e403d61359 | 327 | |
j3 | 23:e8e403d61359 | 328 | |
j3 | 23:e8e403d61359 | 329 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 330 | * @brief OWFamilySkipSetup() |
j3 | 23:e8e403d61359 | 331 | * |
j3 | 23:e8e403d61359 | 332 | * @details Setup the search to skip the current device type on the |
j3 | 23:e8e403d61359 | 333 | * next call to OWNext(). |
j3 | 23:e8e403d61359 | 334 | * |
j3 | 23:e8e403d61359 | 335 | * On Entry: |
j3 | 23:e8e403d61359 | 336 | * |
j3 | 23:e8e403d61359 | 337 | * On Exit: |
j3 | 23:e8e403d61359 | 338 | * |
j3 | 23:e8e403d61359 | 339 | * @return |
j3 | 23:e8e403d61359 | 340 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 341 | void OWFamilySkipSetup(SearchState & searchState); |
j3 | 15:f6cb0d906fb6 | 342 | |
j3 | 23:e8e403d61359 | 343 | |
j3 | 23:e8e403d61359 | 344 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 345 | * @brief OWReadROM() |
j3 | 23:e8e403d61359 | 346 | * |
j3 | 23:e8e403d61359 | 347 | * @details Only use this command with a single drop bus, data |
j3 | 23:e8e403d61359 | 348 | * collisions will occur if more than 1 device on bus. |
j3 | 23:e8e403d61359 | 349 | * Issues READ_ROM command, slave device will respond with ROM ID. |
j3 | 23:e8e403d61359 | 350 | * |
j3 | 23:e8e403d61359 | 351 | * On Entry: |
j3 | 23:e8e403d61359 | 352 | * |
j3 | 23:e8e403d61359 | 353 | * On Exit: |
j3 | 23:e8e403d61359 | 354 | * |
j3 | 23:e8e403d61359 | 355 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 356 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 357 | CmdResult OWReadROM(RomId & romId); |
j3 | 23:e8e403d61359 | 358 | |
j3 | 15:f6cb0d906fb6 | 359 | |
j3 | 23:e8e403d61359 | 360 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 361 | * @brief OWSkipROM() |
j3 | 23:e8e403d61359 | 362 | * |
j3 | 23:e8e403d61359 | 363 | * @details Issue SKIP_ROM command on 1-wire bus |
j3 | 23:e8e403d61359 | 364 | * |
j3 | 23:e8e403d61359 | 365 | * On Entry: |
j3 | 23:e8e403d61359 | 366 | * |
j3 | 23:e8e403d61359 | 367 | * On Exit: |
j3 | 23:e8e403d61359 | 368 | * |
j3 | 23:e8e403d61359 | 369 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 370 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 371 | CmdResult OWSkipROM(void); |
j3 | 23:e8e403d61359 | 372 | |
j3 | 15:f6cb0d906fb6 | 373 | |
j3 | 23:e8e403d61359 | 374 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 375 | * @brief OWMatchROM() |
j3 | 23:e8e403d61359 | 376 | * |
j3 | 23:e8e403d61359 | 377 | * @details Issues MATCH_ROM command on 1-wire bus and then sends |
j3 | 23:e8e403d61359 | 378 | * the rom id in _rom_number |
j3 | 23:e8e403d61359 | 379 | * |
j3 | 23:e8e403d61359 | 380 | * On Entry: |
j3 | 23:e8e403d61359 | 381 | * |
j3 | 23:e8e403d61359 | 382 | * On Exit: |
j3 | 23:e8e403d61359 | 383 | * |
j3 | 23:e8e403d61359 | 384 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 385 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 386 | CmdResult OWMatchROM(const RomId & romId); |
j3 | 23:e8e403d61359 | 387 | |
j3 | 15:f6cb0d906fb6 | 388 | |
j3 | 23:e8e403d61359 | 389 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 390 | * @brief OWOverdriveSkipROM() |
j3 | 23:e8e403d61359 | 391 | * |
j3 | 23:e8e403d61359 | 392 | * @details Issues OVERDRIVE_SKIP rom command. DS248X OW speed |
j3 | 23:e8e403d61359 | 393 | * is set to SPEED_OVERDRIVE |
j3 | 23:e8e403d61359 | 394 | * |
j3 | 23:e8e403d61359 | 395 | * On Entry: |
j3 | 23:e8e403d61359 | 396 | * |
j3 | 23:e8e403d61359 | 397 | * On Exit: |
j3 | 23:e8e403d61359 | 398 | * |
j3 | 23:e8e403d61359 | 399 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 400 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 401 | CmdResult OWOverdriveSkipROM(void); |
j3 | 15:f6cb0d906fb6 | 402 | |
j3 | 15:f6cb0d906fb6 | 403 | |
j3 | 23:e8e403d61359 | 404 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 405 | * @brief OWOverdriveMatchROM() |
j3 | 23:e8e403d61359 | 406 | * |
j3 | 23:e8e403d61359 | 407 | * @details Issues OVERDRIVE_MATCH rom command. DS248X OW speed |
j3 | 23:e8e403d61359 | 408 | * is set to SPEED_OVERDRIVE |
j3 | 23:e8e403d61359 | 409 | * |
j3 | 23:e8e403d61359 | 410 | * On Entry: |
j3 | 23:e8e403d61359 | 411 | * |
j3 | 23:e8e403d61359 | 412 | * On Exit: |
j3 | 23:e8e403d61359 | 413 | * |
j3 | 23:e8e403d61359 | 414 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 415 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 416 | CmdResult OWOverdriveMatchROM(const RomId & romId); |
j3 | 23:e8e403d61359 | 417 | |
j3 | 15:f6cb0d906fb6 | 418 | |
j3 | 23:e8e403d61359 | 419 | /**********************************************************//** |
j3 | 23:e8e403d61359 | 420 | * @brief OWResume() |
j3 | 23:e8e403d61359 | 421 | * |
j3 | 23:e8e403d61359 | 422 | * @details Issues RESUME command, very usefull. Is like skip |
j3 | 23:e8e403d61359 | 423 | * on a multidrop bus, however you must first select the device |
j3 | 23:e8e403d61359 | 424 | * you want to interface with using a MATCH, or SEARCH. The |
j3 | 23:e8e403d61359 | 425 | * device stays selected until another device is selected, |
j3 | 23:e8e403d61359 | 426 | * see slave datasheet for detailed explanation. |
j3 | 23:e8e403d61359 | 427 | * |
j3 | 23:e8e403d61359 | 428 | * On Entry: |
j3 | 23:e8e403d61359 | 429 | * |
j3 | 23:e8e403d61359 | 430 | * On Exit: |
j3 | 23:e8e403d61359 | 431 | * |
j3 | 23:e8e403d61359 | 432 | * @return CmdResult - zero on success, non-zero on failure |
j3 | 23:e8e403d61359 | 433 | **************************************************************/ |
IanBenzMaxim | 24:8942d8478d68 | 434 | CmdResult OWResume(void); |
IanBenzMaxim | 21:00c94aeb533e | 435 | |
IanBenzMaxim | 32:bce180b544ed | 436 | |
IanBenzMaxim | 32:bce180b544ed | 437 | /**********************************************************//** |
IanBenzMaxim | 32:bce180b544ed | 438 | * @brief OWSearch() |
IanBenzMaxim | 32:bce180b544ed | 439 | * |
IanBenzMaxim | 32:bce180b544ed | 440 | * @details The 'OWSearch' function does a general search. This |
IanBenzMaxim | 32:bce180b544ed | 441 | * function continues from the previous search state. The |
IanBenzMaxim | 32:bce180b544ed | 442 | * search state can be reset by using the 'OWFirst' |
IanBenzMaxim | 32:bce180b544ed | 443 | * function. This function contains one parameter |
IanBenzMaxim | 32:bce180b544ed | 444 | * 'alarm_only'. When 'alarm_only' is TRUE (1) the find |
IanBenzMaxim | 32:bce180b544ed | 445 | * alarm command 0xEC is sent instead of the normal search |
IanBenzMaxim | 32:bce180b544ed | 446 | * command 0xF0. Using the find alarm command 0xEC will |
IanBenzMaxim | 32:bce180b544ed | 447 | * limit the search to only 1-Wire devices that are in an |
IanBenzMaxim | 32:bce180b544ed | 448 | * 'alarm' state. |
IanBenzMaxim | 32:bce180b544ed | 449 | * |
IanBenzMaxim | 32:bce180b544ed | 450 | * On Entry: |
IanBenzMaxim | 32:bce180b544ed | 451 | * |
IanBenzMaxim | 32:bce180b544ed | 452 | * On Exit: |
IanBenzMaxim | 32:bce180b544ed | 453 | * |
IanBenzMaxim | 32:bce180b544ed | 454 | * @return CmdResult - zero on success, non-zero on failure |
IanBenzMaxim | 32:bce180b544ed | 455 | **************************************************************/ |
IanBenzMaxim | 32:bce180b544ed | 456 | CmdResult OWSearch(SearchState & searchState); |
IanBenzMaxim | 32:bce180b544ed | 457 | |
IanBenzMaxim | 32:bce180b544ed | 458 | |
IanBenzMaxim | 32:bce180b544ed | 459 | private: |
IanBenzMaxim | 24:8942d8478d68 | 460 | |
IanBenzMaxim | 24:8942d8478d68 | 461 | enum OW_ROM_CMD |
IanBenzMaxim | 24:8942d8478d68 | 462 | { |
IanBenzMaxim | 24:8942d8478d68 | 463 | READ_ROM = 0x33, |
IanBenzMaxim | 24:8942d8478d68 | 464 | MATCH_ROM = 0x55, |
IanBenzMaxim | 24:8942d8478d68 | 465 | SEARCH_ROM = 0xF0, |
IanBenzMaxim | 24:8942d8478d68 | 466 | SKIP_ROM = 0xCC, |
IanBenzMaxim | 24:8942d8478d68 | 467 | RESUME = 0xA5, |
IanBenzMaxim | 24:8942d8478d68 | 468 | OVERDRIVE_SKIP_ROM = 0x3C, |
IanBenzMaxim | 24:8942d8478d68 | 469 | OVERDRIVE_MATCH_ROM = 0x69 |
IanBenzMaxim | 24:8942d8478d68 | 470 | }; |
j3 | 15:f6cb0d906fb6 | 471 | |
IanBenzMaxim | 27:d5aaefa252f1 | 472 | static const std::uint16_t _oddparity[16]; |
j3 | 15:f6cb0d906fb6 | 473 | }; |
j3 | 15:f6cb0d906fb6 | 474 | |
j3 | 15:f6cb0d906fb6 | 475 | |
j3 | 15:f6cb0d906fb6 | 476 | |
j3 | 5:ce108eeb878d | 477 | |
j3 | 5:ce108eeb878d | 478 | |
IanBenzMaxim | 27:d5aaefa252f1 | 479 | #endif /*ONEWIREMASTER_H*/ |