intiial commit

Dependencies:   MAX8614X USBDevice max32630hsp_test

Committer:
phonemacro
Date:
Sun Aug 12 00:02:14 2018 +0000
Revision:
6:0ec9dd0e8eb0
Parent:
5:df9f75bee8ac
Child:
7:5b7f7ec9efe0
Add comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:9e5a4f845510 1 /**********************************************************************
phonemacro 1:854f8a89a527 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:9e5a4f845510 3 *
phonemacro 0:9e5a4f845510 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:9e5a4f845510 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:9e5a4f845510 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:9e5a4f845510 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:9e5a4f845510 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:9e5a4f845510 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:9e5a4f845510 10 *
phonemacro 0:9e5a4f845510 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:9e5a4f845510 12 * in all copies or substantial portions of the Software.
phonemacro 0:9e5a4f845510 13 *
phonemacro 0:9e5a4f845510 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:9e5a4f845510 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:9e5a4f845510 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:9e5a4f845510 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:9e5a4f845510 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:9e5a4f845510 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:9e5a4f845510 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:9e5a4f845510 21 *
phonemacro 0:9e5a4f845510 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:9e5a4f845510 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:9e5a4f845510 24 * Products, Inc. Branding Policy.
phonemacro 0:9e5a4f845510 25 *
phonemacro 0:9e5a4f845510 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:9e5a4f845510 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:9e5a4f845510 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:9e5a4f845510 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:9e5a4f845510 30 * ownership rights.
phonemacro 0:9e5a4f845510 31 **********************************************************************/
phonemacro 0:9e5a4f845510 32
phonemacro 0:9e5a4f845510 33
phonemacro 0:9e5a4f845510 34 #include "mbed.h"
phonemacro 0:9e5a4f845510 35 //#include "max32630fthr.h"
phonemacro 0:9e5a4f845510 36 #include "max32630hsp.h"
phonemacro 0:9e5a4f845510 37 #include "MAX8614X.h"
phonemacro 0:9e5a4f845510 38 #include "USBSerial.h"
phonemacro 0:9e5a4f845510 39
phonemacro 0:9e5a4f845510 40 MAX32630HSP icarus(MAX32630HSP::VIO_1V8);
phonemacro 0:9e5a4f845510 41 // MAX32630FTHR mbed_board(MAX32630FTHR::VIO_1V8);
phonemacro 0:9e5a4f845510 42 SPI spi(P5_1, P5_2, P5_0); /* mosi, miso, sclk */
phonemacro 3:2272f89aad7e 43 //DigitalOut cs(P3_0);
phonemacro 3:2272f89aad7e 44 DigitalOut cs(P5_3);
phonemacro 6:0ec9dd0e8eb0 45 //PinName interrupt_pin = P3_3;
phonemacro 6:0ec9dd0e8eb0 46 //PinnName interrupt_pin = P5_7;
phonemacro 6:0ec9dd0e8eb0 47 //PinName interrupt_pin = P5_5;
phonemacro 6:0ec9dd0e8eb0 48 //PinName interrupt_pin = P3_6;
phonemacro 6:0ec9dd0e8eb0 49 //PinName interrupt_pin = P3_7;
phonemacro 6:0ec9dd0e8eb0 50 //PinName interrupt_pin = P3_2;
phonemacro 6:0ec9dd0e8eb0 51 PinName interrupt_pin = P5_4;
phonemacro 0:9e5a4f845510 52 // Virtual serial port over USB
phonemacro 0:9e5a4f845510 53 USBSerial microUSB;
phonemacro 0:9e5a4f845510 54
phonemacro 0:9e5a4f845510 55 DigitalOut rLED(LED1);
phonemacro 0:9e5a4f845510 56 DigitalOut gLED(LED2);
phonemacro 0:9e5a4f845510 57 DigitalOut bLED(LED3);
phonemacro 0:9e5a4f845510 58 int main()
phonemacro 0:9e5a4f845510 59 {
phonemacro 4:46919eec2c28 60 #define CHALLENGE_SZ 20
phonemacro 4:46919eec2c28 61 static const uint8_t challenge_1[CHALLENGE_SZ] = { // 160 bit
phonemacro 4:46919eec2c28 62 0x5e, 0x81, 0x35, 0x24,
phonemacro 4:46919eec2c28 63 0x56, 0x63, 0xd6, 0x09,
phonemacro 4:46919eec2c28 64 0x99, 0x8d, 0x7b, 0x0d,
phonemacro 4:46919eec2c28 65 0x52, 0x12, 0x84, 0x65,
phonemacro 4:46919eec2c28 66 0xcd, 0x0d, 0xe3, 0x01
phonemacro 4:46919eec2c28 67 };
phonemacro 4:46919eec2c28 68
phonemacro 5:df9f75bee8ac 69 #define MAC_SZ 32
phonemacro 5:df9f75bee8ac 70 uint8_t macData[MAC_SZ];
phonemacro 3:2272f89aad7e 71 uint8_t data[5];
phonemacro 4:46919eec2c28 72 int i;
phonemacro 0:9e5a4f845510 73
phonemacro 0:9e5a4f845510 74 // daplink.printf("daplink serial port\r\n");
phonemacro 0:9e5a4f845510 75 // microUSB.printf("micro USB serial port\r\n");
phonemacro 0:9e5a4f845510 76 rLED = LED_ON;
phonemacro 0:9e5a4f845510 77 gLED = LED_ON;
phonemacro 0:9e5a4f845510 78 bLED = LED_OFF;
phonemacro 0:9e5a4f845510 79
phonemacro 0:9e5a4f845510 80 rLED = LED_OFF;
phonemacro 1:854f8a89a527 81 printf("\r\n\rmax86140 authenication software\r\n");
phonemacro 0:9e5a4f845510 82 MAX8614X m(spi,cs,interrupt_pin);
phonemacro 4:46919eec2c28 83 m.readRegister(MAX8614X::MAX8614X_PART_ID_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 84 printf("device id should be 0x24, reg %02X = %02X\r\n", MAX8614X::MAX8614X_PART_ID_REG, data[0]);
phonemacro 4:46919eec2c28 85
phonemacro 4:46919eec2c28 86 //● Enable SHA_DONE Interrupt
phonemacro 4:46919eec2c28 87 m.writeRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, MAX8614X::MAX8614X_IE_SHA_DONE_EN);
phonemacro 4:46919eec2c28 88
phonemacro 4:46919eec2c28 89 m.readRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 90 printf("enable sha done interrupt, reg %02X = %02X\r\n", MAX8614X::MAX8614X_INT_ENABLE2_REG, data[0]);
phonemacro 4:46919eec2c28 91
phonemacro 4:46919eec2c28 92
phonemacro 4:46919eec2c28 93 //● Enable SHA_EN bit.
phonemacro 5:df9f75bee8ac 94 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN);
phonemacro 3:2272f89aad7e 95
phonemacro 4:46919eec2c28 96 m.readRegister(MAX8614X::MAX8614X_SHA_CFG_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 97 printf("enable sha CFG, reg %02X = %02X\r\n", MAX8614X::MAX8614X_SHA_CFG_REG, data[0]);
phonemacro 4:46919eec2c28 98
phonemacro 4:46919eec2c28 99 //● Write 160-bit random challenge value to RAM using registers MEM_IDX and MEM_DATA.
phonemacro 4:46919eec2c28 100 // Enable Memory Write, Select Bank 0, address 0x00 to 0xFF
phonemacro 4:46919eec2c28 101 m.writeRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, MAX8614X::MAX8614X_MEMCNTRL_WR_EN_MASK | MAX8614X::MAX8614X_MEMCNTRL_BANK0_MASK);
phonemacro 4:46919eec2c28 102 m.readRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 103 printf("MEM CNTRL REG should be 2, reg %02X = = %02X\r\n", MAX8614X::MAX8614X_MEMORY_CONTROL_REG, data[0]);
phonemacro 4:46919eec2c28 104
phonemacro 4:46919eec2c28 105 for (i = 0; i < CHALLENGE_SZ; i++) {
phonemacro 4:46919eec2c28 106 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 4:46919eec2c28 107 m.writeRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, challenge_1[i]);
phonemacro 4:46919eec2c28 108 }
phonemacro 3:2272f89aad7e 109
phonemacro 4:46919eec2c28 110 for (i = 0; i < CHALLENGE_SZ; i++) {
phonemacro 4:46919eec2c28 111 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 4:46919eec2c28 112 m.readRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, data, 1);
phonemacro 4:46919eec2c28 113 printf("%02x ", data[0]);
phonemacro 4:46919eec2c28 114 }
phonemacro 4:46919eec2c28 115 printf("%\r\n");
phonemacro 5:df9f75bee8ac 116 // The message block consists of a 160-bit secret, a 160-bit challenge and 192 bits of constant data. Optionally, the 64-bit
phonemacro 5:df9f75bee8ac 117 // 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
phonemacro 5:df9f75bee8ac 118 // bits of ROM ID are programmable–8 bits each in metal and 8 bits each in OTP bits
phonemacro 4:46919eec2c28 119 //● Write command, with ROM ID (0x35) or without ROM ID (0x36), to SHA_CMD register
phonemacro 5:df9f75bee8ac 120 m.writeRegister(MAX8614X::MAX8614X_SHA_CMD_REG,MAX8614X::MAX8614X_SHACMD_MAC_ROM_ID);
phonemacro 5:df9f75bee8ac 121
phonemacro 5:df9f75bee8ac 122 m.readRegister(MAX8614X::MAX8614X_SHA_CMD_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 123 printf("sha cmd reg should be 0x35 mac rom id, reg %02X = %02X\r\n", MAX8614X::MAX8614X_SHA_CMD_REG, data[0]);
phonemacro 5:df9f75bee8ac 124 m.readRegister(MAX8614X::MAX8614X_INT_STATUS2_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 125 printf("int status2, reg %02X = %X\r\n", MAX8614X::MAX8614X_INT_STATUS2_REG, data[0]);
phonemacro 4:46919eec2c28 126 //● Write 1 to SHA_START and 1 to SHA_EN bit.
phonemacro 5:df9f75bee8ac 127 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACFG_SHA_EN | MAX8614X::MAX8614X_SHACFG_SHA_START);
phonemacro 5:df9f75bee8ac 128 m.readRegister(MAX8614X::MAX8614X_SHA_CFG_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 129 printf("sha CFG reg should be 0x3, reg %02X = %02X\r\n", MAX8614X::MAX8614X_SHA_CFG_REG, data[0]);
phonemacro 4:46919eec2c28 130
phonemacro 4:46919eec2c28 131 //● Wait for SHA_DONE interrupt.
phonemacro 5:df9f75bee8ac 132 m.clearShaComplete();
phonemacro 5:df9f75bee8ac 133 data[0] = 0;
phonemacro 6:0ec9dd0e8eb0 134 // while(!m.isShaComplete()) {
phonemacro 5:df9f75bee8ac 135 while(!m.isShaComplete() && !data[0] ) {
phonemacro 5:df9f75bee8ac 136 m.readRegister(MAX8614X::MAX8614X_INT_STATUS2_REG, data, 1);
phonemacro 6:0ec9dd0e8eb0 137 printf("int status2, reg %02X = %X\r\n", MAX8614X::MAX8614X_INT_STATUS2_REG, data[0]);
phonemacro 5:df9f75bee8ac 138
phonemacro 5:df9f75bee8ac 139 }
phonemacro 4:46919eec2c28 140 // ● Read 256 MAC value from RAM using registers MEM_IDX and MEM_DATA.
phonemacro 5:df9f75bee8ac 141 for (i = 0; i < MAC_SZ; i++) {
phonemacro 5:df9f75bee8ac 142 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 5:df9f75bee8ac 143 m.readRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, data, 1);
phonemacro 5:df9f75bee8ac 144 macData[i] = data[0];
phonemacro 5:df9f75bee8ac 145 printf("%02x ", data[0]);
phonemacro 5:df9f75bee8ac 146 }
phonemacro 5:df9f75bee8ac 147 printf("%\r\n");
phonemacro 5:df9f75bee8ac 148 //● Compare MAC from MAX86140 wth Host's precalculated MAC.
phonemacro 4:46919eec2c28 149 //● Check PASS or FAIL.
phonemacro 4:46919eec2c28 150 //● Disable SHA_EN bit ( Write 0 to SHA_EN bit).
phonemacro 0:9e5a4f845510 151 while(1) {
phonemacro 1:854f8a89a527 152 gLED = !gLED;
phonemacro 0:9e5a4f845510 153 wait(1.0);
phonemacro 0:9e5a4f845510 154 }
phonemacro 0:9e5a4f845510 155 }
phonemacro 0:9e5a4f845510 156