MAX32620HSP (MAXREFDES100) RPC Example for Graphical User Interface
Dependencies: USBDevice
Fork of HSP_Release by
This is an example program for the MAX32620HSP (MAXREFDES100 Health Sensor Platform). It demonstrates all the features of the platform and works with a companion graphical user interface (GUI) to help evaluate/configure/monitor the board. Go to the MAXREFDES100 product page and click on "design resources" to download the companion software. The GUI connects to the board through an RPC interface on a virtual serial port over the USB interface.
The RPC interface provides access to all the features of the board and is available to interface with other development environments such Matlab. This firmware provides realtime data streaming through the RPC interface over USB, and also provides the ability to log the data to flash for untethered battery operation. The data logging settings are configured through the GUI, and the GUI also provides the interface to download logged data.
Details on the RPC interface can be found here: HSP RPC Interface Documentation
Windows
With this program loaded, the MAX32620HSP will appear on your computer as a serial port. On Mac and Linux, this will happen by default. For Windows, you need to install a driver: HSP serial port windows driver
For more details about this platform and how to use it, see the MAXREFDES100 product page.
HSP/LoggingService/Logging_RPC.cpp@3:8e9b9f5818aa, 2017-04-25 (annotated)
- Committer:
- jbradshaw
- Date:
- Tue Apr 25 10:47:10 2017 -0500
- Revision:
- 3:8e9b9f5818aa
- Parent:
- 2:d483f896c7a9
Removed Bulk Erasing, instead a small number of bytes are sampled from each and every page to determine if sector is "dirty", if so sector is erased
Prevents device from sleeping when the firmware detects a series of binary flash page RPC transfers, this increases flash page transfers by %450
when 200mS elapse with the last flash page transfer, normal sleep behaviour is resumed
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 "StringHelper.h" |
jbradshaw | 0:e4a10ed6eb92 | 34 | #include <stdint.h> |
jbradshaw | 0:e4a10ed6eb92 | 35 | #include "Streaming.h" |
jbradshaw | 0:e4a10ed6eb92 | 36 | #include "StringInOut.h" |
jbradshaw | 0:e4a10ed6eb92 | 37 | #include "DataLoggingService.h" |
jbradshaw | 0:e4a10ed6eb92 | 38 | #include "Peripherals.h" |
jbradshaw | 0:e4a10ed6eb92 | 39 | #include "Logging.h" |
jbradshaw | 3:8e9b9f5818aa | 40 | #include "S25FS512.h" |
jbradshaw | 0:e4a10ed6eb92 | 41 | |
jbradshaw | 0:e4a10ed6eb92 | 42 | extern char loggingMissionCmds[4096]; |
jbradshaw | 0:e4a10ed6eb92 | 43 | uint32_t missionCmdIndex; |
jbradshaw | 0:e4a10ed6eb92 | 44 | |
jbradshaw | 0:e4a10ed6eb92 | 45 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 46 | int Logging_RPC_StartMissionDefine(char argStrs[32][32], |
jbradshaw | 0:e4a10ed6eb92 | 47 | char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 48 | uint32_t i; |
jbradshaw | 0:e4a10ed6eb92 | 49 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 50 | |
jbradshaw | 0:e4a10ed6eb92 | 51 | // reset the missionCmdIndex to the beginning of the cmd buffer |
jbradshaw | 0:e4a10ed6eb92 | 52 | missionCmdIndex = 0; |
jbradshaw | 0:e4a10ed6eb92 | 53 | // clear the mission command buffer, fill with zeros |
jbradshaw | 0:e4a10ed6eb92 | 54 | for (i = 0; i < sizeof(loggingMissionCmds); i++) { |
jbradshaw | 0:e4a10ed6eb92 | 55 | loggingMissionCmds[i] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 56 | } |
jbradshaw | 0:e4a10ed6eb92 | 57 | |
jbradshaw | 0:e4a10ed6eb92 | 58 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 59 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 60 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 61 | } |
jbradshaw | 0:e4a10ed6eb92 | 62 | |
jbradshaw | 0:e4a10ed6eb92 | 63 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 64 | int Logging_RPC_AppendMissionCmd(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 65 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 66 | char *strPtr; |
jbradshaw | 0:e4a10ed6eb92 | 67 | uint32_t count = 0; |
jbradshaw | 0:e4a10ed6eb92 | 68 | uint8_t result = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 69 | // append the string to the mission cmd log |
jbradshaw | 0:e4a10ed6eb92 | 70 | strPtr = argStrs[0]; |
jbradshaw | 0:e4a10ed6eb92 | 71 | while (*strPtr != 0) { |
jbradshaw | 0:e4a10ed6eb92 | 72 | loggingMissionCmds[missionCmdIndex] = *strPtr; |
jbradshaw | 0:e4a10ed6eb92 | 73 | missionCmdIndex++; |
jbradshaw | 0:e4a10ed6eb92 | 74 | strPtr++; |
jbradshaw | 0:e4a10ed6eb92 | 75 | // do not overrun buffer |
jbradshaw | 0:e4a10ed6eb92 | 76 | if (missionCmdIndex > (sizeof(loggingMissionCmds) - 2)) { |
jbradshaw | 0:e4a10ed6eb92 | 77 | result = 0xFF; |
jbradshaw | 0:e4a10ed6eb92 | 78 | break; |
jbradshaw | 0:e4a10ed6eb92 | 79 | } |
jbradshaw | 0:e4a10ed6eb92 | 80 | count++; |
jbradshaw | 0:e4a10ed6eb92 | 81 | // do not read more than max count in incoming string |
jbradshaw | 0:e4a10ed6eb92 | 82 | if (count > (32 * 32)) { |
jbradshaw | 0:e4a10ed6eb92 | 83 | result = 0xFF; |
jbradshaw | 0:e4a10ed6eb92 | 84 | break; |
jbradshaw | 0:e4a10ed6eb92 | 85 | } |
jbradshaw | 0:e4a10ed6eb92 | 86 | } |
jbradshaw | 0:e4a10ed6eb92 | 87 | if (result != 0x80) { |
jbradshaw | 0:e4a10ed6eb92 | 88 | reply[0] = 0xFF; |
jbradshaw | 0:e4a10ed6eb92 | 89 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 90 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 91 | } |
jbradshaw | 0:e4a10ed6eb92 | 92 | // add cr/lf to the end of this cmd string |
jbradshaw | 0:e4a10ed6eb92 | 93 | loggingMissionCmds[missionCmdIndex++] = 13; |
jbradshaw | 0:e4a10ed6eb92 | 94 | loggingMissionCmds[missionCmdIndex++] = 10; |
jbradshaw | 0:e4a10ed6eb92 | 95 | |
jbradshaw | 0:e4a10ed6eb92 | 96 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 97 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 98 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 99 | } |
jbradshaw | 0:e4a10ed6eb92 | 100 | |
jbradshaw | 0:e4a10ed6eb92 | 101 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 102 | int Logging_RPC_EndMissionDefine(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 103 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 104 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 105 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 106 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 107 | } |
jbradshaw | 0:e4a10ed6eb92 | 108 | |
jbradshaw | 0:e4a10ed6eb92 | 109 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 110 | int Logging_RPC_WriteMission(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 111 | uint8_t page; |
jbradshaw | 0:e4a10ed6eb92 | 112 | char *ptr; |
jbradshaw | 0:e4a10ed6eb92 | 113 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 114 | |
jbradshaw | 0:e4a10ed6eb92 | 115 | Peripherals::s25FS512()->parameterSectorErase_Helper(0x0); |
jbradshaw | 0:e4a10ed6eb92 | 116 | ptr = loggingMissionCmds; |
jbradshaw | 0:e4a10ed6eb92 | 117 | for (page = 0; page < 16; page++) { |
jbradshaw | 0:e4a10ed6eb92 | 118 | Peripherals::s25FS512()->writePage_Helper(page, (uint8_t *)ptr, 0); |
jbradshaw | 0:e4a10ed6eb92 | 119 | ptr += 256; |
jbradshaw | 0:e4a10ed6eb92 | 120 | } |
jbradshaw | 0:e4a10ed6eb92 | 121 | |
jbradshaw | 0:e4a10ed6eb92 | 122 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 123 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 124 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 125 | } |
jbradshaw | 0:e4a10ed6eb92 | 126 | |
jbradshaw | 0:e4a10ed6eb92 | 127 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 128 | int Logging_RPC_ReadMission(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 129 | char *ptr; |
jbradshaw | 0:e4a10ed6eb92 | 130 | uint32_t i; |
jbradshaw | 0:e4a10ed6eb92 | 131 | // read sector 0 |
jbradshaw | 0:e4a10ed6eb92 | 132 | ptr = loggingMissionCmds; |
jbradshaw | 0:e4a10ed6eb92 | 133 | for (i = 0; i < 16; i++) { |
jbradshaw | 0:e4a10ed6eb92 | 134 | Peripherals::s25FS512()->readPages_Helper(i, i, (uint8_t *)ptr, 0); |
jbradshaw | 0:e4a10ed6eb92 | 135 | ptr += 256; |
jbradshaw | 0:e4a10ed6eb92 | 136 | } |
jbradshaw | 0:e4a10ed6eb92 | 137 | // strip header by shifting payload left |
jbradshaw | 0:e4a10ed6eb92 | 138 | ptr = loggingMissionCmds; |
jbradshaw | 0:e4a10ed6eb92 | 139 | for (i = 0; i < sizeof(loggingMissionCmds); i++) { |
jbradshaw | 0:e4a10ed6eb92 | 140 | if (*ptr == 13) { |
jbradshaw | 0:e4a10ed6eb92 | 141 | *ptr = ':'; |
jbradshaw | 0:e4a10ed6eb92 | 142 | } else if (*ptr == 10) { |
jbradshaw | 0:e4a10ed6eb92 | 143 | *ptr = ' '; |
jbradshaw | 0:e4a10ed6eb92 | 144 | } |
jbradshaw | 0:e4a10ed6eb92 | 145 | ptr++; |
jbradshaw | 0:e4a10ed6eb92 | 146 | } |
jbradshaw | 0:e4a10ed6eb92 | 147 | if (loggingMissionCmds[0] == 0xFF || loggingMissionCmds[0] == 0x0) { |
jbradshaw | 0:e4a10ed6eb92 | 148 | sprintf(loggingMissionCmds, "%s", "null "); |
jbradshaw | 0:e4a10ed6eb92 | 149 | } |
jbradshaw | 0:e4a10ed6eb92 | 150 | // send it out via uart |
jbradshaw | 0:e4a10ed6eb92 | 151 | putStr(loggingMissionCmds); |
jbradshaw | 0:e4a10ed6eb92 | 152 | replyStrs[0][0] = 0; |
jbradshaw | 0:e4a10ed6eb92 | 153 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 154 | } |
jbradshaw | 0:e4a10ed6eb92 | 155 | |
jbradshaw | 0:e4a10ed6eb92 | 156 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 157 | int Logging_RPC_EraseMission(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 158 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 159 | Peripherals::s25FS512()->parameterSectorErase_Helper(0x0); |
jbradshaw | 0:e4a10ed6eb92 | 160 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 161 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 162 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 163 | } |
jbradshaw | 0:e4a10ed6eb92 | 164 | |
jbradshaw | 3:8e9b9f5818aa | 165 | // |
jbradshaw | 3:8e9b9f5818aa | 166 | // small helper function to determine if the X number of a page are FF (empty) |
jbradshaw | 3:8e9b9f5818aa | 167 | // |
jbradshaw | 3:8e9b9f5818aa | 168 | static bool isPartialPageEmpty(uint8_t *ptr, int count) { |
jbradshaw | 3:8e9b9f5818aa | 169 | int i; |
jbradshaw | 3:8e9b9f5818aa | 170 | for (i = 0; i < count; i++) { |
jbradshaw | 3:8e9b9f5818aa | 171 | if (ptr[i] != 0xFF) return false; |
jbradshaw | 3:8e9b9f5818aa | 172 | } |
jbradshaw | 3:8e9b9f5818aa | 173 | return true; |
jbradshaw | 3:8e9b9f5818aa | 174 | } |
jbradshaw | 2:d483f896c7a9 | 175 | |
jbradshaw | 3:8e9b9f5818aa | 176 | // |
jbradshaw | 3:8e9b9f5818aa | 177 | // define the different sector sizes in flash |
jbradshaw | 3:8e9b9f5818aa | 178 | // |
jbradshaw | 3:8e9b9f5818aa | 179 | typedef enum { |
jbradshaw | 3:8e9b9f5818aa | 180 | e4K, |
jbradshaw | 3:8e9b9f5818aa | 181 | e32K, |
jbradshaw | 3:8e9b9f5818aa | 182 | e64K |
jbradshaw | 3:8e9b9f5818aa | 183 | } loggingFlashArea_t; |
jbradshaw | 2:d483f896c7a9 | 184 | |
jbradshaw | 0:e4a10ed6eb92 | 185 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 186 | int Logging_EraseWrittenSectors(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 3:8e9b9f5818aa | 187 | uint32_t i; |
jbradshaw | 3:8e9b9f5818aa | 188 | uint8_t data[512]; |
jbradshaw | 3:8e9b9f5818aa | 189 | uint32_t address; |
jbradshaw | 3:8e9b9f5818aa | 190 | uint32_t pageNumber; |
jbradshaw | 3:8e9b9f5818aa | 191 | bool pageEmpty; |
jbradshaw | 3:8e9b9f5818aa | 192 | uint32_t pagesToScan; |
jbradshaw | 3:8e9b9f5818aa | 193 | loggingFlashArea_t currentArea; |
jbradshaw | 3:8e9b9f5818aa | 194 | uint32_t currentAreaSize; |
jbradshaw | 3:8e9b9f5818aa | 195 | //Peripherals::s25FS512()->bulkErase_Helper(); |
jbradshaw | 3:8e9b9f5818aa | 196 | |
jbradshaw | 3:8e9b9f5818aa | 197 | // |
jbradshaw | 3:8e9b9f5818aa | 198 | // quickly scan through the first few bytes of a page and continue this through a sector |
jbradshaw | 3:8e9b9f5818aa | 199 | // this will determine if the sector needs to be erased or can be skipped |
jbradshaw | 3:8e9b9f5818aa | 200 | // |
jbradshaw | 3:8e9b9f5818aa | 201 | currentArea = e4K; |
jbradshaw | 3:8e9b9f5818aa | 202 | address = 0; |
jbradshaw | 3:8e9b9f5818aa | 203 | // interate through the entire flash |
jbradshaw | 3:8e9b9f5818aa | 204 | while (address < SIZE_OF_EXTERNAL_FLASH) { |
jbradshaw | 3:8e9b9f5818aa | 205 | // determine the size of the current area |
jbradshaw | 3:8e9b9f5818aa | 206 | switch (currentArea) { |
jbradshaw | 3:8e9b9f5818aa | 207 | case e4K: |
jbradshaw | 3:8e9b9f5818aa | 208 | currentAreaSize = ADDRESS_INC_4K; |
jbradshaw | 3:8e9b9f5818aa | 209 | break; |
jbradshaw | 3:8e9b9f5818aa | 210 | case e32K: |
jbradshaw | 3:8e9b9f5818aa | 211 | currentAreaSize = ADDRESS_INC_32K; |
jbradshaw | 3:8e9b9f5818aa | 212 | break; |
jbradshaw | 3:8e9b9f5818aa | 213 | default: |
jbradshaw | 3:8e9b9f5818aa | 214 | currentAreaSize = ADDRESS_INC_64K; |
jbradshaw | 3:8e9b9f5818aa | 215 | break; |
jbradshaw | 3:8e9b9f5818aa | 216 | } |
jbradshaw | 3:8e9b9f5818aa | 217 | pagesToScan = currentAreaSize / SIZE_OF_PAGE; |
jbradshaw | 3:8e9b9f5818aa | 218 | pageNumber = address >> 8; |
jbradshaw | 3:8e9b9f5818aa | 219 | pageEmpty = true; |
jbradshaw | 3:8e9b9f5818aa | 220 | // scan the first few bytes in each page for this area |
jbradshaw | 3:8e9b9f5818aa | 221 | for (i = 0; i < pagesToScan; i++) { |
jbradshaw | 3:8e9b9f5818aa | 222 | Peripherals::s25FS512()->readPartialPage_Helper(pageNumber + i, data, 4); |
jbradshaw | 3:8e9b9f5818aa | 223 | pageEmpty = isPartialPageEmpty(data, 4); |
jbradshaw | 3:8e9b9f5818aa | 224 | if (pageEmpty == false) break; |
jbradshaw | 3:8e9b9f5818aa | 225 | } |
jbradshaw | 3:8e9b9f5818aa | 226 | // if we detected data then erase this sector |
jbradshaw | 3:8e9b9f5818aa | 227 | if (pageEmpty == false) { |
jbradshaw | 3:8e9b9f5818aa | 228 | switch (currentArea) { |
jbradshaw | 3:8e9b9f5818aa | 229 | case e4K: |
jbradshaw | 3:8e9b9f5818aa | 230 | Peripherals::s25FS512()->parameterSectorErase_Helper(address); |
jbradshaw | 3:8e9b9f5818aa | 231 | break; |
jbradshaw | 3:8e9b9f5818aa | 232 | default: |
jbradshaw | 3:8e9b9f5818aa | 233 | Peripherals::s25FS512()->sectorErase_Helper(address); |
jbradshaw | 3:8e9b9f5818aa | 234 | break; |
jbradshaw | 3:8e9b9f5818aa | 235 | } |
jbradshaw | 3:8e9b9f5818aa | 236 | } |
jbradshaw | 3:8e9b9f5818aa | 237 | // update the address with the current area size |
jbradshaw | 3:8e9b9f5818aa | 238 | address += currentAreaSize; |
jbradshaw | 3:8e9b9f5818aa | 239 | // determine the new area in flash |
jbradshaw | 3:8e9b9f5818aa | 240 | if (address < ADDRESS_4K_END) { |
jbradshaw | 3:8e9b9f5818aa | 241 | currentArea = e4K; |
jbradshaw | 3:8e9b9f5818aa | 242 | } else if (address == ADDRESS_32K_START) { |
jbradshaw | 3:8e9b9f5818aa | 243 | currentArea = e32K; |
jbradshaw | 3:8e9b9f5818aa | 244 | } else { |
jbradshaw | 3:8e9b9f5818aa | 245 | currentArea = e64K; |
jbradshaw | 3:8e9b9f5818aa | 246 | } |
jbradshaw | 3:8e9b9f5818aa | 247 | } |
jbradshaw | 0:e4a10ed6eb92 | 248 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 249 | } |
jbradshaw | 0:e4a10ed6eb92 | 250 | |
jbradshaw | 0:e4a10ed6eb92 | 251 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 252 | int Logging_Start(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 253 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 254 | Logging_SetStart(true); |
jbradshaw | 0:e4a10ed6eb92 | 255 | reply[0] = 0x80; // indicate success |
jbradshaw | 0:e4a10ed6eb92 | 256 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 257 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 258 | } |
jbradshaw | 0:e4a10ed6eb92 | 259 | |
jbradshaw | 0:e4a10ed6eb92 | 260 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 261 | int Logging_GetLastWrittenPage(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 262 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 263 | |
jbradshaw | 0:e4a10ed6eb92 | 264 | uint32_t page; |
jbradshaw | 0:e4a10ed6eb92 | 265 | uint32_t lastPage; |
jbradshaw | 0:e4a10ed6eb92 | 266 | uint32_t pageEmpty; |
jbradshaw | 0:e4a10ed6eb92 | 267 | uint8_t data[512]; |
jbradshaw | 0:e4a10ed6eb92 | 268 | |
jbradshaw | 0:e4a10ed6eb92 | 269 | printf("Logging_GetLastWrittenPage "); |
jbradshaw | 0:e4a10ed6eb92 | 270 | fflush(stdout); |
jbradshaw | 0:e4a10ed6eb92 | 271 | lastPage = Logging_GetLoggingEndPage(); |
jbradshaw | 0:e4a10ed6eb92 | 272 | for (page = 2; page <= lastPage; page++) { |
jbradshaw | 0:e4a10ed6eb92 | 273 | // Peripherals::serial()->printf("checking page %d ",page); fflush(stdout); |
jbradshaw | 0:e4a10ed6eb92 | 274 | // sample the page |
jbradshaw | 0:e4a10ed6eb92 | 275 | Peripherals::s25FS512()->readPages_Helper(page, page, data, 0); |
jbradshaw | 0:e4a10ed6eb92 | 276 | pageEmpty = Peripherals::s25FS512()->isPageEmpty(data); |
jbradshaw | 0:e4a10ed6eb92 | 277 | if (pageEmpty != 0) { |
jbradshaw | 0:e4a10ed6eb92 | 278 | break; |
jbradshaw | 0:e4a10ed6eb92 | 279 | } |
jbradshaw | 0:e4a10ed6eb92 | 280 | } |
jbradshaw | 0:e4a10ed6eb92 | 281 | if (page > lastPage) |
jbradshaw | 0:e4a10ed6eb92 | 282 | page = lastPage; |
jbradshaw | 1:9490836294ea | 283 | printf("last page %d, 0x%X ", (unsigned int)page, (unsigned int)page); |
jbradshaw | 0:e4a10ed6eb92 | 284 | fflush(stdout); |
jbradshaw | 0:e4a10ed6eb92 | 285 | reply[0] = page; |
jbradshaw | 0:e4a10ed6eb92 | 286 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 287 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 288 | } |
jbradshaw | 0:e4a10ed6eb92 | 289 | |
jbradshaw | 0:e4a10ed6eb92 | 290 | extern int highDataRate; |
jbradshaw | 0:e4a10ed6eb92 | 291 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 292 | int Logging_StartLoggingUsb(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 293 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 294 | // highDataRate = 0; |
jbradshaw | 0:e4a10ed6eb92 | 295 | LoggingService_StartLoggingUsb(); |
jbradshaw | 0:e4a10ed6eb92 | 296 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 297 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 298 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 299 | } |
jbradshaw | 0:e4a10ed6eb92 | 300 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 301 | int Logging_StartLoggingFlash(char argStrs[32][32], char replyStrs[32][32]) { |
jbradshaw | 0:e4a10ed6eb92 | 302 | uint32_t reply[1]; |
jbradshaw | 0:e4a10ed6eb92 | 303 | // highDataRate = 0; |
jbradshaw | 0:e4a10ed6eb92 | 304 | LoggingService_StartLoggingFlash(); |
jbradshaw | 0:e4a10ed6eb92 | 305 | reply[0] = 0x80; |
jbradshaw | 0:e4a10ed6eb92 | 306 | FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs); |
jbradshaw | 0:e4a10ed6eb92 | 307 | return 0; |
jbradshaw | 0:e4a10ed6eb92 | 308 | } |