intiial commit

Dependencies:   MAX8614X USBDevice max32630hsp_test

Files at this revision

API Documentation at this revision

Comitter:
phonemacro
Date:
Sat Aug 11 10:26:09 2018 +0000
Parent:
3:2272f89aad7e
Child:
5:df9f75bee8ac
Commit message:
Add challenge 1

Changed in this revision

MAX86140.lib Show annotated file Show diff for this revision Revisions of this file
MAX8614X.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX86140.lib	Sat Aug 11 10:26:09 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/MaximIntegrated/code/MAX8614X/#11e0b5b86e1e
--- a/MAX8614X.lib	Sat Aug 11 00:39:38 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/teams/MaximIntegrated/code/MAX8614X/#7ae9b934ee55
--- a/main.cpp	Sat Aug 11 00:39:38 2018 +0000
+++ b/main.cpp	Sat Aug 11 10:26:09 2018 +0000
@@ -51,8 +51,17 @@
 DigitalOut bLED(LED3);
 int main()
 {
+    #define CHALLENGE_SZ 20
+    static const uint8_t challenge_1[CHALLENGE_SZ] = {  // 160 bit
+        0x5e, 0x81, 0x35, 0x24,
+        0x56, 0x63, 0xd6, 0x09,
+        0x99, 0x8d, 0x7b, 0x0d,
+        0x52, 0x12, 0x84, 0x65,
+        0xcd, 0x0d, 0xe3, 0x01
+    };
+
     uint8_t data[5];
-    int c;
+    int i;
 
 //    daplink.printf("daplink serial port\r\n");
 //    microUSB.printf("micro USB serial port\r\n");
@@ -63,13 +72,51 @@
     rLED = LED_OFF;
     printf("\r\n\rmax86140 authenication software\r\n");
     MAX8614X m(spi,cs,interrupt_pin);
-    m.readRegister(0xff, data, 1);
+    m.readRegister(MAX8614X::MAX8614X_PART_ID_REG, data, 1);
     printf("device id should be 0x24, read val = %x\r\n", data[0]);
-    m.writeRegister(0x3,1);
+
+    //● Enable SHA_DONE Interrupt
+    m.writeRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, MAX8614X::MAX8614X_IE_SHA_DONE_EN);
+
+    m.readRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, data, 1);
+    printf("enable sha done interrupt, read val = %d\r\n", data[0]);
+
+
+    //● Enable SHA_EN bit.
+    m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACMD_SHA_EN);
 
-    m.readRegister(0x3, data, 1);
-    printf("enable sha, read val = %d\r\n", data[0]);
+    m.readRegister(MAX8614X::MAX8614X_SHA_CFG_REG, data, 1);
+    printf("enable sha cmd, read val = %d\r\n", data[0]);
+    
+    //● Write 160-bit random challenge value to RAM using registers MEM_IDX and MEM_DATA.
+    // Enable Memory Write, Select Bank 0, address 0x00 to 0xFF
+    m.writeRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, MAX8614X::MAX8614X_MEMCNTRL_WR_EN_MASK | MAX8614X::MAX8614X_MEMCNTRL_BANK0_MASK);
+       m.readRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, data, 1);
+    printf("MEM CNTRL REG should be 2, read val = %d\r\n", data[0]);
+ 
+    for (i = 0; i < CHALLENGE_SZ; i++) {
+        m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
+        m.writeRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, challenge_1[i]);
+    } 
 
+    for (i = 0; i < CHALLENGE_SZ; i++) {
+        m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
+        m.readRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, data, 1);
+        printf("%02x ", data[0]);
+    } 
+    printf("%\r\n");
+    
+    //● Write command, with ROM ID (0x35) or without ROM ID (0x36), to SHA_CMD register
+    //● Write 1 to SHA_START and 1 to SHA_EN bit.
+    
+    //● Wait for SHA_DONE interrupt.
+    //m.clearShaComplete();
+    //while(m.isShaComplete()) {
+    //}   
+    // ● Read 256 MAC value from RAM using registers MEM_IDX and MEM_DATA.
+    //● 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) {
         gLED = !gLED;
         wait(1.0);