intiial commit

Dependencies:   MAX8614X USBDevice max32630hsp_test

Revision:
5:df9f75bee8ac
Parent:
4:46919eec2c28
Child:
6:0ec9dd0e8eb0
diff -r 46919eec2c28 -r df9f75bee8ac main.cpp
--- a/main.cpp	Sat Aug 11 10:26:09 2018 +0000
+++ b/main.cpp	Sat Aug 11 22:03:51 2018 +0000
@@ -42,7 +42,8 @@
 SPI spi(P5_1, P5_2, P5_0); /* mosi, miso, sclk */
 //DigitalOut cs(P3_0);
 DigitalOut cs(P5_3);
-PinName interrupt_pin = P5_4;
+PinName interrupt_pin = P3_2;
+//PinName interrupt_pin = P5_4;
 // Virtual serial port over USB
 USBSerial microUSB; 
 
@@ -60,6 +61,8 @@
         0xcd, 0x0d, 0xe3, 0x01
     };
 
+    #define MAC_SZ 32
+    uint8_t macData[MAC_SZ];
     uint8_t data[5];
     int i;
 
@@ -83,7 +86,7 @@
 
 
     //● Enable SHA_EN bit.
-    m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACMD_SHA_EN);
+    m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN);
 
     m.readRegister(MAX8614X::MAX8614X_SHA_CFG_REG, data, 1);
     printf("enable sha cmd, read val = %d\r\n", data[0]);
@@ -105,16 +108,39 @@
         printf("%02x ", data[0]);
     } 
     printf("%\r\n");
-    
+    // The message block consists of a 160-bit secret, a 160-bit challenge and 192 bits of constant data. Optionally, the 64-bit
+    // ROM ID replaces 64 of the 192 bits of constant data used in the hash operation. 16 bits out of the 160-bit secret and 16
+    // bits of ROM ID are programmable–8 bits each in metal and 8 bits each in OTP bits
     //● Write command, with ROM ID (0x35) or without ROM ID (0x36), to SHA_CMD register
+    m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG,MAX8614X::MAX8614X_SHACMD_MAC_ROM_ID);
+
+    m.readRegister(MAX8614X::MAX8614X_SHA_CMD_REG, data, 1);
+    printf("sha cmd reg should be 0x35 mac rom id, read val = %X\r\n", data[0]);
+        m.readRegister(MAX8614X::MAX8614X_INT_STATUS2_REG, data, 1);
+        printf("int status2, read val = %X\r\n", data[0]);
     //● Write 1 to SHA_START and 1 to SHA_EN bit.
+    m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN | MAX8614X::MAX8614X_SHACFG_SHA_START);
+    m.readRegister(MAX8614X::MAX8614X_SHA_CFG_REG, data, 1);
+    printf("sha CFG reg should be 0x3, read val = %X\r\n", data[0]);
     
     //● Wait for SHA_DONE interrupt.
-    //m.clearShaComplete();
-    //while(m.isShaComplete()) {
-    //}   
+    m.clearShaComplete();
+    data[0] = 0;
+//    while(!m.isShaComplete()) {
+    while(!m.isShaComplete() && !data[0] ) {
+        m.readRegister(MAX8614X::MAX8614X_INT_STATUS2_REG, data, 1);
+        printf("int status2, read val = %X\r\n", data[0]);
+        
+    }   
     // ● Read 256 MAC value from RAM using registers MEM_IDX and MEM_DATA.
-    //● Compare MAC from MAX86140 wth Host's precalculated MAC.
+    for (i = 0; i < MAC_SZ; i++) {
+        m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
+        m.readRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, data, 1);
+        macData[i] = data[0];
+        printf("%02x ", data[0]);
+    } 
+     printf("%\r\n");
+   //● Compare MAC from MAX86140 wth Host's precalculated MAC.
     //● Check PASS or FAIL.
     //● Disable SHA_EN bit ( Write 0 to SHA_EN bit).     
     while(1) {