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@75:8b627804927c, 2016-05-13 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Fri May 13 14:52:50 2016 -0500
- Revision:
- 75:8b627804927c
- Parent:
- 74:23be10c32fa3
- Child:
- 76:84e6c4994e29
Code cleanup.
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 | 73:2cecc1372acc | 37 | #include "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 | 74:23be10c32fa3 | 43 | namespace Masters |
IanBenzMaxim | 73:2cecc1372acc | 44 | { |
IanBenzMaxim | 74:23be10c32fa3 | 45 | /// Interface to the DS2465 1-Wire master and SHA-256 coprocessor. |
IanBenzMaxim | 74:23be10c32fa3 | 46 | class DS2465 : public OneWireMaster, public Authenticators::ISha256MacCoproc |
IanBenzMaxim | 74:23be10c32fa3 | 47 | { |
IanBenzMaxim | 74:23be10c32fa3 | 48 | public: |
IanBenzMaxim | 74:23be10c32fa3 | 49 | /// Delay required after writing an EEPROM segment. |
IanBenzMaxim | 74:23be10c32fa3 | 50 | static const unsigned int eepromSegmentWriteDelayMs = 10; |
IanBenzMaxim | 74:23be10c32fa3 | 51 | /// Delay required after writing an EEPROM page such as the secret memory. |
IanBenzMaxim | 74:23be10c32fa3 | 52 | static const unsigned int eepromPageWriteDelayMs = 8 * eepromSegmentWriteDelayMs; |
IanBenzMaxim | 74:23be10c32fa3 | 53 | /// Delay required for a SHA computation to complete. |
IanBenzMaxim | 74:23be10c32fa3 | 54 | static const unsigned int shaComputationDelayMs = 2; |
IanBenzMaxim | 74:23be10c32fa3 | 55 | |
IanBenzMaxim | 74:23be10c32fa3 | 56 | /// Page region to use for swapping. |
IanBenzMaxim | 74:23be10c32fa3 | 57 | enum PageRegion |
IanBenzMaxim | 74:23be10c32fa3 | 58 | { |
IanBenzMaxim | 74:23be10c32fa3 | 59 | REGION_FULL_PAGE = 0x03, |
IanBenzMaxim | 74:23be10c32fa3 | 60 | REGION_FIRST_HALF = 0x01, |
IanBenzMaxim | 74:23be10c32fa3 | 61 | REGION_SECOND_HALF = 0x02 |
IanBenzMaxim | 74:23be10c32fa3 | 62 | }; |
IanBenzMaxim | 74:23be10c32fa3 | 63 | |
IanBenzMaxim | 74:23be10c32fa3 | 64 | /// Starting memory addresses. |
IanBenzMaxim | 74:23be10c32fa3 | 65 | enum MemoryAddr |
IanBenzMaxim | 74:23be10c32fa3 | 66 | { |
IanBenzMaxim | 74:23be10c32fa3 | 67 | ADDR_SPAD = 0x00, |
IanBenzMaxim | 74:23be10c32fa3 | 68 | ADDR_CMD_REG = 0x60, |
IanBenzMaxim | 74:23be10c32fa3 | 69 | ADDR_STATUS_REG = 0x61, |
IanBenzMaxim | 74:23be10c32fa3 | 70 | ADDR_DATA_REG = 0x62, |
IanBenzMaxim | 74:23be10c32fa3 | 71 | ADDR_MAC_READ = 0x63, |
IanBenzMaxim | 74:23be10c32fa3 | 72 | ADDR_SHA_SELECT_REG = 0x66, |
IanBenzMaxim | 74:23be10c32fa3 | 73 | ADDR_WCFG_REG = 0x67, |
IanBenzMaxim | 74:23be10c32fa3 | 74 | ADDR_TRSTL_REG = 0x68, |
IanBenzMaxim | 74:23be10c32fa3 | 75 | ADDR_TMSP_REG = 0x69, |
IanBenzMaxim | 74:23be10c32fa3 | 76 | ADDR_TW0L_REG = 0x6A, |
IanBenzMaxim | 74:23be10c32fa3 | 77 | ADDR_TREC0_REG = 0x6B, |
IanBenzMaxim | 74:23be10c32fa3 | 78 | ADDR_RWPU_REG = 0x6C, |
IanBenzMaxim | 74:23be10c32fa3 | 79 | ADDR_TW1L_REG = 0x6D, |
IanBenzMaxim | 74:23be10c32fa3 | 80 | ADDR_USER_MEM_PAGE_0 = 0x80, |
IanBenzMaxim | 74:23be10c32fa3 | 81 | ADDR_USER_MEM_PAGE_1 = 0xA0 |
IanBenzMaxim | 74:23be10c32fa3 | 82 | }; |
IanBenzMaxim | 74:23be10c32fa3 | 83 | |
IanBenzMaxim | 74:23be10c32fa3 | 84 | /// Represents a DS2465 configuration. |
IanBenzMaxim | 74:23be10c32fa3 | 85 | class Config |
IanBenzMaxim | 74:23be10c32fa3 | 86 | { |
IanBenzMaxim | 74:23be10c32fa3 | 87 | public: |
IanBenzMaxim | 74:23be10c32fa3 | 88 | /// @{ |
IanBenzMaxim | 74:23be10c32fa3 | 89 | /// 1-Wire Speed |
IanBenzMaxim | 74:23be10c32fa3 | 90 | bool get1WS() const { return m_1WS; } |
IanBenzMaxim | 74:23be10c32fa3 | 91 | void set1WS(bool new1WS) { m_1WS = new1WS; } |
IanBenzMaxim | 74:23be10c32fa3 | 92 | /// @} |
IanBenzMaxim | 21:00c94aeb533e | 93 | |
IanBenzMaxim | 74:23be10c32fa3 | 94 | /// @{ |
IanBenzMaxim | 74:23be10c32fa3 | 95 | /// Strong Pullup |
IanBenzMaxim | 74:23be10c32fa3 | 96 | bool getSPU() const { return m_SPU; } |
IanBenzMaxim | 74:23be10c32fa3 | 97 | void setSPU(bool newSPU) { m_SPU = newSPU; } |
IanBenzMaxim | 74:23be10c32fa3 | 98 | /// @} |
IanBenzMaxim | 74:23be10c32fa3 | 99 | |
IanBenzMaxim | 74:23be10c32fa3 | 100 | /// @{ |
IanBenzMaxim | 74:23be10c32fa3 | 101 | /// 1-Wire Power Down |
IanBenzMaxim | 74:23be10c32fa3 | 102 | bool getPDN() const { return m_PDN; } |
IanBenzMaxim | 74:23be10c32fa3 | 103 | void setPDN(bool newPDN) { m_PDN = newPDN; } |
IanBenzMaxim | 74:23be10c32fa3 | 104 | /// @} |
IanBenzMaxim | 74:23be10c32fa3 | 105 | |
IanBenzMaxim | 74:23be10c32fa3 | 106 | /// @{ |
IanBenzMaxim | 74:23be10c32fa3 | 107 | /// Active Pullup |
IanBenzMaxim | 74:23be10c32fa3 | 108 | bool getAPU() const { return m_APU; } |
IanBenzMaxim | 74:23be10c32fa3 | 109 | void setAPU(bool newAPU) { m_APU = newAPU; } |
IanBenzMaxim | 74:23be10c32fa3 | 110 | /// @} |
IanBenzMaxim | 74:23be10c32fa3 | 111 | |
IanBenzMaxim | 74:23be10c32fa3 | 112 | /// Byte representation that is read from the DS2465. |
IanBenzMaxim | 74:23be10c32fa3 | 113 | uint8_t readByte() const; |
IanBenzMaxim | 74:23be10c32fa3 | 114 | /// Byte respresentation that is written to the DS2465. |
IanBenzMaxim | 74:23be10c32fa3 | 115 | uint8_t writeByte() const; |
IanBenzMaxim | 73:2cecc1372acc | 116 | |
IanBenzMaxim | 74:23be10c32fa3 | 117 | /// Reset to the power-on default config. |
IanBenzMaxim | 74:23be10c32fa3 | 118 | void reset(); |
IanBenzMaxim | 74:23be10c32fa3 | 119 | Config() { reset(); } |
IanBenzMaxim | 74:23be10c32fa3 | 120 | |
IanBenzMaxim | 74:23be10c32fa3 | 121 | private: |
IanBenzMaxim | 74:23be10c32fa3 | 122 | bool m_1WS, m_SPU, m_PDN, m_APU; |
IanBenzMaxim | 74:23be10c32fa3 | 123 | }; |
IanBenzMaxim | 74:23be10c32fa3 | 124 | |
IanBenzMaxim | 74:23be10c32fa3 | 125 | /// @param I2C_interface Configured I2C communication interface for DS2465. |
IanBenzMaxim | 74:23be10c32fa3 | 126 | /// @param I2C_address I2C bus address of the DS2465 in mbed format. |
IanBenzMaxim | 74:23be10c32fa3 | 127 | DS2465(mbed::I2C & I2C_interface, uint8_t I2C_address); |
IanBenzMaxim | 74:23be10c32fa3 | 128 | |
IanBenzMaxim | 74:23be10c32fa3 | 129 | // Const member functions should not change the settings of the DS2465 or affect the state of the 1-Wire bus. |
IanBenzMaxim | 74:23be10c32fa3 | 130 | // Read pointer, scratchpad, MAC output register, and command register on the DS2465 are considered mutable. |
IanBenzMaxim | 74:23be10c32fa3 | 131 | |
IanBenzMaxim | 75:8b627804927c | 132 | /// Performs a soft reset on the DS2465. |
IanBenzMaxim | 75:8b627804927c | 133 | /// @note This is note a 1-Wire Reset. |
IanBenzMaxim | 75:8b627804927c | 134 | OneWireMaster::CmdResult reset(); |
IanBenzMaxim | 74:23be10c32fa3 | 135 | |
IanBenzMaxim | 74:23be10c32fa3 | 136 | /// Write a new configuration to the DS2465. |
IanBenzMaxim | 74:23be10c32fa3 | 137 | /// @param[in] config New configuration to write. |
IanBenzMaxim | 74:23be10c32fa3 | 138 | /// @param verify Verify that the configuration was written successfully. |
IanBenzMaxim | 74:23be10c32fa3 | 139 | OneWireMaster::CmdResult writeConfig(const Config & config, bool verify); |
IanBenzMaxim | 74:23be10c32fa3 | 140 | |
IanBenzMaxim | 74:23be10c32fa3 | 141 | /// Read the current DS2465 configuration. |
IanBenzMaxim | 74:23be10c32fa3 | 142 | /// @returns The cached current configuration. |
IanBenzMaxim | 74:23be10c32fa3 | 143 | Config currentConfig() const { return m_curConfig; } |
IanBenzMaxim | 74:23be10c32fa3 | 144 | |
IanBenzMaxim | 74:23be10c32fa3 | 145 | // DS2465 Memory Commands |
IanBenzMaxim | 21:00c94aeb533e | 146 | |
IanBenzMaxim | 75:8b627804927c | 147 | /// Read memory from the DS2465. |
IanBenzMaxim | 74:23be10c32fa3 | 148 | /// @param addr Address to begin reading from. |
IanBenzMaxim | 74:23be10c32fa3 | 149 | /// @param[out] buf Buffer to hold read data. |
IanBenzMaxim | 74:23be10c32fa3 | 150 | /// @param bufLen Length of buffer, buf, and number of bytes to read. |
IanBenzMaxim | 74:23be10c32fa3 | 151 | /// @param skipSetPointer Assume that the read pointer is already set to the correct address. |
IanBenzMaxim | 74:23be10c32fa3 | 152 | OneWireMaster::CmdResult readMemory(uint8_t addr, uint8_t * buf, size_t bufLen, bool skipSetPointer = false) const; |
IanBenzMaxim | 74:23be10c32fa3 | 153 | |
IanBenzMaxim | 75:8b627804927c | 154 | /// Write to SRAM memory on the DS2465. |
IanBenzMaxim | 74:23be10c32fa3 | 155 | /// @param addr Address to begin writing to. |
IanBenzMaxim | 74:23be10c32fa3 | 156 | /// @param[in] buf Buffer containing the data to write. |
IanBenzMaxim | 74:23be10c32fa3 | 157 | /// @param bufLen Length of buffer, buf, and number of bytes to write. |
IanBenzMaxim | 74:23be10c32fa3 | 158 | OneWireMaster::CmdResult writeMemory(uint8_t addr, const uint8_t * buf, size_t bufLen) { return cWriteMemory(addr, buf, bufLen); } |
IanBenzMaxim | 74:23be10c32fa3 | 159 | |
IanBenzMaxim | 75:8b627804927c | 160 | /// Write data to the scratchpad area of the DS2465. |
IanBenzMaxim | 74:23be10c32fa3 | 161 | /// @param[in] buf Buffer containing the data to write. |
IanBenzMaxim | 74:23be10c32fa3 | 162 | /// @param bufLen Length of buffer, buf, and the number of bytes to write. |
IanBenzMaxim | 74:23be10c32fa3 | 163 | OneWireMaster::CmdResult writeScratchpad(const uint8_t * buf, size_t bufLen) const { return cWriteMemory(ADDR_SPAD, buf, bufLen); } |
IanBenzMaxim | 74:23be10c32fa3 | 164 | |
IanBenzMaxim | 74:23be10c32fa3 | 165 | /// Copy the scratchpad contents to an EEPROM memory page. |
IanBenzMaxim | 74:23be10c32fa3 | 166 | /// @param pageNum Page number to copy to. |
IanBenzMaxim | 74:23be10c32fa3 | 167 | OneWireMaster::CmdResult copyScratchpadToPage(unsigned int pageNum) { return copyScratchpad(false, pageNum, false, 0); } |
IanBenzMaxim | 74:23be10c32fa3 | 168 | |
IanBenzMaxim | 74:23be10c32fa3 | 169 | /// Copy the scratchpad contents to an EEPROM memory segment. |
IanBenzMaxim | 74:23be10c32fa3 | 170 | /// @param pageNum Page number to copy to. |
IanBenzMaxim | 74:23be10c32fa3 | 171 | /// @param segmentNum Segment number to copy to. |
IanBenzMaxim | 74:23be10c32fa3 | 172 | OneWireMaster::CmdResult copyScratchpadToSegment(unsigned int pageNum, unsigned int segmentNum) { return copyScratchpad(false, pageNum, true, segmentNum); } |
IanBenzMaxim | 74:23be10c32fa3 | 173 | |
IanBenzMaxim | 74:23be10c32fa3 | 174 | /// Copy the scratchpad contents to the secret EEPROM memory page. |
IanBenzMaxim | 74:23be10c32fa3 | 175 | OneWireMaster::CmdResult copyScratchpadToSecret() { return copyScratchpad(true, 0, false, 0); } |
IanBenzMaxim | 74:23be10c32fa3 | 176 | |
IanBenzMaxim | 74:23be10c32fa3 | 177 | // 1-Wire Master Commands |
IanBenzMaxim | 75:8b627804927c | 178 | virtual OneWireMaster::CmdResult OWInitMaster(); |
IanBenzMaxim | 75:8b627804927c | 179 | virtual OneWireMaster::CmdResult OWReset(); |
IanBenzMaxim | 75:8b627804927c | 180 | virtual OneWireMaster::CmdResult OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel); |
IanBenzMaxim | 75:8b627804927c | 181 | virtual OneWireMaster::CmdResult OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel); |
IanBenzMaxim | 75:8b627804927c | 182 | virtual OneWireMaster::CmdResult OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel); |
IanBenzMaxim | 75:8b627804927c | 183 | virtual OneWireMaster::CmdResult OWReadBlock(uint8_t *recvBuf, uint8_t recvLen); |
IanBenzMaxim | 75:8b627804927c | 184 | virtual OneWireMaster::CmdResult OWWriteBlock(const uint8_t *sendBuf, uint8_t sendLen); |
IanBenzMaxim | 75:8b627804927c | 185 | virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed newSpeed); |
IanBenzMaxim | 74:23be10c32fa3 | 186 | /// @note The DS2465 only supports enabling strong pullup following a 1-Wire read or write operation. |
IanBenzMaxim | 75:8b627804927c | 187 | virtual OneWireMaster::CmdResult OWSetLevel(OWLevel newLevel); |
IanBenzMaxim | 75:8b627804927c | 188 | virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & searchDirection, uint8_t & sbr, uint8_t & tsb); |
IanBenzMaxim | 74:23be10c32fa3 | 189 | |
IanBenzMaxim | 74:23be10c32fa3 | 190 | /// Write the last computed MAC to the 1-Wire bus |
IanBenzMaxim | 74:23be10c32fa3 | 191 | OneWireMaster::CmdResult OWWriteBlockMac(); |
IanBenzMaxim | 74:23be10c32fa3 | 192 | |
IanBenzMaxim | 74:23be10c32fa3 | 193 | // DS2465 Coprocessor Commands |
IanBenzMaxim | 74:23be10c32fa3 | 194 | |
IanBenzMaxim | 74:23be10c32fa3 | 195 | /// Compute Next Master Secret with scratchpad data. |
IanBenzMaxim | 74:23be10c32fa3 | 196 | OneWireMaster::CmdResult computeNextMasterSecret() { return computeNextMasterSecret(false, 0, REGION_FULL_PAGE); } |
IanBenzMaxim | 74:23be10c32fa3 | 197 | |
IanBenzMaxim | 74:23be10c32fa3 | 198 | /// Compute Next Master Secret with page swapping. |
IanBenzMaxim | 74:23be10c32fa3 | 199 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 200 | /// @param region Region of the page to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 201 | OneWireMaster::CmdResult computeNextMasterSecretSwap(unsigned int pageNum, PageRegion region) { return computeNextMasterSecret(true, pageNum, region); } |
IanBenzMaxim | 21:00c94aeb533e | 202 | |
IanBenzMaxim | 74:23be10c32fa3 | 203 | /// Compute Write MAC with scratchpad data. |
IanBenzMaxim | 74:23be10c32fa3 | 204 | /// @param regwrite True if writing to a register or false if regular memory. |
IanBenzMaxim | 74:23be10c32fa3 | 205 | OneWireMaster::CmdResult computeWriteMac(bool regwrite) const { return computeWriteMac(regwrite, false, 0, 0); } |
IanBenzMaxim | 74:23be10c32fa3 | 206 | |
IanBenzMaxim | 74:23be10c32fa3 | 207 | /// Compute Write MAC with page swapping. |
IanBenzMaxim | 74:23be10c32fa3 | 208 | /// @param regwrite True if writing to a register or false if regular memory. |
IanBenzMaxim | 74:23be10c32fa3 | 209 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 210 | /// @param segmentNum Segment number to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 211 | OneWireMaster::CmdResult computeWriteMacSwap(bool regwrite, unsigned int pageNum, unsigned int segmentNum) const { return computeWriteMac(regwrite, true, pageNum, segmentNum); } |
IanBenzMaxim | 74:23be10c32fa3 | 212 | |
IanBenzMaxim | 74:23be10c32fa3 | 213 | /// Compute Slave Secret (S-Secret) with scratchpad data. |
IanBenzMaxim | 74:23be10c32fa3 | 214 | OneWireMaster::CmdResult computeSlaveSecret() { return computeSlaveSecret(false, 0, REGION_FULL_PAGE); } |
IanBenzMaxim | 74:23be10c32fa3 | 215 | |
IanBenzMaxim | 74:23be10c32fa3 | 216 | /// Compute Slave Secret (S-Secret) with page swapping. |
IanBenzMaxim | 74:23be10c32fa3 | 217 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 218 | /// @param region Region of the page to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 219 | OneWireMaster::CmdResult computeSlaveSecretSwap(unsigned int pageNum, PageRegion region) { return computeSlaveSecret(true, pageNum, region); } |
IanBenzMaxim | 74:23be10c32fa3 | 220 | |
IanBenzMaxim | 74:23be10c32fa3 | 221 | /// Compute Authentication MAC with scratchpad data. |
IanBenzMaxim | 74:23be10c32fa3 | 222 | OneWireMaster::CmdResult computeAuthMac() const { return computeAuthMac(false, 0, REGION_FULL_PAGE); } |
IanBenzMaxim | 74:23be10c32fa3 | 223 | |
IanBenzMaxim | 74:23be10c32fa3 | 224 | /// Compute Authentication MAC with page swapping. |
IanBenzMaxim | 74:23be10c32fa3 | 225 | /// @param pageNum Page number to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 226 | /// @param region Region of the page to swap in. |
IanBenzMaxim | 74:23be10c32fa3 | 227 | OneWireMaster::CmdResult computeAuthMacSwap(unsigned int pageNum, PageRegion region) const { return computeAuthMac(true, pageNum, region); } |
IanBenzMaxim | 74:23be10c32fa3 | 228 | |
IanBenzMaxim | 74:23be10c32fa3 | 229 | // ISha256MacCoproc Commands |
IanBenzMaxim | 74:23be10c32fa3 | 230 | virtual ISha256MacCoproc::CmdResult setMasterSecret(const Secret & masterSecret); |
IanBenzMaxim | 74:23be10c32fa3 | 231 | virtual ISha256MacCoproc::CmdResult computeSlaveSecret(const DevicePage & devicePage, const DeviceScratchpad & deviceScratchpad, const SlaveSecretData & slaveSecretData); |
IanBenzMaxim | 74:23be10c32fa3 | 232 | virtual ISha256MacCoproc::CmdResult computeWriteMac(const WriteMacData & writeMacData, Mac & mac) const; |
IanBenzMaxim | 74:23be10c32fa3 | 233 | virtual ISha256MacCoproc::CmdResult computeAuthMac(const DevicePage & devicePage, const DeviceScratchpad & challenge, const AuthMacData & authMacData, Mac & mac) const; |
IanBenzMaxim | 74:23be10c32fa3 | 234 | |
IanBenzMaxim | 74:23be10c32fa3 | 235 | private: |
IanBenzMaxim | 74:23be10c32fa3 | 236 | mbed::I2C & m_I2C_interface; |
IanBenzMaxim | 74:23be10c32fa3 | 237 | uint8_t m_I2C_address; |
IanBenzMaxim | 74:23be10c32fa3 | 238 | Config m_curConfig; |
IanBenzMaxim | 74:23be10c32fa3 | 239 | |
IanBenzMaxim | 74:23be10c32fa3 | 240 | /// Polls the DS2465 status waiting for the 1-Wire Busy bit (1WB) to be cleared. |
IanBenzMaxim | 74:23be10c32fa3 | 241 | /// @param[out] pStatus Optionally retrive the status byte when 1WB cleared. |
IanBenzMaxim | 74:23be10c32fa3 | 242 | /// @returns Success or TimeoutError if poll limit reached. |
IanBenzMaxim | 74:23be10c32fa3 | 243 | OneWireMaster::CmdResult pollBusy(uint8_t * pStatus = NULL); |
IanBenzMaxim | 74:23be10c32fa3 | 244 | |
IanBenzMaxim | 74:23be10c32fa3 | 245 | /// Ensure that the desired 1-Wire level is set in the configuration. |
IanBenzMaxim | 74:23be10c32fa3 | 246 | /// @param level Desired 1-Wire level. |
IanBenzMaxim | 74:23be10c32fa3 | 247 | OneWireMaster::CmdResult configureLevel(OWLevel level); |
IanBenzMaxim | 74:23be10c32fa3 | 248 | |
IanBenzMaxim | 74:23be10c32fa3 | 249 | /// Const version of writeMemory() for internal use. |
IanBenzMaxim | 74:23be10c32fa3 | 250 | OneWireMaster::CmdResult cWriteMemory(uint8_t addr, const uint8_t * buf, size_t bufLen) const; |
IanBenzMaxim | 74:23be10c32fa3 | 251 | |
IanBenzMaxim | 74:23be10c32fa3 | 252 | // Legacy implementations |
IanBenzMaxim | 74:23be10c32fa3 | 253 | OneWireMaster::CmdResult OWWriteBlock(bool tx_mac, const uint8_t *tran_buf, uint8_t tran_len); |
IanBenzMaxim | 74:23be10c32fa3 | 254 | OneWireMaster::CmdResult copyScratchpad(bool destSecret, unsigned int pageNum, bool notFull, unsigned int segmentNum); |
IanBenzMaxim | 74:23be10c32fa3 | 255 | OneWireMaster::CmdResult computeNextMasterSecret(bool swap, unsigned int pageNum, PageRegion region); |
IanBenzMaxim | 74:23be10c32fa3 | 256 | OneWireMaster::CmdResult computeWriteMac(bool regwrite, bool swap, unsigned int pageNum, unsigned int segmentNum) const; |
IanBenzMaxim | 74:23be10c32fa3 | 257 | OneWireMaster::CmdResult computeSlaveSecret(bool swap, unsigned int pageNum, PageRegion region); |
IanBenzMaxim | 74:23be10c32fa3 | 258 | OneWireMaster::CmdResult computeAuthMac(bool swap, unsigned int pageNum, PageRegion region) const; |
IanBenzMaxim | 74:23be10c32fa3 | 259 | }; |
IanBenzMaxim | 74:23be10c32fa3 | 260 | } |
IanBenzMaxim | 73:2cecc1372acc | 261 | } |
IanBenzMaxim | 21:00c94aeb533e | 262 | |
IanBenzMaxim | 21:00c94aeb533e | 263 | #endif |