TEST_CODE_ApplyTo2V1_API

Dependencies:   SDFileSystem max32630fthr USBDevice

Committer:
china_sn0w
Date:
Mon Jun 22 05:27:48 2020 +0000
Revision:
3:35b05d91568d
Parent:
1:7530b7eb757a
Child:
4:217334c3a5b2
1.2Alpha;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
china_sn0w 0:5a9619496af2 1 /*******************************************************************************
china_sn0w 0:5a9619496af2 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
china_sn0w 0:5a9619496af2 3 *
china_sn0w 0:5a9619496af2 4 * Permission is hereby granted, free of charge, to any person obtaining a
china_sn0w 0:5a9619496af2 5 * copy of this software and associated documentation files (the "Software"),
china_sn0w 0:5a9619496af2 6 * to deal in the Software without restriction, including without limitation
china_sn0w 0:5a9619496af2 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
china_sn0w 0:5a9619496af2 8 * and/or sell copies of the Software, and to permit persons to whom the
china_sn0w 0:5a9619496af2 9 * Software is furnished to do so, subject to the following conditions:
china_sn0w 0:5a9619496af2 10 *
china_sn0w 0:5a9619496af2 11 * The above copyright notice and this permission notice shall be included
china_sn0w 0:5a9619496af2 12 * in all copies or substantial portions of the Software.
china_sn0w 0:5a9619496af2 13 *
china_sn0w 0:5a9619496af2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
china_sn0w 0:5a9619496af2 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
china_sn0w 0:5a9619496af2 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
china_sn0w 0:5a9619496af2 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
china_sn0w 0:5a9619496af2 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
china_sn0w 0:5a9619496af2 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
china_sn0w 0:5a9619496af2 20 * OTHER DEALINGS IN THE SOFTWARE.
china_sn0w 0:5a9619496af2 21 *
china_sn0w 0:5a9619496af2 22 * Except as contained in this notice, the name of Maxim Integrated
china_sn0w 0:5a9619496af2 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
china_sn0w 0:5a9619496af2 24 * Products, Inc. Branding Policy.
china_sn0w 0:5a9619496af2 25 *
china_sn0w 0:5a9619496af2 26 * The mere transfer of this software does not imply any licenses
china_sn0w 0:5a9619496af2 27 * of trade secrets, proprietary technology, copyrights, patents,
china_sn0w 0:5a9619496af2 28 * trademarks, maskwork rights, or any other form of intellectual
china_sn0w 0:5a9619496af2 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
china_sn0w 0:5a9619496af2 30 * ownership rights.
china_sn0w 0:5a9619496af2 31 *******************************************************************************
china_sn0w 0:5a9619496af2 32 */
china_sn0w 0:5a9619496af2 33 #include "mbed.h"
china_sn0w 0:5a9619496af2 34 #include "max32630fthr.h"
china_sn0w 0:5a9619496af2 35 #include "USBSerial.h"
china_sn0w 0:5a9619496af2 36 #include "I2CSlave.h"
china_sn0w 1:7530b7eb757a 37 #include "CmdHandler.h"
china_sn0w 1:7530b7eb757a 38 #include "DUT_RegConfig.h"
china_sn0w 1:7530b7eb757a 39 #include "AVDD_CONFIG.h"
china_sn0w 1:7530b7eb757a 40 #include "ServoRun.h"
china_sn0w 1:7530b7eb757a 41 #include "SDFileSystem.h"
china_sn0w 1:7530b7eb757a 42 #include "AnalogIn.h"
china_sn0w 1:7530b7eb757a 43
china_sn0w 1:7530b7eb757a 44 #define EVIC
china_sn0w 1:7530b7eb757a 45
china_sn0w 1:7530b7eb757a 46 void usb_rx_callback(void);
china_sn0w 1:7530b7eb757a 47 void usb_receive(void);
china_sn0w 0:5a9619496af2 48
china_sn0w 0:5a9619496af2 49 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
china_sn0w 0:5a9619496af2 50
china_sn0w 0:5a9619496af2 51 // Hardware serial port over DAPLink
china_sn0w 3:35b05d91568d 52 //Serial uart(P3_1, P3_0);
china_sn0w 0:5a9619496af2 53
china_sn0w 1:7530b7eb757a 54 I2C i2c_v(P3_4, P3_5);
china_sn0w 0:5a9619496af2 55
china_sn0w 0:5a9619496af2 56 // Virtual serial port over USB
china_sn0w 0:5a9619496af2 57 USBSerial microUSB;
china_sn0w 0:5a9619496af2 58 DigitalOut rLED(LED1);
china_sn0w 0:5a9619496af2 59 DigitalOut gLED(LED2);
china_sn0w 0:5a9619496af2 60 DigitalOut bLED(LED3);
china_sn0w 0:5a9619496af2 61
china_sn0w 1:7530b7eb757a 62 //======for EVIC
china_sn0w 1:7530b7eb757a 63 #ifdef EVIC
china_sn0w 1:7530b7eb757a 64 AnalogIn ain(AIN_1);
china_sn0w 1:7530b7eb757a 65 DigitalOut xSHUT(P5_3);
china_sn0w 1:7530b7eb757a 66 InterruptIn chip_int(P3_2);
china_sn0w 1:7530b7eb757a 67 //AnalogIn()
china_sn0w 1:7530b7eb757a 68 DigitalOut AVDDEN(P3_3);
china_sn0w 1:7530b7eb757a 69 DigitalOut HIGH_EN(P5_6);
china_sn0w 1:7530b7eb757a 70 DigitalOut A0(P4_0);
china_sn0w 1:7530b7eb757a 71
china_sn0w 3:35b05d91568d 72 DigitalOut PULSE(P3_0);
china_sn0w 3:35b05d91568d 73 DigitalOut DI(P3_1);
china_sn0w 3:35b05d91568d 74
china_sn0w 3:35b05d91568d 75 DigitalOut TRIM_EN(P5_5);
china_sn0w 1:7530b7eb757a 76
china_sn0w 1:7530b7eb757a 77 SDFileSystem sd(P0_5, P0_6, P0_4, P0_7, "sd"); // mosi, miso, sclk, cs
china_sn0w 1:7530b7eb757a 78 #endif
china_sn0w 1:7530b7eb757a 79 //======
china_sn0w 1:7530b7eb757a 80
china_sn0w 1:7530b7eb757a 81 //======for Ofilm
china_sn0w 1:7530b7eb757a 82 #ifdef OFILM
china_sn0w 1:7530b7eb757a 83 DigitalOut xSHUT(P5_4);
china_sn0w 1:7530b7eb757a 84 DigitalOut EN_Power(P5_3);
china_sn0w 1:7530b7eb757a 85 DigitalOut EN_OSC(P5_5);
china_sn0w 1:7530b7eb757a 86 InterruptIn chip_int(P3_3);
china_sn0w 1:7530b7eb757a 87 #endif
china_sn0w 1:7530b7eb757a 88 //======
china_sn0w 1:7530b7eb757a 89
china_sn0w 1:7530b7eb757a 90
china_sn0w 1:7530b7eb757a 91
china_sn0w 1:7530b7eb757a 92 //Queue<uint8_t, 2048> cmd_queue;
china_sn0w 1:7530b7eb757a 93
china_sn0w 1:7530b7eb757a 94 Thread cmd_handle_thread;
china_sn0w 1:7530b7eb757a 95 Thread coutinu_measure_thread;
china_sn0w 1:7530b7eb757a 96 Thread Histogram_thread;
china_sn0w 1:7530b7eb757a 97 Thread Sevo_Thread;
china_sn0w 1:7530b7eb757a 98 //Thread usb_receive_thread;
china_sn0w 1:7530b7eb757a 99
china_sn0w 1:7530b7eb757a 100 Semaphore usb_semph(32);
china_sn0w 1:7530b7eb757a 101
china_sn0w 0:5a9619496af2 102 // main() runs in its own thread in the OS
china_sn0w 0:5a9619496af2 103 // (note the calls to Thread::wait below for delays)
china_sn0w 0:5a9619496af2 104 int main()
china_sn0w 0:5a9619496af2 105 {
china_sn0w 1:7530b7eb757a 106 //microUSB.printf("micro USB serial port\r\n");
china_sn0w 1:7530b7eb757a 107
china_sn0w 1:7530b7eb757a 108 float v = 2.7;
china_sn0w 1:7530b7eb757a 109 uint8_t test = 0;
china_sn0w 1:7530b7eb757a 110 float V_I[10];
china_sn0w 0:5a9619496af2 111
china_sn0w 1:7530b7eb757a 112 #ifdef EVIC
china_sn0w 1:7530b7eb757a 113 xSHUT = 1;
china_sn0w 1:7530b7eb757a 114 AVDDEN = 1;
china_sn0w 1:7530b7eb757a 115 HIGH_EN = 0;
china_sn0w 1:7530b7eb757a 116 A0 = 0;
china_sn0w 1:7530b7eb757a 117 DI = 0;
china_sn0w 1:7530b7eb757a 118 PULSE = 0;
china_sn0w 3:35b05d91568d 119 TRIM_EN = 0;
china_sn0w 1:7530b7eb757a 120 #endif
china_sn0w 1:7530b7eb757a 121
china_sn0w 1:7530b7eb757a 122 #ifdef OFILM
china_sn0w 1:7530b7eb757a 123 xSHUT = 1;
china_sn0w 1:7530b7eb757a 124 EN_Power = 0;
china_sn0w 1:7530b7eb757a 125 EN_OSC = 0;
china_sn0w 1:7530b7eb757a 126 #endif
china_sn0w 1:7530b7eb757a 127
china_sn0w 1:7530b7eb757a 128 //uart.baud(115200);
china_sn0w 1:7530b7eb757a 129 microUSB.attach(usb_rx_callback);
china_sn0w 1:7530b7eb757a 130 chip_int.rise(InterruptHandle);
china_sn0w 0:5a9619496af2 131
china_sn0w 0:5a9619496af2 132 rLED = LED_OFF;
china_sn0w 1:7530b7eb757a 133 gLED = LED_OFF;
china_sn0w 1:7530b7eb757a 134 bLED = LED_OFF;
china_sn0w 1:7530b7eb757a 135
china_sn0w 1:7530b7eb757a 136 i2c_v.frequency(100000);
china_sn0w 0:5a9619496af2 137
china_sn0w 1:7530b7eb757a 138 SetVoltageAVDD(3.3);
china_sn0w 0:5a9619496af2 139
china_sn0w 3:35b05d91568d 140 wait(1);
china_sn0w 3:35b05d91568d 141 //DUT_RegInit();
china_sn0w 3:35b05d91568d 142 //wait(1);
china_sn0w 1:7530b7eb757a 143 //DUT_FirmwareInit();
china_sn0w 3:35b05d91568d 144 DeviceAllInit(0x68, 0xE2, 0x31);
china_sn0w 1:7530b7eb757a 145
china_sn0w 1:7530b7eb757a 146 cmd_handle_thread.start(CmdHandleTask);
china_sn0w 1:7530b7eb757a 147 coutinu_measure_thread.start(ContinuousMeasureReport);
china_sn0w 1:7530b7eb757a 148 Histogram_thread.start(HistogramReport);
china_sn0w 1:7530b7eb757a 149 //usb_receive_thread.start(usb_receive);
china_sn0w 1:7530b7eb757a 150 Sevo_Thread.start(ServoRunThread);
china_sn0w 1:7530b7eb757a 151
china_sn0w 1:7530b7eb757a 152 while(1) {
china_sn0w 1:7530b7eb757a 153 //microUSB.printf("micro USB serial port\r\n");
china_sn0w 1:7530b7eb757a 154 //microUSB.writeBlock((uint8_t*)"Hello", 5);
china_sn0w 0:5a9619496af2 155 bLED = !bLED;
china_sn0w 1:7530b7eb757a 156
china_sn0w 1:7530b7eb757a 157 V_I[0] = ain.read()*5000.0f;
china_sn0w 1:7530b7eb757a 158 HandleFreqReport(V_I);
china_sn0w 1:7530b7eb757a 159 //SetVoltageAVDD(v);
china_sn0w 1:7530b7eb757a 160 //v = v + 0.1;
china_sn0w 1:7530b7eb757a 161 //if(v > 3.7)
china_sn0w 1:7530b7eb757a 162 // v = 2.7;
china_sn0w 0:5a9619496af2 163 wait(2);
china_sn0w 1:7530b7eb757a 164
china_sn0w 1:7530b7eb757a 165 //if(test < 10)
china_sn0w 1:7530b7eb757a 166 // ServoRun(1,10);//Back 10mm
china_sn0w 1:7530b7eb757a 167 //else if(test > 10)
china_sn0w 1:7530b7eb757a 168 // ServoRun(0,10);//Forward 10mm
china_sn0w 1:7530b7eb757a 169 //test++;
china_sn0w 1:7530b7eb757a 170 //if(test == 20)
china_sn0w 1:7530b7eb757a 171 // test = 0;
china_sn0w 0:5a9619496af2 172 }
china_sn0w 0:5a9619496af2 173 }
china_sn0w 0:5a9619496af2 174
china_sn0w 1:7530b7eb757a 175 void usb_rx_callback(void)
china_sn0w 1:7530b7eb757a 176 {
china_sn0w 1:7530b7eb757a 177 //usb_semph.release();
china_sn0w 1:7530b7eb757a 178 }
china_sn0w 1:7530b7eb757a 179
china_sn0w 1:7530b7eb757a 180
china_sn0w 1:7530b7eb757a 181