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.

Revision:
33:a4c015046956
Parent:
32:bce180b544ed
Child:
34:11fffbe98ef9
diff -r bce180b544ed -r a4c015046956 OneWire_Masters/DS2465/DS2465.cpp
--- a/OneWire_Masters/DS2465/DS2465.cpp	Wed Mar 30 16:50:29 2016 -0500
+++ b/OneWire_Masters/DS2465/DS2465.cpp	Thu Mar 31 11:56:01 2016 -0500
@@ -97,7 +97,7 @@
 // Returns: true write successful
 //          false failure to complete read
 //
-OneWireMaster::CmdResult DS2465::Compute_NextMasterSecret(bool swap, unsigned int pageNum, PageRegion region)
+OneWireMaster::CmdResult DS2465::computeNextMasterSecret(bool swap, unsigned int pageNum, PageRegion region)
 {
    std::uint8_t command[2] = { CMD_CNMS, (swap ? (0xC8 | (pageNum << 4) | region) : 0xBF) };
    return WriteMemory(ADDR_CMD_REG, command, 2);
@@ -114,7 +114,7 @@
 // Returns: true write successful
 //          false failure to complete read
 //
-OneWireMaster::CmdResult DS2465::Compute_WriteMAC(bool regwrite, bool swap, unsigned int pageNum, unsigned int segmentNum) const
+OneWireMaster::CmdResult DS2465::computeWriteMac(bool regwrite, bool swap, unsigned int pageNum, unsigned int segmentNum) const
 {
    std::uint8_t command[2] = { CMD_CSWM, ((regwrite << 7) | (swap << 6) | (pageNum << 4) | segmentNum) };
    return CWriteMemory(ADDR_CMD_REG, command, 2);
@@ -130,7 +130,7 @@
 // Returns: true write successful
 //          false failure to complete read
 //
-OneWireMaster::CmdResult DS2465::Compute_AuthMAC(bool swap, unsigned int pageNum, PageRegion region) const
+OneWireMaster::CmdResult DS2465::computeAuthMac(bool swap, unsigned int pageNum, PageRegion region) const
 {
    std::uint8_t command[2] = { CMD_CSAM, (swap ? (0xC8 | (pageNum << 4) | region) : 0xBF) };
    return CWriteMemory(ADDR_CMD_REG, command, 2);
@@ -146,7 +146,7 @@
 // Returns: true write successful
 //          false failure to complete read
 //
-OneWireMaster::CmdResult DS2465::Compute_SSecret(bool swap, unsigned int pageNum, PageRegion region)
+OneWireMaster::CmdResult DS2465::computeSlaveSecret(bool swap, unsigned int pageNum, PageRegion region)
 {
    std::uint8_t command[2] = { CMD_CSS, (swap ? (0xC8 | (pageNum << 4) | region) : 0xBF) };
    return WriteMemory(ADDR_CMD_REG, command, 2);
@@ -155,10 +155,10 @@
 
 
 
-ISha256MacCoprocessor::CmdResult DS2465::setMasterSecret(const std::uint8_t (&secret)[secret_len])
+ISha256MacCoprocessor::CmdResult DS2465::setMasterSecret(const Secret & secret)
 {
   OneWireMaster::CmdResult result;
-  result = WriteMemory(ADDR_SPAD, secret, secret_len);
+  result = WriteMemory(ADDR_SPAD, secret, secret.length);
   if (result == OneWireMaster::Success)
     result = CopyScratchpad(1, 0, 1, 0);
   if (result == OneWireMaster::Success)
@@ -166,72 +166,70 @@
   return (result == OneWireMaster::Success ? ISha256MacCoprocessor::Success : ISha256MacCoprocessor::OperationFailure);
 }
 
-ISha256MacCoprocessor::CmdResult DS2465::ComputeAndRead_WriteMAC(const std::uint8_t (&WriteMAC_data)[WriteMAC_data_len], std::uint8_t (&mac)[mac_len]) const
+ISha256MacCoprocessor::CmdResult DS2465::computeWriteMac(const WriteMacData & writeMacData, Mac & mac) const
 {
   OneWireMaster::CmdResult result;
   // Write input data to scratchpad
-  result = WriteScratchpad(WriteMAC_data, WriteMAC_data_len);
+  result = WriteScratchpad(writeMacData, writeMacData.length);
   // Compute MAC
   if (result == OneWireMaster::Success)
-    result = Compute_WriteMAC(false, false, 0, 0);
+    result = computeWriteMac(false, false, 0, 0);
   if (result == OneWireMaster::Success)
   {
     wait_ms(SHA_COMPUTATION_DELAY);
     // Read MAC from register
-    result = ReadMemory(ADDR_MAC_READ, mac, mac_len, true);
+    result = ReadMemory(ADDR_MAC_READ, mac, mac.length, true);
   }
   return (result == OneWireMaster::Success ? ISha256MacCoprocessor::Success : ISha256MacCoprocessor::OperationFailure);
 }
 
-ISha256MacCoprocessor::CmdResult DS2465::ComputeAndRead_AuthMAC(const std::uint8_t (&devicePage)[devicePage_len], const std::uint8_t (&challenge)[deviceScratchpad_len],
-                                    const std::uint8_t (&AuthMAC_data)[AuthMAC_data_len], std::uint8_t (&mac)[mac_len]) const
+ISha256MacCoprocessor::CmdResult DS2465::computeAuthMac(const DevicePage & devicePage, const DeviceScratchpad & challenge, const AuthMacData & authMacData, Mac & mac) const
 {
   OneWireMaster::CmdResult result;
   int addr = ADDR_SPAD;
   // Write input data to scratchpad
-  result = CWriteMemory(addr, devicePage, devicePage_len);
+  result = CWriteMemory(addr, devicePage, devicePage.length);
   if (result == OneWireMaster::Success)
   {
-    addr += devicePage_len;
-    result = CWriteMemory(addr, challenge, deviceScratchpad_len);
+    addr += devicePage.length;
+    result = CWriteMemory(addr, challenge, challenge.length);
   }
   if (result == OneWireMaster::Success)
   {
-    addr += deviceScratchpad_len;
-    result = CWriteMemory(addr, AuthMAC_data, AuthMAC_data_len);
+    addr += challenge.length;
+    result = CWriteMemory(addr, authMacData, authMacData.length);
   }
   // Compute MAC
   if (result == OneWireMaster::Success)
-    result = Compute_AuthMAC(false, 0, REGION_FULL_PAGE);
+    result = computeAuthMac(false, 0, REGION_FULL_PAGE);
   if (result == OneWireMaster::Success)
   {
     wait_ms(SHA_COMPUTATION_DELAY * 2);
     // Read MAC from register
-    result = ReadMemory(ADDR_MAC_READ, mac, mac_len, true);
+    result = ReadMemory(ADDR_MAC_READ, mac, mac.length, true);
   }
   return (result == OneWireMaster::Success ? ISha256MacCoprocessor::Success : ISha256MacCoprocessor::OperationFailure);
 }
 
-ISha256MacCoprocessor::CmdResult DS2465::Compute_SSecret(const std::uint8_t (&devicePage)[devicePage_len], const std::uint8_t (&deviceScratchpad)[deviceScratchpad_len],
-                             const std::uint8_t (&SSecret_data)[SSecret_data_len])
+ISha256MacCoprocessor::CmdResult DS2465::computeSlaveSecret(const DevicePage & devicePage, const DeviceScratchpad & deviceScratchpad, const SlaveSecretData & slaveSecretData)
 {
   OneWireMaster::CmdResult result;
   int addr = ADDR_SPAD;
   // Write input data to scratchpad
-  result = WriteMemory(addr, devicePage, devicePage_len);
+  result = WriteMemory(addr, devicePage, devicePage.length);
   if (result == OneWireMaster::Success)
   {
-    addr += devicePage_len;
-    result = WriteMemory(addr, deviceScratchpad, deviceScratchpad_len);
+    addr += devicePage.length;
+    result = WriteMemory(addr, deviceScratchpad, deviceScratchpad.length);
   }
   if (result == OneWireMaster::Success)
   {
-    addr += deviceScratchpad_len;
-    result = WriteMemory(addr, SSecret_data, SSecret_data_len);
+    addr += deviceScratchpad.length;
+    result = WriteMemory(addr, slaveSecretData, slaveSecretData.length);
   }
   // Compute secret
   if (result == OneWireMaster::Success)
-    result = Compute_SSecret(false, 0, REGION_FULL_PAGE);
+    result = computeSlaveSecret(false, 0, REGION_FULL_PAGE);
   if (result == OneWireMaster::Success)
     wait_ms(SHA_COMPUTATION_DELAY * 2);
   return (result == OneWireMaster::Success ? ISha256MacCoprocessor::Success : ISha256MacCoprocessor::OperationFailure);