Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
mfruge
Date:
Tue Aug 13 14:42:37 2019 +0000
Revision:
142:85b71cfd617e
Parent:
141:cf38f48a2a49
Added functions to ROMCommands to add Alarm Search functionality

Who changed what in which revision?

UserRevisionLine numberNew 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 104:3f48daed532b 33 #include "Masters/OneWireMaster.h"
j3 15:f6cb0d906fb6 34
IanBenzMaxim 90:c233d1c265ff 35 namespace OneWire
IanBenzMaxim 77:529edb329ee0 36 {
j3 141:cf38f48a2a49 37 OneWireMaster::CmdResult OneWireMaster::OWWriteBlock(const uint8_t *sendBuf, size_t sendLen)
IanBenzMaxim 77:529edb329ee0 38 {
IanBenzMaxim 120:200109b73e3c 39 CmdResult result = OperationFailure;
IanBenzMaxim 77:529edb329ee0 40
j3 141:cf38f48a2a49 41 for (size_t idx = 0; idx < sendLen; idx++)
IanBenzMaxim 77:529edb329ee0 42 {
IanBenzMaxim 90:c233d1c265ff 43 result = OWWriteByte(sendBuf[idx]);
IanBenzMaxim 90:c233d1c265ff 44 if (result != Success)
IanBenzMaxim 90:c233d1c265ff 45 {
IanBenzMaxim 90:c233d1c265ff 46 break;
IanBenzMaxim 90:c233d1c265ff 47 }
IanBenzMaxim 77:529edb329ee0 48 }
IanBenzMaxim 77:529edb329ee0 49
IanBenzMaxim 90:c233d1c265ff 50 return result;
IanBenzMaxim 77:529edb329ee0 51 }
IanBenzMaxim 77:529edb329ee0 52
j3 141:cf38f48a2a49 53 OneWireMaster::CmdResult OneWireMaster::OWReadBlock(uint8_t *recvBuf, size_t recvLen)
IanBenzMaxim 77:529edb329ee0 54 {
IanBenzMaxim 120:200109b73e3c 55 CmdResult result = OperationFailure;
IanBenzMaxim 77:529edb329ee0 56
j3 141:cf38f48a2a49 57 for (size_t idx = 0; idx < recvLen; idx++)
IanBenzMaxim 77:529edb329ee0 58 {
IanBenzMaxim 90:c233d1c265ff 59 result = OWReadByte(recvBuf[idx]);
IanBenzMaxim 90:c233d1c265ff 60 if (result != Success)
IanBenzMaxim 77:529edb329ee0 61 {
IanBenzMaxim 77:529edb329ee0 62 break;
IanBenzMaxim 77:529edb329ee0 63 }
IanBenzMaxim 90:c233d1c265ff 64 }
IanBenzMaxim 77:529edb329ee0 65
IanBenzMaxim 90:c233d1c265ff 66 return result;
IanBenzMaxim 77:529edb329ee0 67 }
IanBenzMaxim 77:529edb329ee0 68
IanBenzMaxim 90:c233d1c265ff 69 OneWireMaster::CmdResult OneWireMaster::OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb)
IanBenzMaxim 77:529edb329ee0 70 {
IanBenzMaxim 90:c233d1c265ff 71 CmdResult result;
IanBenzMaxim 90:c233d1c265ff 72 result = OWReadBit(sbr);
IanBenzMaxim 90:c233d1c265ff 73 if (result == Success)
IanBenzMaxim 90:c233d1c265ff 74 {
IanBenzMaxim 90:c233d1c265ff 75 result = OWReadBit(tsb);
IanBenzMaxim 90:c233d1c265ff 76 }
IanBenzMaxim 90:c233d1c265ff 77 if (result == Success)
IanBenzMaxim 90:c233d1c265ff 78 {
IanBenzMaxim 90:c233d1c265ff 79 if (sbr)
IanBenzMaxim 90:c233d1c265ff 80 {
IanBenzMaxim 90:c233d1c265ff 81 searchDirection = WriteOne;
IanBenzMaxim 90:c233d1c265ff 82 }
IanBenzMaxim 90:c233d1c265ff 83 else if (tsb)
IanBenzMaxim 90:c233d1c265ff 84 {
IanBenzMaxim 90:c233d1c265ff 85 searchDirection = WriteZero;
IanBenzMaxim 90:c233d1c265ff 86 }
IanBenzMaxim 90:c233d1c265ff 87 // else: use search_direction parameter
IanBenzMaxim 90:c233d1c265ff 88
IanBenzMaxim 90:c233d1c265ff 89 result = OWWriteBit((searchDirection == WriteOne) ? 1 : 0);
IanBenzMaxim 90:c233d1c265ff 90 }
IanBenzMaxim 90:c233d1c265ff 91 return result;
IanBenzMaxim 77:529edb329ee0 92 }
IanBenzMaxim 77:529edb329ee0 93 }