TEST_CODE_ApplyTo2V1_API
Dependencies: SDFileSystem max32630fthr USBDevice
main.cpp@4:217334c3a5b2, 2020-07-28 (annotated)
- Committer:
- china_sn0w
- Date:
- Tue Jul 28 01:40:05 2020 +0000
- Revision:
- 4:217334c3a5b2
- Parent:
- 3:35b05d91568d
A
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:217334c3a5b2 | 98 | Thread AutoSingle; |
china_sn0w | 1:7530b7eb757a | 99 | //Thread usb_receive_thread; |
china_sn0w | 1:7530b7eb757a | 100 | |
china_sn0w | 1:7530b7eb757a | 101 | Semaphore usb_semph(32); |
china_sn0w | 1:7530b7eb757a | 102 | |
china_sn0w | 0:5a9619496af2 | 103 | // main() runs in its own thread in the OS |
china_sn0w | 0:5a9619496af2 | 104 | // (note the calls to Thread::wait below for delays) |
china_sn0w | 0:5a9619496af2 | 105 | int main() |
china_sn0w | 0:5a9619496af2 | 106 | { |
china_sn0w | 1:7530b7eb757a | 107 | //microUSB.printf("micro USB serial port\r\n"); |
china_sn0w | 1:7530b7eb757a | 108 | |
china_sn0w | 1:7530b7eb757a | 109 | float v = 2.7; |
china_sn0w | 1:7530b7eb757a | 110 | uint8_t test = 0; |
china_sn0w | 1:7530b7eb757a | 111 | float V_I[10]; |
china_sn0w | 0:5a9619496af2 | 112 | |
china_sn0w | 1:7530b7eb757a | 113 | #ifdef EVIC |
china_sn0w | 1:7530b7eb757a | 114 | xSHUT = 1; |
china_sn0w | 1:7530b7eb757a | 115 | AVDDEN = 1; |
china_sn0w | 1:7530b7eb757a | 116 | HIGH_EN = 0; |
china_sn0w | 1:7530b7eb757a | 117 | A0 = 0; |
china_sn0w | 1:7530b7eb757a | 118 | DI = 0; |
china_sn0w | 1:7530b7eb757a | 119 | PULSE = 0; |
china_sn0w | 3:35b05d91568d | 120 | TRIM_EN = 0; |
china_sn0w | 1:7530b7eb757a | 121 | #endif |
china_sn0w | 1:7530b7eb757a | 122 | |
china_sn0w | 1:7530b7eb757a | 123 | #ifdef OFILM |
china_sn0w | 1:7530b7eb757a | 124 | xSHUT = 1; |
china_sn0w | 1:7530b7eb757a | 125 | EN_Power = 0; |
china_sn0w | 1:7530b7eb757a | 126 | EN_OSC = 0; |
china_sn0w | 1:7530b7eb757a | 127 | #endif |
china_sn0w | 1:7530b7eb757a | 128 | |
china_sn0w | 1:7530b7eb757a | 129 | //uart.baud(115200); |
china_sn0w | 1:7530b7eb757a | 130 | microUSB.attach(usb_rx_callback); |
china_sn0w | 1:7530b7eb757a | 131 | chip_int.rise(InterruptHandle); |
china_sn0w | 0:5a9619496af2 | 132 | |
china_sn0w | 0:5a9619496af2 | 133 | rLED = LED_OFF; |
china_sn0w | 1:7530b7eb757a | 134 | gLED = LED_OFF; |
china_sn0w | 1:7530b7eb757a | 135 | bLED = LED_OFF; |
china_sn0w | 1:7530b7eb757a | 136 | |
china_sn0w | 1:7530b7eb757a | 137 | i2c_v.frequency(100000); |
china_sn0w | 0:5a9619496af2 | 138 | |
china_sn0w | 1:7530b7eb757a | 139 | SetVoltageAVDD(3.3); |
china_sn0w | 0:5a9619496af2 | 140 | |
china_sn0w | 3:35b05d91568d | 141 | wait(1); |
china_sn0w | 3:35b05d91568d | 142 | //DUT_RegInit(); |
china_sn0w | 3:35b05d91568d | 143 | //wait(1); |
china_sn0w | 1:7530b7eb757a | 144 | //DUT_FirmwareInit(); |
china_sn0w | 3:35b05d91568d | 145 | DeviceAllInit(0x68, 0xE2, 0x31); |
china_sn0w | 1:7530b7eb757a | 146 | |
china_sn0w | 1:7530b7eb757a | 147 | cmd_handle_thread.start(CmdHandleTask); |
china_sn0w | 1:7530b7eb757a | 148 | coutinu_measure_thread.start(ContinuousMeasureReport); |
china_sn0w | 1:7530b7eb757a | 149 | Histogram_thread.start(HistogramReport); |
china_sn0w | 1:7530b7eb757a | 150 | //usb_receive_thread.start(usb_receive); |
china_sn0w | 1:7530b7eb757a | 151 | Sevo_Thread.start(ServoRunThread); |
china_sn0w | 4:217334c3a5b2 | 152 | AutoSingle.start(AutoSingleMeasurment); |
china_sn0w | 1:7530b7eb757a | 153 | |
china_sn0w | 1:7530b7eb757a | 154 | while(1) { |
china_sn0w | 1:7530b7eb757a | 155 | //microUSB.printf("micro USB serial port\r\n"); |
china_sn0w | 1:7530b7eb757a | 156 | //microUSB.writeBlock((uint8_t*)"Hello", 5); |
china_sn0w | 0:5a9619496af2 | 157 | bLED = !bLED; |
china_sn0w | 1:7530b7eb757a | 158 | |
china_sn0w | 1:7530b7eb757a | 159 | V_I[0] = ain.read()*5000.0f; |
china_sn0w | 1:7530b7eb757a | 160 | HandleFreqReport(V_I); |
china_sn0w | 1:7530b7eb757a | 161 | //SetVoltageAVDD(v); |
china_sn0w | 1:7530b7eb757a | 162 | //v = v + 0.1; |
china_sn0w | 1:7530b7eb757a | 163 | //if(v > 3.7) |
china_sn0w | 1:7530b7eb757a | 164 | // v = 2.7; |
china_sn0w | 0:5a9619496af2 | 165 | wait(2); |
china_sn0w | 1:7530b7eb757a | 166 | |
china_sn0w | 1:7530b7eb757a | 167 | //if(test < 10) |
china_sn0w | 1:7530b7eb757a | 168 | // ServoRun(1,10);//Back 10mm |
china_sn0w | 1:7530b7eb757a | 169 | //else if(test > 10) |
china_sn0w | 1:7530b7eb757a | 170 | // ServoRun(0,10);//Forward 10mm |
china_sn0w | 1:7530b7eb757a | 171 | //test++; |
china_sn0w | 1:7530b7eb757a | 172 | //if(test == 20) |
china_sn0w | 1:7530b7eb757a | 173 | // test = 0; |
china_sn0w | 0:5a9619496af2 | 174 | } |
china_sn0w | 0:5a9619496af2 | 175 | } |
china_sn0w | 0:5a9619496af2 | 176 | |
china_sn0w | 1:7530b7eb757a | 177 | void usb_rx_callback(void) |
china_sn0w | 1:7530b7eb757a | 178 | { |
china_sn0w | 1:7530b7eb757a | 179 | //usb_semph.release(); |
china_sn0w | 1:7530b7eb757a | 180 | } |
china_sn0w | 1:7530b7eb757a | 181 | |
china_sn0w | 1:7530b7eb757a | 182 | |
china_sn0w | 1:7530b7eb757a | 183 |