V1.1 For EVIC

Dependencies:   SDFileSystem max32630fthr USBDevice

Committer:
china_sn0w
Date:
Thu May 28 02:30:39 2020 +0000
Revision:
1:7530b7eb757a
Parent:
0:5a9619496af2
Child:
3:35b05d91568d
V1.1

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 1:7530b7eb757a 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 1:7530b7eb757a 72 DigitalOut PULSE(P5_1);
china_sn0w 1:7530b7eb757a 73 DigitalOut DI(P5_2);
china_sn0w 1:7530b7eb757a 74
china_sn0w 1:7530b7eb757a 75 SDFileSystem sd(P0_5, P0_6, P0_4, P0_7, "sd"); // mosi, miso, sclk, cs
china_sn0w 1:7530b7eb757a 76 #endif
china_sn0w 1:7530b7eb757a 77 //======
china_sn0w 1:7530b7eb757a 78
china_sn0w 1:7530b7eb757a 79 //======for Ofilm
china_sn0w 1:7530b7eb757a 80 #ifdef OFILM
china_sn0w 1:7530b7eb757a 81 DigitalOut xSHUT(P5_4);
china_sn0w 1:7530b7eb757a 82 DigitalOut EN_Power(P5_3);
china_sn0w 1:7530b7eb757a 83 DigitalOut EN_OSC(P5_5);
china_sn0w 1:7530b7eb757a 84 InterruptIn chip_int(P3_3);
china_sn0w 1:7530b7eb757a 85 #endif
china_sn0w 1:7530b7eb757a 86 //======
china_sn0w 1:7530b7eb757a 87
china_sn0w 1:7530b7eb757a 88
china_sn0w 1:7530b7eb757a 89
china_sn0w 1:7530b7eb757a 90 //Queue<uint8_t, 2048> cmd_queue;
china_sn0w 1:7530b7eb757a 91
china_sn0w 1:7530b7eb757a 92 Thread cmd_handle_thread;
china_sn0w 1:7530b7eb757a 93 Thread coutinu_measure_thread;
china_sn0w 1:7530b7eb757a 94 Thread Histogram_thread;
china_sn0w 1:7530b7eb757a 95 Thread Sevo_Thread;
china_sn0w 1:7530b7eb757a 96 //Thread usb_receive_thread;
china_sn0w 1:7530b7eb757a 97
china_sn0w 1:7530b7eb757a 98 Semaphore usb_semph(32);
china_sn0w 1:7530b7eb757a 99
china_sn0w 0:5a9619496af2 100 // main() runs in its own thread in the OS
china_sn0w 0:5a9619496af2 101 // (note the calls to Thread::wait below for delays)
china_sn0w 0:5a9619496af2 102 int main()
china_sn0w 0:5a9619496af2 103 {
china_sn0w 1:7530b7eb757a 104 //microUSB.printf("micro USB serial port\r\n");
china_sn0w 1:7530b7eb757a 105
china_sn0w 1:7530b7eb757a 106 float v = 2.7;
china_sn0w 1:7530b7eb757a 107 uint8_t test = 0;
china_sn0w 1:7530b7eb757a 108 float V_I[10];
china_sn0w 0:5a9619496af2 109
china_sn0w 1:7530b7eb757a 110 #ifdef EVIC
china_sn0w 1:7530b7eb757a 111 xSHUT = 1;
china_sn0w 1:7530b7eb757a 112 AVDDEN = 1;
china_sn0w 1:7530b7eb757a 113 HIGH_EN = 0;
china_sn0w 1:7530b7eb757a 114 A0 = 0;
china_sn0w 1:7530b7eb757a 115 DI = 0;
china_sn0w 1:7530b7eb757a 116 PULSE = 0;
china_sn0w 1:7530b7eb757a 117 #endif
china_sn0w 1:7530b7eb757a 118
china_sn0w 1:7530b7eb757a 119 #ifdef OFILM
china_sn0w 1:7530b7eb757a 120 xSHUT = 1;
china_sn0w 1:7530b7eb757a 121 EN_Power = 0;
china_sn0w 1:7530b7eb757a 122 EN_OSC = 0;
china_sn0w 1:7530b7eb757a 123 #endif
china_sn0w 1:7530b7eb757a 124
china_sn0w 1:7530b7eb757a 125 //uart.baud(115200);
china_sn0w 1:7530b7eb757a 126 microUSB.attach(usb_rx_callback);
china_sn0w 1:7530b7eb757a 127 chip_int.rise(InterruptHandle);
china_sn0w 0:5a9619496af2 128
china_sn0w 0:5a9619496af2 129 rLED = LED_OFF;
china_sn0w 1:7530b7eb757a 130 gLED = LED_OFF;
china_sn0w 1:7530b7eb757a 131 bLED = LED_OFF;
china_sn0w 1:7530b7eb757a 132
china_sn0w 1:7530b7eb757a 133 i2c_v.frequency(100000);
china_sn0w 0:5a9619496af2 134
china_sn0w 1:7530b7eb757a 135 SetVoltageAVDD(3.3);
china_sn0w 0:5a9619496af2 136
china_sn0w 1:7530b7eb757a 137 //wait(1);
china_sn0w 1:7530b7eb757a 138 DUT_RegInit();
china_sn0w 1:7530b7eb757a 139 wait(1);
china_sn0w 1:7530b7eb757a 140 //DUT_FirmwareInit();
china_sn0w 1:7530b7eb757a 141
china_sn0w 1:7530b7eb757a 142 cmd_handle_thread.start(CmdHandleTask);
china_sn0w 1:7530b7eb757a 143 coutinu_measure_thread.start(ContinuousMeasureReport);
china_sn0w 1:7530b7eb757a 144 Histogram_thread.start(HistogramReport);
china_sn0w 1:7530b7eb757a 145 //usb_receive_thread.start(usb_receive);
china_sn0w 1:7530b7eb757a 146 Sevo_Thread.start(ServoRunThread);
china_sn0w 1:7530b7eb757a 147
china_sn0w 1:7530b7eb757a 148 while(1) {
china_sn0w 1:7530b7eb757a 149 //microUSB.printf("micro USB serial port\r\n");
china_sn0w 1:7530b7eb757a 150 //microUSB.writeBlock((uint8_t*)"Hello", 5);
china_sn0w 0:5a9619496af2 151 bLED = !bLED;
china_sn0w 1:7530b7eb757a 152
china_sn0w 1:7530b7eb757a 153 V_I[0] = ain.read()*5000.0f;
china_sn0w 1:7530b7eb757a 154 HandleFreqReport(V_I);
china_sn0w 1:7530b7eb757a 155 //SetVoltageAVDD(v);
china_sn0w 1:7530b7eb757a 156 //v = v + 0.1;
china_sn0w 1:7530b7eb757a 157 //if(v > 3.7)
china_sn0w 1:7530b7eb757a 158 // v = 2.7;
china_sn0w 0:5a9619496af2 159 wait(2);
china_sn0w 1:7530b7eb757a 160
china_sn0w 1:7530b7eb757a 161 //if(test < 10)
china_sn0w 1:7530b7eb757a 162 // ServoRun(1,10);//Back 10mm
china_sn0w 1:7530b7eb757a 163 //else if(test > 10)
china_sn0w 1:7530b7eb757a 164 // ServoRun(0,10);//Forward 10mm
china_sn0w 1:7530b7eb757a 165 //test++;
china_sn0w 1:7530b7eb757a 166 //if(test == 20)
china_sn0w 1:7530b7eb757a 167 // test = 0;
china_sn0w 0:5a9619496af2 168 }
china_sn0w 0:5a9619496af2 169 }
china_sn0w 0:5a9619496af2 170
china_sn0w 1:7530b7eb757a 171 void usb_rx_callback(void)
china_sn0w 1:7530b7eb757a 172 {
china_sn0w 1:7530b7eb757a 173 //usb_semph.release();
china_sn0w 1:7530b7eb757a 174 }
china_sn0w 1:7530b7eb757a 175
china_sn0w 1:7530b7eb757a 176
china_sn0w 1:7530b7eb757a 177