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.
Diff: Slaves/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp
- Revision:
- 113:13e2865603df
- Parent:
- 104:3f48daed532b
- Child:
- 120:200109b73e3c
--- a/Slaves/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp Mon Aug 08 23:25:51 2016 +0000 +++ b/Slaves/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp Tue Aug 09 12:35:22 2016 -0500 @@ -30,7 +30,7 @@ * ownership rights. **********************************************************************/ -#include "Slaves/Authenticators/DS28E15_22_25/DS28E15_22_25.h" +#include "DS28E15_22_25.h" #include "Masters/OneWireMaster.h" #include "Utilities/crc.h" #include "wait_api.h" @@ -53,6 +53,22 @@ AuthWriteBlockProtection = 0xCC, }; +/// Number for memory pages for each device. +enum MemoryPages +{ + DS28E25_Pages = 16, + DS28E22_Pages = 8, + DS28E15_Pages = 2 +}; + +/// Number of protection blocks for each device. +enum ProtectionBlocks +{ + DS28E25_Blocks = 8, + DS28E22_Blocks = 4, + DS28E15_Blocks = 4 +}; + DS28E15_22_25::Segment DS28E15_22_25::Page::toSegment(unsigned int segmentNum) const { if (segmentNum > (segmentsPerPage - 1)) @@ -139,64 +155,12 @@ } } -DS28E15_22_25::DS28E15_22_25(RandomAccessRomIterator & selector, bool lowVoltage) - : OneWireSlave(selector), m_lowVoltage(lowVoltage) +DS28E15_22_25::DS28E15_22_25(RandomAccessRomIterator & selector, bool lowVoltage, FamilyCode variant) + : OneWireSlave(selector), m_lowVoltage(lowVoltage), m_variant(variant) { std::memset(m_manId, 0x00, m_manId.length); } -DS28E15_22_25::MemoryPages DS28E15_22_25::memoryPages() -{ - MemoryPages pages; - - switch (romId().familyCode()) - { - case DS28E25_Family: - pages = DS28E25_Pages; - break; - - case DS28E22_Family: - pages = DS28E22_Pages; - break; - - case DS28E15_Family: - pages = DS28E15_Pages; - break; - - default: - pages = Unknown_Pages; - break; - } - - return pages; -} - -DS28E15_22_25::ProtectionBlocks DS28E15_22_25::protectionBlocks() -{ - ProtectionBlocks blocks; - - switch (romId().familyCode()) - { - case DS28E25_Family: - blocks = DS28E25_Blocks; - break; - - case DS28E22_Family: - blocks = DS28E22_Blocks; - break; - - case DS28E15_Family: - blocks = DS28E15_Blocks; - break; - - default: - blocks = Unknown_Blocks; - break; - } - - return blocks; -} - OneWireSlave::CmdResult DS28E15_22_25::writeAuthBlockProtection(const ISha256MacCoproc & MacCoproc, const BlockProtection & newProtection, const BlockProtection & oldProtection) { uint8_t buf[256], cs; @@ -340,30 +304,6 @@ return result; } -template <DS28E15_22_25::ProtectionBlocks blocks> OneWireSlave::CmdResult DS28E15_22_25::readAllBlockProtection(BlockProtection(&protection)[blocks]) const -{ - uint8_t buf[blocks]; - CmdResult result = readStatus(false, true, 0, buf); - if (result == Success) - { - for (size_t i = 0; i < blocks; i++) - { - protection[i].setStatusByte(buf[i]); - } - } - return result; -} - -OneWireSlave::CmdResult DS28E15_22_25::readAllBlockProtection(BlockProtection(&protection)[DS28E15_Blocks]) const -{ - return readAllBlockProtection<DS28E15_Blocks>(protection); -} - -OneWireSlave::CmdResult DS28E15_22_25::readAllBlockProtection(BlockProtection(&protection)[DS28E25_Blocks]) const -{ - return readAllBlockProtection<DS28E25_Blocks>(protection); -} - OneWireSlave::CmdResult DS28E15_22_25::readPersonality(Personality & personality) const { return readStatus(true, false, 0, personality.bytes); @@ -394,7 +334,7 @@ { // Convert to page number for DS28E22 and DS28E25 buf[cnt] = blockNum; - if ((romId().familyCode() == DS28E25_Family) || (romId().familyCode() == DS28E22_Family)) + if ((m_variant == DS28E25_Family) || (m_variant == DS28E22_Family)) { buf[cnt] *= ds28e22_25_pagesPerBlock; } @@ -416,7 +356,7 @@ { rdnum = 1; } - else if ((romId().familyCode() == DS28E22_Family) || (romId().familyCode() == DS28E25_Family)) + else if ((m_variant == DS28E22_Family) || (m_variant == DS28E25_Family)) { rdnum = DS28E25_Pages; // Need to read extra data on DS28E22 to get CRC16. } @@ -447,9 +387,9 @@ // copy the data to the read buffer rdnum -= crcLen; - if (allpages && ((romId().familyCode() == DS28E25_Family) || (romId().familyCode() == DS28E22_Family))) + if (allpages && ((m_variant == DS28E25_Family) || (m_variant == DS28E22_Family))) { - if (romId().familyCode() == DS28E22_Family) + if (m_variant == DS28E22_Family) { rdnum -= (DS28E25_Pages - DS28E22_Pages); } @@ -605,7 +545,7 @@ } buf[cnt++] = ReadWriteScratchpad; - if ((romId().familyCode() == DS28E25_Family) || (romId().familyCode() == DS28E22_Family)) + if ((m_variant == DS28E25_Family) || (m_variant == DS28E22_Family)) { buf[cnt++] = 0x20; } @@ -660,7 +600,7 @@ } buf[cnt++] = ReadWriteScratchpad; - if ((romId().familyCode() == DS28E25_Family) || (romId().familyCode() == DS28E22_Family)) + if ((m_variant == DS28E25_Family) || (m_variant == DS28E22_Family)) { buf[cnt++] = 0x2F; } @@ -867,7 +807,7 @@ uint16_t CRC16 = 0; // DS28E25/DS28E22, crc gets calculagted with CS byte - if ((romId().familyCode() == DS28E25_Family) || (romId().familyCode() == DS28E22_Family)) + if ((m_variant == DS28E25_Family) || (m_variant == DS28E22_Family)) { if (continuing) { @@ -1039,7 +979,7 @@ uint16_t CRC16 = 0; // DS28E25/DS28E22, crc gets calculagted with CS byte - if ((romId().familyCode() == DS28E25_Family) || (romId().familyCode() == DS28E22_Family)) + if ((m_variant == DS28E25_Family) || (m_variant == DS28E22_Family)) { if (continuing) CRC16 = calculateCrc16(CRC16, 0xAA);