Host software for the MAX30001 ECG, PACE, biopotential, bioimpedance, R-to-R peak sensor. Hosted on the MAX32630FTHR.
Dependencies: SDFileSystem USBDevice max32630fthr
Fork of MAX30001 SYS EvKit by
MAX30001-MAX32630FTHR ECG Evaluation System
The MAX30001 EVKIT SYS-MBED Evaluation System (EV System) is used to evaluates the MAX30001 sensor, which is an ECG (electrocardiogram), biopotential and bioimpedance analog front end solution for wearable applications. The full evaluation system consists of the MAX32630FTHR board, MAX30001 EVKIT sensor board and the evaluation software. The evaluation kit features ECG, PACE, R-to-R (R-peak timing) detection; bioimpedance (BioZ) AFE; and raw data logging.
The MAX30001 EVKIT evaluation system is assembled, tested and contains the necessary circuitry and connections to evaluate the MAX30001 ECG sensor.
When evaluated as an evaluation system, the MAX32630FTHR board provides the necessary logic rails, master clock, SPI, USB-to-Serial interfaces that are needed to evaluate the MAX30001 sensor board. MAX32630FTHR can be used as an independent development platform.
Communication between the PC and the MAX32630FTHR board is facilitated by a Windows 7, Windows 8 and Windows 10 compatible software that provides a simple and intuitive graphical user interface (GUI).
For more information, visit the wiki pages by clicking the wiki tab above and MAX30001EVSYS product page.
C++ source code, library for the MAX30001 ECG drivers are in the links at the bottom of this page. The sample code includes the ability to log data to the SD card of the MAX32630FTHR.
MAX30001 EVKIT Pinout Connections
Where to Buy
HSP/LoggingService/DataLoggingService.cpp@0:8e4630a71eb1, 2018-04-05 (annotated)
- Committer:
- Emre.Eken@IST-LT-35101.maxim-ic.internal
- Date:
- Thu Apr 05 10:53:26 2018 +0300
- Revision:
- 0:8e4630a71eb1
mbed os 5.8.1 compatible
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 1 | /******************************************************************************* |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 3 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 5 | * copy of this software and associated documentation files (the "Software"), |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 6 | * to deal in the Software without restriction, including without limitation |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 9 | * Software is furnished to do so, subject to the following conditions: |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 10 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 11 | * The above copyright notice and this permission notice shall be included |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 12 | * in all copies or substantial portions of the Software. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 13 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 21 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 24 | * Products, Inc. Branding Policy. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 25 | * |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 26 | * The mere transfer of this software does not imply any licenses |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 30 | * ownership rights. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 31 | ******************************************************************************* |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 32 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 33 | #include "mbed.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 34 | #include "Logging.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 35 | #include "Streaming.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 36 | #include "RpcServer.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 37 | #include "S25FS512.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 38 | #include "PacketFifo.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 39 | #include "DataLoggingService.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 40 | #include "HspLed.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 41 | #include "MAX30001_helper.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 42 | #include "StringInOut.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 43 | #include "StringHelper.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 44 | #include "Peripherals.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 45 | #include "Device_Logging.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 46 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 47 | /// BMP280 logging object reference |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 48 | extern Device_Logging *bmp280_Logging; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 49 | /// MAX14720 instance 0 logging object reference |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 50 | extern Device_Logging *MAX30205_0_Logging; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 51 | /// MAX14720 instance 1 logging object reference |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 52 | extern Device_Logging *MAX30205_1_Logging; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 53 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 54 | #define PING_PONG_BUFFER_SIZE 512 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 55 | #define HALF_OF_PING_PONG_BUFFER_SIZE PING_PONG_BUFFER_SIZE / 2 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 56 | #define MISSION_DEFINITION_SIZE 4096 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 57 | #define MISSION_FILE_NAME_LEN 32 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 58 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 59 | eLoggingTrigger loggingTrigger; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 60 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 61 | /// file on SDCard where mission strings are stored |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 62 | char missionFileName[MISSION_FILE_NAME_LEN] = "/sd/missions.txt"; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 63 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 64 | /// data file on SDCard where mission strings are stored |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 65 | char dataFileName[MISSION_FILE_NAME_LEN] = "/sd/data.txt"; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 66 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 67 | /// buffer where mission strings are stored |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 68 | char loggingMissionCmds[MISSION_DEFINITION_SIZE]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 69 | /// This houses two 256 byte ram concatenated to act as a ping-pong |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 70 | uint8_t PingPong_SRAM[PING_PONG_BUFFER_SIZE]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 71 | uint32_t buttonTrigger = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 72 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 73 | eLoggingOutput loggingOutput; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 74 | // extern int bleStartCommand; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 75 | bool volatile globalFlag; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 76 | extern int highDataRate; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 77 | static uint32_t currentPage; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 78 | static uint32_t sramIndex; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 79 | /// flag to indicate that sram buffer 0 is dirty and will need to be flushed |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 80 | static uint32_t sram_buffer_0_dirty; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 81 | /// flag to indicate that sram buffer 1 is dirty and will need to be flushed |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 82 | static uint32_t sram_buffer_1_dirty; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 83 | /// usb byte buffer for sending out a bulk transfer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 84 | static uint8_t usb_block[64]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 85 | /// running index used to accumulate bytes to send as a block via bulk transfer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 86 | static uint16_t usb_block_index = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 87 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 88 | typedef enum { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 89 | eStartEvent_NULL, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 90 | eStartEvent_BLE, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 91 | eStartEvent_BUTTON, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 92 | eStartEvent_RPC_TO_USB, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 93 | eStartEvent_RPC_TO_FLASH |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 94 | } eStartEvent; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 95 | static eStartEvent startEvent; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 96 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 97 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 98 | * @brief Sets a flag to start USB logging (streaming) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 99 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 100 | void LoggingService_StartLoggingUsb(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 101 | loggingTrigger = eTriggerLog_RPC_USB; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 102 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 103 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 104 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 105 | * @brief Sets a flag to start flash logging |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 106 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 107 | void LoggingService_StartLoggingFlash(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 108 | loggingTrigger = eTriggerLog_RPC_FLASH; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 109 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 110 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 111 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 112 | * @brief Checks the various logging start condition |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 113 | * @return 1 if a start condition is true, 0 if there is no start condition |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 114 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 115 | static bool _LoggingService_CheckStartCondition(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 116 | bool buttonPressed; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 117 | buttonPressed = Peripherals::pushButton()->GetButtonFallState(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 118 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 119 | // default not logging USB or flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 120 | loggingOutput = eLogToNothing; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 121 | startEvent = eStartEvent_NULL; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 122 | if (buttonPressed) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 123 | Peripherals::pushButton()->clearButtonFallState(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 124 | // a falling state has been detected... wait for a fraction of a second and |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 125 | // re-read the pin |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 126 | // only start datalogging if the pin was released within this wait time |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 127 | wait(0.75f); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 128 | int buttonRead = Peripherals::pushButton()->Read(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 129 | // if after a period of time the button is still pressed then get out |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 130 | if (buttonRead == 0) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 131 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 132 | buttonTrigger = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 133 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 134 | loggingTrigger = eTriggerLog_BUTTON; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 135 | loggingOutput = eLogToFlash; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 136 | startEvent = eStartEvent_BUTTON; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 137 | return true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 138 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 139 | if (loggingTrigger == eTriggerLog_RPC_FLASH) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 140 | loggingOutput = eLogToFlash; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 141 | startEvent = eStartEvent_RPC_TO_FLASH; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 142 | return true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 143 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 144 | /*if (Peripherals::hspBLE()->getStartDataLogging()) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 145 | loggingTrigger = eTriggerLog_BLE; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 146 | loggingOutput = eLogToFlash; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 147 | startEvent = eStartEvent_BLE; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 148 | return true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 149 | }*/ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 150 | // check if start is from RPC call for USB streaming |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 151 | if (loggingTrigger == eTriggerLog_RPC_USB) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 152 | loggingOutput = eLogtoUsb; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 153 | startEvent = eStartEvent_RPC_TO_USB; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 154 | return true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 155 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 156 | return false; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 157 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 158 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 159 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 160 | * @brief Read the mission string from flash into a buffer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 161 | * @return false if a mission was not defined, true if mission was read and |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 162 | * buffered |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 163 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 164 | static bool _LoggingService_ReadMissionFromFlash(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 165 | // get mission from flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 166 | Logging_ReadMissionFromFlash((uint8_t *)loggingMissionCmds); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 167 | if (Logging_IsMissionDefined((uint8_t *)loggingMissionCmds) == 0) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 168 | return false; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 169 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 170 | printf(loggingMissionCmds); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 171 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 172 | RPC_ProcessCmds(loggingMissionCmds); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 173 | return true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 174 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 175 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 176 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 177 | * @brief Read the mission string from SDCARD into a buffer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 178 | * @return false if a mission was not defined, true if mission was read and |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 179 | * buffered |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 180 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 181 | static bool _LoggingService_ReadMissionFromSDCard(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 182 | // get mission from flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 183 | Logging_ReadMissionFromSDCard((uint8_t *)loggingMissionCmds); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 184 | if (Logging_IsMissionDefined((uint8_t *)loggingMissionCmds) == 0) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 185 | return false; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 186 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 187 | printf(loggingMissionCmds); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 188 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 189 | RPC_ProcessCmds(loggingMissionCmds); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 190 | return true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 191 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 192 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 193 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 194 | * @brief Process a RPC command that is pointed to. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 195 | * @param cmd RPC string to process |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 196 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 197 | void ProcessCmd(char *cmd) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 198 | char cmd_[256]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 199 | char reply[512]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 200 | strcpy(cmd_, cmd); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 201 | RPC_call(cmd_, reply); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 202 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 203 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 204 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 205 | * @brief Buffer sensor fifo data in ram buffers, when a ram buffer is full (a |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 206 | * flash page worth of data is accumulated) then flash that buffer. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 207 | * A buffer ping pong method is used so that one buffer can be flashing as |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 208 | * the other buffer fills with sensor fifo data. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 209 | * @param fifoData Sensor data taken from the fifo to be stored into flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 210 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 211 | static void _LoggingServer_OutputToFlash(uint32_t fifoData) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 212 | uint32_t index; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 213 | char str[128]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 214 | uint8_t *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 215 | // |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 216 | // Log To Flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 217 | // |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 218 | // i.e. there is data, read one 32-bit size data at a time. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 219 | // put the fifo data into the ping-pong SRAM |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 220 | PingPong_SRAM[sramIndex++] = fifoData & 0xFF; // LSByte goes into index N |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 221 | PingPong_SRAM[sramIndex++] = (fifoData >> 8) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 222 | PingPong_SRAM[sramIndex++] = (fifoData >> 16) & 0xFF; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 223 | PingPong_SRAM[sramIndex++] = (fifoData >> 24) & 0xFF; // MSByte goes into index N+3 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 224 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 225 | // flag this buffer as dirty |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 226 | if (sramIndex <= 256) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 227 | sram_buffer_0_dirty = 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 228 | else |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 229 | sram_buffer_1_dirty = 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 230 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 231 | if (sramIndex == 256 || |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 232 | sramIndex == 512) // Either Ping SRAM or Pong SRAM location is full |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 233 | { // therefore write to Flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 234 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 235 | index = sramIndex - 256; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 236 | ptr = &PingPong_SRAM[index]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 237 | sprintf(str, "currentPage=%d", currentPage); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 238 | Peripherals::s25FS512()->writePage_Helper(currentPage, ptr, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 239 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 240 | // this page is no longer dirty |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 241 | if (index == 0) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 242 | sram_buffer_0_dirty = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 243 | if (index == 256) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 244 | sram_buffer_1_dirty = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 245 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 246 | currentPage++; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 247 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 248 | sramIndex = sramIndex % 512; // Wrap around the index |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 249 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 250 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 251 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 252 | * @brief Buffer sensor fifo data in ram buffers, when a ram buffer is full (a |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 253 | * flash page worth of data is accumulated) then flash that buffer. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 254 | * A buffer ping pong method is used so that one buffer can be flashing as |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 255 | * the other buffer fills with sensor fifo data. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 256 | * @param fifoData Sensor data taken from the fifo to be stored into flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 257 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 258 | static void _LoggingServer_OutputToSDCard(FILE* fp, uint32_t fifoData) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 259 | if (fp != NULL){ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 260 | fwrite(&fifoData,sizeof(fifoData),1,fp); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 261 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 262 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 263 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 264 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 265 | * @brief If flash ram buffers are flagged as dirty, flush to flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 266 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 267 | static void _LoggingServer_WriteDirtySramBufferToFlash(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 268 | uint8_t *ptr = PingPong_SRAM; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 269 | if (sram_buffer_0_dirty == 0 && sram_buffer_1_dirty == 0) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 270 | return; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 271 | if (sram_buffer_0_dirty == 1) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 272 | ptr += 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 273 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 274 | if (sram_buffer_1_dirty == 1) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 275 | ptr += 256; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 276 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 277 | printf("_LoggingServer_WriteDirtySramBufferToFlash:%d,%d\n", |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 278 | sram_buffer_0_dirty, sram_buffer_1_dirty); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 279 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 280 | // s25fs512_WritePage_Helper(currentPage, ptr, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 281 | Peripherals::s25FS512()->writePage_Helper(currentPage, ptr, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 282 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 283 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 284 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 285 | * @brief Initialize the USB block running index |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 286 | * @param fifoData Sensor data taken from the fifo to be sent out USB |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 287 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 288 | static void _LoggingServer_OutputToCdcAcm(uint32_t fifoData) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 289 | uint8_t *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 290 | uint8_t str[16]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 291 | sprintf((char *)str, "%X ", fifoData); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 292 | ptr = str; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 293 | usb_block_index = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 294 | while (*ptr != 0) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 295 | usb_block[usb_block_index] = *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 296 | ptr++; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 297 | usb_block_index++; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 298 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 299 | Peripherals::usbSerial()->writeBlock(usb_block, usb_block_index); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 300 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 301 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 302 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 303 | * @brief Initialize the USB block running index |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 304 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 305 | static void _LoggingServer_OutputToCdcAcm_Start(void) { usb_block_index = 0; } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 306 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 307 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 308 | * @brief Buffer up fifoData from sensors, do a USB block transfer if buffer is |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 309 | * full |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 310 | * @param fifoData Sensor data taken from the fifo to be send out USB within a |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 311 | * bulk block transfer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 312 | * @return Return the success status of the writeblock operation |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 313 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 314 | static bool _LoggingServer_OutputToCdcAcm_Block(uint32_t fifoData) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 315 | uint8_t str[64]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 316 | uint8_t *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 317 | bool result; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 318 | // |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 319 | // Log to CDCACM |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 320 | // |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 321 | result = true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 322 | sprintf((char *)str, "%X ", fifoData); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 323 | ptr = str; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 324 | while (*ptr != 0) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 325 | usb_block[usb_block_index] = *ptr; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 326 | ptr++; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 327 | usb_block_index++; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 328 | if (usb_block_index >= 64) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 329 | result = Peripherals::usbSerial()->writeBlock(usb_block, 64); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 330 | usb_block_index = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 331 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 332 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 333 | return result; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 334 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 335 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 336 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 337 | * @brief Output a full USB block via bulk transfer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 338 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 339 | static void _LoggingServer_OutputToCdcAcm_End(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 340 | if (usb_block_index == 0) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 341 | return; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 342 | Peripherals::usbSerial()->writeBlock(usb_block, usb_block_index - 1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 343 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 344 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 345 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 346 | * @brief Blink LED pattern that indicates that the flash end boundary has been |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 347 | * reached |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 348 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 349 | static void BlinkEndOfDatalogging(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 350 | // blink to signal end of logging |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 351 | Peripherals::hspLed()->pattern(0x55555555, 20); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 352 | wait(2); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 353 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 354 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 355 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 356 | * @brief Reads the first data page of flash, if all FF's then the page is empty |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 357 | * @return 1 if the flash is empty as indicated by the first data page of the |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 358 | * flash, 0 if not |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 359 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 360 | int isFlashEmpty(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 361 | int i; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 362 | uint8_t data[256]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 363 | int firstDataPage = Logging_GetLoggingStartPage(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 364 | Peripherals::s25FS512()->readPages_Helper(firstDataPage, firstDataPage, data, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 365 | for (i = 0; i < 256; i++) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 366 | if (data[i] != 0xFF) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 367 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 368 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 369 | return 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 370 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 371 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 372 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 373 | * @brief Reads the first data from SDCard, if all FF's then the page is empty |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 374 | * @return 1 if the flash is empty as indicated by the first data page of the |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 375 | * flash, 0 if not |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 376 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 377 | int isSDCardWithoutDataLog(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 378 | FILE *fp = NULL; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 379 | fp = fopen(dataFileName, "rb"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 380 | if (fp != NULL) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 381 | uint8_t count = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 382 | do |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 383 | { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 384 | count ++; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 385 | char c = (char)fgetc(fp); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 386 | if (count > 2) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 387 | { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 388 | fclose(fp); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 389 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 390 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 391 | } while(!feof(fp)); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 392 | fclose(fp); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 393 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 394 | return 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 395 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 396 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 397 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 398 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 399 | * @brief Blink LED pattern that indicates that the flash is not empty and a new |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 400 | * flash logging session can not occur |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 401 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 402 | void BlinkFlashNotEmpty(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 403 | Peripherals::hspLed()->pattern(0x55555555, 20); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 404 | wait(1); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 405 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 406 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 407 | void ExecuteDefaultMission(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 408 | ProcessCmd("/MAX30001/CAL_InitStart 01 01 01 03 7FF 00"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 409 | ProcessCmd("/MAX30001/ECG_InitStart 01 01 01 00 02 03 1F 0 00 00 01"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 410 | ProcessCmd("/MAX30001/RtoR_InitStart 01 03 0F 00 03 01 00 00 01"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 411 | ProcessCmd("/MAX30001/Rbias_FMSTR_Init 01 02 01 01 00"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 412 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 413 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 414 | void LoggingService_Init(void) { loggingTrigger = eTriggerLog_NULL; } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 415 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 416 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 417 | * @brief This routine checks to see if a USB or flash logging action needs to be taken |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 418 | * The routine checks for a start condition via button press, USB command, or BLE command |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 419 | * Once one of these start conditions is present, the logging begins until stopped or memory is full |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 420 | * @return 1 if successful, 0 if error or logging was aborted and no logging occurred |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 421 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 422 | uint8_t LoggingService_ServiceRoutine(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 423 | uint32_t fifoData; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 424 | uint32_t endPage; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 425 | FILE *fp; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 426 | USBSerial *usbSerial = Peripherals::usbSerial(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 427 | // BMP280 *bmp280 = Peripherals::bmp280(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 428 | bool buttonPressed; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 429 | bool endSDLogging = false; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 430 | int packetBurstCount = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 431 | HspLed *hspLed = Peripherals::hspLed(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 432 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 433 | sramIndex = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 434 | // only start logging if conditions exist |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 435 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 436 | if (_LoggingService_CheckStartCondition() == false) return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 437 | printf("Begin Logging..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 438 | if (startEvent == eStartEvent_NULL) printf("eStartEvent_NULL..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 439 | if (startEvent == eStartEvent_BLE) printf("eStartEvent_BLE..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 440 | if (startEvent == eStartEvent_BUTTON) printf("eStartEvent_BUTTON..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 441 | if (startEvent == eStartEvent_RPC_TO_USB) printf("eStartEvent_RPC_TO_USB..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 442 | if (startEvent == eStartEvent_RPC_TO_FLASH) printf("eStartEvent_RPC_TO_FLASH..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 443 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 444 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 445 | // start logging stuttered blink pattern |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 446 | hspLed->pattern(0xA0F3813, 20); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 447 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 448 | if (startEvent == eStartEvent_RPC_TO_FLASH || |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 449 | startEvent == eStartEvent_BUTTON) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 450 | // check to see if datalog already in flash... abort and force user to erase |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 451 | // flash if needed |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 452 | if (loggingOutput == eLogToFlash) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 453 | if (isSDCardWithoutDataLog() == 0) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 454 | Logging_SetStart(false); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 455 | // bleStartCommand = 0x00; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 456 | BlinkFlashNotEmpty(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 457 | hspLed->blink(1000); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 458 | printf("Abort Logging, flash log exists. "); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 459 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 460 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 461 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 462 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 463 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 464 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 465 | if (startEvent == eStartEvent_BLE) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 466 | // check for mission in flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 467 | if (_LoggingService_ReadMissionFromSDCard() == false) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 468 | // if there is no mission in flash then do a default mission for the sake |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 469 | // of ble Android app working "out-of-the-box" and stream RtoR and Accel |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 470 | printf("No Mission in Flash...ExecuteDefaultMission..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 471 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 472 | ExecuteDefaultMission(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 473 | // do not log this data |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 474 | loggingOutput = eLogToNothing; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 475 | } else { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 476 | // there is a mission in flash check if there is already logged data |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 477 | if (isSDCardWithoutDataLog() == 0) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 478 | // just do default mission |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 479 | printf("Logged Data Detected...ExecuteDefaultMission..."); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 480 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 481 | ExecuteDefaultMission(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 482 | // do not log this data |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 483 | loggingOutput = eLogToNothing; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 484 | } else { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 485 | // flag that we are logging to flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 486 | loggingOutput = eLogToFlash; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 487 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 488 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 489 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 490 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 491 | // if we are logging to flash then read mission in flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 492 | if (loggingOutput == eLogToFlash) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 493 | if (_LoggingService_ReadMissionFromSDCard() == |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 494 | false) { // if there is no mission in flash then get out |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 495 | Logging_SetStart(false); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 496 | Peripherals::hspLed()->pattern(0xC3C3C3C3, 20); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 497 | wait(2); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 498 | printf("Abort Logging, Mission does not exist. "); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 499 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 500 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 501 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 502 | currentPage = Logging_GetLoggingStartPage(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 503 | endPage = Logging_GetLoggingEndPage(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 504 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 505 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 506 | MAX30001_Helper_SetupInterrupts(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 507 | if (MAX30001_AnyStreamingSet() == 1) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 508 | MAX30001_Helper_StartSync(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 509 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 510 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 511 | SetDataLoggingStream(TRUE); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 512 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 513 | while (usbSerial->readable()) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 514 | usbSerial->_getc(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 515 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 516 | fifo_clear(GetUSBIncomingFifo()); // clear USB serial incoming fifo |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 517 | fifo_clear(GetStreamOutFifo()); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 518 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 519 | sram_buffer_0_dirty = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 520 | sram_buffer_1_dirty = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 521 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 522 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 523 | if (loggingOutput == eLogToNothing) printf("eLogToNothing..."); fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 524 | if (loggingOutput == eLogToFlash) printf("eLogToFlash..."); fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 525 | if (loggingOutput == eLogtoUsb) printf("eLogtoUsb..."); fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 526 | printf("highDataRate=%d...",highDataRate); fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 527 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 528 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 529 | Peripherals::timestampTimer()->reset(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 530 | Peripherals::timestampTimer()->start(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 531 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 532 | _LoggingServer_OutputToCdcAcm_Start(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 533 | while (1) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 534 | if (loggingOutput == eLogToFlash) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 535 | // check if we are at the end of flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 536 | if (currentPage >= endPage) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 537 | BlinkEndOfDatalogging(); // blink for 3 seconds to signal end of logging |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 538 | break; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 539 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 540 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 541 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 542 | if (startEvent == eStartEvent_BUTTON) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 543 | buttonPressed = Peripherals::pushButton()->GetButtonFallState(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 544 | if (buttonPressed) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 545 | printf("button pressed, flush the FIFO buffer to SDCard before ending logging\r\n"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 546 | Peripherals::pushButton()->clearButtonFallState(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 547 | // if there is a dirty sram buffer... flush it to flash |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 548 | _LoggingServer_WriteDirtySramBufferToFlash(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 549 | endSDLogging = true; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 550 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 551 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 552 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 553 | if (startEvent == eStartEvent_RPC_TO_USB || |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 554 | startEvent == eStartEvent_RPC_TO_FLASH) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 555 | if (usbSerial->available()) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 556 | if (loggingOutput == eLogToFlash) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 557 | _LoggingServer_WriteDirtySramBufferToFlash(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 558 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 559 | wait(0.2f); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 560 | while (usbSerial->available()) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 561 | usbSerial->_getc(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 562 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 563 | fifo_clear(GetUSBIncomingFifo()); // clear USB serial incoming fifo |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 564 | fifo_clear(GetStreamOutFifo()); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 565 | break; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 566 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 567 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 568 | if (fp == NULL && loggingOutput == eLogToFlash) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 569 | fp = fopen(dataFileName, "ab+"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 570 | // check to see if data is available |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 571 | packetBurstCount = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 572 | while (PacketFifo_Empty() == 0) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 573 | printf("*"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 574 | if (packetBurstCount >= 100 && endSDLogging == false) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 575 | break; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 576 | fifoData = PacketFifo_GetUint32(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 577 | if (loggingOutput == eLogToFlash) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 578 | //_LoggingServer_OutputToFlash(fifoData); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 579 | _LoggingServer_OutputToSDCard(fp, fifoData); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 580 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 581 | if (loggingOutput == eLogtoUsb) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 582 | if (highDataRate == 0) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 583 | _LoggingServer_OutputToCdcAcm(fifoData); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 584 | else |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 585 | _LoggingServer_OutputToCdcAcm_Block(fifoData); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 586 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 587 | packetBurstCount++; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 588 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 589 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 590 | if (endSDLogging) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 591 | endSDLogging = false; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 592 | if (fp != NULL) fclose(fp); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 593 | fp == NULL; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 594 | BlinkEndOfDatalogging(); // blink for 3 seconds to signal end of logging |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 595 | break; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 596 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 597 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 598 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 599 | _LoggingServer_OutputToCdcAcm_End(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 600 | printf("End Logging.\n"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 601 | fflush(stdout); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 602 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 603 | MAX30001_Helper_Stop(); // if any MAX30001 streams have been started, stop |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 604 | // them |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 605 | SetDataLoggingStream(FALSE); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 606 | Peripherals::timestampTimer()->stop(); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 607 | hspLed->blink(1000); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 608 | // default to non-usb packet speed optimizing |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 609 | highDataRate = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 610 | loggingTrigger = eTriggerLog_NULL; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 611 | return 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 612 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 613 |