intiial commit

Dependencies:   MAX8614X USBDevice max32630hsp_test

Committer:
phonemacro
Date:
Sat Aug 11 10:26:09 2018 +0000
Revision:
4:46919eec2c28
Parent:
3:2272f89aad7e
Child:
5:df9f75bee8ac
Add challenge 1

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 0:9e5a4f845510 45 PinName interrupt_pin = P5_4;
phonemacro 0:9e5a4f845510 46 // Virtual serial port over USB
phonemacro 0:9e5a4f845510 47 USBSerial microUSB;
phonemacro 0:9e5a4f845510 48
phonemacro 0:9e5a4f845510 49 DigitalOut rLED(LED1);
phonemacro 0:9e5a4f845510 50 DigitalOut gLED(LED2);
phonemacro 0:9e5a4f845510 51 DigitalOut bLED(LED3);
phonemacro 0:9e5a4f845510 52 int main()
phonemacro 0:9e5a4f845510 53 {
phonemacro 4:46919eec2c28 54 #define CHALLENGE_SZ 20
phonemacro 4:46919eec2c28 55 static const uint8_t challenge_1[CHALLENGE_SZ] = { // 160 bit
phonemacro 4:46919eec2c28 56 0x5e, 0x81, 0x35, 0x24,
phonemacro 4:46919eec2c28 57 0x56, 0x63, 0xd6, 0x09,
phonemacro 4:46919eec2c28 58 0x99, 0x8d, 0x7b, 0x0d,
phonemacro 4:46919eec2c28 59 0x52, 0x12, 0x84, 0x65,
phonemacro 4:46919eec2c28 60 0xcd, 0x0d, 0xe3, 0x01
phonemacro 4:46919eec2c28 61 };
phonemacro 4:46919eec2c28 62
phonemacro 3:2272f89aad7e 63 uint8_t data[5];
phonemacro 4:46919eec2c28 64 int i;
phonemacro 0:9e5a4f845510 65
phonemacro 0:9e5a4f845510 66 // daplink.printf("daplink serial port\r\n");
phonemacro 0:9e5a4f845510 67 // microUSB.printf("micro USB serial port\r\n");
phonemacro 0:9e5a4f845510 68 rLED = LED_ON;
phonemacro 0:9e5a4f845510 69 gLED = LED_ON;
phonemacro 0:9e5a4f845510 70 bLED = LED_OFF;
phonemacro 0:9e5a4f845510 71
phonemacro 0:9e5a4f845510 72 rLED = LED_OFF;
phonemacro 1:854f8a89a527 73 printf("\r\n\rmax86140 authenication software\r\n");
phonemacro 0:9e5a4f845510 74 MAX8614X m(spi,cs,interrupt_pin);
phonemacro 4:46919eec2c28 75 m.readRegister(MAX8614X::MAX8614X_PART_ID_REG, data, 1);
phonemacro 1:854f8a89a527 76 printf("device id should be 0x24, read val = %x\r\n", data[0]);
phonemacro 4:46919eec2c28 77
phonemacro 4:46919eec2c28 78 //● Enable SHA_DONE Interrupt
phonemacro 4:46919eec2c28 79 m.writeRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, MAX8614X::MAX8614X_IE_SHA_DONE_EN);
phonemacro 4:46919eec2c28 80
phonemacro 4:46919eec2c28 81 m.readRegister(MAX8614X::MAX8614X_INT_ENABLE2_REG, data, 1);
phonemacro 4:46919eec2c28 82 printf("enable sha done interrupt, read val = %d\r\n", data[0]);
phonemacro 4:46919eec2c28 83
phonemacro 4:46919eec2c28 84
phonemacro 4:46919eec2c28 85 //● Enable SHA_EN bit.
phonemacro 4:46919eec2c28 86 m.writeRegister(MAX8614X::MAX8614X_SHA_CFG_REG,MAX8614X::MAX8614X_SHACMD_SHA_EN);
phonemacro 3:2272f89aad7e 87
phonemacro 4:46919eec2c28 88 m.readRegister(MAX8614X::MAX8614X_SHA_CFG_REG, data, 1);
phonemacro 4:46919eec2c28 89 printf("enable sha cmd, read val = %d\r\n", data[0]);
phonemacro 4:46919eec2c28 90
phonemacro 4:46919eec2c28 91 //● Write 160-bit random challenge value to RAM using registers MEM_IDX and MEM_DATA.
phonemacro 4:46919eec2c28 92 // Enable Memory Write, Select Bank 0, address 0x00 to 0xFF
phonemacro 4:46919eec2c28 93 m.writeRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, MAX8614X::MAX8614X_MEMCNTRL_WR_EN_MASK | MAX8614X::MAX8614X_MEMCNTRL_BANK0_MASK);
phonemacro 4:46919eec2c28 94 m.readRegister(MAX8614X::MAX8614X_MEMORY_CONTROL_REG, data, 1);
phonemacro 4:46919eec2c28 95 printf("MEM CNTRL REG should be 2, read val = %d\r\n", data[0]);
phonemacro 4:46919eec2c28 96
phonemacro 4:46919eec2c28 97 for (i = 0; i < CHALLENGE_SZ; i++) {
phonemacro 4:46919eec2c28 98 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 4:46919eec2c28 99 m.writeRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, challenge_1[i]);
phonemacro 4:46919eec2c28 100 }
phonemacro 3:2272f89aad7e 101
phonemacro 4:46919eec2c28 102 for (i = 0; i < CHALLENGE_SZ; i++) {
phonemacro 4:46919eec2c28 103 m.writeRegister(MAX8614X::MAX8614X_MEMORY_INDEX_REG, i);
phonemacro 4:46919eec2c28 104 m.readRegister(MAX8614X::MAX8614X_MEMORY_DATA_REG, data, 1);
phonemacro 4:46919eec2c28 105 printf("%02x ", data[0]);
phonemacro 4:46919eec2c28 106 }
phonemacro 4:46919eec2c28 107 printf("%\r\n");
phonemacro 4:46919eec2c28 108
phonemacro 4:46919eec2c28 109 //● Write command, with ROM ID (0x35) or without ROM ID (0x36), to SHA_CMD register
phonemacro 4:46919eec2c28 110 //● Write 1 to SHA_START and 1 to SHA_EN bit.
phonemacro 4:46919eec2c28 111
phonemacro 4:46919eec2c28 112 //● Wait for SHA_DONE interrupt.
phonemacro 4:46919eec2c28 113 //m.clearShaComplete();
phonemacro 4:46919eec2c28 114 //while(m.isShaComplete()) {
phonemacro 4:46919eec2c28 115 //}
phonemacro 4:46919eec2c28 116 // ● Read 256 MAC value from RAM using registers MEM_IDX and MEM_DATA.
phonemacro 4:46919eec2c28 117 //● Compare MAC from MAX86140 wth Host's precalculated MAC.
phonemacro 4:46919eec2c28 118 //● Check PASS or FAIL.
phonemacro 4:46919eec2c28 119 //● Disable SHA_EN bit ( Write 0 to SHA_EN bit).
phonemacro 0:9e5a4f845510 120 while(1) {
phonemacro 1:854f8a89a527 121 gLED = !gLED;
phonemacro 0:9e5a4f845510 122 wait(1.0);
phonemacro 0:9e5a4f845510 123 }
phonemacro 0:9e5a4f845510 124 }
phonemacro 0:9e5a4f845510 125