Aleksandrs Gumenuks / MaximInterface_Extended

Dependents:   mbed_DS28EC20_GPIO

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RomCommands.hpp Source File

RomCommands.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2017 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 MaximInterface_RomCommands
00037 #define MaximInterface_RomCommands
00038 
00039 #include <stdint.h>
00040 #include <MaximInterface/Utilities/Export.h>
00041 #include <MaximInterface/Utilities/RomId.hpp>
00042 #include "OneWireMaster.hpp"
00043 
00044 namespace MaximInterface {
00045 
00046 /// State used by Search ROM command.
00047 struct SearchRomState {
00048   RomId::array romId;
00049   int_least8_t lastDiscrepancy;
00050   int_least8_t lastFamilyDiscrepancy;
00051   bool lastDevice;
00052 
00053   SearchRomState()
00054       : romId(), lastDiscrepancy(0), lastFamilyDiscrepancy(0),
00055         lastDevice(false) {}
00056     
00057   explicit SearchRomState(RomId::const_span romId)
00058       : lastDiscrepancy(64), lastFamilyDiscrepancy(0), lastDevice(false) {
00059     copy(romId, make_span(this->romId));
00060   }
00061       
00062   explicit SearchRomState(RomId::element familyCode)
00063       : romId(), lastDiscrepancy(64), lastFamilyDiscrepancy(0),
00064         lastDevice(false) {
00065     setFamilyCode(romId, familyCode);
00066   }
00067 };
00068 
00069 /// @brief
00070 /// Set the search state to skip the current device family on the next
00071 /// Search ROM command.
00072 MaximInterface_EXPORT void skipCurrentFamily(SearchRomState & searchState);
00073 
00074 /// Verify that the device with the specified ROM ID is present.
00075 MaximInterface_EXPORT error_code verifyRom(OneWireMaster & master,
00076                                            RomId::const_span romId);
00077 
00078 /// @brief Use Read ROM command to read ROM ID from device on bus.
00079 /// @note
00080 /// Only use this command with a single-drop bus.
00081 /// Data collisions will occur if there is more than one device on the bus.
00082 /// @param master 1-Wire master for operation.
00083 /// @param[out] romId ROM ID read from device.
00084 MaximInterface_EXPORT error_code readRom(OneWireMaster & master,
00085                                          RomId::span romId);
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 MaximInterface_EXPORT error_code 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 MaximInterface_EXPORT error_code 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 MaximInterface_EXPORT error_code 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 MaximInterface_EXPORT error_code overdriveMatchRom(OneWireMaster & master,
00116                                                    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 MaximInterface_EXPORT error_code 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 MaximInterface_EXPORT error_code searchRom(OneWireMaster & master,
00131                                            SearchRomState & searchState);
00132 
00133 } // namespace MaximInterface
00134 
00135 #endif