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 98:c4ac93efc036 1 /// @file RomCommands.h
j3 104:3f48daed532b 2 /******************************************************************//**
j3 104:3f48daed532b 3 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 104:3f48daed532b 4 *
j3 104:3f48daed532b 5 * Permission is hereby granted, free of charge, to any person obtaining a
j3 104:3f48daed532b 6 * copy of this software and associated documentation files (the "Software"),
j3 104:3f48daed532b 7 * to deal in the Software without restriction, including without limitation
j3 104:3f48daed532b 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 104:3f48daed532b 9 * and/or sell copies of the Software, and to permit persons to whom the
j3 104:3f48daed532b 10 * Software is furnished to do so, subject to the following conditions:
j3 104:3f48daed532b 11 *
j3 104:3f48daed532b 12 * The above copyright notice and this permission notice shall be included
j3 104:3f48daed532b 13 * in all copies or substantial portions of the Software.
j3 104:3f48daed532b 14 *
j3 104:3f48daed532b 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 104:3f48daed532b 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 104:3f48daed532b 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 104:3f48daed532b 18 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 104:3f48daed532b 19 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 104:3f48daed532b 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 104:3f48daed532b 21 * OTHER DEALINGS IN THE SOFTWARE.
j3 104:3f48daed532b 22 *
j3 104:3f48daed532b 23 * Except as contained in this notice, the name of Maxim Integrated
j3 104:3f48daed532b 24 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 104:3f48daed532b 25 * Products, Inc. Branding Policy.
j3 104:3f48daed532b 26 *
j3 104:3f48daed532b 27 * The mere transfer of this software does not imply any licenses
j3 104:3f48daed532b 28 * of trade secrets, proprietary technology, copyrights, patents,
j3 104:3f48daed532b 29 * trademarks, maskwork rights, or any other form of intellectual
j3 104:3f48daed532b 30 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 104:3f48daed532b 31 * ownership rights.
j3 104:3f48daed532b 32 **********************************************************************/
IanBenzMaxim 98:c4ac93efc036 33
IanBenzMaxim 90:c233d1c265ff 34 #ifndef OneWire_RomCommands
IanBenzMaxim 90:c233d1c265ff 35 #define OneWire_RomCommands
IanBenzMaxim 90:c233d1c265ff 36
IanBenzMaxim 90:c233d1c265ff 37 #include <stdint.h>
j3 104:3f48daed532b 38 #include "RomId/RomId.h"
IanBenzMaxim 90:c233d1c265ff 39 #include "Masters/OneWireMaster.h"
IanBenzMaxim 90:c233d1c265ff 40
IanBenzMaxim 90:c233d1c265ff 41 namespace OneWire
IanBenzMaxim 90:c233d1c265ff 42 {
IanBenzMaxim 99:871eb0058a16 43 /// Procedural 1-Wire ROM Commands for enumerating and selecting devices.
IanBenzMaxim 90:c233d1c265ff 44 namespace RomCommands
IanBenzMaxim 90:c233d1c265ff 45 {
IanBenzMaxim 90:c233d1c265ff 46 /// State used by all ROM ID search functions.
IanBenzMaxim 90:c233d1c265ff 47 struct SearchState
IanBenzMaxim 90:c233d1c265ff 48 {
IanBenzMaxim 90:c233d1c265ff 49 RomId romId;
IanBenzMaxim 90:c233d1c265ff 50 uint8_t last_discrepancy;
IanBenzMaxim 90:c233d1c265ff 51 uint8_t last_family_discrepancy;
IanBenzMaxim 90:c233d1c265ff 52 bool last_device_flag;
IanBenzMaxim 90:c233d1c265ff 53
IanBenzMaxim 90:c233d1c265ff 54 /// Reset to the search state to start at the beginning.
IanBenzMaxim 90:c233d1c265ff 55 void reset();
IanBenzMaxim 90:c233d1c265ff 56
IanBenzMaxim 90:c233d1c265ff 57 /// Setup the search to find the device type 'family_code'
IanBenzMaxim 90:c233d1c265ff 58 /// on the next call to OWNext() if it is present.
IanBenzMaxim 90:c233d1c265ff 59 void findFamily(uint8_t familyCode);
IanBenzMaxim 90:c233d1c265ff 60
IanBenzMaxim 90:c233d1c265ff 61 /// Setup the search to skip the current device type on the
IanBenzMaxim 90:c233d1c265ff 62 /// next call to OWNext().
IanBenzMaxim 90:c233d1c265ff 63 void skipCurrentFamily();
IanBenzMaxim 90:c233d1c265ff 64
IanBenzMaxim 90:c233d1c265ff 65 SearchState() { reset(); }
IanBenzMaxim 90:c233d1c265ff 66 };
IanBenzMaxim 90:c233d1c265ff 67
j3 93:e496a45ce796 68 ///Find the 'first' devices on the 1-Wire bus.
IanBenzMaxim 90:c233d1c265ff 69 OneWireMaster::CmdResult OWFirst(OneWireMaster & master, SearchState & searchState);
IanBenzMaxim 90:c233d1c265ff 70
IanBenzMaxim 90:c233d1c265ff 71 /// Find the 'next' devices on the 1-Wire bus.
IanBenzMaxim 90:c233d1c265ff 72 OneWireMaster::CmdResult OWNext(OneWireMaster & master, SearchState & searchState);
IanBenzMaxim 90:c233d1c265ff 73
IanBenzMaxim 90:c233d1c265ff 74 /// Verify that the device with the specified ROM ID is present.
IanBenzMaxim 90:c233d1c265ff 75 OneWireMaster::CmdResult OWVerify(OneWireMaster & master, const RomId & romId);
IanBenzMaxim 90:c233d1c265ff 76
IanBenzMaxim 90:c233d1c265ff 77 /// Use Read ROM command to read ROM ID from device on bus.
IanBenzMaxim 90:c233d1c265ff 78 /// @note Only use this command with a single drop bus, data
IanBenzMaxim 90:c233d1c265ff 79 /// collisions will occur if more than 1 device on bus.
IanBenzMaxim 90:c233d1c265ff 80 /// @param[out] romId ROM ID read from device.
IanBenzMaxim 90:c233d1c265ff 81 OneWireMaster::CmdResult OWReadRom(OneWireMaster & master, RomId & romId);
IanBenzMaxim 90:c233d1c265ff 82
IanBenzMaxim 90:c233d1c265ff 83 /// Issue Skip ROM command on bus.
IanBenzMaxim 90:c233d1c265ff 84 /// @note Only use this command with a single drop bus, data
IanBenzMaxim 90:c233d1c265ff 85 /// collisions will occur if more than 1 device on bus.
IanBenzMaxim 90:c233d1c265ff 86 OneWireMaster::CmdResult OWSkipRom(OneWireMaster & master);
IanBenzMaxim 90:c233d1c265ff 87
IanBenzMaxim 90:c233d1c265ff 88 /// Use the Match ROM command to select the device by its known ID.
IanBenzMaxim 90:c233d1c265ff 89 /// @note This command causes all devices supporting Overdrive
IanBenzMaxim 90:c233d1c265ff 90 /// mode to switch to Overdrive timing.
IanBenzMaxim 90:c233d1c265ff 91 /// @param[in] romId ROM ID of device to select.
IanBenzMaxim 90:c233d1c265ff 92 OneWireMaster::CmdResult OWMatchRom(OneWireMaster & master, const RomId & romId);
IanBenzMaxim 90:c233d1c265ff 93
IanBenzMaxim 90:c233d1c265ff 94 /// Issue Overdrive Skip ROM command on bus.
IanBenzMaxim 90:c233d1c265ff 95 /// @note This command causes all devices supporting Overdrive
IanBenzMaxim 90:c233d1c265ff 96 /// mode to switch to Overdrive timing.
IanBenzMaxim 90:c233d1c265ff 97 /// @note Only use this command with a single drop bus, data
IanBenzMaxim 90:c233d1c265ff 98 /// collisions will occur if more than 1 device on bus.
IanBenzMaxim 90:c233d1c265ff 99 OneWireMaster::CmdResult OWOverdriveSkipRom(OneWireMaster & master);
IanBenzMaxim 90:c233d1c265ff 100
IanBenzMaxim 90:c233d1c265ff 101 /// Use the Overdrive Match ROM command to select the device by its known ID.
IanBenzMaxim 90:c233d1c265ff 102 /// @param[in] romId ROM ID of device to select.
IanBenzMaxim 90:c233d1c265ff 103 OneWireMaster::CmdResult OWOverdriveMatchRom(OneWireMaster & master, const RomId & romId);
IanBenzMaxim 90:c233d1c265ff 104
IanBenzMaxim 90:c233d1c265ff 105 /// Perform a Resume ROM command on bus.
IanBenzMaxim 90:c233d1c265ff 106 /// @details Resumes communication with the last device selected
IanBenzMaxim 90:c233d1c265ff 107 /// though a Match ROM or Search ROM operation.
IanBenzMaxim 90:c233d1c265ff 108 OneWireMaster::CmdResult OWResume(OneWireMaster & master);
IanBenzMaxim 90:c233d1c265ff 109
IanBenzMaxim 90:c233d1c265ff 110 /// Find device on the 1-Wire bus.
IanBenzMaxim 90:c233d1c265ff 111 /// @details This command uses the Search ROM command to enumerate all 1-Wire devices in sequence.
IanBenzMaxim 90:c233d1c265ff 112 /// Begin with a new search state and continue using the same search state until the last
IanBenzMaxim 90:c233d1c265ff 113 /// device flag is set which indicates that all devices have been discovered.
IanBenzMaxim 90:c233d1c265ff 114 OneWireMaster::CmdResult OWSearch(OneWireMaster & master, SearchState & searchState);
mfruge 142:85b71cfd617e 115
mfruge 142:85b71cfd617e 116 /// Find Alarming Devices on 1-Wire bus.
mfruge 142:85b71cfd617e 117 /// @details This command uses the Alarm Search ROM command to enumerate all 1-Wire devices with active alarms
mfruge 142:85b71cfd617e 118 /// Begin with a new search state and continue using the same search state until the last
mfruge 142:85b71cfd617e 119 /// device flag is set which indicates that all devices have been discovered.
mfruge 142:85b71cfd617e 120 OneWireMaster::CmdResult OWAlarmSearch(OneWireMaster & master, SearchState & searchState);
mfruge 142:85b71cfd617e 121
mfruge 142:85b71cfd617e 122 /// Find the first Alarming device on the 1-Wire bus.
mfruge 142:85b71cfd617e 123 /// @details This command resets the SearchState and uses the Alarm Search command to enumerate the first actively alarming device on the bus, in numerical order by ROM ID.
mfruge 142:85b71cfd617e 124 OneWireMaster::CmdResult OWFirstAlarm(OneWireMaster & master, SearchState & searchState);
mfruge 142:85b71cfd617e 125
mfruge 142:85b71cfd617e 126 /// Find the next Alarming Device on the 1-Wire bus.
mfruge 142:85b71cfd617e 127 /// @details This command uses the Alarm Search command to enumerate the next actively alarming device on the bus, which is determined by the current searchState.
mfruge 142:85b71cfd617e 128 OneWireMaster::CmdResult OWNextAlarm(OneWireMaster & master, SearchState & searchState);
mfruge 142:85b71cfd617e 129
mfruge 142:85b71cfd617e 130 /// Helper function for the above search functions
mfruge 142:85b71cfd617e 131 OneWireMaster::CmdResult OWSearchAll(OneWireMaster & master, SearchState & searchState, bool alarmSearch);
mfruge 142:85b71cfd617e 132
IanBenzMaxim 90:c233d1c265ff 133 }
IanBenzMaxim 90:c233d1c265ff 134 }
IanBenzMaxim 90:c233d1c265ff 135
IanBenzMaxim 90:c233d1c265ff 136 #endif