Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
IanBenzMaxim
Date:
Mon Nov 06 14:39:18 2017 -0600
Revision:
0:f77ad7f72d04
Child:
6:a8c83a2e6fa4
Initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:f77ad7f72d04 1 /*******************************************************************************
IanBenzMaxim 0:f77ad7f72d04 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 0:f77ad7f72d04 3 *
IanBenzMaxim 0:f77ad7f72d04 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 0:f77ad7f72d04 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 0:f77ad7f72d04 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 0:f77ad7f72d04 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 0:f77ad7f72d04 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 0:f77ad7f72d04 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 0:f77ad7f72d04 10 *
IanBenzMaxim 0:f77ad7f72d04 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 0:f77ad7f72d04 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 0:f77ad7f72d04 13 *
IanBenzMaxim 0:f77ad7f72d04 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 0:f77ad7f72d04 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 0:f77ad7f72d04 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 0:f77ad7f72d04 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 0:f77ad7f72d04 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 0:f77ad7f72d04 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 0:f77ad7f72d04 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 0:f77ad7f72d04 21 *
IanBenzMaxim 0:f77ad7f72d04 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 24 * Products, Inc. Branding Policy.
IanBenzMaxim 0:f77ad7f72d04 25 *
IanBenzMaxim 0:f77ad7f72d04 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 0:f77ad7f72d04 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 0:f77ad7f72d04 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 0:f77ad7f72d04 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 0:f77ad7f72d04 30 * ownership rights.
IanBenzMaxim 0:f77ad7f72d04 31 *******************************************************************************/
IanBenzMaxim 0:f77ad7f72d04 32
IanBenzMaxim 0:f77ad7f72d04 33 #ifndef MaximInterface_DS2465
IanBenzMaxim 0:f77ad7f72d04 34 #define MaximInterface_DS2465
IanBenzMaxim 0:f77ad7f72d04 35
IanBenzMaxim 0:f77ad7f72d04 36 #include <MaximInterface/Links/I2CMaster.hpp>
IanBenzMaxim 0:f77ad7f72d04 37 #include <MaximInterface/Links/OneWireMaster.hpp>
IanBenzMaxim 0:f77ad7f72d04 38 #include <MaximInterface/Links/Sleep.hpp>
IanBenzMaxim 0:f77ad7f72d04 39 #include <MaximInterface/Utilities/Export.h>
IanBenzMaxim 0:f77ad7f72d04 40 #include <MaximInterface/Utilities/Sha256.hpp>
IanBenzMaxim 0:f77ad7f72d04 41
IanBenzMaxim 0:f77ad7f72d04 42 namespace MaximInterface {
IanBenzMaxim 0:f77ad7f72d04 43
IanBenzMaxim 0:f77ad7f72d04 44 /// Interface to the DS2465 1-Wire master and SHA-256 coprocessor.
IanBenzMaxim 0:f77ad7f72d04 45 class DS2465 : public OneWireMaster {
IanBenzMaxim 0:f77ad7f72d04 46 public:
IanBenzMaxim 0:f77ad7f72d04 47 enum ErrorValue { HardwareError = 1, ArgumentOutOfRangeError };
IanBenzMaxim 0:f77ad7f72d04 48
IanBenzMaxim 0:f77ad7f72d04 49 /// 1-Wire port adjustment parameters.
IanBenzMaxim 0:f77ad7f72d04 50 /// @note See datasheet page 13.
IanBenzMaxim 0:f77ad7f72d04 51 enum PortParameter {
IanBenzMaxim 0:f77ad7f72d04 52 tRSTL_STD,
IanBenzMaxim 0:f77ad7f72d04 53 tRSTL_OD,
IanBenzMaxim 0:f77ad7f72d04 54 tMSP_STD,
IanBenzMaxim 0:f77ad7f72d04 55 tMSP_OD,
IanBenzMaxim 0:f77ad7f72d04 56 tW0L_STD,
IanBenzMaxim 0:f77ad7f72d04 57 tW0L_OD,
IanBenzMaxim 0:f77ad7f72d04 58 tREC0,
IanBenzMaxim 0:f77ad7f72d04 59 RWPU,
IanBenzMaxim 0:f77ad7f72d04 60 tW1L_OD
IanBenzMaxim 0:f77ad7f72d04 61 };
IanBenzMaxim 0:f77ad7f72d04 62
IanBenzMaxim 0:f77ad7f72d04 63 /// Page region to use for swapping.
IanBenzMaxim 0:f77ad7f72d04 64 enum PageRegion { FullPage = 0x03, FirstHalf = 0x01, SecondHalf = 0x02 };
IanBenzMaxim 0:f77ad7f72d04 65
IanBenzMaxim 0:f77ad7f72d04 66 /// Holds the contents of a device memory segment.
IanBenzMaxim 0:f77ad7f72d04 67 typedef array<uint_least8_t, 4> Segment;
IanBenzMaxim 0:f77ad7f72d04 68
IanBenzMaxim 0:f77ad7f72d04 69 /// Holds the contents of a device memory page.
IanBenzMaxim 0:f77ad7f72d04 70 typedef array<uint_least8_t, 32> Page;
IanBenzMaxim 0:f77ad7f72d04 71
IanBenzMaxim 0:f77ad7f72d04 72 static const int memoryPages = 2;
IanBenzMaxim 0:f77ad7f72d04 73 static const int segmentsPerPage = Page::csize / Segment::csize;
IanBenzMaxim 0:f77ad7f72d04 74
IanBenzMaxim 0:f77ad7f72d04 75 /// Represents a DS2465 configuration.
IanBenzMaxim 0:f77ad7f72d04 76 class Config {
IanBenzMaxim 0:f77ad7f72d04 77 public:
IanBenzMaxim 0:f77ad7f72d04 78 /// Default construct with power-on config.
IanBenzMaxim 0:f77ad7f72d04 79 explicit Config(uint_least8_t readByte = optionAPU)
IanBenzMaxim 0:f77ad7f72d04 80 : readByte_(readByte & 0xF) {}
IanBenzMaxim 0:f77ad7f72d04 81
IanBenzMaxim 0:f77ad7f72d04 82 /// @{
IanBenzMaxim 0:f77ad7f72d04 83 /// 1-Wire Speed
IanBenzMaxim 0:f77ad7f72d04 84 bool get1WS() const { return (readByte_ & option1WS) == option1WS; }
IanBenzMaxim 0:f77ad7f72d04 85 void set1WS(bool new1WS) {
IanBenzMaxim 0:f77ad7f72d04 86 if (new1WS) {
IanBenzMaxim 0:f77ad7f72d04 87 readByte_ |= option1WS;
IanBenzMaxim 0:f77ad7f72d04 88 } else {
IanBenzMaxim 0:f77ad7f72d04 89 readByte_ &= ~option1WS;
IanBenzMaxim 0:f77ad7f72d04 90 }
IanBenzMaxim 0:f77ad7f72d04 91 }
IanBenzMaxim 0:f77ad7f72d04 92 /// @}
IanBenzMaxim 0:f77ad7f72d04 93
IanBenzMaxim 0:f77ad7f72d04 94 /// @{
IanBenzMaxim 0:f77ad7f72d04 95 /// Strong Pullup
IanBenzMaxim 0:f77ad7f72d04 96 bool getSPU() const { return (readByte_ & optionSPU) == optionSPU; }
IanBenzMaxim 0:f77ad7f72d04 97 void setSPU(bool newSPU) {
IanBenzMaxim 0:f77ad7f72d04 98 if (newSPU) {
IanBenzMaxim 0:f77ad7f72d04 99 readByte_ |= optionSPU;
IanBenzMaxim 0:f77ad7f72d04 100 } else {
IanBenzMaxim 0:f77ad7f72d04 101 readByte_ &= ~optionSPU;
IanBenzMaxim 0:f77ad7f72d04 102 }
IanBenzMaxim 0:f77ad7f72d04 103 }
IanBenzMaxim 0:f77ad7f72d04 104 /// @}
IanBenzMaxim 0:f77ad7f72d04 105
IanBenzMaxim 0:f77ad7f72d04 106 /// @{
IanBenzMaxim 0:f77ad7f72d04 107 /// 1-Wire Power Down
IanBenzMaxim 0:f77ad7f72d04 108 bool getPDN() const { return (readByte_ & optionPDN) == optionPDN; }
IanBenzMaxim 0:f77ad7f72d04 109 void setPDN(bool newPDN) {
IanBenzMaxim 0:f77ad7f72d04 110 if (newPDN) {
IanBenzMaxim 0:f77ad7f72d04 111 readByte_ |= optionPDN;
IanBenzMaxim 0:f77ad7f72d04 112 } else {
IanBenzMaxim 0:f77ad7f72d04 113 readByte_ &= ~optionPDN;
IanBenzMaxim 0:f77ad7f72d04 114 }
IanBenzMaxim 0:f77ad7f72d04 115 }
IanBenzMaxim 0:f77ad7f72d04 116 /// @}
IanBenzMaxim 0:f77ad7f72d04 117
IanBenzMaxim 0:f77ad7f72d04 118 /// @{
IanBenzMaxim 0:f77ad7f72d04 119 /// Active Pullup
IanBenzMaxim 0:f77ad7f72d04 120 bool getAPU() const { return (readByte_ & optionAPU) == optionAPU; }
IanBenzMaxim 0:f77ad7f72d04 121 void setAPU(bool newAPU) {
IanBenzMaxim 0:f77ad7f72d04 122 if (newAPU) {
IanBenzMaxim 0:f77ad7f72d04 123 readByte_ |= optionAPU;
IanBenzMaxim 0:f77ad7f72d04 124 } else {
IanBenzMaxim 0:f77ad7f72d04 125 readByte_ &= ~optionAPU;
IanBenzMaxim 0:f77ad7f72d04 126 }
IanBenzMaxim 0:f77ad7f72d04 127 }
IanBenzMaxim 0:f77ad7f72d04 128 /// @}
IanBenzMaxim 0:f77ad7f72d04 129
IanBenzMaxim 0:f77ad7f72d04 130 /// Byte representation that is read from the DS2465.
IanBenzMaxim 0:f77ad7f72d04 131 uint_least8_t readByte() const { return readByte_; }
IanBenzMaxim 0:f77ad7f72d04 132
IanBenzMaxim 0:f77ad7f72d04 133 private:
IanBenzMaxim 0:f77ad7f72d04 134 static const unsigned int option1WS = 0x8;
IanBenzMaxim 0:f77ad7f72d04 135 static const unsigned int optionSPU = 0x4;
IanBenzMaxim 0:f77ad7f72d04 136 static const unsigned int optionPDN = 0x2;
IanBenzMaxim 0:f77ad7f72d04 137 static const unsigned int optionAPU = 0x1;
IanBenzMaxim 0:f77ad7f72d04 138
IanBenzMaxim 0:f77ad7f72d04 139 uint_least8_t readByte_;
IanBenzMaxim 0:f77ad7f72d04 140 };
IanBenzMaxim 0:f77ad7f72d04 141
IanBenzMaxim 0:f77ad7f72d04 142 // Const member functions should not change the settings of the DS2465 or
IanBenzMaxim 0:f77ad7f72d04 143 // affect the state of the 1-Wire bus. Read pointer, scratchpad, MAC output
IanBenzMaxim 0:f77ad7f72d04 144 // register, and command register on the DS2465 are considered mutable.
IanBenzMaxim 0:f77ad7f72d04 145
IanBenzMaxim 0:f77ad7f72d04 146 DS2465(const Sleep & sleep, I2CMaster & i2cMaster,
IanBenzMaxim 0:f77ad7f72d04 147 uint_least8_t i2cAddress = 0x30)
IanBenzMaxim 0:f77ad7f72d04 148 : sleep(&sleep), i2cMaster(&i2cMaster), i2cAddress_(i2cAddress & 0xFE) {}
IanBenzMaxim 0:f77ad7f72d04 149
IanBenzMaxim 0:f77ad7f72d04 150 void setSleep(const Sleep & sleep) { this->sleep = &sleep; }
IanBenzMaxim 0:f77ad7f72d04 151 void setI2CMaster(I2CMaster & i2cMaster) { this->i2cMaster = &i2cMaster; }
IanBenzMaxim 0:f77ad7f72d04 152 uint_least8_t i2cAddress() const { return i2cAddress_; }
IanBenzMaxim 0:f77ad7f72d04 153 void setI2CAddress(uint_least8_t i2cAddress) {
IanBenzMaxim 0:f77ad7f72d04 154 this->i2cAddress_ = (i2cAddress & 0xFE);
IanBenzMaxim 0:f77ad7f72d04 155 }
IanBenzMaxim 0:f77ad7f72d04 156
IanBenzMaxim 0:f77ad7f72d04 157 /// Initialize hardware for use.
IanBenzMaxim 0:f77ad7f72d04 158 MaximInterface_EXPORT error_code initialize(Config config = Config());
IanBenzMaxim 0:f77ad7f72d04 159
IanBenzMaxim 0:f77ad7f72d04 160 /// Write a new configuration to the DS2465.
IanBenzMaxim 0:f77ad7f72d04 161 /// @param[in] config New configuration to write.
IanBenzMaxim 0:f77ad7f72d04 162 MaximInterface_EXPORT error_code writeConfig(Config config);
IanBenzMaxim 0:f77ad7f72d04 163
IanBenzMaxim 0:f77ad7f72d04 164 /// Write a new port configuration parameter to the DS2465.
IanBenzMaxim 0:f77ad7f72d04 165 /// @param[in] param Parameter to adjust.
IanBenzMaxim 0:f77ad7f72d04 166 /// @param[in] val New parameter value to set. Consult datasheet for value
IanBenzMaxim 0:f77ad7f72d04 167 /// mappings.
IanBenzMaxim 0:f77ad7f72d04 168 MaximInterface_EXPORT error_code writePortParameter(PortParameter param,
IanBenzMaxim 0:f77ad7f72d04 169 int val);
IanBenzMaxim 0:f77ad7f72d04 170
IanBenzMaxim 0:f77ad7f72d04 171 // 1-Wire Master Commands
IanBenzMaxim 0:f77ad7f72d04 172
IanBenzMaxim 0:f77ad7f72d04 173 MaximInterface_EXPORT virtual error_code reset();
IanBenzMaxim 0:f77ad7f72d04 174 MaximInterface_EXPORT virtual error_code touchBitSetLevel(bool & sendRecvBit,
IanBenzMaxim 0:f77ad7f72d04 175 Level afterLevel);
IanBenzMaxim 0:f77ad7f72d04 176 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 177 readByteSetLevel(uint_least8_t & recvByte, Level afterLevel);
IanBenzMaxim 0:f77ad7f72d04 178 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 179 writeByteSetLevel(uint_least8_t sendByte, Level afterLevel);
IanBenzMaxim 0:f77ad7f72d04 180 MaximInterface_EXPORT virtual error_code readBlock(uint_least8_t * recvBuf,
IanBenzMaxim 0:f77ad7f72d04 181 size_t recvLen);
IanBenzMaxim 0:f77ad7f72d04 182 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 183 writeBlock(const uint_least8_t * sendBuf, size_t sendLen);
IanBenzMaxim 0:f77ad7f72d04 184 MaximInterface_EXPORT virtual error_code setSpeed(Speed newSpeed);
IanBenzMaxim 0:f77ad7f72d04 185 /// @note The DS2465 only supports enabling strong pullup following a 1-Wire
IanBenzMaxim 0:f77ad7f72d04 186 /// read or write operation.
IanBenzMaxim 0:f77ad7f72d04 187 MaximInterface_EXPORT virtual error_code setLevel(Level newLevel);
IanBenzMaxim 0:f77ad7f72d04 188 MaximInterface_EXPORT virtual error_code triplet(TripletData & data);
IanBenzMaxim 0:f77ad7f72d04 189
IanBenzMaxim 0:f77ad7f72d04 190 // DS2465 Coprocessor Commands
IanBenzMaxim 0:f77ad7f72d04 191
IanBenzMaxim 0:f77ad7f72d04 192 /// Read data from an EEPROM memory page.
IanBenzMaxim 0:f77ad7f72d04 193 /// @param pageNum Page number to read from.
IanBenzMaxim 0:f77ad7f72d04 194 MaximInterface_EXPORT error_code readPage(int pageNum, Page & data) const;
IanBenzMaxim 0:f77ad7f72d04 195
IanBenzMaxim 0:f77ad7f72d04 196 /// Write data to an EEPROM memory page.
IanBenzMaxim 0:f77ad7f72d04 197 /// @param pageNum Page number to copy to.
IanBenzMaxim 0:f77ad7f72d04 198 MaximInterface_EXPORT error_code writePage(int pageNum, const Page & data);
IanBenzMaxim 0:f77ad7f72d04 199
IanBenzMaxim 0:f77ad7f72d04 200 /// Write data to an EEPROM memory segment.
IanBenzMaxim 0:f77ad7f72d04 201 /// @param pageNum Page number to copy to.
IanBenzMaxim 0:f77ad7f72d04 202 /// @param segmentNum Segment number to copy to.
IanBenzMaxim 0:f77ad7f72d04 203 MaximInterface_EXPORT error_code writeSegment(int pageNum, int segmentNum,
IanBenzMaxim 0:f77ad7f72d04 204 const Segment & data);
IanBenzMaxim 0:f77ad7f72d04 205
IanBenzMaxim 0:f77ad7f72d04 206 /// Write data to the secret EEPROM memory page.
IanBenzMaxim 0:f77ad7f72d04 207 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 208 writeMasterSecret(const Sha256::Hash & masterSecret);
IanBenzMaxim 0:f77ad7f72d04 209
IanBenzMaxim 0:f77ad7f72d04 210 /// Compute Next Master Secret.
IanBenzMaxim 0:f77ad7f72d04 211 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 212 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 213 computeNextMasterSecret(const Sha256::SlaveSecretData & data);
IanBenzMaxim 0:f77ad7f72d04 214
IanBenzMaxim 0:f77ad7f72d04 215 /// Compute Next Master Secret with page swapping.
IanBenzMaxim 0:f77ad7f72d04 216 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 217 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 218 /// @param region Region of the page to swap in.
IanBenzMaxim 0:f77ad7f72d04 219 MaximInterface_EXPORT error_code computeNextMasterSecretWithSwap(
IanBenzMaxim 0:f77ad7f72d04 220 const Sha256::SlaveSecretData & data, int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 221
IanBenzMaxim 0:f77ad7f72d04 222 /// Compute Write MAC.
IanBenzMaxim 0:f77ad7f72d04 223 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 224 /// @param[out] mac Computed Write MAC.
IanBenzMaxim 0:f77ad7f72d04 225 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 226 computeWriteMac(const Sha256::WriteMacData & data, Sha256::Hash & mac) const;
IanBenzMaxim 0:f77ad7f72d04 227
IanBenzMaxim 0:f77ad7f72d04 228 /// Compute Write MAC.
IanBenzMaxim 0:f77ad7f72d04 229 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 230 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 231 computeAndTransmitWriteMac(const Sha256::WriteMacData & data) const;
IanBenzMaxim 0:f77ad7f72d04 232
IanBenzMaxim 0:f77ad7f72d04 233 /// Compute Write MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 234 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 235 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 236 /// @param segmentNum Segment number to swap in.
IanBenzMaxim 0:f77ad7f72d04 237 /// @param[out] mac Computed Write MAC.
IanBenzMaxim 0:f77ad7f72d04 238 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 239 computeWriteMacWithSwap(const Sha256::WriteMacData & data, int pageNum,
IanBenzMaxim 0:f77ad7f72d04 240 int segmentNum, Sha256::Hash & mac) const;
IanBenzMaxim 0:f77ad7f72d04 241
IanBenzMaxim 0:f77ad7f72d04 242 /// Compute Write MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 243 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 244 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 245 /// @param segmentNum Segment number to swap in.
IanBenzMaxim 0:f77ad7f72d04 246 MaximInterface_EXPORT error_code computeAndTransmitWriteMacWithSwap(
IanBenzMaxim 0:f77ad7f72d04 247 const Sha256::WriteMacData & data, int pageNum, int segmentNum) const;
IanBenzMaxim 0:f77ad7f72d04 248
IanBenzMaxim 0:f77ad7f72d04 249 /// Compute Slave Secret (S-Secret).
IanBenzMaxim 0:f77ad7f72d04 250 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 251 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 252 computeSlaveSecret(const Sha256::SlaveSecretData & data);
IanBenzMaxim 0:f77ad7f72d04 253
IanBenzMaxim 0:f77ad7f72d04 254 /// Compute Slave Secret (S-Secret) with page swapping.
IanBenzMaxim 0:f77ad7f72d04 255 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 256 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 257 /// @param region Region of the page to swap in.
IanBenzMaxim 0:f77ad7f72d04 258 MaximInterface_EXPORT error_code computeSlaveSecretWithSwap(
IanBenzMaxim 0:f77ad7f72d04 259 const Sha256::SlaveSecretData & data, int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 260
IanBenzMaxim 0:f77ad7f72d04 261 /// Compute Authentication MAC.
IanBenzMaxim 0:f77ad7f72d04 262 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 263 /// @param[out] mac Computed Auth MAC.
IanBenzMaxim 0:f77ad7f72d04 264 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 265 computeAuthMac(const Sha256::AuthMacData & data, Sha256::Hash & mac) const;
IanBenzMaxim 0:f77ad7f72d04 266
IanBenzMaxim 0:f77ad7f72d04 267 /// Compute Authentication MAC.
IanBenzMaxim 0:f77ad7f72d04 268 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 269 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 270 computeAndTransmitAuthMac(const Sha256::AuthMacData & data) const;
IanBenzMaxim 0:f77ad7f72d04 271
IanBenzMaxim 0:f77ad7f72d04 272 /// Compute Authentication MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 273 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 274 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 275 /// @param region Region of the page to swap in.
IanBenzMaxim 0:f77ad7f72d04 276 /// @param[out] mac Computed Auth MAC.
IanBenzMaxim 0:f77ad7f72d04 277 MaximInterface_EXPORT error_code
IanBenzMaxim 0:f77ad7f72d04 278 computeAuthMacWithSwap(const Sha256::AuthMacData & data, int pageNum,
IanBenzMaxim 0:f77ad7f72d04 279 PageRegion region, Sha256::Hash & mac) const;
IanBenzMaxim 0:f77ad7f72d04 280
IanBenzMaxim 0:f77ad7f72d04 281 /// Compute Authentication MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 282 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 283 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 284 /// @param region Region of the page to swap in.
IanBenzMaxim 0:f77ad7f72d04 285 MaximInterface_EXPORT error_code computeAndTransmitAuthMacWithSwap(
IanBenzMaxim 0:f77ad7f72d04 286 const Sha256::AuthMacData & data, int pageNum, PageRegion region) const;
IanBenzMaxim 0:f77ad7f72d04 287
IanBenzMaxim 0:f77ad7f72d04 288 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 0:f77ad7f72d04 289
IanBenzMaxim 0:f77ad7f72d04 290 private:
IanBenzMaxim 0:f77ad7f72d04 291 const Sleep * sleep;
IanBenzMaxim 0:f77ad7f72d04 292 I2CMaster * i2cMaster;
IanBenzMaxim 0:f77ad7f72d04 293 uint_least8_t i2cAddress_;
IanBenzMaxim 0:f77ad7f72d04 294 Config curConfig;
IanBenzMaxim 0:f77ad7f72d04 295
IanBenzMaxim 0:f77ad7f72d04 296 /// Performs a soft reset on the DS2465.
IanBenzMaxim 0:f77ad7f72d04 297 /// @note This is not a 1-Wire Reset.
IanBenzMaxim 0:f77ad7f72d04 298 error_code resetDevice();
IanBenzMaxim 0:f77ad7f72d04 299
IanBenzMaxim 0:f77ad7f72d04 300 /// Polls the DS2465 status waiting for the 1-Wire Busy bit (1WB) to be cleared.
IanBenzMaxim 0:f77ad7f72d04 301 /// @param[out] pStatus Optionally retrive the status byte when 1WB cleared.
IanBenzMaxim 0:f77ad7f72d04 302 /// @returns Success or TimeoutError if poll limit reached.
IanBenzMaxim 0:f77ad7f72d04 303 error_code pollBusy(uint_least8_t * pStatus = NULL) const;
IanBenzMaxim 0:f77ad7f72d04 304
IanBenzMaxim 0:f77ad7f72d04 305 /// Ensure that the desired 1-Wire level is set in the configuration.
IanBenzMaxim 0:f77ad7f72d04 306 /// @param level Desired 1-Wire level.
IanBenzMaxim 0:f77ad7f72d04 307 error_code configureLevel(Level level);
IanBenzMaxim 0:f77ad7f72d04 308
IanBenzMaxim 0:f77ad7f72d04 309 /// Const since only for internal use.
IanBenzMaxim 0:f77ad7f72d04 310 error_code writeMemory(uint_least8_t addr, const uint_least8_t * buf,
IanBenzMaxim 0:f77ad7f72d04 311 size_t bufLen) const;
IanBenzMaxim 0:f77ad7f72d04 312
IanBenzMaxim 0:f77ad7f72d04 313 /// Read memory from the DS2465.
IanBenzMaxim 0:f77ad7f72d04 314 /// @param addr Address to begin reading from.
IanBenzMaxim 0:f77ad7f72d04 315 /// @param[out] buf Buffer to hold read data.
IanBenzMaxim 0:f77ad7f72d04 316 /// @param bufLen Length of buffer, buf, and number of bytes to read.
IanBenzMaxim 0:f77ad7f72d04 317 error_code readMemory(uint_least8_t addr, uint_least8_t * buf,
IanBenzMaxim 0:f77ad7f72d04 318 size_t bufLen) const;
IanBenzMaxim 0:f77ad7f72d04 319
IanBenzMaxim 0:f77ad7f72d04 320 /// Read memory from the DS2465 at the current pointer.
IanBenzMaxim 0:f77ad7f72d04 321 /// @param[out] buf Buffer to hold read data.
IanBenzMaxim 0:f77ad7f72d04 322 /// @param bufLen Length of buffer, buf, and number of bytes to read.
IanBenzMaxim 0:f77ad7f72d04 323 error_code readMemory(uint_least8_t * buf, size_t bufLen) const;
IanBenzMaxim 0:f77ad7f72d04 324
IanBenzMaxim 0:f77ad7f72d04 325 /// Write the last computed MAC to the 1-Wire bus.
IanBenzMaxim 0:f77ad7f72d04 326 error_code writeMacBlock() const;
IanBenzMaxim 0:f77ad7f72d04 327
IanBenzMaxim 0:f77ad7f72d04 328 error_code computeWriteMac(const Sha256::WriteMacData & data) const;
IanBenzMaxim 0:f77ad7f72d04 329
IanBenzMaxim 0:f77ad7f72d04 330 error_code computeWriteMacWithSwap(const Sha256::WriteMacData & data,
IanBenzMaxim 0:f77ad7f72d04 331 int pageNum, int segmentNum) const;
IanBenzMaxim 0:f77ad7f72d04 332
IanBenzMaxim 0:f77ad7f72d04 333 error_code computeAuthMac(const Sha256::AuthMacData & data) const;
IanBenzMaxim 0:f77ad7f72d04 334
IanBenzMaxim 0:f77ad7f72d04 335 error_code computeAuthMacWithSwap(const Sha256::AuthMacData & data,
IanBenzMaxim 0:f77ad7f72d04 336 int pageNum, PageRegion region) const;
IanBenzMaxim 0:f77ad7f72d04 337
IanBenzMaxim 0:f77ad7f72d04 338 // Legacy implementations
IanBenzMaxim 0:f77ad7f72d04 339 error_code copyScratchpad(bool destSecret, int pageNum, bool notFull,
IanBenzMaxim 0:f77ad7f72d04 340 int segmentNum);
IanBenzMaxim 0:f77ad7f72d04 341
IanBenzMaxim 0:f77ad7f72d04 342 error_code computeNextMasterSecret(bool swap, int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 343
IanBenzMaxim 0:f77ad7f72d04 344 error_code computeWriteMac(bool regwrite, bool swap, int pageNum,
IanBenzMaxim 0:f77ad7f72d04 345 int segmentNum) const;
IanBenzMaxim 0:f77ad7f72d04 346
IanBenzMaxim 0:f77ad7f72d04 347 error_code computeSlaveSecret(bool swap, int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 348
IanBenzMaxim 0:f77ad7f72d04 349 error_code computeAuthMac(bool swap, int pageNum, PageRegion region) const;
IanBenzMaxim 0:f77ad7f72d04 350 };
IanBenzMaxim 0:f77ad7f72d04 351
IanBenzMaxim 0:f77ad7f72d04 352 inline error_code make_error_code(DS2465::ErrorValue e) {
IanBenzMaxim 0:f77ad7f72d04 353 return error_code(e, DS2465::errorCategory());
IanBenzMaxim 0:f77ad7f72d04 354 }
IanBenzMaxim 0:f77ad7f72d04 355
IanBenzMaxim 0:f77ad7f72d04 356 } // namespace MaximInterface
IanBenzMaxim 0:f77ad7f72d04 357
IanBenzMaxim 0:f77ad7f72d04 358 #endif