Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Mon May 16 15:18:09 2016 -0500
Revision:
78:0cbbac7f2016
Parent:
77:529edb329ee0
Code cleanup.

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