Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Tue Sep 06 09:25:52 2016 -0500
Revision:
120:200109b73e3c
Parent:
104:3f48daed532b
Child:
139:f0e0a7976846
Fixed potential issues flagged by GCC.

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