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-MAX32630FTHR-ECG-EVKIT by
HSP/LoggingService/Logging.cpp@13:6031b0bd9773, 2018-07-24 (annotated)
- Committer:
- Emre.Eken
- Date:
- Tue Jul 24 15:22:35 2018 +0300
- Revision:
- 13:6031b0bd9773
- Parent:
- 0:8e4630a71eb1
.hgtags is added.
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 "RpcServer.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 35 | #include "Logging.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 36 | #include "S25FS512.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 37 | #include "Peripherals.h" |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 38 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 39 | /// length of flash page as dictated by the device |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 40 | #define LENGTH_OF_FLASH_PAGE 256 // length of flash page in bytes |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 41 | /// size in bytes of the external flash device on the HSP platform |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 42 | #define SIZE_OF_EXTERNAL_FLASH \ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 43 | (16777216 / 2) // length of external flash in bytes |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 44 | /// start page of where the mission is defined |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 45 | #define MISSION_DEFINITION_START_PAGE 0x00 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 46 | /// end page of the mission |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 47 | #define MISSION_DEFINITION_END_PAGE 0x0F |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 48 | /// page of where the logging data starts |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 49 | #define LOGGING_START_PAGE 0x12 |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 50 | /// the last logging page |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 51 | #define LOGGING_END_PAGE (SIZE_OF_EXTERNAL_FLASH / LENGTH_OF_FLASH_PAGE) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 52 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 53 | /// static flag to know if logging was started via RPC |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 54 | static bool startLoggingViaRpc = false; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 55 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 56 | extern char missionFileName[32]; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 57 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 58 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 59 | * @brief This will read the mission location and if there is something valid, |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 60 | * then run the Logging_ProcessMissionCmds() |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 61 | * @param cmdBuffer buffer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 62 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 63 | uint32_t Logging_IsMissionDefined(uint8_t *cmdBuffer) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 64 | uint32_t valid = 1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 65 | if ((cmdBuffer[0] == 0xFF) || (cmdBuffer[0] == 0x0)) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 66 | valid = 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 67 | return valid; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 68 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 69 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 70 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 71 | * @brief Read the mission from flash and place in buffer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 72 | * @param buffer pointer to byte array that will contain the read results |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 73 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 74 | int8_t Logging_ReadMissionFromFlash(uint8_t *buffer) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 75 | return Peripherals::s25FS512()->readPages_Helper( |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 76 | MISSION_DEFINITION_START_PAGE, MISSION_DEFINITION_END_PAGE, buffer, 0); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 77 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 78 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 79 | /** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 80 | * @brief Read the mission from SDCard and place in buffer |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 81 | * @param buffer pointer to byte array that will contain the read results |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 82 | */ |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 83 | int8_t Logging_ReadMissionFromSDCard(uint8_t *buffer) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 84 | FILE *fp = NULL; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 85 | if (buffer == NULL) |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 86 | return -1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 87 | fp = fopen(missionFileName, "r"); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 88 | if (fp != NULL) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 89 | do |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 90 | { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 91 | char c = (char)fgetc(fp); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 92 | *buffer++ = c; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 93 | } while(!feof(fp)); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 94 | fclose(fp); |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 95 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 96 | else |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 97 | return -1; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 98 | return 0; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 99 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 100 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 101 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 102 | // return the page where mission is defined, Mission specific |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 103 | uint32_t Logging_GetMissionStartPage(void) { |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 104 | return MISSION_DEFINITION_START_PAGE; |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 105 | } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 106 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 107 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 108 | // return the page where the mission definition ends, Mission specific |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 109 | uint32_t Logging_GetMissionEndPage(void) { return MISSION_DEFINITION_END_PAGE; } |
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 | // Returns the location where the Writing can start from, for data logging... |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 113 | uint32_t Logging_GetLoggingStartPage(void) { return LOGGING_START_PAGE; } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 114 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 115 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 116 | // Returns the end location available where the Flash ends essentially.... for |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 117 | // data logging. |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 118 | uint32_t Logging_GetLoggingEndPage(void) { return LOGGING_END_PAGE; } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 119 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 120 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 121 | void Logging_SetStart(bool state) { startLoggingViaRpc = state; } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 122 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 123 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 124 | bool Logging_GetStart(void) { return startLoggingViaRpc; } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 125 | |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 126 | //****************************************************************************** |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 127 | // for debugging... always say that usb is not connected... for easy bench |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 128 | // testing |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 129 | uint32_t Usb_IsConnected(void) { return 0; } |
Emre.Eken@IST-LT-35101.maxim-ic.internal | 0:8e4630a71eb1 | 130 |