intiial commit

Dependencies:   MAX8614X USBDevice max32630hsp_test

Revision:
17:e260080d3468
Parent:
16:d0f8cf9f160d
Child:
18:a0356b3e6ed9
--- a/main.cpp	Thu Aug 16 22:00:44 2018 +0000
+++ b/main.cpp	Thu Aug 16 22:30:29 2018 +0000
@@ -109,6 +109,16 @@
         0x79def309,
         0x685981a3
     };
+    uint32_t expectedResponse_2_noRomID[RESPONSE_LEN32] = {  // 160 bit, no ROM
+        0x1a7135a2,
+        0x51b99ca8,
+        0xbdd9245e,
+        0xb9c8e758,
+        0x770ec1c4,
+        0x474ffcc7,
+        0x828afe4d,
+        0x9cb3de6d
+    };
     uint32_t chip_response[RESPONSE_LEN32];
     bool valid = 0;
 
@@ -128,19 +138,27 @@
 //    m.readRegister(MAX8614X::MAX8614X_PART_ID_REG, data, 1);
 //    printf("device id should be 0x24, reg %02X = %02X\r\n", MAX8614X::MAX8614X_PART_ID_REG, data[0]);
 
-//    executeSha256(m, challenge_A, CHALLENGE_SZ_NO_SECRET, 1);
+    //● Compare MAC from MAX86140 wth Host's precalculated MAC.
+//    executeSha256(m, challenge_A, CHALLENGE_SZ_NO_SECRET, 1, chip_response);
+
     executeSha256(m, challenge_1, CHALLENGE_SZ_NO_SECRET, 1, chip_response);
+    //● Check PASS or FAIL.
     valid = isTheChipAuthenicated(chip_response, expectedResponse_1_romID);
     if (valid)
         printf("\r\n             Challenge 1 passed\r\n\r\n");
     else
         printf("\r\n             Challenge 1 failed\r\n\r\n");
-//    executeSha256(m, challenge_2, CHALLENGE_SZ_NO_SECRET, 0);
+
+    executeSha256(m, challenge_2, CHALLENGE_SZ_NO_SECRET, 0, chip_response);
+    valid = isTheChipAuthenicated(chip_response, expectedResponse_2_noRomID);
+    if (valid)
+        printf("\r\n             Challenge 2 passed\r\n\r\n");
+    else
+        printf("\r\n             Challenge 2 failed\r\n\r\n");
 //    executeSha256(m, challenge_3, CHALLENGE_SZ_NO_SECRET, 1);
 //    executeSha256(m, challenge_4, CHALLENGE_SZ_NO_SECRET, 0);
-    //- Compare MAC from MAX86140 wth Host's precalculated MAC.
-    //- Check PASS or FAIL.
-    //- Disable SHA_EN bit ( Write 0 to SHA_EN bit).     
+    //● Check PASS or FAIL.
+    //● Disable SHA_EN bit ( Write 0 to SHA_EN bit).     
     while(1) {
         gLED = !gLED;
         wait(1.0);
@@ -256,14 +274,14 @@
         printf("ROMID \r\n");
 //        m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG, MAX8614X::MAX8614X_SHACMD_MAC_ROM_ID);
         m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG, MAX8614X::MAX8614X_SHACMD_MAC_ROM_ID);
-        wait(1);
+//        wait(1);
 }
     else
 {
          printf("no ROMID \r\n");
 //       m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG,MAX8614X::MAX8614X_SHACMD_MAC_NO_ROM_ID);
        m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG,MAX8614X::MAX8614X_SHACMD_MAC_NO_ROM_ID);
-        wait(1);
+//        wait(1);
 }
 
 
@@ -281,13 +299,11 @@
 ///    printf("sha CFG reg should be 0x3,  reg %02X = %02X\r\n", MAX8614X::MAX8614X_SHA_CFG_REG, data[0]);
     
     //● Wait for SHA_DONE interrupt.
-    m.clearShaComplete();
     data[0] = 0;
-//  while(!m.isShaComplete()) {
-    while(!m.isShaComplete() && !data[0] ) {
+    k = 0;
+    while(!data[0] && k < 100) {
         m.readRegister(MAX8614X::MAX8614X_INT_STATUS2_REG, data, 1);
-        printf("int status2, reg %02X = %X\r\n", MAX8614X::MAX8614X_INT_STATUS2_REG, data[0]);
-        
+        k++;
     }
     // ● Read 256 MAC value from RAM using registers MEM_IDX and MEM_DATA.
     printf("\r\n Raw Output\r\n\r\n");