Fork of the offical HSP_RPC_GUI firmware

Dependencies:   USBDevice

Fork of MAXREFDES100 firmware for MAX32620HSP

Committer:
jbradshaw
Date:
Fri Apr 21 18:10:37 2017 -0500
Revision:
2:d483f896c7a9
Parent:
1:9490836294ea
Child:
3:8e9b9f5818aa
Force a bulk flash erase when erasing data to assure proper erasure state

Who changed what in which revision?

UserRevisionLine numberNew 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 0:e4a10ed6eb92 40
jbradshaw 0:e4a10ed6eb92 41 extern char loggingMissionCmds[4096];
jbradshaw 0:e4a10ed6eb92 42 uint32_t missionCmdIndex;
jbradshaw 0:e4a10ed6eb92 43
jbradshaw 0:e4a10ed6eb92 44 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 45 int Logging_RPC_StartMissionDefine(char argStrs[32][32],
jbradshaw 0:e4a10ed6eb92 46 char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 47 uint32_t i;
jbradshaw 0:e4a10ed6eb92 48 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 49
jbradshaw 0:e4a10ed6eb92 50 // reset the missionCmdIndex to the beginning of the cmd buffer
jbradshaw 0:e4a10ed6eb92 51 missionCmdIndex = 0;
jbradshaw 0:e4a10ed6eb92 52 // clear the mission command buffer, fill with zeros
jbradshaw 0:e4a10ed6eb92 53 for (i = 0; i < sizeof(loggingMissionCmds); i++) {
jbradshaw 0:e4a10ed6eb92 54 loggingMissionCmds[i] = 0;
jbradshaw 0:e4a10ed6eb92 55 }
jbradshaw 0:e4a10ed6eb92 56
jbradshaw 0:e4a10ed6eb92 57 reply[0] = 0x80;
jbradshaw 0:e4a10ed6eb92 58 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 59 return 0;
jbradshaw 0:e4a10ed6eb92 60 }
jbradshaw 0:e4a10ed6eb92 61
jbradshaw 0:e4a10ed6eb92 62 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 63 int Logging_RPC_AppendMissionCmd(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 64 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 65 char *strPtr;
jbradshaw 0:e4a10ed6eb92 66 uint32_t count = 0;
jbradshaw 0:e4a10ed6eb92 67 uint8_t result = 0x80;
jbradshaw 0:e4a10ed6eb92 68 // append the string to the mission cmd log
jbradshaw 0:e4a10ed6eb92 69 strPtr = argStrs[0];
jbradshaw 0:e4a10ed6eb92 70 while (*strPtr != 0) {
jbradshaw 0:e4a10ed6eb92 71 loggingMissionCmds[missionCmdIndex] = *strPtr;
jbradshaw 0:e4a10ed6eb92 72 missionCmdIndex++;
jbradshaw 0:e4a10ed6eb92 73 strPtr++;
jbradshaw 0:e4a10ed6eb92 74 // do not overrun buffer
jbradshaw 0:e4a10ed6eb92 75 if (missionCmdIndex > (sizeof(loggingMissionCmds) - 2)) {
jbradshaw 0:e4a10ed6eb92 76 result = 0xFF;
jbradshaw 0:e4a10ed6eb92 77 break;
jbradshaw 0:e4a10ed6eb92 78 }
jbradshaw 0:e4a10ed6eb92 79 count++;
jbradshaw 0:e4a10ed6eb92 80 // do not read more than max count in incoming string
jbradshaw 0:e4a10ed6eb92 81 if (count > (32 * 32)) {
jbradshaw 0:e4a10ed6eb92 82 result = 0xFF;
jbradshaw 0:e4a10ed6eb92 83 break;
jbradshaw 0:e4a10ed6eb92 84 }
jbradshaw 0:e4a10ed6eb92 85 }
jbradshaw 0:e4a10ed6eb92 86 if (result != 0x80) {
jbradshaw 0:e4a10ed6eb92 87 reply[0] = 0xFF;
jbradshaw 0:e4a10ed6eb92 88 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 89 return 0;
jbradshaw 0:e4a10ed6eb92 90 }
jbradshaw 0:e4a10ed6eb92 91 // add cr/lf to the end of this cmd string
jbradshaw 0:e4a10ed6eb92 92 loggingMissionCmds[missionCmdIndex++] = 13;
jbradshaw 0:e4a10ed6eb92 93 loggingMissionCmds[missionCmdIndex++] = 10;
jbradshaw 0:e4a10ed6eb92 94
jbradshaw 0:e4a10ed6eb92 95 reply[0] = 0x80;
jbradshaw 0:e4a10ed6eb92 96 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 97 return 0;
jbradshaw 0:e4a10ed6eb92 98 }
jbradshaw 0:e4a10ed6eb92 99
jbradshaw 0:e4a10ed6eb92 100 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 101 int Logging_RPC_EndMissionDefine(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 102 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 103 reply[0] = 0x80;
jbradshaw 0:e4a10ed6eb92 104 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 105 return 0;
jbradshaw 0:e4a10ed6eb92 106 }
jbradshaw 0:e4a10ed6eb92 107
jbradshaw 0:e4a10ed6eb92 108 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 109 int Logging_RPC_WriteMission(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 110 uint8_t page;
jbradshaw 0:e4a10ed6eb92 111 char *ptr;
jbradshaw 0:e4a10ed6eb92 112 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 113
jbradshaw 0:e4a10ed6eb92 114 Peripherals::s25FS512()->parameterSectorErase_Helper(0x0);
jbradshaw 0:e4a10ed6eb92 115 ptr = loggingMissionCmds;
jbradshaw 0:e4a10ed6eb92 116 for (page = 0; page < 16; page++) {
jbradshaw 0:e4a10ed6eb92 117 Peripherals::s25FS512()->writePage_Helper(page, (uint8_t *)ptr, 0);
jbradshaw 0:e4a10ed6eb92 118 ptr += 256;
jbradshaw 0:e4a10ed6eb92 119 }
jbradshaw 0:e4a10ed6eb92 120
jbradshaw 0:e4a10ed6eb92 121 reply[0] = 0x80;
jbradshaw 0:e4a10ed6eb92 122 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 123 return 0;
jbradshaw 0:e4a10ed6eb92 124 }
jbradshaw 0:e4a10ed6eb92 125
jbradshaw 0:e4a10ed6eb92 126 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 127 int Logging_RPC_ReadMission(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 128 char *ptr;
jbradshaw 0:e4a10ed6eb92 129 uint32_t i;
jbradshaw 0:e4a10ed6eb92 130 // read sector 0
jbradshaw 0:e4a10ed6eb92 131 ptr = loggingMissionCmds;
jbradshaw 0:e4a10ed6eb92 132 for (i = 0; i < 16; i++) {
jbradshaw 0:e4a10ed6eb92 133 Peripherals::s25FS512()->readPages_Helper(i, i, (uint8_t *)ptr, 0);
jbradshaw 0:e4a10ed6eb92 134 ptr += 256;
jbradshaw 0:e4a10ed6eb92 135 }
jbradshaw 0:e4a10ed6eb92 136 // strip header by shifting payload left
jbradshaw 0:e4a10ed6eb92 137 ptr = loggingMissionCmds;
jbradshaw 0:e4a10ed6eb92 138 for (i = 0; i < sizeof(loggingMissionCmds); i++) {
jbradshaw 0:e4a10ed6eb92 139 if (*ptr == 13) {
jbradshaw 0:e4a10ed6eb92 140 *ptr = ':';
jbradshaw 0:e4a10ed6eb92 141 } else if (*ptr == 10) {
jbradshaw 0:e4a10ed6eb92 142 *ptr = ' ';
jbradshaw 0:e4a10ed6eb92 143 }
jbradshaw 0:e4a10ed6eb92 144 ptr++;
jbradshaw 0:e4a10ed6eb92 145 }
jbradshaw 0:e4a10ed6eb92 146 if (loggingMissionCmds[0] == 0xFF || loggingMissionCmds[0] == 0x0) {
jbradshaw 0:e4a10ed6eb92 147 sprintf(loggingMissionCmds, "%s", "null ");
jbradshaw 0:e4a10ed6eb92 148 }
jbradshaw 0:e4a10ed6eb92 149 // send it out via uart
jbradshaw 0:e4a10ed6eb92 150 putStr(loggingMissionCmds);
jbradshaw 0:e4a10ed6eb92 151 replyStrs[0][0] = 0;
jbradshaw 0:e4a10ed6eb92 152 return 0;
jbradshaw 0:e4a10ed6eb92 153 }
jbradshaw 0:e4a10ed6eb92 154
jbradshaw 0:e4a10ed6eb92 155 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 156 int Logging_RPC_EraseMission(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 157 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 158 Peripherals::s25FS512()->parameterSectorErase_Helper(0x0);
jbradshaw 0:e4a10ed6eb92 159 reply[0] = 0x80;
jbradshaw 0:e4a10ed6eb92 160 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 161 return 0;
jbradshaw 0:e4a10ed6eb92 162 }
jbradshaw 0:e4a10ed6eb92 163
jbradshaw 0:e4a10ed6eb92 164 #define SECTOR_SIZE_256K 0x10000
jbradshaw 0:e4a10ed6eb92 165 #define PAGE_INC_256K 0x400
jbradshaw 0:e4a10ed6eb92 166 #define SECTOR_SIZE_4K 0x1000
jbradshaw 0:e4a10ed6eb92 167 #define PAGE_INC_4K 0x10
jbradshaw 0:e4a10ed6eb92 168 #define TOTAL_SECTOR_NUMBER 263
jbradshaw 0:e4a10ed6eb92 169
jbradshaw 2:d483f896c7a9 170
jbradshaw 2:d483f896c7a9 171 #define ADDRESS_INC_4K 0x1000
jbradshaw 2:d483f896c7a9 172 #define ADDRESS_INC_32K 0x8000
jbradshaw 2:d483f896c7a9 173 #define ADDRESS_INC_64K 0x10000
jbradshaw 2:d483f896c7a9 174
jbradshaw 2:d483f896c7a9 175 #define ADDRESS_4K_START 0x0
jbradshaw 2:d483f896c7a9 176 #define ADDRESS_4K_END 0x8000
jbradshaw 2:d483f896c7a9 177
jbradshaw 2:d483f896c7a9 178 #define ADDRESS_32K_START 0x8000
jbradshaw 2:d483f896c7a9 179 #define ADDRESS_32k_END 0x10000
jbradshaw 2:d483f896c7a9 180
jbradshaw 2:d483f896c7a9 181 #define ADDRESS_64K_START 0x10000
jbradshaw 2:d483f896c7a9 182 #define ADDRESS_64k_END 0x2000000
jbradshaw 2:d483f896c7a9 183
jbradshaw 2:d483f896c7a9 184 #define SIZE_OF_EXTERNAL_FLASH 0x2000000 // 33,554,432 Bytes
jbradshaw 2:d483f896c7a9 185
jbradshaw 0:e4a10ed6eb92 186 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 187 int Logging_EraseWrittenSectors(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 2:d483f896c7a9 188 Peripherals::s25FS512()->bulkErase_Helper();
jbradshaw 0:e4a10ed6eb92 189 return 0;
jbradshaw 0:e4a10ed6eb92 190 }
jbradshaw 0:e4a10ed6eb92 191
jbradshaw 0:e4a10ed6eb92 192 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 193 int Logging_Start(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 194 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 195 Logging_SetStart(true);
jbradshaw 0:e4a10ed6eb92 196 reply[0] = 0x80; // indicate success
jbradshaw 0:e4a10ed6eb92 197 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 198 return 0;
jbradshaw 0:e4a10ed6eb92 199 }
jbradshaw 0:e4a10ed6eb92 200
jbradshaw 0:e4a10ed6eb92 201 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 202 int Logging_GetLastWrittenPage(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 203 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 204
jbradshaw 0:e4a10ed6eb92 205 uint32_t page;
jbradshaw 0:e4a10ed6eb92 206 uint32_t lastPage;
jbradshaw 0:e4a10ed6eb92 207 uint32_t pageEmpty;
jbradshaw 0:e4a10ed6eb92 208 uint8_t data[512];
jbradshaw 0:e4a10ed6eb92 209
jbradshaw 0:e4a10ed6eb92 210 printf("Logging_GetLastWrittenPage ");
jbradshaw 0:e4a10ed6eb92 211 fflush(stdout);
jbradshaw 0:e4a10ed6eb92 212 lastPage = Logging_GetLoggingEndPage();
jbradshaw 0:e4a10ed6eb92 213 for (page = 2; page <= lastPage; page++) {
jbradshaw 0:e4a10ed6eb92 214 // Peripherals::serial()->printf("checking page %d ",page); fflush(stdout);
jbradshaw 0:e4a10ed6eb92 215 // sample the page
jbradshaw 0:e4a10ed6eb92 216 Peripherals::s25FS512()->readPages_Helper(page, page, data, 0);
jbradshaw 0:e4a10ed6eb92 217 pageEmpty = Peripherals::s25FS512()->isPageEmpty(data);
jbradshaw 0:e4a10ed6eb92 218 if (pageEmpty != 0) {
jbradshaw 0:e4a10ed6eb92 219 break;
jbradshaw 0:e4a10ed6eb92 220 }
jbradshaw 0:e4a10ed6eb92 221 }
jbradshaw 0:e4a10ed6eb92 222 if (page > lastPage)
jbradshaw 0:e4a10ed6eb92 223 page = lastPage;
jbradshaw 1:9490836294ea 224 printf("last page %d, 0x%X ", (unsigned int)page, (unsigned int)page);
jbradshaw 0:e4a10ed6eb92 225 fflush(stdout);
jbradshaw 0:e4a10ed6eb92 226 reply[0] = page;
jbradshaw 0:e4a10ed6eb92 227 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 228 return 0;
jbradshaw 0:e4a10ed6eb92 229 }
jbradshaw 0:e4a10ed6eb92 230
jbradshaw 0:e4a10ed6eb92 231 extern int highDataRate;
jbradshaw 0:e4a10ed6eb92 232 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 233 int Logging_StartLoggingUsb(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 234 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 235 // highDataRate = 0;
jbradshaw 0:e4a10ed6eb92 236 LoggingService_StartLoggingUsb();
jbradshaw 0:e4a10ed6eb92 237 reply[0] = 0x80;
jbradshaw 0:e4a10ed6eb92 238 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 239 return 0;
jbradshaw 0:e4a10ed6eb92 240 }
jbradshaw 0:e4a10ed6eb92 241 //******************************************************************************
jbradshaw 0:e4a10ed6eb92 242 int Logging_StartLoggingFlash(char argStrs[32][32], char replyStrs[32][32]) {
jbradshaw 0:e4a10ed6eb92 243 uint32_t reply[1];
jbradshaw 0:e4a10ed6eb92 244 // highDataRate = 0;
jbradshaw 0:e4a10ed6eb92 245 LoggingService_StartLoggingFlash();
jbradshaw 0:e4a10ed6eb92 246 reply[0] = 0x80;
jbradshaw 0:e4a10ed6eb92 247 FormatReply32(reply, sizeof(reply) / sizeof(uint32_t), replyStrs);
jbradshaw 0:e4a10ed6eb92 248 return 0;
jbradshaw 0:e4a10ed6eb92 249 }