Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
OneWire_Masters/DS2465/DS2465.hpp
- Committer:
- IanBenzMaxim
- Date:
- 2016-03-31
- Revision:
- 33:a4c015046956
- Parent:
- 32:bce180b544ed
- Child:
- 34:11fffbe98ef9
File content as of revision 33:a4c015046956:
#ifndef DS2465_H #define DS2465_H #include "OneWire_Masters/OneWireMaster.h" #include "OneWire_Masters/ISha256MacCoprocessor.hpp" namespace mbed { class I2C; } class DS2465 : public OneWireMaster, public ISha256MacCoprocessor { public: enum PageRegion { REGION_FULL_PAGE = 0x03, REGION_FIRST_HALF = 0x01, REGION_SECOND_HALF = 0x02 }; enum MemoryAddr { ADDR_SPAD = 0x00, ADDR_CMD_REG = 0x60, ADDR_STATUS_REG = 0x61, ADDR_DATA_REG = 0x62, ADDR_MAC_READ = 0x63, ADDR_SHA_SELECT_REG = 0x66, ADDR_WCFG_REG = 0x67, ADDR_TRSTL_REG = 0x68, ADDR_TMSP_REG = 0x69, ADDR_TW0L_REG = 0x6A, ADDR_TREC0_REG = 0x6B, ADDR_RWPU_REG = 0x6C, ADDR_TW1L_REG = 0x6D, ADDR_USER_MEM_PAGE_0 = 0x80, ADDR_USER_MEM_PAGE_1 = 0xA0 }; struct Config { bool c1WS, cSPU, cPDN, cAPU; std::uint8_t readByte() const; std::uint8_t writeByte() const; void reset(); Config() { reset(); } }; DS2465(mbed::I2C & I2C_interface, std::uint8_t I2C_address); // Const member functions should not change the settings of the DS2465 or affect the state of the 1-Wire bus. // Read pointer, scratchpad, MAC output register, and command register on the DS2465 are considered mutable. //Misc. Functions OneWireMaster::CmdResult Detect(void); OneWireMaster::CmdResult Reset(void); // Resets DS2465 (NOTE: This is NOT a 1-Wire Reset) OneWireMaster::CmdResult WriteConfig(const Config & config); Config CurrentConfig() const; // DS2465 Memory Commands OneWireMaster::CmdResult ReadMemory(std::uint8_t addr, std::uint8_t * buf, std::size_t bufLen, bool skip_set_pointer = false) const; OneWireMaster::CmdResult WriteMemory(std::uint8_t addr, const std::uint8_t * buf, std::size_t bufLen) { return CWriteMemory(addr, buf, bufLen); } OneWireMaster::CmdResult WriteScratchpad(const std::uint8_t * buf, std::size_t bufLen) const { return CWriteMemory(ADDR_SPAD, buf, bufLen); } OneWireMaster::CmdResult CopyScratchpad(bool dest_secret, unsigned int pageNum, bool notFull, unsigned int segmentNum); // 1-Wire Master Commands virtual OneWireMaster::CmdResult OWInitMaster(void); virtual OneWireMaster::CmdResult OWReset(void); // Issues a 1-Wire Reset Pulse virtual OneWireMaster::CmdResult OWTouchBit(std::uint8_t & sendrecvbit, OWLevel after_level); virtual OneWireMaster::CmdResult OWReadByte(std::uint8_t & recvbyte, OWLevel after_level); virtual OneWireMaster::CmdResult OWWriteByte(std::uint8_t sendbyte, OWLevel after_level); virtual OneWireMaster::CmdResult OWReadBlock(std::uint8_t *rx_buf, std::uint8_t rx_len); virtual OneWireMaster::CmdResult OWWriteBlock(const std::uint8_t *tran_buf, std::uint8_t tran_len); OneWireMaster::CmdResult OWWriteBlock(bool tx_mac, const std::uint8_t *tran_buf, std::uint8_t tran_len); virtual OneWireMaster::CmdResult OWSetSpeed(OWSpeed new_speed); virtual OneWireMaster::CmdResult OWSetLevel(OWLevel new_level); virtual OneWireMaster::CmdResult OWTriplet(SearchDirection & search_direction, std::uint8_t & sbr, std::uint8_t & tsb); //DS2465 Coprocessor Commands OneWireMaster::CmdResult computeNextMasterSecret(bool swap, unsigned int pageNum, PageRegion region); OneWireMaster::CmdResult computeWriteMac(bool regwrite, bool swap, unsigned int pageNum, unsigned int segmentNum) const; OneWireMaster::CmdResult computeSlaveSecret(bool swap, unsigned int pageNum, PageRegion region); OneWireMaster::CmdResult computeAuthMac(bool swap, unsigned int pageNum, PageRegion region) const; // ISha256MacCoprocessor Commands virtual ISha256MacCoprocessor::CmdResult setMasterSecret(const Secret & secret); virtual ISha256MacCoprocessor::CmdResult computeWriteMac(const WriteMacData & writeMacData, Mac & mac) const; virtual ISha256MacCoprocessor::CmdResult computeAuthMac(const DevicePage & devicePage, const DeviceScratchpad & challenge, const AuthMacData & authMacData, Mac & mac) const; virtual ISha256MacCoprocessor::CmdResult computeSlaveSecret(const DevicePage & devicePage, const DeviceScratchpad & deviceScratchpad, const SlaveSecretData & slaveSecretData); private: mbed::I2C & m_I2C_interface; std::uint8_t m_I2C_address; Config m_curConfig; OneWireMaster::CmdResult CWriteMemory(std::uint8_t addr, const std::uint8_t * buf, std::size_t bufLen) const; OneWireMaster::CmdResult PollBusy(std::uint8_t * pStatus = NULL); OneWireMaster::CmdResult ConfigureLevel(OWLevel level); }; #endif