MAX30001-MAX32630FTHR SYS EvKit

Dependencies:   USBDevice max32630fthr

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 #include "mbed.h"
00034 #include "max32630fthr.h"
00035 #include "SDBlockDevice.h"
00036 #include "USBSerial.h"
00037 #include "QuadSpiInterface.h"
00038 #include "S25FS512.h"
00039 #include "MAX30001.h"
00040 #include "HspLed.h"
00041 #include "PushButton.h"
00042 #include "version.h"
00043 #include "Peripherals.h"
00044 #include "Streaming.h"
00045 #include "RpcServer.h"
00046 #include "DataLoggingService.h"
00047 #include "StringInOut.h"
00048 
00049 //Init PMIC on FTHR board and set logic thresholds to 3.3V
00050 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00051 
00052 SDBlockDevice sd(P0_5, P0_6, P0_4, P0_7); //mosi, miso, sclk, cs
00053 
00054 ///
00055 /// wire Interfaces
00056 ///
00057 /// Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and non-blocking
00058 USBSerial usbSerial(0x0b6a, 0x7531, 0x0001, false);
00059 
00060 //SD card insertion detection pin
00061 DigitalIn SDDetect(P2_2, PullUp);
00062 
00063 /// DigitalOut for CS
00064 DigitalOut cs(P5_6);
00065 
00066 /// SPI Master 2 with SPI0_SS for use with MAX30001
00067 SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // used by MAX30001
00068 
00069 QuadSpiInterface quadSpiInterface(SPI1_MOSI, SPI1_MISO, SPI1_SCK,SPI1_SS); // used by S25FS512
00070 
00071 ///Debug port
00072 Serial Debug(USBTX, USBRX);
00073 
00074 ///
00075 /// Devices
00076 ///
00077 
00078 /// External Flash
00079 S25FS512 s25fs512(&quadSpiInterface);
00080 
00081 /// ECG device
00082 MAX30001 max30001(&spi, &cs);
00083 
00084 InterruptIn max30001_InterruptB(P5_5);
00085 InterruptIn max30001_Interrupt2B(P5_4);
00086 
00087 /// HSP platform LED
00088 HspLed hspLed(LED_RED);
00089 
00090 /// Packet TimeStamp Timer, set for 1uS
00091 Timer timestampTimer;
00092 
00093 /// HSP Platform push button
00094 PushButton pushButton(SW1);
00095 
00096 int main()
00097 {
00098     //boost baudrate so we can get messages while running gui
00099     Debug.baud(115200);
00100 
00101     // local input state of the RPC
00102     int inputState;
00103     // RPC request buffer
00104     char request[128];
00105     // RPC reply buffer
00106     char reply[128];
00107 
00108     // display start banner
00109     Debug.printf("Maxim Integrated mbed hSensor %d.%d.%d %02d/%02d/%02d\n",
00110       VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH,
00111       VERSION_MONTH, VERSION_DAY, VERSION_SHORT_YEAR);
00112     fflush(stdout);
00113 
00114     // turn on red led
00115     Debug.printf("Init HSPLED...\n");
00116     fflush(stdout);
00117     hspLed.on();
00118 
00119     // set NVIC priorities for GPIO to prevent priority inversion
00120     Debug.printf("Init NVIC Priorities...\n");
00121     fflush(stdout);
00122     NVIC_SetPriority(GPIO_P0_IRQn, 5);
00123     NVIC_SetPriority(GPIO_P1_IRQn, 5);
00124     NVIC_SetPriority(GPIO_P2_IRQn, 5);
00125     NVIC_SetPriority(GPIO_P3_IRQn, 5);
00126     NVIC_SetPriority(GPIO_P4_IRQn, 5);
00127     NVIC_SetPriority(GPIO_P5_IRQn, 5);
00128     NVIC_SetPriority(GPIO_P6_IRQn, 5);
00129     // used by the MAX30001
00130     NVIC_SetPriority(SPIM2_IRQn, 0);
00131 
00132     // Be able to statically reference these devices anywhere in the application
00133     Peripherals::setS25FS512(&s25fs512);
00134     Peripherals::setUSBSerial(&usbSerial);
00135     Peripherals::setTimestampTimer(&timestampTimer);
00136     Peripherals::setHspLed(&hspLed);
00137     Peripherals::setPushButton(&pushButton);
00138     Peripherals::setMAX30001(&max30001);
00139     Peripherals::setSdFS(&sd);
00140     Peripherals::setSDDetect(&SDDetect);
00141 
00142     // init the S25FS256 external flash device
00143     Debug.printf("Init S25FS512...\n");
00144     fflush(stdout);
00145     s25fs512.init();
00146 
00147     // start blinking led1
00148     Debug.printf("Init HSPLED Blink...\n");
00149     fflush(stdout);
00150     hspLed.blink(1000);
00151 
00152     //
00153     // MAX30001
00154     //
00155     Debug.printf("Init MAX30001 callbacks, interrupts...\n");
00156     fflush(stdout);
00157     max30001_InterruptB.disable_irq();
00158     max30001_Interrupt2B.disable_irq();
00159     max30001_InterruptB.mode(PullUp);
00160     max30001_InterruptB.fall(&MAX30001Mid_IntB_Handler);
00161     max30001_Interrupt2B.mode(PullUp);
00162     max30001_Interrupt2B.fall(&MAX30001Mid_Int2B_Handler);
00163     max30001_InterruptB.enable_irq();
00164     max30001_Interrupt2B.enable_irq();
00165     MAX30001_AllowInterrupts(1);
00166     max30001.max30001_sw_rst(); // Do a software reset of the MAX30001
00167     max30001.max30001_INT_assignment(MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,   MAX30001::MAX30001_NO_INT,  //  en_enint_loc,      en_eovf_loc,   en_fstint_loc,
00168                                        MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_NO_INT,  //  en_dcloffint_loc,  en_bint_loc,   en_bovf_loc,
00169                                        MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_NO_INT,  //  en_bover_loc,      en_bundr_loc,  en_bcgmon_loc,
00170                                        MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,   MAX30001::MAX30001_NO_INT,  //  en_pint_loc,       en_povf_loc,   en_pedge_loc,
00171                                        MAX30001::MAX30001_INT_2B,   MAX30001::MAX30001_INT_B,    MAX30001::MAX30001_NO_INT,  //  en_lonint_loc,     en_rrint_loc,  en_samp_loc,
00172                                        MAX30001::MAX30001_INT_ODNR, MAX30001::MAX30001_INT_ODNR);                            //  intb_Type,         int2b_Type)
00173     max30001.onDataAvailable(&StreamPacketUint32);
00174 
00175     // initialize the RPC server
00176     Debug.printf("Init RPC Server...\n");
00177     fflush(stdout);
00178     RPC_init();
00179 
00180     // initialize the logging service
00181     Debug.printf("Init LoggingService...\n");
00182     fflush(stdout);
00183     LoggingService_Init();
00184 
00185     // initialize the SD disk
00186     sd.init();
00187 
00188     // start main loop
00189     Debug.printf("Start main loop...\n");
00190     fflush(stdout);
00191 
00192     while(1)
00193     {
00194       // get a RPC string if one is available
00195       inputState = getLine(request, sizeof(request));
00196       // if a string has been captured, process string
00197       if (inputState == GETLINE_DONE)
00198       {
00199         //Send request to debug port
00200         Debug.printf(request);
00201         // process the RPC string
00202         RPC_call(request, reply);
00203         //Send reply to debug port
00204         Debug.printf(reply);
00205         // output the reply
00206         putStr(reply);
00207       }
00208 
00209       // process any logging or streaming requests
00210       LoggingService_ServiceRoutine();
00211     }
00212 }