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