Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: RomId/RomCommands.h
- Revision:
- 103:6dcbb5166da1
- Parent:
- 99:871eb0058a16
- Child:
- 104:3f48daed532b
diff -r d3a7e4990b59 -r 6dcbb5166da1 RomId/RomCommands.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RomId/RomCommands.h Thu Jul 07 13:56:44 2016 -0500 @@ -0,0 +1,87 @@ +/// @file RomCommands.h + +#ifndef OneWire_RomCommands +#define OneWire_RomCommands + +#include <stdint.h> +#include "RomId.h" +#include "Masters/OneWireMaster.h" + +namespace OneWire +{ + /// Procedural 1-Wire ROM Commands for enumerating and selecting devices. + namespace RomCommands + { + /// State used by all ROM ID search functions. + struct SearchState + { + RomId romId; + uint8_t last_discrepancy; + uint8_t last_family_discrepancy; + bool last_device_flag; + + /// Reset to the search state to start at the beginning. + void reset(); + + /// Setup the search to find the device type 'family_code' + /// on the next call to OWNext() if it is present. + void findFamily(uint8_t familyCode); + + /// Setup the search to skip the current device type on the + /// next call to OWNext(). + void skipCurrentFamily(); + + SearchState() { reset(); } + }; + + ///Find the 'first' devices on the 1-Wire bus. + OneWireMaster::CmdResult OWFirst(OneWireMaster & master, SearchState & searchState); + + /// Find the 'next' devices on the 1-Wire bus. + OneWireMaster::CmdResult OWNext(OneWireMaster & master, SearchState & searchState); + + /// Verify that the device with the specified ROM ID is present. + OneWireMaster::CmdResult OWVerify(OneWireMaster & master, const RomId & romId); + + /// Use Read ROM command to read ROM ID from device on bus. + /// @note Only use this command with a single drop bus, data + /// collisions will occur if more than 1 device on bus. + /// @param[out] romId ROM ID read from device. + OneWireMaster::CmdResult OWReadRom(OneWireMaster & master, RomId & romId); + + /// Issue Skip ROM command on bus. + /// @note Only use this command with a single drop bus, data + /// collisions will occur if more than 1 device on bus. + OneWireMaster::CmdResult OWSkipRom(OneWireMaster & master); + + /// Use the Match ROM command to select the device by its known ID. + /// @note This command causes all devices supporting Overdrive + /// mode to switch to Overdrive timing. + /// @param[in] romId ROM ID of device to select. + OneWireMaster::CmdResult OWMatchRom(OneWireMaster & master, const RomId & romId); + + /// Issue Overdrive Skip ROM command on bus. + /// @note This command causes all devices supporting Overdrive + /// mode to switch to Overdrive timing. + /// @note Only use this command with a single drop bus, data + /// collisions will occur if more than 1 device on bus. + OneWireMaster::CmdResult OWOverdriveSkipRom(OneWireMaster & master); + + /// Use the Overdrive Match ROM command to select the device by its known ID. + /// @param[in] romId ROM ID of device to select. + OneWireMaster::CmdResult OWOverdriveMatchRom(OneWireMaster & master, const RomId & romId); + + /// Perform a Resume ROM command on bus. + /// @details Resumes communication with the last device selected + /// though a Match ROM or Search ROM operation. + OneWireMaster::CmdResult OWResume(OneWireMaster & master); + + /// Find device on the 1-Wire bus. + /// @details This command uses the Search ROM command to enumerate all 1-Wire devices in sequence. + /// Begin with a new search state and continue using the same search state until the last + /// device flag is set which indicates that all devices have been discovered. + OneWireMaster::CmdResult OWSearch(OneWireMaster & master, SearchState & searchState); + } +} + +#endif