1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.
Dependents: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
Superseded by MaximInterface.
Masters/DS2465/DS2465.h@142:85b71cfd617e, 2019-08-13 (annotated)
- Committer:
- mfruge
- Date:
- Tue Aug 13 14:42:37 2019 +0000
- Revision:
- 142:85b71cfd617e
- Parent:
- 141:cf38f48a2a49
Added functions to ROMCommands to add Alarm Search functionality
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IanBenzMaxim | 75:8b627804927c | 1 | /******************************************************************//** |
IanBenzMaxim | 75:8b627804927c | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
IanBenzMaxim | 75:8b627804927c | 3 | * |
IanBenzMaxim | 75:8b627804927c | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
IanBenzMaxim | 75:8b627804927c | 5 | * copy of this software and associated documentation files (the "Software"), |
IanBenzMaxim | 75:8b627804927c | 6 | * to deal in the Software without restriction, including without limitation |
IanBenzMaxim | 75:8b627804927c | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
IanBenzMaxim | 75:8b627804927c | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
IanBenzMaxim | 75:8b627804927c | 9 | * Software is furnished to do so, subject to the following conditions: |
IanBenzMaxim | 75:8b627804927c | 10 | * |
IanBenzMaxim | 75:8b627804927c | 11 | * The above copyright notice and this permission notice shall be included |
IanBenzMaxim | 75:8b627804927c | 12 | * in all copies or substantial portions of the Software. |
IanBenzMaxim | 75:8b627804927c | 13 | * |
IanBenzMaxim | 75:8b627804927c | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
IanBenzMaxim | 75:8b627804927c | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
IanBenzMaxim | 75:8b627804927c | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
IanBenzMaxim | 75:8b627804927c | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
IanBenzMaxim | 75:8b627804927c | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
IanBenzMaxim | 75:8b627804927c | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
IanBenzMaxim | 75:8b627804927c | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
IanBenzMaxim | 75:8b627804927c | 21 | * |
IanBenzMaxim | 75:8b627804927c | 22 | * Except as contained in this notice, the name of Maxim Integrated |
IanBenzMaxim | 75:8b627804927c | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
IanBenzMaxim | 75:8b627804927c | 24 | * Products, Inc. Branding Policy. |
IanBenzMaxim | 75:8b627804927c | 25 | * |
IanBenzMaxim | 75:8b627804927c | 26 | * The mere transfer of this software does not imply any licenses |
IanBenzMaxim | 75:8b627804927c | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
IanBenzMaxim | 75:8b627804927c | 28 | * trademarks, maskwork rights, or any other form of intellectual |
IanBenzMaxim | 75:8b627804927c | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
IanBenzMaxim | 75:8b627804927c | 30 | * ownership rights. |
IanBenzMaxim | 75:8b627804927c | 31 | **********************************************************************/ |
IanBenzMaxim | 75:8b627804927c | 32 | |
IanBenzMaxim | 73:2cecc1372acc | 33 | #ifndef OneWire_Masters_DS2465 |
IanBenzMaxim | 73:2cecc1372acc | 34 | #define OneWire_Masters_DS2465 |
IanBenzMaxim | 21:00c94aeb533e | 35 | |
IanBenzMaxim | 73:2cecc1372acc | 36 | #include "Masters/OneWireMaster.h" |
IanBenzMaxim | 86:2ce08ca58b9e | 37 | #include "Slaves/Authenticators/ISha256MacCoproc.h" |
IanBenzMaxim | 21:00c94aeb533e | 38 | |
IanBenzMaxim | 47:307dc45952db | 39 | namespace mbed { class I2C; } |
IanBenzMaxim | 27:d5aaefa252f1 | 40 | |
IanBenzMaxim | 73:2cecc1372acc | 41 | namespace OneWire |
IanBenzMaxim | 21:00c94aeb533e | 42 | { |
IanBenzMaxim | 76:84e6c4994e29 | 43 | /// Interface to the DS2465 1-Wire master and SHA-256 coprocessor. |
IanBenzMaxim | 76:84e6c4994e29 | 44 | class DS2465 : public OneWireMaster, public ISha256MacCoproc |
IanBenzMaxim | 73:2cecc1372acc | 45 | { |
IanBenzMaxim | 76:84e6c4994e29 | 46 | public: |
IanBenzMaxim | 76:84e6c4994e29 | 47 | /// Delay required after writing an EEPROM segment. |
IanBenzMaxim | 76:84e6c4994e29 | 48 | static const unsigned int eepromSegmentWriteDelayMs = 10; |
IanBenzMaxim | 76:84e6c4994e29 | 49 | /// Delay required after writing an EEPROM page such as the secret memory. |
IanBenzMaxim | 76:84e6c4994e29 | 50 | static const unsigned int eepromPageWriteDelayMs = 8 * eepromSegmentWriteDelayMs; |
IanBenzMaxim | 76:84e6c4994e29 | 51 | /// Delay required for a SHA computation to complete. |
IanBenzMaxim | 76:84e6c4994e29 | 52 | static const unsigned int shaComputationDelayMs = 2; |
IanBenzMaxim | 76:84e6c4994e29 | 53 | |
IanBenzMaxim | 76:84e6c4994e29 | 54 | /// Page region to use for swapping. |
IanBenzMaxim | 76:84e6c4994e29 | 55 | enum PageRegion |
IanBenzMaxim | 76:84e6c4994e29 | 56 | { |
IanBenzMaxim | 78:0cbbac7f2016 | 57 | FullPage = 0x03, |
IanBenzMaxim | 78:0cbbac7f2016 | 58 | FirstHalf = 0x01, |
IanBenzMaxim | 78:0cbbac7f2016 | 59 | SecondHalf = 0x02 |
IanBenzMaxim | 76:84e6c4994e29 | 60 | }; |
IanBenzMaxim | 76:84e6c4994e29 | 61 | |
IanBenzMaxim | 76:84e6c4994e29 | 62 | /// Starting memory addresses. |
IanBenzMaxim | 78:0cbbac7f2016 | 63 | enum MemoryAddress |
IanBenzMaxim | 76:84e6c4994e29 | 64 | { |
IanBenzMaxim | 78:0cbbac7f2016 | 65 | Scratchpad = 0x00, |
IanBenzMaxim | 78:0cbbac7f2016 | 66 | CommandReg = 0x60, |
IanBenzMaxim | 78:0cbbac7f2016 | 67 | StatusReg = 0x61, |
IanBenzMaxim | 78:0cbbac7f2016 | 68 | ReadDataReg = 0x62, |
IanBenzMaxim | 78:0cbbac7f2016 | 69 | MacReadoutReg = 0x63, |
IanBenzMaxim | 78:0cbbac7f2016 | 70 | MemoryProtectionReg = 0x64, |
IanBenzMaxim | 78:0cbbac7f2016 | 71 | ConfigReg = 0x67, |
IanBenzMaxim | 78:0cbbac7f2016 | 72 | tRSTL_Reg = 0x68, |
IanBenzMaxim | 78:0cbbac7f2016 | 73 | tMSP_Reg = 0x69, |
IanBenzMaxim | 78:0cbbac7f2016 | 74 | tW0L_Reg = 0x6A, |
IanBenzMaxim | 78:0cbbac7f2016 | 75 | tREC0_Reg = 0x6B, |
IanBenzMaxim | 78:0cbbac7f2016 | 76 | RWPU_Reg = 0x6C, |
IanBenzMaxim | 78:0cbbac7f2016 | 77 | tW1L_Reg = 0x6D, |
IanBenzMaxim | 78:0cbbac7f2016 | 78 | UserMemoryPage0 = 0x80, |
IanBenzMaxim | 78:0cbbac7f2016 | 79 | UserMemoryPage1 = 0xA0 |
IanBenzMaxim | 76:84e6c4994e29 | 80 | }; |
IanBenzMaxim | 76:84e6c4994e29 | 81 | |
IanBenzMaxim | 76:84e6c4994e29 | 82 | /// Represents a DS2465 configuration. |
IanBenzMaxim | 76:84e6c4994e29 | 83 | class Config |
IanBenzMaxim | 74:23be10c32fa3 | 84 | { |
IanBenzMaxim | 74:23be10c32fa3 | 85 | public: |
IanBenzMaxim | 76:84e6c4994e29 | 86 | /// @{ |
IanBenzMaxim | 76:84e6c4994e29 | 87 | /// 1-Wire Speed |
IanBenzMaxim | 76:84e6c4994e29 | 88 | bool get1WS() const { return m_1WS; } |
IanBenzMaxim | 76:84e6c4994e29 | 89 | void set1WS(bool new1WS) { m_1WS = new1WS; } |
IanBenzMaxim | 76:84e6c4994e29 | 90 | /// @} |
IanBenzMaxim | 21:00c94aeb533e | 91 | |
IanBenzMaxim | 76:84e6c4994e29 | 92 | /// @{ |
IanBenzMaxim | 76:84e6c4994e29 | 93 | /// Strong Pullup |
IanBenzMaxim | 76:84e6c4994e29 | 94 | bool getSPU() const { return m_SPU; } |
IanBenzMaxim | 76:84e6c4994e29 | 95 | void setSPU(bool newSPU) { m_SPU = newSPU; } |
IanBenzMaxim | 76:84e6c4994e29 | 96 | /// @} |
IanBenzMaxim | 74:23be10c32fa3 | 97 | |
IanBenzMaxim | 76:84e6c4994e29 | 98 | /// @{ |
IanBenzMaxim | 76:84e6c4994e29 | 99 | /// 1-Wire Power Down |
IanBenzMaxim | 76:84e6c4994e29 | 100 | bool getPDN() const { return m_PDN; } |
IanBenzMaxim | 76:84e6c4994e29 | 101 | void setPDN(bool newPDN) { m_PDN = newPDN; } |
IanBenzMaxim | 76:84e6c4994e29 | 102 | /// @} |
IanBenzMaxim | 74:23be10c32fa3 | 103 | |
IanBenzMaxim | 76:84e6c4994e29 | 104 | /// @{ |
IanBenzMaxim | 76:84e6c4994e29 | 105 | /// Active Pullup |
IanBenzMaxim | 76:84e6c4994e29 | 106 | bool getAPU() const { return m_APU; } |
IanBenzMaxim | 76:84e6c4994e29 | 107 | void setAPU(bool newAPU) { m_APU = newAPU; } |
IanBenzMaxim | 76:84e6c4994e29 | 108 | /// @} |
IanBenzMaxim | 21:00c94aeb533e | 109 | |
IanBenzMaxim | 76:84e6c4994e29 | 110 | /// Byte representation that is read from the DS2465. |
IanBenzMaxim | 76:84e6c4994e29 | 111 | uint8_t readByte() const; |
IanBenzMaxim | 76:84e6c4994e29 | 112 | /// Byte respresentation that is written to the DS2465. |
IanBenzMaxim | 76:84e6c4994e29 | 113 | uint8_t writeByte() const; |
IanBenzMaxim | 74:23be10c32fa3 | 114 | |
IanBenzMaxim | 76:84e6c4994e29 | 115 | /// Reset to the power-on default config. |
IanBenzMaxim | 76:84e6c4994e29 | 116 | void reset(); |
IanBenzMaxim | 76:84e6c4994e29 | 117 | Config() { reset(); } |
IanBenzMaxim | 74:23be10c32fa3 | 118 | |
IanBenzMaxim | 74:23be10c32fa3 | 119 | private: |
IanBenzMaxim | 76:84e6c4994e29 | 120 | bool m_1WS, m_SPU, m_PDN, m_APU; |
IanBenzMaxim | 76:84e6c4994e29 | 121 | }; |
IanBenzMaxim | 76:84e6c4994e29 | 122 | |
IanBenzMaxim | 76:84e6c4994e29 | 123 | /// @param I2C_interface Configured I2C communication interface for DS2465. |
IanBenzMaxim | 76:84e6c4994e29 | 124 | /// @param I2C_address I2C bus address of the DS2465 in mbed format. |
j3 | 139:f0e0a7976846 | 125 | DS2465(mbed::I2C & I2C_interface, uint8_t I2C_address = 0x30); |
IanBenzMaxim | 76:84e6c4994e29 | 126 | |
IanBenzMaxim | 76:84e6c4994e29 | 127 | // Const member functions should not change the settings of the DS2465 or affect the state of the 1-Wire bus. |
IanBenzMaxim | 76:84e6c4994e29 | 128 | // Read pointer, scratchpad, MAC output register, and command register on the DS2465 are considered mutable. |
IanBenzMaxim | 76:84e6c4994e29 | 129 | |
IanBenzMaxim | 76:84e6c4994e29 | 130 | /// Performs a soft reset on the DS2465. |
IanBenzMaxim | 98:c4ac93efc036 | 131 | /// @note This is not a 1-Wire Reset. |
IanBenzMaxim | 76:84e6c4994e29 | 132 | OneWireMaster::CmdResult reset(); |
IanBenzMaxim | 76:84e6c4994e29 | 133 | |
IanBenzMaxim | 76:84e6c4994e29 | 134 | /// Write a new configuration to the DS2465. |
IanBenzMaxim | 76:84e6c4994e29 | 135 | /// @param[in] config New configuration to write. |
IanBenzMaxim | 76:84e6c4994e29 | 136 | /// @param verify Verify that the configuration was written successfully. |
IanBenzMaxim | 76:84e6c4994e29 | 137 | OneWireMaster::CmdResult writeConfig(const Config & config, bool verify); |
IanBenzMaxim | 76:84e6c4994e29 | 138 | |
IanBenzMaxim | 76:84e6c4994e29 | 139 | /// Read the current DS2465 configuration. |
IanBenzMaxim | 76:84e6c4994e29 | 140 | /// @returns The cached current configuration. |
IanBenzMaxim | 76:84e6c4994e29 | 141 | Config currentConfig() const { return m_curConfig; } |
IanBenzMaxim | 76:84e6c4994e29 | 142 | |
IanBenzMaxim | 76:84e6c4994e29 | 143 | // DS2465 Memory Commands |
IanBenzMaxim | 76:84e6c4994e29 | 144 | |
IanBenzMaxim | 76:84e6c4994e29 | 145 | /// Read memory from the DS2465. |
IanBenzMaxim | 76:84e6c4994e29 | 146 | /// @param addr Address to begin reading from. |
IanBenzMaxim | 76:84e6c4994e29 | 147 | /// @param[out] buf Buffer to hold read data. |
IanBenzMaxim | 76:84e6c4994e29 | 148 | /// @param bufLen Length of buffer, buf, and number of bytes to read. |
IanBenzMaxim | 76:84e6c4994e29 | 149 | /// @param skipSetPointer Assume that the read pointer is already set to the correct address. |
IanBenzMaxim | 76:84e6c4994e29 | 150 | OneWireMaster::CmdResult readMemory(uint8_t addr, uint8_t * buf, size_t bufLen, bool skipSetPointer = false) const; |
IanBenzMaxim | 74:23be10c32fa3 | 151 | |
IanBenzMaxim | 76:84e6c4994e29 | 152 | /// Write to SRAM memory on the DS2465. |
IanBenzMaxim | 76:84e6c4994e29 | 153 | /// @param addr Address to begin writing to. |
IanBenzMaxim | 76:84e6c4994e29 | 154 | /// @param[in] buf Buffer containing the data to write. |
IanBenzMaxim | 76:84e6c4994e29 | 155 | /// @param bufLen Length of buffer, buf, and number of bytes to write. |
IanBenzMaxim | 76:84e6c4994e29 | 156 | OneWireMaster::CmdResult writeMemory(uint8_t addr, const uint8_t * buf, size_t bufLen) { return cWriteMemory(addr, buf, bufLen); } |
IanBenzMaxim | 76:84e6c4994e29 | 157 | |
IanBenzMaxim | 76:84e6c4994e29 | 158 | /// Write data to the scratchpad area of the DS2465. |
IanBenzMaxim | 76:84e6c4994e29 | 159 | /// @param[in] buf Buffer containing the data to write. |
IanBenzMaxim | 76:84e6c4994e29 | 160 | /// @param bufLen Length of buffer, buf, and the number of bytes to write. |
IanBenzMaxim | 78:0cbbac7f2016 | 161 | OneWireMaster::CmdResult writeScratchpad(const uint8_t * buf, size_t bufLen) const { return cWriteMemory(Scratchpad, buf, bufLen); } |
IanBenzMaxim | 76:84e6c4994e29 | 162 | |
IanBenzMaxim | 76:84e6c4994e29 | 163 | /// Copy the scratchpad contents to an EEPROM memory page. |
IanBenzMaxim | 76:84e6c4994e29 | 164 | /// @param pageNum Page number to copy to. |
IanBenzMaxim | 76:84e6c4994e29 | 165 | OneWireMaster::CmdResult copyScratchpadToPage(unsigned int pageNum) { return copyScratchpad(false, pageNum, false, 0); } |
IanBenzMaxim | 74:23be10c32fa3 | 166 | |
IanBenzMaxim | 76:84e6c4994e29 | 167 | /// Copy the scratchpad contents to an EEPROM memory segment. |
IanBenzMaxim | 76:84e6c4994e29 | 168 | /// @param pageNum Page number to copy to. |
IanBenzMaxim | 76:84e6c4994e29 | 169 | /// @param segmentNum Segment number to copy to. |
IanBenzMaxim | 76:84e6c4994e29 | 170 | OneWireMaster::CmdResult copyScratchpadToSegment(unsigned int pageNum, unsigned int segmentNum) { return copyScratchpad(false, pageNum, true, segmentNum); } |
IanBenzMaxim | 76:84e6c4994e29 | 171 | |
IanBenzMaxim | 76:84e6c4994e29 | 172 | /// Copy the scratchpad contents to the secret EEPROM memory page. |
IanBenzMaxim | 76:84e6c4994e29 | 173 | OneWireMaster::CmdResult copyScratchpadToSecret() { return copyScratchpad(true, 0, false, 0); } |
IanBenzMaxim | 76:84e6c4994e29 | 174 | |
IanBenzMaxim | 76:84e6c4994e29 | 175 | // 1-Wire Master Commands |
IanBenzMaxim | 76:84e6c4994e29 | 176 | virtual OneWireMaster::CmdResult OWInitMaster(); |
IanBenzMaxim | 76:84e6c4994e29 | 177 | virtual OneWireMaster::CmdResult OWReset(); |
IanBenzMaxim | 76:84e6c4994e29 | 178 | virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel); |
IanBenzMaxim | 76:84e6c4994e29 | 179 | virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel); |
IanBenzMaxim | 76:84e6c4994e29 | 180 | virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel); |
j3 | 141:cf38f48a2a49 | 181 | virtual OneWireMaster::CmdResult OWReadBlock(uint8_t *recvBuf, size_t recvLen); |
j3 | 141:cf38f48a2a49 | 182 | virtual OneWireMaster::CmdResult OWWriteBlock(const uint8_t *sendBuf, size_t sendLen); |
IanBenzMaxim | 76:84e6c4994e29 | 183 | virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed); |
IanBenzMaxim | 76:84e6c4994e29 | 184 | /// @note The DS2465 only supports enabling strong pullup following a 1-Wire read or write operation. |
IanBenzMaxim | 76:84e6c4994e29 | 185 | virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel); |
IanBenzMaxim | 76:84e6c4994e29 | 186 | virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb); |
IanBenzMaxim | 74:23be10c32fa3 | 187 | |
IanBenzMaxim | 76:84e6c4994e29 | 188 | /// Write the last computed MAC to the 1-Wire bus |
IanBenzMaxim | 76:84e6c4994e29 | 189 | OneWireMaster::CmdResult OWWriteBlockMac(); |
IanBenzMaxim | 76:84e6c4994e29 | 190 | |
IanBenzMaxim | 76:84e6c4994e29 | 191 | // DS2465 Coprocessor Commands |
IanBenzMaxim | 76:84e6c4994e29 | 192 | |
IanBenzMaxim | 76:84e6c4994e29 | 193 | /// Compute Next Master Secret with scratchpad data. |
IanBenzMaxim | 78:0cbbac7f2016 | 194 | OneWireMaster::CmdResult computeNextMasterSecret() { return computeNextMasterSecret(false, 0, FullPage); } |
IanBenzMaxim | 76:84e6c4994e29 | 195 | |
IanBenzMaxim | 76:84e6c4994e29 | 196 | /// Compute Next Master Secret with page swapping. |
IanBenzMaxim | 76:84e6c4994e29 | 197 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 198 | /// @param region Region of the page to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 199 | OneWireMaster::CmdResult computeNextMasterSecretSwap(unsigned int pageNum, PageRegion region) { return computeNextMasterSecret(true, pageNum, region); } |
IanBenzMaxim | 76:84e6c4994e29 | 200 | |
IanBenzMaxim | 76:84e6c4994e29 | 201 | /// Compute Write MAC with scratchpad data. |
IanBenzMaxim | 76:84e6c4994e29 | 202 | /// @param regwrite True if writing to a register or false if regular memory. |
IanBenzMaxim | 76:84e6c4994e29 | 203 | OneWireMaster::CmdResult computeWriteMac(bool regwrite) const { return computeWriteMac(regwrite, false, 0, 0); } |
IanBenzMaxim | 76:84e6c4994e29 | 204 | |
IanBenzMaxim | 76:84e6c4994e29 | 205 | /// Compute Write MAC with page swapping. |
IanBenzMaxim | 76:84e6c4994e29 | 206 | /// @param regwrite True if writing to a register or false if regular memory. |
IanBenzMaxim | 76:84e6c4994e29 | 207 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 208 | /// @param segmentNum Segment number to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 209 | OneWireMaster::CmdResult computeWriteMacSwap(bool regwrite, unsigned int pageNum, unsigned int segmentNum) const { return computeWriteMac(regwrite, true, pageNum, segmentNum); } |
IanBenzMaxim | 76:84e6c4994e29 | 210 | |
IanBenzMaxim | 76:84e6c4994e29 | 211 | /// Compute Slave Secret (S-Secret) with scratchpad data. |
IanBenzMaxim | 78:0cbbac7f2016 | 212 | OneWireMaster::CmdResult computeSlaveSecret() { return computeSlaveSecret(false, 0, FullPage); } |
IanBenzMaxim | 76:84e6c4994e29 | 213 | |
IanBenzMaxim | 76:84e6c4994e29 | 214 | /// Compute Slave Secret (S-Secret) with page swapping. |
IanBenzMaxim | 76:84e6c4994e29 | 215 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 216 | /// @param region Region of the page to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 217 | OneWireMaster::CmdResult computeSlaveSecretSwap(unsigned int pageNum, PageRegion region) { return computeSlaveSecret(true, pageNum, region); } |
IanBenzMaxim | 76:84e6c4994e29 | 218 | |
IanBenzMaxim | 76:84e6c4994e29 | 219 | /// Compute Authentication MAC with scratchpad data. |
IanBenzMaxim | 78:0cbbac7f2016 | 220 | OneWireMaster::CmdResult computeAuthMac() const { return computeAuthMac(false, 0, FullPage); } |
IanBenzMaxim | 74:23be10c32fa3 | 221 | |
IanBenzMaxim | 76:84e6c4994e29 | 222 | /// Compute Authentication MAC with page swapping. |
IanBenzMaxim | 76:84e6c4994e29 | 223 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 224 | /// @param region Region of the page to swap in. |
IanBenzMaxim | 76:84e6c4994e29 | 225 | OneWireMaster::CmdResult computeAuthMacSwap(unsigned int pageNum, PageRegion region) const { return computeAuthMac(true, pageNum, region); } |
IanBenzMaxim | 76:84e6c4994e29 | 226 | |
IanBenzMaxim | 76:84e6c4994e29 | 227 | // ISha256MacCoproc Commands |
IanBenzMaxim | 76:84e6c4994e29 | 228 | virtual ISha256MacCoproc::CmdResult setMasterSecret(const Secret & masterSecret); |
IanBenzMaxim | 76:84e6c4994e29 | 229 | virtual ISha256MacCoproc::CmdResult computeSlaveSecret(const DevicePage & devicePage, const DeviceScratchpad & deviceScratchpad, const SlaveSecretData & slaveSecretData); |
IanBenzMaxim | 76:84e6c4994e29 | 230 | virtual ISha256MacCoproc::CmdResult computeWriteMac(const WriteMacData & writeMacData, Mac & mac) const; |
IanBenzMaxim | 76:84e6c4994e29 | 231 | virtual ISha256MacCoproc::CmdResult computeAuthMac(const DevicePage & devicePage, const DeviceScratchpad & challenge, const AuthMacData & authMacData, Mac & mac) const; |
IanBenzMaxim | 76:84e6c4994e29 | 232 | |
IanBenzMaxim | 76:84e6c4994e29 | 233 | private: |
IanBenzMaxim | 76:84e6c4994e29 | 234 | mbed::I2C & m_I2C_interface; |
IanBenzMaxim | 76:84e6c4994e29 | 235 | uint8_t m_I2C_address; |
IanBenzMaxim | 76:84e6c4994e29 | 236 | Config m_curConfig; |
IanBenzMaxim | 76:84e6c4994e29 | 237 | |
IanBenzMaxim | 76:84e6c4994e29 | 238 | /// Polls the DS2465 status waiting for the 1-Wire Busy bit (1WB) to be cleared. |
IanBenzMaxim | 76:84e6c4994e29 | 239 | /// @param[out] pStatus Optionally retrive the status byte when 1WB cleared. |
IanBenzMaxim | 76:84e6c4994e29 | 240 | /// @returns Success or TimeoutError if poll limit reached. |
IanBenzMaxim | 76:84e6c4994e29 | 241 | OneWireMaster::CmdResult pollBusy(uint8_t * pStatus = NULL); |
IanBenzMaxim | 76:84e6c4994e29 | 242 | |
IanBenzMaxim | 76:84e6c4994e29 | 243 | /// Ensure that the desired 1-Wire level is set in the configuration. |
IanBenzMaxim | 76:84e6c4994e29 | 244 | /// @param level Desired 1-Wire level. |
IanBenzMaxim | 76:84e6c4994e29 | 245 | OneWireMaster::CmdResult configureLevel(OWLevel level); |
IanBenzMaxim | 76:84e6c4994e29 | 246 | |
IanBenzMaxim | 76:84e6c4994e29 | 247 | /// Const version of writeMemory() for internal use. |
IanBenzMaxim | 76:84e6c4994e29 | 248 | OneWireMaster::CmdResult cWriteMemory(uint8_t addr, const uint8_t * buf, size_t bufLen) const; |
IanBenzMaxim | 76:84e6c4994e29 | 249 | |
IanBenzMaxim | 76:84e6c4994e29 | 250 | // Legacy implementations |
IanBenzMaxim | 76:84e6c4994e29 | 251 | OneWireMaster::CmdResult copyScratchpad(bool destSecret, unsigned int pageNum, bool notFull, unsigned int segmentNum); |
IanBenzMaxim | 76:84e6c4994e29 | 252 | OneWireMaster::CmdResult computeNextMasterSecret(bool swap, unsigned int pageNum, PageRegion region); |
IanBenzMaxim | 76:84e6c4994e29 | 253 | OneWireMaster::CmdResult computeWriteMac(bool regwrite, bool swap, unsigned int pageNum, unsigned int segmentNum) const; |
IanBenzMaxim | 76:84e6c4994e29 | 254 | OneWireMaster::CmdResult computeSlaveSecret(bool swap, unsigned int pageNum, PageRegion region); |
IanBenzMaxim | 76:84e6c4994e29 | 255 | OneWireMaster::CmdResult computeAuthMac(bool swap, unsigned int pageNum, PageRegion region) const; |
IanBenzMaxim | 76:84e6c4994e29 | 256 | }; |
IanBenzMaxim | 73:2cecc1372acc | 257 | } |
IanBenzMaxim | 21:00c94aeb533e | 258 | |
IanBenzMaxim | 21:00c94aeb533e | 259 | #endif |