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:
104:3f48daed532b
Added functions to ROMCommands to add Alarm Search functionality

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 78:0cbbac7f2016 1 /******************************************************************//**
IanBenzMaxim 78:0cbbac7f2016 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 78:0cbbac7f2016 3 *
IanBenzMaxim 78:0cbbac7f2016 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 78:0cbbac7f2016 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 78:0cbbac7f2016 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 78:0cbbac7f2016 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 78:0cbbac7f2016 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 78:0cbbac7f2016 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 78:0cbbac7f2016 10 *
IanBenzMaxim 78:0cbbac7f2016 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 78:0cbbac7f2016 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 78:0cbbac7f2016 13 *
IanBenzMaxim 78:0cbbac7f2016 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 78:0cbbac7f2016 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 78:0cbbac7f2016 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 78:0cbbac7f2016 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 78:0cbbac7f2016 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 78:0cbbac7f2016 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 78:0cbbac7f2016 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 78:0cbbac7f2016 21 *
IanBenzMaxim 78:0cbbac7f2016 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 78:0cbbac7f2016 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 78:0cbbac7f2016 24 * Products, Inc. Branding Policy.
IanBenzMaxim 78:0cbbac7f2016 25 *
IanBenzMaxim 78:0cbbac7f2016 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 78:0cbbac7f2016 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 78:0cbbac7f2016 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 78:0cbbac7f2016 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 78:0cbbac7f2016 30 * ownership rights.
IanBenzMaxim 78:0cbbac7f2016 31 **********************************************************************/
IanBenzMaxim 78:0cbbac7f2016 32
IanBenzMaxim 77:529edb329ee0 33 #ifndef OneWire_RomIterator
IanBenzMaxim 77:529edb329ee0 34 #define OneWire_RomIterator
IanBenzMaxim 77:529edb329ee0 35
IanBenzMaxim 77:529edb329ee0 36 #include <stdint.h>
j3 104:3f48daed532b 37 #include "RomId/RomCommands.h"
IanBenzMaxim 77:529edb329ee0 38
IanBenzMaxim 77:529edb329ee0 39 namespace OneWire
IanBenzMaxim 77:529edb329ee0 40 {
IanBenzMaxim 90:c233d1c265ff 41 class OneWireMaster;
IanBenzMaxim 90:c233d1c265ff 42
IanBenzMaxim 77:529edb329ee0 43 /// Controls selection of 1-Wire devices on the bus through ROM commands.
IanBenzMaxim 77:529edb329ee0 44 class RomIterator
IanBenzMaxim 77:529edb329ee0 45 {
IanBenzMaxim 77:529edb329ee0 46 private:
IanBenzMaxim 77:529edb329ee0 47 OneWireMaster & owMaster;
IanBenzMaxim 77:529edb329ee0 48
IanBenzMaxim 89:3a0e12c9b898 49 protected:
IanBenzMaxim 77:529edb329ee0 50 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 51 RomIterator(OneWireMaster & master) : owMaster(master) { }
IanBenzMaxim 89:3a0e12c9b898 52
IanBenzMaxim 89:3a0e12c9b898 53 public:
IanBenzMaxim 77:529edb329ee0 54 virtual ~RomIterator() { }
IanBenzMaxim 77:529edb329ee0 55
IanBenzMaxim 77:529edb329ee0 56 /// The 1-Wire master used to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 57 OneWireMaster & master() const { return owMaster; }
IanBenzMaxim 77:529edb329ee0 58 };
IanBenzMaxim 77:529edb329ee0 59
IanBenzMaxim 77:529edb329ee0 60 /// Iterates through all 1-Wire devices in a sequential first to last order.
IanBenzMaxim 77:529edb329ee0 61 class ForwardRomIterator : public RomIterator
IanBenzMaxim 77:529edb329ee0 62 {
IanBenzMaxim 77:529edb329ee0 63 public:
IanBenzMaxim 77:529edb329ee0 64 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 65 ForwardRomIterator(OneWireMaster & master) : RomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 66
IanBenzMaxim 77:529edb329ee0 67 /// Indicates that current device is the last.
IanBenzMaxim 77:529edb329ee0 68 virtual bool lastDevice() const = 0;
IanBenzMaxim 77:529edb329ee0 69
IanBenzMaxim 77:529edb329ee0 70 /// Select the first device in the sequence.
IanBenzMaxim 77:529edb329ee0 71 virtual OneWireMaster::CmdResult selectFirstDevice() = 0;
IanBenzMaxim 77:529edb329ee0 72
IanBenzMaxim 77:529edb329ee0 73 /// Select the next device in the sequence.
IanBenzMaxim 77:529edb329ee0 74 virtual OneWireMaster::CmdResult selectNextDevice() = 0;
IanBenzMaxim 77:529edb329ee0 75
IanBenzMaxim 77:529edb329ee0 76 /// Reselect the current device for an additional operation.
IanBenzMaxim 77:529edb329ee0 77 virtual OneWireMaster::CmdResult reselectCurrentDevice() = 0;
IanBenzMaxim 77:529edb329ee0 78 };
IanBenzMaxim 77:529edb329ee0 79
IanBenzMaxim 77:529edb329ee0 80 /// Iterates through all 1-Wire devices sequentially using the search procedure.
IanBenzMaxim 77:529edb329ee0 81 class ForwardSearchRomIterator : public ForwardRomIterator
IanBenzMaxim 77:529edb329ee0 82 {
IanBenzMaxim 77:529edb329ee0 83 protected:
IanBenzMaxim 90:c233d1c265ff 84 RomCommands::SearchState searchState;
IanBenzMaxim 77:529edb329ee0 85
IanBenzMaxim 77:529edb329ee0 86 public:
IanBenzMaxim 77:529edb329ee0 87 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 88 ForwardSearchRomIterator(OneWireMaster & master) : ForwardRomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 89
IanBenzMaxim 77:529edb329ee0 90 /// ROM ID of the currently selected device.
IanBenzMaxim 77:529edb329ee0 91 const RomId & selectedDevice() const { return searchState.romId; }
IanBenzMaxim 77:529edb329ee0 92
IanBenzMaxim 77:529edb329ee0 93 virtual bool lastDevice() const;
IanBenzMaxim 77:529edb329ee0 94 virtual OneWireMaster::CmdResult selectFirstDevice();
IanBenzMaxim 77:529edb329ee0 95 virtual OneWireMaster::CmdResult selectNextDevice();
IanBenzMaxim 77:529edb329ee0 96 virtual OneWireMaster::CmdResult reselectCurrentDevice();
IanBenzMaxim 77:529edb329ee0 97
IanBenzMaxim 77:529edb329ee0 98 /// Select the first device in the sequence beginning with the given family.
IanBenzMaxim 77:529edb329ee0 99 /// @param familyCode Family code to select.
IanBenzMaxim 77:529edb329ee0 100 OneWireMaster::CmdResult selectFirstDeviceInFamily(uint8_t familyCode);
IanBenzMaxim 77:529edb329ee0 101
IanBenzMaxim 77:529edb329ee0 102 /// Select the first device in the next sequential family skipping all remaining devices
IanBenzMaxim 77:529edb329ee0 103 /// in the current family.
IanBenzMaxim 77:529edb329ee0 104 OneWireMaster::CmdResult selectNextFamilyDevice();
IanBenzMaxim 77:529edb329ee0 105 };
IanBenzMaxim 77:529edb329ee0 106
IanBenzMaxim 77:529edb329ee0 107 /// Iterates though 1-Wire devices on the bus using random selection by ROM ID.
IanBenzMaxim 77:529edb329ee0 108 class RandomAccessRomIterator : public RomIterator
IanBenzMaxim 77:529edb329ee0 109 {
IanBenzMaxim 77:529edb329ee0 110 public:
IanBenzMaxim 77:529edb329ee0 111 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 112 RandomAccessRomIterator(OneWireMaster & master) : RomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 113
IanBenzMaxim 77:529edb329ee0 114 /// Select the device with the given ROM ID.
IanBenzMaxim 77:529edb329ee0 115 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId) = 0;
IanBenzMaxim 77:529edb329ee0 116 };
IanBenzMaxim 77:529edb329ee0 117
IanBenzMaxim 77:529edb329ee0 118 /// Iterator for a singledrop 1-Wire bus.
IanBenzMaxim 77:529edb329ee0 119 class SingledropRomIterator : public RandomAccessRomIterator
IanBenzMaxim 77:529edb329ee0 120 {
IanBenzMaxim 77:529edb329ee0 121 public:
IanBenzMaxim 77:529edb329ee0 122 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 123 SingledropRomIterator(OneWireMaster & master) : RandomAccessRomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 124
IanBenzMaxim 77:529edb329ee0 125 /// Select the one and only device.
IanBenzMaxim 90:c233d1c265ff 126 OneWireMaster::CmdResult selectDevice() { return RomCommands::OWSkipRom(master()); }
IanBenzMaxim 77:529edb329ee0 127 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
IanBenzMaxim 77:529edb329ee0 128 };
IanBenzMaxim 77:529edb329ee0 129
IanBenzMaxim 77:529edb329ee0 130 /// Iterator for a multidrop 1-Wire bus.
IanBenzMaxim 77:529edb329ee0 131 class MultidropRomIterator : public RandomAccessRomIterator
IanBenzMaxim 88:cac71903b1cd 132 {
IanBenzMaxim 77:529edb329ee0 133 public:
IanBenzMaxim 77:529edb329ee0 134 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 135 MultidropRomIterator(OneWireMaster & master) : RandomAccessRomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 136
IanBenzMaxim 77:529edb329ee0 137 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
IanBenzMaxim 77:529edb329ee0 138 };
IanBenzMaxim 89:3a0e12c9b898 139
IanBenzMaxim 89:3a0e12c9b898 140 /// Iterator for a multidrop 1-Wire bus where slaves support the Resume ROM command.
IanBenzMaxim 89:3a0e12c9b898 141 class MultidropRomIteratorWithResume : public RandomAccessRomIterator
IanBenzMaxim 89:3a0e12c9b898 142 {
IanBenzMaxim 89:3a0e12c9b898 143 private:
IanBenzMaxim 89:3a0e12c9b898 144 RomId lastRom;
IanBenzMaxim 89:3a0e12c9b898 145
IanBenzMaxim 89:3a0e12c9b898 146 public:
IanBenzMaxim 89:3a0e12c9b898 147 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 89:3a0e12c9b898 148 MultidropRomIteratorWithResume(OneWireMaster & master)
IanBenzMaxim 89:3a0e12c9b898 149 : RandomAccessRomIterator(master), lastRom() { }
IanBenzMaxim 89:3a0e12c9b898 150
IanBenzMaxim 89:3a0e12c9b898 151 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
IanBenzMaxim 89:3a0e12c9b898 152 };
IanBenzMaxim 77:529edb329ee0 153 }
IanBenzMaxim 77:529edb329ee0 154
IanBenzMaxim 77:529edb329ee0 155 #endif