Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Thu May 12 14:38:16 2016 -0500
Revision:
73:2cecc1372acc
Parent:
OneWire_Bridge/DS28E17/ds28e17.cpp@27:d5aaefa252f1
Child:
74:23be10c32fa3
Added namespaces. Renamed files and directories for consistency. Use <stdint.h> instead of <cstdint> since it is not supported by C++98.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 4:ca27db159b10 1 /******************************************************************//**
j3 4:ca27db159b10 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 4:ca27db159b10 3 *
j3 4:ca27db159b10 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 4:ca27db159b10 5 * copy of this software and associated documentation files (the "Software"),
j3 4:ca27db159b10 6 * to deal in the Software without restriction, including without limitation
j3 4:ca27db159b10 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 4:ca27db159b10 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 4:ca27db159b10 9 * Software is furnished to do so, subject to the following conditions:
j3 4:ca27db159b10 10 *
j3 4:ca27db159b10 11 * The above copyright notice and this permission notice shall be included
j3 4:ca27db159b10 12 * in all copies or substantial portions of the Software.
j3 4:ca27db159b10 13 *
j3 4:ca27db159b10 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 4:ca27db159b10 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 4:ca27db159b10 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 4:ca27db159b10 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 4:ca27db159b10 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 4:ca27db159b10 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 4:ca27db159b10 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 4:ca27db159b10 21 *
j3 4:ca27db159b10 22 * Except as contained in this notice, the name of Maxim Integrated
j3 4:ca27db159b10 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 4:ca27db159b10 24 * Products, Inc. Branding Policy.
j3 4:ca27db159b10 25 *
j3 4:ca27db159b10 26 * The mere transfer of this software does not imply any licenses
j3 4:ca27db159b10 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 4:ca27db159b10 28 * trademarks, maskwork rights, or any other form of intellectual
j3 4:ca27db159b10 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 4:ca27db159b10 30 * ownership rights.
j3 4:ca27db159b10 31 **********************************************************************/
j3 4:ca27db159b10 32
IanBenzMaxim 73:2cecc1372acc 33 #include "DS28E17.h"
IanBenzMaxim 73:2cecc1372acc 34 #include "Masters/OneWireMaster.h"
j3 4:ca27db159b10 35
IanBenzMaxim 73:2cecc1372acc 36 using OneWire::Bridge::DS28E17;
IanBenzMaxim 73:2cecc1372acc 37 using OneWire::Masters::OneWireMaster;
j3 4:ca27db159b10 38
IanBenzMaxim 73:2cecc1372acc 39 const uint16_t DS28E17::_oddparity[] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
j3 4:ca27db159b10 40
j3 4:ca27db159b10 41
j3 4:ca27db159b10 42 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 43 DS28E17::DS28E17(OneWireMaster &owm)
IanBenzMaxim 73:2cecc1372acc 44 : _owm(owm)
j3 4:ca27db159b10 45 {
j3 7:78a8857b3810 46
j3 4:ca27db159b10 47 }
j3 4:ca27db159b10 48
j3 4:ca27db159b10 49
j3 4:ca27db159b10 50 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 51 DS28E17::CmdResult DS28E17::I2C_WriteDataWithStop(uint8_t I2C_addr, uint8_t length,
j3 7:78a8857b3810 52 uint8_t *data, uint8_t &status,
j3 7:78a8857b3810 53 uint8_t &wr_status)
j3 4:ca27db159b10 54 {
IanBenzMaxim 73:2cecc1372acc 55 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 4:ca27db159b10 56
j3 7:78a8857b3810 57 size_t send_cnt = 0;
j3 7:78a8857b3810 58 uint8_t send_block[0xff];
j3 7:78a8857b3810 59
IanBenzMaxim 73:2cecc1372acc 60 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 61
j3 23:e8e403d61359 62 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 63 {
j3 7:78a8857b3810 64 //seed the crc
j3 7:78a8857b3810 65 _crc16 = 0;
j3 7:78a8857b3810 66
j3 7:78a8857b3810 67 // Form the 1-Wire Packet
j3 7:78a8857b3810 68
j3 7:78a8857b3810 69 // I2C Write Data with Stop command
j3 7:78a8857b3810 70 send_block[send_cnt] = CMD_I2C_WRITE_W_STOP;
j3 7:78a8857b3810 71 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 72
j3 7:78a8857b3810 73 // I2C Address
j3 7:78a8857b3810 74 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 75 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 76
j3 7:78a8857b3810 77 // Length field
j3 7:78a8857b3810 78 send_block[send_cnt] = length;
j3 7:78a8857b3810 79 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 80
j3 7:78a8857b3810 81 // Form the write data
j3 17:b646b1e3970b 82 for (size_t idx = 0; idx < length; idx++)
j3 7:78a8857b3810 83 {
j3 7:78a8857b3810 84 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 85 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 86 }
j3 7:78a8857b3810 87
j3 7:78a8857b3810 88 // Form the CRC16
j3 7:78a8857b3810 89 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 90 send_block[send_cnt++] = ((uint8_t)(_crc16 & 0xFF));
j3 7:78a8857b3810 91 send_block[send_cnt++] = ((uint8_t)((_crc16 >> 8) & 0xFF));
j3 7:78a8857b3810 92
j3 7:78a8857b3810 93 // Send Packet
j3 17:b646b1e3970b 94 bridge_result = send_packet(send_block, send_cnt, status, wr_status);
j3 7:78a8857b3810 95 }
j3 4:ca27db159b10 96
j3 17:b646b1e3970b 97 return bridge_result;
j3 4:ca27db159b10 98 }
j3 4:ca27db159b10 99
j3 4:ca27db159b10 100
j3 4:ca27db159b10 101 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 102 DS28E17::CmdResult DS28E17::I2C_WriteDataNoStop(uint8_t I2C_addr, uint8_t length,
j3 7:78a8857b3810 103 uint8_t *data, uint8_t &status,
j3 7:78a8857b3810 104 uint8_t &wr_status)
j3 4:ca27db159b10 105 {
IanBenzMaxim 73:2cecc1372acc 106 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 4:ca27db159b10 107
j3 7:78a8857b3810 108 size_t send_cnt = 0;
j3 7:78a8857b3810 109 uint8_t send_block[0xff];
j3 7:78a8857b3810 110
IanBenzMaxim 73:2cecc1372acc 111 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 112
j3 23:e8e403d61359 113 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 114 {
j3 7:78a8857b3810 115 // seed the crc
j3 7:78a8857b3810 116 _crc16 = 0;
j3 7:78a8857b3810 117
j3 7:78a8857b3810 118 // I2C Write Data with Stop command
j3 7:78a8857b3810 119 send_block[send_cnt] = CMD_I2C_WRITE_NO_STOP;
j3 7:78a8857b3810 120 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 121
j3 7:78a8857b3810 122 // I2C Address
j3 7:78a8857b3810 123 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 124 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 125
j3 7:78a8857b3810 126 // Length field
j3 7:78a8857b3810 127 send_block[send_cnt] = length;
j3 7:78a8857b3810 128 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 129
j3 7:78a8857b3810 130 // Form the write data
j3 17:b646b1e3970b 131 for(size_t idx = 0; idx < length; idx++)
j3 7:78a8857b3810 132 {
j3 7:78a8857b3810 133 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 134 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 135 }
j3 7:78a8857b3810 136
j3 7:78a8857b3810 137 // Form the CRC16
j3 7:78a8857b3810 138 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 139 send_block[send_cnt++] = ((uint8_t)(_crc16 & 0xFF));
j3 7:78a8857b3810 140 send_block[send_cnt++] = ((uint8_t)((_crc16 >> 8) & 0xFF));
j3 7:78a8857b3810 141
j3 7:78a8857b3810 142 // Send Packet
j3 17:b646b1e3970b 143 bridge_result = send_packet(send_block, send_cnt, status, wr_status);
j3 7:78a8857b3810 144 }
j3 7:78a8857b3810 145
j3 17:b646b1e3970b 146 return bridge_result;
j3 4:ca27db159b10 147 }
j3 4:ca27db159b10 148
j3 4:ca27db159b10 149
j3 4:ca27db159b10 150 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 151 DS28E17::CmdResult DS28E17::I2C_WriteDataOnly(uint8_t length, uint8_t *data,
j3 7:78a8857b3810 152 uint8_t &status, uint8_t &wr_status)
j3 4:ca27db159b10 153 {
IanBenzMaxim 73:2cecc1372acc 154 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 4:ca27db159b10 155
j3 7:78a8857b3810 156 size_t send_cnt = 0;
j3 7:78a8857b3810 157 uint8_t send_block[0xff];
j3 7:78a8857b3810 158
IanBenzMaxim 73:2cecc1372acc 159 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 160
j3 23:e8e403d61359 161 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 162 {
j3 7:78a8857b3810 163 // seed the crc
j3 7:78a8857b3810 164 _crc16 = 0;
j3 7:78a8857b3810 165
j3 7:78a8857b3810 166 // Form the 1-Wire Packet
j3 7:78a8857b3810 167
j3 7:78a8857b3810 168 // I2C Write Data with Stop command
j3 7:78a8857b3810 169 send_block[send_cnt] = CMD_I2C_WRITE_ONLY;
j3 7:78a8857b3810 170 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 171
j3 7:78a8857b3810 172 // Length field
j3 7:78a8857b3810 173 send_block[send_cnt] = length;
j3 7:78a8857b3810 174 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 175
j3 7:78a8857b3810 176 // Form the write data
j3 17:b646b1e3970b 177 for (size_t idx = 0; idx < length; idx++)
j3 7:78a8857b3810 178 {
j3 7:78a8857b3810 179 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 180 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 181 }
j3 7:78a8857b3810 182
j3 7:78a8857b3810 183 // Form the CRC16\
j3 7:78a8857b3810 184 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 185 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 186 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 187
j3 7:78a8857b3810 188 // Send Packet
j3 17:b646b1e3970b 189 bridge_result = send_packet(send_block, send_cnt, status, wr_status);
j3 7:78a8857b3810 190 }
j3 7:78a8857b3810 191
j3 17:b646b1e3970b 192 return bridge_result;
j3 4:ca27db159b10 193 }
j3 4:ca27db159b10 194
j3 4:ca27db159b10 195
j3 4:ca27db159b10 196 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 197 DS28E17::CmdResult DS28E17::I2C_WriteDataOnlyWithStop(uint8_t length, uint8_t *data,
j3 7:78a8857b3810 198 uint8_t &status, uint8_t &wr_status)
j3 4:ca27db159b10 199 {
IanBenzMaxim 73:2cecc1372acc 200 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 4:ca27db159b10 201
j3 7:78a8857b3810 202 size_t send_cnt = 0;
j3 7:78a8857b3810 203 uint8_t send_block[0xff];
j3 7:78a8857b3810 204
IanBenzMaxim 73:2cecc1372acc 205 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 206
j3 23:e8e403d61359 207 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 208 {
j3 7:78a8857b3810 209 //seed the crc
j3 7:78a8857b3810 210 _crc16 = 0;
j3 7:78a8857b3810 211
j3 7:78a8857b3810 212 // Form the 1-Wire Packet
j3 7:78a8857b3810 213
j3 7:78a8857b3810 214 // I2C Write Data with Stop command
j3 7:78a8857b3810 215 send_block[send_cnt] = CMD_I2C_WRITE_ONLY_W_STOP;
j3 7:78a8857b3810 216 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 217
j3 7:78a8857b3810 218 // Length field
j3 7:78a8857b3810 219 send_block[send_cnt] = length;
j3 7:78a8857b3810 220 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 221
j3 7:78a8857b3810 222 // Form the write data
j3 17:b646b1e3970b 223 for (size_t idx = 0; idx < length; idx++)
j3 7:78a8857b3810 224 {
j3 7:78a8857b3810 225 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 226 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 227 }
j3 7:78a8857b3810 228
j3 7:78a8857b3810 229 // Form the CRC16
j3 7:78a8857b3810 230 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 231 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 232 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 233
j3 7:78a8857b3810 234 // Send Packet
j3 17:b646b1e3970b 235 bridge_result = send_packet(send_block, send_cnt, status, wr_status);
j3 17:b646b1e3970b 236 }
j3 7:78a8857b3810 237
j3 17:b646b1e3970b 238 return bridge_result;
j3 4:ca27db159b10 239 }
j3 4:ca27db159b10 240
j3 4:ca27db159b10 241
j3 4:ca27db159b10 242 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 243 DS28E17::CmdResult DS28E17::I2C_WriteReadDataWithStop(uint8_t I2C_addr, uint8_t length,
j3 4:ca27db159b10 244 uint8_t *data, uint8_t nu_bytes_read,
j3 7:78a8857b3810 245 uint8_t &status, uint8_t &wr_status,
j3 4:ca27db159b10 246 uint8_t *read_data)
j3 4:ca27db159b10 247 {
IanBenzMaxim 73:2cecc1372acc 248 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 4:ca27db159b10 249
j3 7:78a8857b3810 250 size_t send_cnt = 0;
j3 7:78a8857b3810 251 size_t idx = 0;
j3 7:78a8857b3810 252 uint8_t send_block[0xff];
j3 7:78a8857b3810 253
IanBenzMaxim 73:2cecc1372acc 254 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 255
j3 23:e8e403d61359 256 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 257 {
j3 7:78a8857b3810 258 //seed the crc
j3 7:78a8857b3810 259 _crc16 = 0;
j3 7:78a8857b3810 260
j3 7:78a8857b3810 261 // Form the 1-Wire Packet
j3 7:78a8857b3810 262
j3 7:78a8857b3810 263 // I2C Write Data with Stop command
j3 7:78a8857b3810 264 send_block[send_cnt] = CMD_I2C_WRITE_READ_W_STOP;
j3 7:78a8857b3810 265 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 266
j3 7:78a8857b3810 267 // I2C Address
j3 7:78a8857b3810 268 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 269 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 270
j3 7:78a8857b3810 271 // Length field
j3 7:78a8857b3810 272 send_block[send_cnt] = length;
j3 7:78a8857b3810 273 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 274
j3 7:78a8857b3810 275 // Form the write data
j3 7:78a8857b3810 276 for (idx = 0; idx < length; idx++)
j3 7:78a8857b3810 277 {
j3 7:78a8857b3810 278 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 279 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 280 }
j3 7:78a8857b3810 281
j3 7:78a8857b3810 282 // # of bytes to Read field
j3 7:78a8857b3810 283 send_block[send_cnt] = nu_bytes_read;
j3 7:78a8857b3810 284 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 285
j3 7:78a8857b3810 286 // Form the CRC16
j3 7:78a8857b3810 287 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 288 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 289 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 290
j3 7:78a8857b3810 291 // Send Packet
j3 17:b646b1e3970b 292 bridge_result = send_packet(send_block, send_cnt, status, wr_status);
IanBenzMaxim 73:2cecc1372acc 293 if(bridge_result == DS28E17::Success)
j3 7:78a8857b3810 294 {
j3 17:b646b1e3970b 295 ow_result = _owm.OWReadBlock(read_data, nu_bytes_read);
j3 23:e8e403d61359 296 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 297 {
IanBenzMaxim 73:2cecc1372acc 298 bridge_result = DS28E17::Success;
j3 7:78a8857b3810 299 }
j3 17:b646b1e3970b 300 else
j3 17:b646b1e3970b 301 {
IanBenzMaxim 73:2cecc1372acc 302 bridge_result = DS28E17::CommsReadBlockError;
j3 17:b646b1e3970b 303 }
j3 7:78a8857b3810 304 }
j3 7:78a8857b3810 305 }
j3 7:78a8857b3810 306
j3 17:b646b1e3970b 307 return bridge_result;
j3 4:ca27db159b10 308 }
j3 4:ca27db159b10 309
j3 4:ca27db159b10 310
j3 4:ca27db159b10 311 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 312 DS28E17::CmdResult DS28E17::I2C_ReadDataWithStop(uint8_t I2C_addr, uint8_t nu_bytes_read,
j3 7:78a8857b3810 313 uint8_t &status, uint8_t *read_data)
j3 4:ca27db159b10 314 {
IanBenzMaxim 73:2cecc1372acc 315 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 4:ca27db159b10 316
j3 7:78a8857b3810 317 size_t send_cnt = 0;
j3 7:78a8857b3810 318 uint8_t send_block[0xff];
j3 7:78a8857b3810 319
IanBenzMaxim 73:2cecc1372acc 320 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 321
j3 23:e8e403d61359 322 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 323 {
j3 7:78a8857b3810 324 //seed the crc for transmit bytes
j3 7:78a8857b3810 325 _crc16 = 0;
j3 7:78a8857b3810 326
j3 7:78a8857b3810 327 // Form the 1-Wire Packet to send
j3 7:78a8857b3810 328
j3 7:78a8857b3810 329 // I2C Write Data with Stop command
j3 7:78a8857b3810 330 send_block[send_cnt] = CMD_I2C_READ_W_STOP;
j3 7:78a8857b3810 331 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 332
j3 7:78a8857b3810 333 // I2C Address
j3 7:78a8857b3810 334 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 335 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 336
j3 7:78a8857b3810 337 // # of bytes to Read field
j3 7:78a8857b3810 338 send_block[send_cnt] = nu_bytes_read;
j3 7:78a8857b3810 339 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 340
j3 7:78a8857b3810 341 // Form the CRC16
j3 7:78a8857b3810 342 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 343 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 344 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 345
j3 7:78a8857b3810 346 // Send Packet
j3 17:b646b1e3970b 347 bridge_result = send_packet(send_block, send_cnt, status);
IanBenzMaxim 73:2cecc1372acc 348 if(bridge_result == DS28E17::Success)
j3 7:78a8857b3810 349 {
j3 17:b646b1e3970b 350 ow_result = _owm.OWReadBlock(read_data, nu_bytes_read);
j3 23:e8e403d61359 351 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 352 {
IanBenzMaxim 73:2cecc1372acc 353 bridge_result = DS28E17::Success;
j3 7:78a8857b3810 354 }
j3 17:b646b1e3970b 355 else
j3 17:b646b1e3970b 356 {
IanBenzMaxim 73:2cecc1372acc 357 bridge_result = DS28E17::CommsReadBlockError;
j3 17:b646b1e3970b 358 }
j3 7:78a8857b3810 359 }
j3 7:78a8857b3810 360 }
j3 7:78a8857b3810 361
j3 17:b646b1e3970b 362 return bridge_result;
j3 4:ca27db159b10 363 }
j3 4:ca27db159b10 364
j3 4:ca27db159b10 365
j3 4:ca27db159b10 366 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 367 DS28E17::CmdResult DS28E17::WriteConfigReg(uint8_t data)
j3 7:78a8857b3810 368 {
IanBenzMaxim 73:2cecc1372acc 369 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 7:78a8857b3810 370
IanBenzMaxim 73:2cecc1372acc 371 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 372
j3 23:e8e403d61359 373 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 374 {
j3 7:78a8857b3810 375 // Send CMD and Data
j3 17:b646b1e3970b 376 uint8_t send_block[] = {CMD_WRITE_CONFIG_REG, data};
j3 17:b646b1e3970b 377
j3 17:b646b1e3970b 378 ow_result = _owm.OWWriteBlock(send_block, 2);
j3 23:e8e403d61359 379 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 380 {
j3 17:b646b1e3970b 381 _i2c_speed = data & 0x03; // Save off _i2c_speed setting to be used by other functions
IanBenzMaxim 73:2cecc1372acc 382 bridge_result = DS28E17::Success;
j3 17:b646b1e3970b 383 }
j3 17:b646b1e3970b 384 else
j3 17:b646b1e3970b 385 {
IanBenzMaxim 73:2cecc1372acc 386 bridge_result = DS28E17::CommsWriteBlockError;
j3 17:b646b1e3970b 387 }
j3 7:78a8857b3810 388 }
j3 7:78a8857b3810 389
j3 17:b646b1e3970b 390 return bridge_result;
j3 7:78a8857b3810 391 }
j3 7:78a8857b3810 392
j3 7:78a8857b3810 393
j3 7:78a8857b3810 394 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 395 DS28E17::CmdResult DS28E17::ReadConfigReg(uint8_t & config)
j3 7:78a8857b3810 396 {
IanBenzMaxim 73:2cecc1372acc 397 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 7:78a8857b3810 398
IanBenzMaxim 73:2cecc1372acc 399 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 400
j3 23:e8e403d61359 401 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 402 {
j3 7:78a8857b3810 403 // Send CMD and receive Data
j3 17:b646b1e3970b 404 ow_result = _owm.OWWriteByte(CMD_READ_CONFIG_REG);
j3 23:e8e403d61359 405 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 406 {
j3 17:b646b1e3970b 407 ow_result = _owm.OWReadByte(config);
j3 23:e8e403d61359 408 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 409 {
IanBenzMaxim 73:2cecc1372acc 410 bridge_result = DS28E17::Success;
j3 17:b646b1e3970b 411 }
j3 17:b646b1e3970b 412 else
j3 17:b646b1e3970b 413 {
IanBenzMaxim 73:2cecc1372acc 414 bridge_result = DS28E17::CommsReadByteError;
j3 17:b646b1e3970b 415 }
j3 17:b646b1e3970b 416 }
j3 17:b646b1e3970b 417 else
j3 17:b646b1e3970b 418 {
IanBenzMaxim 73:2cecc1372acc 419 bridge_result = DS28E17::CommsWriteByteError;
j3 17:b646b1e3970b 420 }
j3 7:78a8857b3810 421 }
j3 7:78a8857b3810 422
j3 17:b646b1e3970b 423 return bridge_result;
j3 7:78a8857b3810 424 }
j3 7:78a8857b3810 425
j3 7:78a8857b3810 426
j3 7:78a8857b3810 427 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 428 DS28E17::CmdResult DS28E17::DisableOWMode()
j3 7:78a8857b3810 429 {
IanBenzMaxim 73:2cecc1372acc 430 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 7:78a8857b3810 431
IanBenzMaxim 73:2cecc1372acc 432 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 433
j3 23:e8e403d61359 434 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 435 {
j3 7:78a8857b3810 436 // Send CMD
j3 17:b646b1e3970b 437 ow_result = _owm.OWWriteByte(CMD_DISABLE_OW_MODE);
j3 23:e8e403d61359 438 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 439 {
IanBenzMaxim 73:2cecc1372acc 440 bridge_result = DS28E17::Success;
j3 17:b646b1e3970b 441 }
j3 17:b646b1e3970b 442 else
j3 17:b646b1e3970b 443 {
IanBenzMaxim 73:2cecc1372acc 444 bridge_result = DS28E17::CommsWriteByteError;
j3 17:b646b1e3970b 445 }
j3 7:78a8857b3810 446 }
j3 7:78a8857b3810 447
j3 17:b646b1e3970b 448 return bridge_result;
j3 7:78a8857b3810 449 }
j3 7:78a8857b3810 450
j3 7:78a8857b3810 451
j3 7:78a8857b3810 452 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 453 DS28E17::CmdResult DS28E17::EnableSleepMode()
j3 7:78a8857b3810 454 {
IanBenzMaxim 73:2cecc1372acc 455 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 7:78a8857b3810 456
IanBenzMaxim 73:2cecc1372acc 457 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 458
j3 23:e8e403d61359 459 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 460 {
j3 7:78a8857b3810 461 // Send CMD
j3 17:b646b1e3970b 462 ow_result = _owm.OWWriteByte(CMD_ENABLE_SLEEP_MODE);
j3 23:e8e403d61359 463 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 464 {
IanBenzMaxim 73:2cecc1372acc 465 bridge_result = DS28E17::Success;
j3 17:b646b1e3970b 466 }
j3 17:b646b1e3970b 467 else
j3 17:b646b1e3970b 468 {
IanBenzMaxim 73:2cecc1372acc 469 bridge_result = DS28E17::CommsWriteByteError;
j3 17:b646b1e3970b 470 }
j3 7:78a8857b3810 471 }
j3 7:78a8857b3810 472
j3 17:b646b1e3970b 473 return bridge_result;
j3 7:78a8857b3810 474 }
j3 7:78a8857b3810 475
j3 7:78a8857b3810 476
j3 7:78a8857b3810 477 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 478 DS28E17::CmdResult DS28E17::ReadDeviceRevision(uint8_t & rev)
j3 7:78a8857b3810 479 {
IanBenzMaxim 73:2cecc1372acc 480 DS28E17::CmdResult bridge_result = DS28E17::OperationFailure;
j3 7:78a8857b3810 481
IanBenzMaxim 73:2cecc1372acc 482 OneWireMaster::CmdResult ow_result = _owm.OWMatchROM(romId);
j3 17:b646b1e3970b 483
j3 23:e8e403d61359 484 if(ow_result == OneWireMaster::Success)
j3 7:78a8857b3810 485 {
j3 7:78a8857b3810 486 // Send CMD and receive Data
j3 17:b646b1e3970b 487 ow_result = _owm.OWWriteByte(CMD_READ_DEVICE_REV);
j3 23:e8e403d61359 488 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 489 {
j3 17:b646b1e3970b 490 ow_result = _owm.OWReadByte(rev);
j3 23:e8e403d61359 491 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 492 {
IanBenzMaxim 73:2cecc1372acc 493 bridge_result = DS28E17::Success;
j3 17:b646b1e3970b 494 }
j3 17:b646b1e3970b 495 else
j3 17:b646b1e3970b 496 {
IanBenzMaxim 73:2cecc1372acc 497 bridge_result = DS28E17::CommsReadByteError;
j3 17:b646b1e3970b 498 }
j3 17:b646b1e3970b 499 }
j3 17:b646b1e3970b 500 else
j3 17:b646b1e3970b 501 {
IanBenzMaxim 73:2cecc1372acc 502 bridge_result = DS28E17::CommsWriteByteError;
j3 17:b646b1e3970b 503 }
j3 7:78a8857b3810 504 }
j3 7:78a8857b3810 505
j3 17:b646b1e3970b 506 return bridge_result;
j3 7:78a8857b3810 507 }
j3 7:78a8857b3810 508
j3 7:78a8857b3810 509
j3 7:78a8857b3810 510 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 511 uint16_t DS28E17::docrc16(uint16_t data)
j3 7:78a8857b3810 512 {
j3 7:78a8857b3810 513 data = ((data ^ (_crc16 & 0xff)) & 0xff);
j3 7:78a8857b3810 514 _crc16 >>= 8;
j3 7:78a8857b3810 515
IanBenzMaxim 73:2cecc1372acc 516 if (DS28E17::_oddparity[data & 0xf] ^ DS28E17::_oddparity[data >> 4])
j3 7:78a8857b3810 517 {
j3 7:78a8857b3810 518 _crc16 ^= 0xc001;
j3 7:78a8857b3810 519 }
j3 7:78a8857b3810 520
j3 7:78a8857b3810 521 data <<= 6;
j3 7:78a8857b3810 522 _crc16 ^= data;
j3 7:78a8857b3810 523 data <<= 1;
j3 7:78a8857b3810 524 _crc16 ^= data;
j3 7:78a8857b3810 525
j3 7:78a8857b3810 526 return _crc16;
j3 7:78a8857b3810 527 }
j3 7:78a8857b3810 528
j3 7:78a8857b3810 529
j3 17:b646b1e3970b 530 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 531 DS28E17::CmdResult DS28E17::send_packet(const uint8_t * data, uint8_t data_length,
j3 17:b646b1e3970b 532 uint8_t & status, uint8_t & wr_status)
j3 17:b646b1e3970b 533 {
IanBenzMaxim 73:2cecc1372acc 534 DS28E17::CmdResult bridge_result = DS28E17::CommsWriteBlockError;
j3 17:b646b1e3970b 535 uint32_t poll_count = 0;
j3 17:b646b1e3970b 536
j3 23:e8e403d61359 537 OneWireMaster::CmdResult ow_result = _owm.OWWriteBlock(data, data_length);
j3 17:b646b1e3970b 538
j3 23:e8e403d61359 539 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 540 {
j3 17:b646b1e3970b 541 // Poll for Zero 1-Wire bit and return if an error occurs
j3 17:b646b1e3970b 542 uint8_t recvbit = 0x01;
j3 17:b646b1e3970b 543 do
j3 17:b646b1e3970b 544 {
j3 17:b646b1e3970b 545 ow_result = _owm.OWReadBit(recvbit);
j3 17:b646b1e3970b 546 }
j3 23:e8e403d61359 547 while(recvbit && (poll_count++ < POLL_LIMIT) && (ow_result == OneWireMaster::Success));
j3 17:b646b1e3970b 548
j3 23:e8e403d61359 549 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 550 {
j3 17:b646b1e3970b 551 if(poll_count < POLL_LIMIT)
j3 17:b646b1e3970b 552 {
j3 17:b646b1e3970b 553 //Read Status and write status
j3 17:b646b1e3970b 554 uint8_t read_block[2];
j3 17:b646b1e3970b 555
j3 17:b646b1e3970b 556 ow_result = _owm.OWReadBlock(read_block, 2);
j3 17:b646b1e3970b 557
j3 23:e8e403d61359 558 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 559 {
j3 17:b646b1e3970b 560 status = read_block[0];
j3 17:b646b1e3970b 561 wr_status = read_block[1];
IanBenzMaxim 73:2cecc1372acc 562 bridge_result = DS28E17::Success;
j3 17:b646b1e3970b 563 }
j3 17:b646b1e3970b 564 else
j3 17:b646b1e3970b 565 {
IanBenzMaxim 73:2cecc1372acc 566 bridge_result = DS28E17::CommsReadBlockError;
j3 17:b646b1e3970b 567 }
j3 17:b646b1e3970b 568 }
j3 17:b646b1e3970b 569 else
j3 17:b646b1e3970b 570 {
IanBenzMaxim 73:2cecc1372acc 571 bridge_result = DS28E17::TimeoutError;
j3 17:b646b1e3970b 572 }
j3 17:b646b1e3970b 573 }
j3 17:b646b1e3970b 574 else
j3 17:b646b1e3970b 575 {
IanBenzMaxim 73:2cecc1372acc 576 bridge_result = DS28E17::CommsReadBitError;
j3 17:b646b1e3970b 577 }
j3 17:b646b1e3970b 578 }
j3 17:b646b1e3970b 579
j3 17:b646b1e3970b 580 return bridge_result;
j3 17:b646b1e3970b 581 }
j3 17:b646b1e3970b 582
j3 17:b646b1e3970b 583
j3 17:b646b1e3970b 584 //*********************************************************************
IanBenzMaxim 73:2cecc1372acc 585 DS28E17::CmdResult DS28E17::send_packet(const uint8_t * data, uint8_t data_length,
j3 17:b646b1e3970b 586 uint8_t & status)
j3 17:b646b1e3970b 587 {
IanBenzMaxim 73:2cecc1372acc 588 DS28E17::CmdResult bridge_result = DS28E17::CommsWriteBlockError;
j3 17:b646b1e3970b 589 uint32_t poll_count = 0;
j3 17:b646b1e3970b 590
j3 23:e8e403d61359 591 OneWireMaster::CmdResult ow_result = _owm.OWWriteBlock(data, data_length);
j3 17:b646b1e3970b 592
j3 23:e8e403d61359 593 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 594 {
j3 17:b646b1e3970b 595 // Poll for Zero 1-Wire bit and return if an error occurs
j3 17:b646b1e3970b 596 uint8_t recvbit = 0x01;
j3 17:b646b1e3970b 597 do
j3 17:b646b1e3970b 598 {
j3 17:b646b1e3970b 599 ow_result = _owm.OWReadBit(recvbit);
j3 17:b646b1e3970b 600 }
j3 23:e8e403d61359 601 while(recvbit && (poll_count++ < POLL_LIMIT) && (ow_result == OneWireMaster::Success));
j3 17:b646b1e3970b 602
j3 23:e8e403d61359 603 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 604 {
j3 17:b646b1e3970b 605 if(poll_count < POLL_LIMIT)
j3 17:b646b1e3970b 606 {
j3 17:b646b1e3970b 607 //Read Status
j3 17:b646b1e3970b 608 ow_result = _owm.OWReadByte(status);
j3 23:e8e403d61359 609 if(ow_result == OneWireMaster::Success)
j3 17:b646b1e3970b 610 {
IanBenzMaxim 73:2cecc1372acc 611 bridge_result = DS28E17::Success;
j3 17:b646b1e3970b 612 }
j3 17:b646b1e3970b 613 else
j3 17:b646b1e3970b 614 {
IanBenzMaxim 73:2cecc1372acc 615 bridge_result = DS28E17::CommsReadByteError;
j3 17:b646b1e3970b 616 }
j3 17:b646b1e3970b 617 }
j3 17:b646b1e3970b 618 else
j3 17:b646b1e3970b 619 {
IanBenzMaxim 73:2cecc1372acc 620 bridge_result = DS28E17::TimeoutError;
j3 17:b646b1e3970b 621 }
j3 17:b646b1e3970b 622 }
j3 17:b646b1e3970b 623 else
j3 17:b646b1e3970b 624 {
IanBenzMaxim 73:2cecc1372acc 625 bridge_result = DS28E17::CommsReadBitError;
j3 17:b646b1e3970b 626 }
j3 17:b646b1e3970b 627 }
j3 17:b646b1e3970b 628
j3 17:b646b1e3970b 629 return bridge_result;
j3 17:b646b1e3970b 630 }
j3 17:b646b1e3970b 631