Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Thu Jun 16 10:45:24 2016 -0500
Revision:
89:3a0e12c9b898
Parent:
88:cac71903b1cd
Child:
90:c233d1c265ff
Added iterator for Resume as a new class to differentiate.

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>
IanBenzMaxim 77:529edb329ee0 37 #include "Masters/OneWireMaster.h"
IanBenzMaxim 77:529edb329ee0 38
IanBenzMaxim 77:529edb329ee0 39 namespace OneWire
IanBenzMaxim 77:529edb329ee0 40 {
IanBenzMaxim 77:529edb329ee0 41 /// Controls selection of 1-Wire devices on the bus through ROM commands.
IanBenzMaxim 77:529edb329ee0 42 class RomIterator
IanBenzMaxim 77:529edb329ee0 43 {
IanBenzMaxim 77:529edb329ee0 44 private:
IanBenzMaxim 77:529edb329ee0 45 OneWireMaster & owMaster;
IanBenzMaxim 77:529edb329ee0 46
IanBenzMaxim 89:3a0e12c9b898 47 protected:
IanBenzMaxim 77:529edb329ee0 48 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 49 RomIterator(OneWireMaster & master) : owMaster(master) { }
IanBenzMaxim 89:3a0e12c9b898 50
IanBenzMaxim 89:3a0e12c9b898 51 public:
IanBenzMaxim 77:529edb329ee0 52 virtual ~RomIterator() { }
IanBenzMaxim 77:529edb329ee0 53
IanBenzMaxim 77:529edb329ee0 54 /// The 1-Wire master used to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 55 OneWireMaster & master() const { return owMaster; }
IanBenzMaxim 77:529edb329ee0 56 };
IanBenzMaxim 77:529edb329ee0 57
IanBenzMaxim 77:529edb329ee0 58 /// Iterates through all 1-Wire devices in a sequential first to last order.
IanBenzMaxim 77:529edb329ee0 59 class ForwardRomIterator : public RomIterator
IanBenzMaxim 77:529edb329ee0 60 {
IanBenzMaxim 77:529edb329ee0 61 public:
IanBenzMaxim 77:529edb329ee0 62 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 63 ForwardRomIterator(OneWireMaster & master) : RomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 64
IanBenzMaxim 77:529edb329ee0 65 /// Indicates that current device is the last.
IanBenzMaxim 77:529edb329ee0 66 virtual bool lastDevice() const = 0;
IanBenzMaxim 77:529edb329ee0 67
IanBenzMaxim 77:529edb329ee0 68 /// Select the first device in the sequence.
IanBenzMaxim 77:529edb329ee0 69 virtual OneWireMaster::CmdResult selectFirstDevice() = 0;
IanBenzMaxim 77:529edb329ee0 70
IanBenzMaxim 77:529edb329ee0 71 /// Select the next device in the sequence.
IanBenzMaxim 77:529edb329ee0 72 virtual OneWireMaster::CmdResult selectNextDevice() = 0;
IanBenzMaxim 77:529edb329ee0 73
IanBenzMaxim 77:529edb329ee0 74 /// Reselect the current device for an additional operation.
IanBenzMaxim 77:529edb329ee0 75 virtual OneWireMaster::CmdResult reselectCurrentDevice() = 0;
IanBenzMaxim 77:529edb329ee0 76 };
IanBenzMaxim 77:529edb329ee0 77
IanBenzMaxim 77:529edb329ee0 78 /// Iterates through all 1-Wire devices sequentially using the search procedure.
IanBenzMaxim 77:529edb329ee0 79 class ForwardSearchRomIterator : public ForwardRomIterator
IanBenzMaxim 77:529edb329ee0 80 {
IanBenzMaxim 77:529edb329ee0 81 protected:
IanBenzMaxim 77:529edb329ee0 82 OneWireMaster::SearchState searchState;
IanBenzMaxim 77:529edb329ee0 83
IanBenzMaxim 77:529edb329ee0 84 public:
IanBenzMaxim 77:529edb329ee0 85 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 86 ForwardSearchRomIterator(OneWireMaster & master) : ForwardRomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 87
IanBenzMaxim 77:529edb329ee0 88 /// ROM ID of the currently selected device.
IanBenzMaxim 77:529edb329ee0 89 const RomId & selectedDevice() const { return searchState.romId; }
IanBenzMaxim 77:529edb329ee0 90
IanBenzMaxim 77:529edb329ee0 91 virtual bool lastDevice() const;
IanBenzMaxim 77:529edb329ee0 92 virtual OneWireMaster::CmdResult selectFirstDevice();
IanBenzMaxim 77:529edb329ee0 93 virtual OneWireMaster::CmdResult selectNextDevice();
IanBenzMaxim 77:529edb329ee0 94 virtual OneWireMaster::CmdResult reselectCurrentDevice();
IanBenzMaxim 77:529edb329ee0 95
IanBenzMaxim 77:529edb329ee0 96 /// Select the first device in the sequence beginning with the given family.
IanBenzMaxim 77:529edb329ee0 97 /// @param familyCode Family code to select.
IanBenzMaxim 77:529edb329ee0 98 OneWireMaster::CmdResult selectFirstDeviceInFamily(uint8_t familyCode);
IanBenzMaxim 77:529edb329ee0 99
IanBenzMaxim 77:529edb329ee0 100 /// Select the first device in the next sequential family skipping all remaining devices
IanBenzMaxim 77:529edb329ee0 101 /// in the current family.
IanBenzMaxim 77:529edb329ee0 102 OneWireMaster::CmdResult selectNextFamilyDevice();
IanBenzMaxim 77:529edb329ee0 103 };
IanBenzMaxim 77:529edb329ee0 104
IanBenzMaxim 77:529edb329ee0 105 /// Iterates though 1-Wire devices on the bus using random selection by ROM ID.
IanBenzMaxim 77:529edb329ee0 106 class RandomAccessRomIterator : public RomIterator
IanBenzMaxim 77:529edb329ee0 107 {
IanBenzMaxim 77:529edb329ee0 108 public:
IanBenzMaxim 77:529edb329ee0 109 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 110 RandomAccessRomIterator(OneWireMaster & master) : RomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 111
IanBenzMaxim 77:529edb329ee0 112 /// Select the device with the given ROM ID.
IanBenzMaxim 77:529edb329ee0 113 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId) = 0;
IanBenzMaxim 77:529edb329ee0 114 };
IanBenzMaxim 77:529edb329ee0 115
IanBenzMaxim 77:529edb329ee0 116 /// Iterator for a singledrop 1-Wire bus.
IanBenzMaxim 77:529edb329ee0 117 class SingledropRomIterator : public RandomAccessRomIterator
IanBenzMaxim 77:529edb329ee0 118 {
IanBenzMaxim 77:529edb329ee0 119 public:
IanBenzMaxim 77:529edb329ee0 120 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 121 SingledropRomIterator(OneWireMaster & master) : RandomAccessRomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 122
IanBenzMaxim 77:529edb329ee0 123 /// Select the one and only device.
IanBenzMaxim 77:529edb329ee0 124 OneWireMaster::CmdResult selectDevice() { return master().OWSkipRom(); }
IanBenzMaxim 77:529edb329ee0 125 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
IanBenzMaxim 77:529edb329ee0 126 };
IanBenzMaxim 77:529edb329ee0 127
IanBenzMaxim 77:529edb329ee0 128 /// Iterator for a multidrop 1-Wire bus.
IanBenzMaxim 77:529edb329ee0 129 class MultidropRomIterator : public RandomAccessRomIterator
IanBenzMaxim 88:cac71903b1cd 130 {
IanBenzMaxim 77:529edb329ee0 131 public:
IanBenzMaxim 77:529edb329ee0 132 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 77:529edb329ee0 133 MultidropRomIterator(OneWireMaster & master) : RandomAccessRomIterator(master) { }
IanBenzMaxim 77:529edb329ee0 134
IanBenzMaxim 77:529edb329ee0 135 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
IanBenzMaxim 77:529edb329ee0 136 };
IanBenzMaxim 89:3a0e12c9b898 137
IanBenzMaxim 89:3a0e12c9b898 138 /// Iterator for a multidrop 1-Wire bus where slaves support the Resume ROM command.
IanBenzMaxim 89:3a0e12c9b898 139 class MultidropRomIteratorWithResume : public RandomAccessRomIterator
IanBenzMaxim 89:3a0e12c9b898 140 {
IanBenzMaxim 89:3a0e12c9b898 141 private:
IanBenzMaxim 89:3a0e12c9b898 142 RomId lastRom;
IanBenzMaxim 89:3a0e12c9b898 143
IanBenzMaxim 89:3a0e12c9b898 144 public:
IanBenzMaxim 89:3a0e12c9b898 145 /// @param master 1-Wire master to use to issue ROM commands.
IanBenzMaxim 89:3a0e12c9b898 146 MultidropRomIteratorWithResume(OneWireMaster & master)
IanBenzMaxim 89:3a0e12c9b898 147 : RandomAccessRomIterator(master), lastRom() { }
IanBenzMaxim 89:3a0e12c9b898 148
IanBenzMaxim 89:3a0e12c9b898 149 virtual OneWireMaster::CmdResult selectDevice(const RomId & romId);
IanBenzMaxim 89:3a0e12c9b898 150 };
IanBenzMaxim 77:529edb329ee0 151 }
IanBenzMaxim 77:529edb329ee0 152
IanBenzMaxim 77:529edb329ee0 153 #endif