Device interface library for multiple platforms including Mbed.
Dependents: DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#
RomCommands.hpp
00001 /******************************************************************************* 00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 *******************************************************************************/ 00032 00033 /// @file 00034 /// @brief ROM Commands for enumerating and selecting 1-Wire devices. 00035 00036 #ifndef MaximInterfaceCore_RomCommands_hpp 00037 #define MaximInterfaceCore_RomCommands_hpp 00038 00039 #include <stdint.h> 00040 #include "Algorithm.hpp" 00041 #include "Config.hpp" 00042 #include "OneWireMaster.hpp" 00043 #include "RomId.hpp" 00044 00045 namespace MaximInterfaceCore { 00046 00047 /// State used by Search ROM command. 00048 struct SearchRomState { 00049 RomId::array romId; 00050 int_least8_t lastDiscrepancy; 00051 int_least8_t lastFamilyDiscrepancy; 00052 bool lastDevice; 00053 00054 SearchRomState() 00055 : romId(), lastDiscrepancy(0), lastFamilyDiscrepancy(0), 00056 lastDevice(false) {} 00057 00058 explicit SearchRomState(RomId::const_span romId) 00059 : lastDiscrepancy(64), lastFamilyDiscrepancy(0), lastDevice(false) { 00060 copy(romId, make_span(this->romId)); 00061 } 00062 00063 explicit SearchRomState(RomId::element familyCode) 00064 : romId(), lastDiscrepancy(64), lastFamilyDiscrepancy(0), 00065 lastDevice(false) { 00066 romId.front() = familyCode; 00067 } 00068 }; 00069 00070 /// @brief 00071 /// Set the search state to skip the current device family on the next 00072 /// Search ROM command. 00073 MaximInterfaceCore_EXPORT void skipCurrentFamily(SearchRomState & searchState); 00074 00075 /// Verify that the device with the specified ROM ID is present. 00076 MaximInterfaceCore_EXPORT Result<void> verifyRom(OneWireMaster & master, 00077 RomId::const_span romId); 00078 00079 /// @brief Use Read ROM command to read ROM ID from device on bus. 00080 /// @note 00081 /// Only use this command with a single-drop bus. 00082 /// Data collisions will occur if there is more than one device on the bus. 00083 /// @param master 1-Wire master for operation. 00084 /// @returns ROM ID read from device. 00085 MaximInterfaceCore_EXPORT Result<RomId::array> readRom(OneWireMaster & master); 00086 00087 /// @brief Issue Skip ROM command on bus. 00088 /// @note 00089 /// Only use this command with a single-drop bus. 00090 /// Data collisions will occur if there is more than one device on the bus. 00091 MaximInterfaceCore_EXPORT Result<void> skipRom(OneWireMaster & master); 00092 00093 /// @brief Use the Match ROM command to select the device by its known ID. 00094 /// @note 00095 /// This command causes all devices supporting Overdrive mode to switch to 00096 /// Overdrive timing. 00097 /// @param master 1-Wire master for operation. 00098 /// @param[in] romId ROM ID of device to select. 00099 MaximInterfaceCore_EXPORT Result<void> matchRom(OneWireMaster & master, 00100 RomId::const_span romId); 00101 00102 /// @brief Issue Overdrive Skip ROM command on bus. 00103 /// @note 00104 /// This command causes all devices supporting Overdrive mode to switch to 00105 /// Overdrive timing. 00106 /// @note 00107 /// Only use this command with a single-drop bus. 00108 /// Data collisions will occur if there is more than one device on the bus. 00109 MaximInterfaceCore_EXPORT Result<void> overdriveSkipRom(OneWireMaster & master); 00110 00111 /// @brief 00112 /// Use the Overdrive Match ROM command to select the device by its known ID. 00113 /// @param master 1-Wire master for operation. 00114 /// @param[in] romId ROM ID of device to select. 00115 MaximInterfaceCore_EXPORT Result<void> 00116 overdriveMatchRom(OneWireMaster & master, RomId::const_span romId); 00117 00118 /// @brief Perform a Resume ROM command on bus. 00119 /// @details 00120 /// Resumes communication with the last device selected through a Match ROM or 00121 /// Search ROM operation. 00122 MaximInterfaceCore_EXPORT Result<void> resumeRom(OneWireMaster & master); 00123 00124 /// @brief Find device on the 1-Wire bus. 00125 /// @details 00126 /// This command uses the Search ROM command to enumerate all 1-Wire devices in 00127 /// sequence. Begin with a new search state and continue using the same search 00128 /// state until the last device flag is set which indicates that all devices 00129 /// have been discovered. 00130 MaximInterfaceCore_EXPORT Result<void> searchRom(OneWireMaster & master, 00131 SearchRomState & searchState); 00132 00133 } // namespace MaximInterfaceCore 00134 00135 #endif
Generated on Tue Jul 12 2022 11:13:16 by 1.7.2