Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
reARMnimator
Date:
Mon Jan 06 15:54:55 2020 +0000
Revision:
10:de4b8812877d
Parent:
7:471901a04573
Fixed inappropriate include path.

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 6:a8c83a2e6fa4 39 #include <MaximInterface/Utilities/array_span.hpp>
IanBenzMaxim 0:f77ad7f72d04 40 #include <MaximInterface/Utilities/Export.h>
IanBenzMaxim 0:f77ad7f72d04 41 #include <MaximInterface/Utilities/Sha256.hpp>
IanBenzMaxim 0:f77ad7f72d04 42
IanBenzMaxim 0:f77ad7f72d04 43 namespace MaximInterface {
IanBenzMaxim 0:f77ad7f72d04 44
IanBenzMaxim 0:f77ad7f72d04 45 /// Interface to the DS2465 1-Wire master and SHA-256 coprocessor.
IanBenzMaxim 0:f77ad7f72d04 46 class DS2465 : public OneWireMaster {
IanBenzMaxim 0:f77ad7f72d04 47 public:
IanBenzMaxim 0:f77ad7f72d04 48 enum ErrorValue { HardwareError = 1, ArgumentOutOfRangeError };
IanBenzMaxim 0:f77ad7f72d04 49
IanBenzMaxim 7:471901a04573 50 /// @brief 1-Wire port adjustment parameters.
IanBenzMaxim 0:f77ad7f72d04 51 /// @note See datasheet page 13.
IanBenzMaxim 0:f77ad7f72d04 52 enum PortParameter {
IanBenzMaxim 0:f77ad7f72d04 53 tRSTL_STD,
IanBenzMaxim 0:f77ad7f72d04 54 tRSTL_OD,
IanBenzMaxim 0:f77ad7f72d04 55 tMSP_STD,
IanBenzMaxim 0:f77ad7f72d04 56 tMSP_OD,
IanBenzMaxim 0:f77ad7f72d04 57 tW0L_STD,
IanBenzMaxim 0:f77ad7f72d04 58 tW0L_OD,
IanBenzMaxim 0:f77ad7f72d04 59 tREC0,
IanBenzMaxim 0:f77ad7f72d04 60 RWPU,
IanBenzMaxim 0:f77ad7f72d04 61 tW1L_OD
IanBenzMaxim 0:f77ad7f72d04 62 };
IanBenzMaxim 0:f77ad7f72d04 63
IanBenzMaxim 0:f77ad7f72d04 64 /// Page region to use for swapping.
IanBenzMaxim 0:f77ad7f72d04 65 enum PageRegion { FullPage = 0x03, FirstHalf = 0x01, SecondHalf = 0x02 };
IanBenzMaxim 0:f77ad7f72d04 66
IanBenzMaxim 0:f77ad7f72d04 67 /// Holds the contents of a device memory segment.
IanBenzMaxim 6:a8c83a2e6fa4 68 typedef array_span<uint_least8_t, 4> Segment;
IanBenzMaxim 0:f77ad7f72d04 69
IanBenzMaxim 0:f77ad7f72d04 70 /// Holds the contents of a device memory page.
IanBenzMaxim 6:a8c83a2e6fa4 71 typedef array_span<uint_least8_t, 32> Page;
IanBenzMaxim 0:f77ad7f72d04 72
IanBenzMaxim 0:f77ad7f72d04 73 static const int memoryPages = 2;
IanBenzMaxim 6:a8c83a2e6fa4 74 static const int segmentsPerPage = Page::size / Segment::size;
IanBenzMaxim 0:f77ad7f72d04 75
IanBenzMaxim 0:f77ad7f72d04 76 /// Represents a DS2465 configuration.
IanBenzMaxim 0:f77ad7f72d04 77 class Config {
IanBenzMaxim 0:f77ad7f72d04 78 public:
IanBenzMaxim 0:f77ad7f72d04 79 /// Default construct with power-on config.
IanBenzMaxim 0:f77ad7f72d04 80 explicit Config(uint_least8_t readByte = optionAPU)
IanBenzMaxim 0:f77ad7f72d04 81 : readByte_(readByte & 0xF) {}
IanBenzMaxim 0:f77ad7f72d04 82
IanBenzMaxim 7:471901a04573 83 /// @name 1WS
IanBenzMaxim 7:471901a04573 84 /// @brief 1-Wire Speed
IanBenzMaxim 0:f77ad7f72d04 85 /// @{
IanBenzMaxim 7:471901a04573 86
IanBenzMaxim 7:471901a04573 87 /// Get 1WS bit.
IanBenzMaxim 0:f77ad7f72d04 88 bool get1WS() const { return (readByte_ & option1WS) == option1WS; }
IanBenzMaxim 6:a8c83a2e6fa4 89
IanBenzMaxim 7:471901a04573 90 /// Set 1WS bit.
IanBenzMaxim 6:a8c83a2e6fa4 91 Config & set1WS(bool new1WS) {
IanBenzMaxim 0:f77ad7f72d04 92 if (new1WS) {
IanBenzMaxim 0:f77ad7f72d04 93 readByte_ |= option1WS;
IanBenzMaxim 0:f77ad7f72d04 94 } else {
IanBenzMaxim 0:f77ad7f72d04 95 readByte_ &= ~option1WS;
IanBenzMaxim 0:f77ad7f72d04 96 }
IanBenzMaxim 6:a8c83a2e6fa4 97 return *this;
IanBenzMaxim 0:f77ad7f72d04 98 }
IanBenzMaxim 7:471901a04573 99
IanBenzMaxim 0:f77ad7f72d04 100 /// @}
IanBenzMaxim 0:f77ad7f72d04 101
IanBenzMaxim 7:471901a04573 102 /// @name SPU
IanBenzMaxim 7:471901a04573 103 /// @brief Strong Pullup
IanBenzMaxim 0:f77ad7f72d04 104 /// @{
IanBenzMaxim 7:471901a04573 105
IanBenzMaxim 7:471901a04573 106 /// Get SPU bit.
IanBenzMaxim 0:f77ad7f72d04 107 bool getSPU() const { return (readByte_ & optionSPU) == optionSPU; }
IanBenzMaxim 6:a8c83a2e6fa4 108
IanBenzMaxim 7:471901a04573 109 /// Set SPU bit.
IanBenzMaxim 6:a8c83a2e6fa4 110 Config & setSPU(bool newSPU) {
IanBenzMaxim 0:f77ad7f72d04 111 if (newSPU) {
IanBenzMaxim 0:f77ad7f72d04 112 readByte_ |= optionSPU;
IanBenzMaxim 0:f77ad7f72d04 113 } else {
IanBenzMaxim 0:f77ad7f72d04 114 readByte_ &= ~optionSPU;
IanBenzMaxim 0:f77ad7f72d04 115 }
IanBenzMaxim 6:a8c83a2e6fa4 116 return *this;
IanBenzMaxim 0:f77ad7f72d04 117 }
IanBenzMaxim 7:471901a04573 118
IanBenzMaxim 0:f77ad7f72d04 119 /// @}
IanBenzMaxim 0:f77ad7f72d04 120
IanBenzMaxim 7:471901a04573 121 /// @name PDN
IanBenzMaxim 7:471901a04573 122 /// @brief 1-Wire Power Down
IanBenzMaxim 0:f77ad7f72d04 123 /// @{
IanBenzMaxim 7:471901a04573 124
IanBenzMaxim 7:471901a04573 125 /// Get PDN bit.
IanBenzMaxim 0:f77ad7f72d04 126 bool getPDN() const { return (readByte_ & optionPDN) == optionPDN; }
IanBenzMaxim 6:a8c83a2e6fa4 127
IanBenzMaxim 7:471901a04573 128 /// Set PDN bit.
IanBenzMaxim 6:a8c83a2e6fa4 129 Config & setPDN(bool newPDN) {
IanBenzMaxim 0:f77ad7f72d04 130 if (newPDN) {
IanBenzMaxim 0:f77ad7f72d04 131 readByte_ |= optionPDN;
IanBenzMaxim 0:f77ad7f72d04 132 } else {
IanBenzMaxim 0:f77ad7f72d04 133 readByte_ &= ~optionPDN;
IanBenzMaxim 0:f77ad7f72d04 134 }
IanBenzMaxim 6:a8c83a2e6fa4 135 return *this;
IanBenzMaxim 0:f77ad7f72d04 136 }
IanBenzMaxim 7:471901a04573 137
IanBenzMaxim 0:f77ad7f72d04 138 /// @}
IanBenzMaxim 0:f77ad7f72d04 139
IanBenzMaxim 7:471901a04573 140 /// @name APU
IanBenzMaxim 7:471901a04573 141 /// @brief Active Pullup
IanBenzMaxim 0:f77ad7f72d04 142 /// @{
IanBenzMaxim 7:471901a04573 143
IanBenzMaxim 7:471901a04573 144 /// Get APU bit.
IanBenzMaxim 0:f77ad7f72d04 145 bool getAPU() const { return (readByte_ & optionAPU) == optionAPU; }
IanBenzMaxim 6:a8c83a2e6fa4 146
IanBenzMaxim 7:471901a04573 147 /// Set APU bit.
IanBenzMaxim 6:a8c83a2e6fa4 148 Config & setAPU(bool newAPU) {
IanBenzMaxim 0:f77ad7f72d04 149 if (newAPU) {
IanBenzMaxim 0:f77ad7f72d04 150 readByte_ |= optionAPU;
IanBenzMaxim 0:f77ad7f72d04 151 } else {
IanBenzMaxim 0:f77ad7f72d04 152 readByte_ &= ~optionAPU;
IanBenzMaxim 0:f77ad7f72d04 153 }
IanBenzMaxim 6:a8c83a2e6fa4 154 return *this;
IanBenzMaxim 0:f77ad7f72d04 155 }
IanBenzMaxim 7:471901a04573 156
IanBenzMaxim 0:f77ad7f72d04 157 /// @}
IanBenzMaxim 0:f77ad7f72d04 158
IanBenzMaxim 0:f77ad7f72d04 159 /// Byte representation that is read from the DS2465.
IanBenzMaxim 0:f77ad7f72d04 160 uint_least8_t readByte() const { return readByte_; }
IanBenzMaxim 0:f77ad7f72d04 161
IanBenzMaxim 0:f77ad7f72d04 162 private:
IanBenzMaxim 0:f77ad7f72d04 163 static const unsigned int option1WS = 0x8;
IanBenzMaxim 0:f77ad7f72d04 164 static const unsigned int optionSPU = 0x4;
IanBenzMaxim 0:f77ad7f72d04 165 static const unsigned int optionPDN = 0x2;
IanBenzMaxim 0:f77ad7f72d04 166 static const unsigned int optionAPU = 0x1;
IanBenzMaxim 0:f77ad7f72d04 167
IanBenzMaxim 0:f77ad7f72d04 168 uint_least8_t readByte_;
IanBenzMaxim 0:f77ad7f72d04 169 };
IanBenzMaxim 0:f77ad7f72d04 170
IanBenzMaxim 0:f77ad7f72d04 171 // Const member functions should not change the settings of the DS2465 or
IanBenzMaxim 0:f77ad7f72d04 172 // affect the state of the 1-Wire bus. Read pointer, scratchpad, MAC output
IanBenzMaxim 0:f77ad7f72d04 173 // register, and command register on the DS2465 are considered mutable.
IanBenzMaxim 0:f77ad7f72d04 174
IanBenzMaxim 6:a8c83a2e6fa4 175 DS2465(Sleep & sleep, I2CMaster & master, uint_least8_t address = 0x30)
IanBenzMaxim 6:a8c83a2e6fa4 176 : sleep(&sleep), master(&master), address_(address & 0xFE) {}
IanBenzMaxim 0:f77ad7f72d04 177
IanBenzMaxim 6:a8c83a2e6fa4 178 void setSleep(Sleep & sleep) { this->sleep = &sleep; }
IanBenzMaxim 6:a8c83a2e6fa4 179
IanBenzMaxim 6:a8c83a2e6fa4 180 void setMaster(I2CMaster & master) { this->master = &master; }
IanBenzMaxim 6:a8c83a2e6fa4 181
IanBenzMaxim 6:a8c83a2e6fa4 182 uint_least8_t address() const { return address_; }
IanBenzMaxim 6:a8c83a2e6fa4 183
IanBenzMaxim 6:a8c83a2e6fa4 184 void setAddress(uint_least8_t address) { address_ = address & 0xFE; }
IanBenzMaxim 0:f77ad7f72d04 185
IanBenzMaxim 0:f77ad7f72d04 186 /// Initialize hardware for use.
IanBenzMaxim 0:f77ad7f72d04 187 MaximInterface_EXPORT error_code initialize(Config config = Config());
IanBenzMaxim 0:f77ad7f72d04 188
IanBenzMaxim 7:471901a04573 189 /// @brief Write a new configuration to the DS2465.
IanBenzMaxim 0:f77ad7f72d04 190 /// @param[in] config New configuration to write.
IanBenzMaxim 0:f77ad7f72d04 191 MaximInterface_EXPORT error_code writeConfig(Config config);
IanBenzMaxim 0:f77ad7f72d04 192
IanBenzMaxim 7:471901a04573 193 /// @brief Write a new port configuration parameter to the DS2465.
IanBenzMaxim 0:f77ad7f72d04 194 /// @param[in] param Parameter to adjust.
IanBenzMaxim 7:471901a04573 195 /// @param[in] val
IanBenzMaxim 7:471901a04573 196 /// New parameter value to set. Consult datasheet for value mappings.
IanBenzMaxim 0:f77ad7f72d04 197 MaximInterface_EXPORT error_code writePortParameter(PortParameter param,
IanBenzMaxim 0:f77ad7f72d04 198 int val);
IanBenzMaxim 0:f77ad7f72d04 199
IanBenzMaxim 0:f77ad7f72d04 200 // 1-Wire Master Commands
IanBenzMaxim 0:f77ad7f72d04 201
IanBenzMaxim 0:f77ad7f72d04 202 MaximInterface_EXPORT virtual error_code reset();
IanBenzMaxim 6:a8c83a2e6fa4 203
IanBenzMaxim 0:f77ad7f72d04 204 MaximInterface_EXPORT virtual error_code touchBitSetLevel(bool & sendRecvBit,
IanBenzMaxim 0:f77ad7f72d04 205 Level afterLevel);
IanBenzMaxim 6:a8c83a2e6fa4 206
IanBenzMaxim 0:f77ad7f72d04 207 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 208 readByteSetLevel(uint_least8_t & recvByte, Level afterLevel);
IanBenzMaxim 6:a8c83a2e6fa4 209
IanBenzMaxim 0:f77ad7f72d04 210 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 0:f77ad7f72d04 211 writeByteSetLevel(uint_least8_t sendByte, Level afterLevel);
IanBenzMaxim 6:a8c83a2e6fa4 212
IanBenzMaxim 6:a8c83a2e6fa4 213 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 6:a8c83a2e6fa4 214 readBlock(span<uint_least8_t> recvBuf);
IanBenzMaxim 6:a8c83a2e6fa4 215
IanBenzMaxim 0:f77ad7f72d04 216 MaximInterface_EXPORT virtual error_code
IanBenzMaxim 6:a8c83a2e6fa4 217 writeBlock(span<const uint_least8_t> sendBuf);
IanBenzMaxim 6:a8c83a2e6fa4 218
IanBenzMaxim 0:f77ad7f72d04 219 MaximInterface_EXPORT virtual error_code setSpeed(Speed newSpeed);
IanBenzMaxim 6:a8c83a2e6fa4 220
IanBenzMaxim 7:471901a04573 221 /// @copydoc OneWireMaster::setLevel
IanBenzMaxim 7:471901a04573 222 /// @note
IanBenzMaxim 7:471901a04573 223 /// The DS2465 only supports enabling strong pullup following a 1-Wire read or
IanBenzMaxim 7:471901a04573 224 /// write operation.
IanBenzMaxim 0:f77ad7f72d04 225 MaximInterface_EXPORT virtual error_code setLevel(Level newLevel);
IanBenzMaxim 6:a8c83a2e6fa4 226
IanBenzMaxim 0:f77ad7f72d04 227 MaximInterface_EXPORT virtual error_code triplet(TripletData & data);
IanBenzMaxim 0:f77ad7f72d04 228
IanBenzMaxim 0:f77ad7f72d04 229 // DS2465 Coprocessor Commands
IanBenzMaxim 6:a8c83a2e6fa4 230
IanBenzMaxim 7:471901a04573 231 /// @brief Read data from an EEPROM memory page.
IanBenzMaxim 0:f77ad7f72d04 232 /// @param pageNum Page number to read from.
IanBenzMaxim 7:471901a04573 233 /// @param[out] data Data that was read.
IanBenzMaxim 6:a8c83a2e6fa4 234 MaximInterface_EXPORT error_code readPage(int pageNum, Page::span data) const;
IanBenzMaxim 0:f77ad7f72d04 235
IanBenzMaxim 7:471901a04573 236 /// @brief Write data to an EEPROM memory page.
IanBenzMaxim 0:f77ad7f72d04 237 /// @param pageNum Page number to copy to.
IanBenzMaxim 7:471901a04573 238 /// @param data Data to write.
IanBenzMaxim 6:a8c83a2e6fa4 239 MaximInterface_EXPORT error_code writePage(int pageNum,
IanBenzMaxim 6:a8c83a2e6fa4 240 Page::const_span data);
IanBenzMaxim 0:f77ad7f72d04 241
IanBenzMaxim 7:471901a04573 242 /// @brief Write data to an EEPROM memory segment.
IanBenzMaxim 0:f77ad7f72d04 243 /// @param pageNum Page number to copy to.
IanBenzMaxim 0:f77ad7f72d04 244 /// @param segmentNum Segment number to copy to.
IanBenzMaxim 7:471901a04573 245 /// @param data Data to write.
IanBenzMaxim 0:f77ad7f72d04 246 MaximInterface_EXPORT error_code writeSegment(int pageNum, int segmentNum,
IanBenzMaxim 6:a8c83a2e6fa4 247 Segment::const_span data);
IanBenzMaxim 0:f77ad7f72d04 248
IanBenzMaxim 0:f77ad7f72d04 249 /// Write data to the secret EEPROM memory page.
IanBenzMaxim 0:f77ad7f72d04 250 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 251 writeMasterSecret(Sha256::Hash::const_span masterSecret);
IanBenzMaxim 0:f77ad7f72d04 252
IanBenzMaxim 7:471901a04573 253 /// @brief Compute Next Master Secret.
IanBenzMaxim 0:f77ad7f72d04 254 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 255 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 256 computeNextMasterSecret(Sha256::AuthenticationData::const_span data);
IanBenzMaxim 0:f77ad7f72d04 257
IanBenzMaxim 7:471901a04573 258 /// @brief Compute Next Master Secret with page swapping.
IanBenzMaxim 0:f77ad7f72d04 259 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 260 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 261 /// @param region Region of the page to swap in.
IanBenzMaxim 6:a8c83a2e6fa4 262 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 263 computeNextMasterSecretWithSwap(Sha256::AuthenticationData::const_span data,
IanBenzMaxim 6:a8c83a2e6fa4 264 int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 265
IanBenzMaxim 7:471901a04573 266 /// @brief Compute Write MAC.
IanBenzMaxim 0:f77ad7f72d04 267 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 268 /// @param[out] mac Computed Write MAC.
IanBenzMaxim 6:a8c83a2e6fa4 269 MaximInterface_EXPORT error_code computeWriteMac(
IanBenzMaxim 6:a8c83a2e6fa4 270 Sha256::WriteMacData::const_span data, Sha256::Hash::span mac) const;
IanBenzMaxim 0:f77ad7f72d04 271
IanBenzMaxim 7:471901a04573 272 /// @brief Compute Write MAC.
IanBenzMaxim 0:f77ad7f72d04 273 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 274 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 275 computeAndTransmitWriteMac(Sha256::WriteMacData::const_span data) const;
IanBenzMaxim 0:f77ad7f72d04 276
IanBenzMaxim 7:471901a04573 277 /// @brief Compute Write MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 278 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 279 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 280 /// @param segmentNum Segment number to swap in.
IanBenzMaxim 0:f77ad7f72d04 281 /// @param[out] mac Computed Write MAC.
IanBenzMaxim 0:f77ad7f72d04 282 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 283 computeWriteMacWithSwap(Sha256::WriteMacData::const_span data, int pageNum,
IanBenzMaxim 6:a8c83a2e6fa4 284 int segmentNum, Sha256::Hash::span mac) const;
IanBenzMaxim 0:f77ad7f72d04 285
IanBenzMaxim 7:471901a04573 286 /// @brief Compute Write MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 287 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 288 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 289 /// @param segmentNum Segment number to swap in.
IanBenzMaxim 0:f77ad7f72d04 290 MaximInterface_EXPORT error_code computeAndTransmitWriteMacWithSwap(
IanBenzMaxim 6:a8c83a2e6fa4 291 Sha256::WriteMacData::const_span data, int pageNum, int segmentNum) const;
IanBenzMaxim 0:f77ad7f72d04 292
IanBenzMaxim 7:471901a04573 293 /// @brief Compute Slave Secret (S-Secret).
IanBenzMaxim 0:f77ad7f72d04 294 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 295 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 296 computeSlaveSecret(Sha256::AuthenticationData::const_span data);
IanBenzMaxim 0:f77ad7f72d04 297
IanBenzMaxim 7:471901a04573 298 /// @brief Compute Slave Secret (S-Secret) with page swapping.
IanBenzMaxim 0:f77ad7f72d04 299 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 300 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 301 /// @param region Region of the page to swap in.
IanBenzMaxim 6:a8c83a2e6fa4 302 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 303 computeSlaveSecretWithSwap(Sha256::AuthenticationData::const_span data,
IanBenzMaxim 6:a8c83a2e6fa4 304 int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 305
IanBenzMaxim 7:471901a04573 306 /// @brief Compute Authentication MAC.
IanBenzMaxim 0:f77ad7f72d04 307 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 308 /// @param[out] mac Computed Auth MAC.
IanBenzMaxim 0:f77ad7f72d04 309 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 310 computeAuthMac(Sha256::AuthenticationData::const_span data,
IanBenzMaxim 6:a8c83a2e6fa4 311 Sha256::Hash::span mac) const;
IanBenzMaxim 0:f77ad7f72d04 312
IanBenzMaxim 7:471901a04573 313 /// @brief Compute Authentication MAC.
IanBenzMaxim 0:f77ad7f72d04 314 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 315 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 316 computeAndTransmitAuthMac(Sha256::AuthenticationData::const_span data) const;
IanBenzMaxim 0:f77ad7f72d04 317
IanBenzMaxim 7:471901a04573 318 /// @brief Compute Authentication MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 319 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 320 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 321 /// @param region Region of the page to swap in.
IanBenzMaxim 0:f77ad7f72d04 322 /// @param[out] mac Computed Auth MAC.
IanBenzMaxim 6:a8c83a2e6fa4 323 MaximInterface_EXPORT error_code computeAuthMacWithSwap(
IanBenzMaxim 6:a8c83a2e6fa4 324 Sha256::AuthenticationData::const_span data, int pageNum,
IanBenzMaxim 6:a8c83a2e6fa4 325 PageRegion region, Sha256::Hash::span mac) const;
IanBenzMaxim 0:f77ad7f72d04 326
IanBenzMaxim 7:471901a04573 327 /// @brief Compute Authentication MAC with page swapping.
IanBenzMaxim 0:f77ad7f72d04 328 /// @param data Combined data fields for computation.
IanBenzMaxim 0:f77ad7f72d04 329 /// @param pageNum Page number to swap in.
IanBenzMaxim 0:f77ad7f72d04 330 /// @param region Region of the page to swap in.
IanBenzMaxim 6:a8c83a2e6fa4 331 MaximInterface_EXPORT error_code
IanBenzMaxim 6:a8c83a2e6fa4 332 computeAndTransmitAuthMacWithSwap(Sha256::AuthenticationData::const_span data,
IanBenzMaxim 6:a8c83a2e6fa4 333 int pageNum, PageRegion region) const;
IanBenzMaxim 0:f77ad7f72d04 334
IanBenzMaxim 0:f77ad7f72d04 335 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 0:f77ad7f72d04 336
IanBenzMaxim 0:f77ad7f72d04 337 private:
IanBenzMaxim 0:f77ad7f72d04 338 const Sleep * sleep;
IanBenzMaxim 6:a8c83a2e6fa4 339 I2CMaster * master;
IanBenzMaxim 6:a8c83a2e6fa4 340 uint_least8_t address_;
IanBenzMaxim 0:f77ad7f72d04 341 Config curConfig;
IanBenzMaxim 0:f77ad7f72d04 342
IanBenzMaxim 7:471901a04573 343 /// @brief Performs a soft reset on the DS2465.
IanBenzMaxim 0:f77ad7f72d04 344 /// @note This is not a 1-Wire Reset.
IanBenzMaxim 0:f77ad7f72d04 345 error_code resetDevice();
IanBenzMaxim 0:f77ad7f72d04 346
IanBenzMaxim 7:471901a04573 347 /// @brief
IanBenzMaxim 7:471901a04573 348 /// Polls the DS2465 status waiting for the 1-Wire Busy bit (1WB) to be
IanBenzMaxim 7:471901a04573 349 /// cleared.
IanBenzMaxim 0:f77ad7f72d04 350 /// @param[out] pStatus Optionally retrive the status byte when 1WB cleared.
IanBenzMaxim 0:f77ad7f72d04 351 /// @returns Success or TimeoutError if poll limit reached.
IanBenzMaxim 0:f77ad7f72d04 352 error_code pollBusy(uint_least8_t * pStatus = NULL) const;
IanBenzMaxim 0:f77ad7f72d04 353
IanBenzMaxim 7:471901a04573 354 /// @brief Ensure that the desired 1-Wire level is set in the configuration.
IanBenzMaxim 0:f77ad7f72d04 355 /// @param level Desired 1-Wire level.
IanBenzMaxim 0:f77ad7f72d04 356 error_code configureLevel(Level level);
IanBenzMaxim 0:f77ad7f72d04 357
IanBenzMaxim 7:471901a04573 358 /// @note Const since only for internal use.
IanBenzMaxim 6:a8c83a2e6fa4 359 error_code writeMemory(uint_least8_t addr,
IanBenzMaxim 6:a8c83a2e6fa4 360 span<const uint_least8_t> buf) const;
IanBenzMaxim 0:f77ad7f72d04 361
IanBenzMaxim 7:471901a04573 362 /// @brief Read memory from the DS2465.
IanBenzMaxim 0:f77ad7f72d04 363 /// @param addr Address to begin reading from.
IanBenzMaxim 0:f77ad7f72d04 364 /// @param[out] buf Buffer to hold read data.
IanBenzMaxim 6:a8c83a2e6fa4 365 error_code readMemory(uint_least8_t addr, span<uint_least8_t> buf) const;
IanBenzMaxim 0:f77ad7f72d04 366
IanBenzMaxim 7:471901a04573 367 /// @brief Read memory from the DS2465 at the current pointer.
IanBenzMaxim 0:f77ad7f72d04 368 /// @param[out] buf Buffer to hold read data.
IanBenzMaxim 6:a8c83a2e6fa4 369 error_code readMemory(span<uint_least8_t> buf) const;
IanBenzMaxim 0:f77ad7f72d04 370
IanBenzMaxim 0:f77ad7f72d04 371 /// Write the last computed MAC to the 1-Wire bus.
IanBenzMaxim 0:f77ad7f72d04 372 error_code writeMacBlock() const;
IanBenzMaxim 0:f77ad7f72d04 373
IanBenzMaxim 6:a8c83a2e6fa4 374 error_code computeWriteMac(Sha256::WriteMacData::const_span data) const;
IanBenzMaxim 0:f77ad7f72d04 375
IanBenzMaxim 6:a8c83a2e6fa4 376 error_code computeWriteMacWithSwap(Sha256::WriteMacData::const_span data,
IanBenzMaxim 0:f77ad7f72d04 377 int pageNum, int segmentNum) const;
IanBenzMaxim 0:f77ad7f72d04 378
IanBenzMaxim 6:a8c83a2e6fa4 379 error_code computeAuthMac(Sha256::AuthenticationData::const_span data) const;
IanBenzMaxim 0:f77ad7f72d04 380
IanBenzMaxim 6:a8c83a2e6fa4 381 error_code computeAuthMacWithSwap(Sha256::AuthenticationData::const_span data,
IanBenzMaxim 0:f77ad7f72d04 382 int pageNum, PageRegion region) const;
IanBenzMaxim 0:f77ad7f72d04 383
IanBenzMaxim 0:f77ad7f72d04 384 // Legacy implementations
IanBenzMaxim 0:f77ad7f72d04 385 error_code copyScratchpad(bool destSecret, int pageNum, bool notFull,
IanBenzMaxim 0:f77ad7f72d04 386 int segmentNum);
IanBenzMaxim 0:f77ad7f72d04 387
IanBenzMaxim 0:f77ad7f72d04 388 error_code computeNextMasterSecret(bool swap, int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 389
IanBenzMaxim 0:f77ad7f72d04 390 error_code computeWriteMac(bool regwrite, bool swap, int pageNum,
IanBenzMaxim 0:f77ad7f72d04 391 int segmentNum) const;
IanBenzMaxim 0:f77ad7f72d04 392
IanBenzMaxim 0:f77ad7f72d04 393 error_code computeSlaveSecret(bool swap, int pageNum, PageRegion region);
IanBenzMaxim 0:f77ad7f72d04 394
IanBenzMaxim 0:f77ad7f72d04 395 error_code computeAuthMac(bool swap, int pageNum, PageRegion region) const;
IanBenzMaxim 0:f77ad7f72d04 396 };
IanBenzMaxim 0:f77ad7f72d04 397
IanBenzMaxim 0:f77ad7f72d04 398 inline error_code make_error_code(DS2465::ErrorValue e) {
IanBenzMaxim 0:f77ad7f72d04 399 return error_code(e, DS2465::errorCategory());
IanBenzMaxim 0:f77ad7f72d04 400 }
IanBenzMaxim 0:f77ad7f72d04 401
IanBenzMaxim 0:f77ad7f72d04 402 } // namespace MaximInterface
IanBenzMaxim 0:f77ad7f72d04 403
IanBenzMaxim 0:f77ad7f72d04 404 #endif