MAX30001-MAX32630FTHR SYS EvKit

Dependencies:   USBDevice max32630fthr

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Logging.cpp Source File

Logging.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 #include "mbed.h"
00034 #include "RpcServer.h"
00035 #include "Logging.h"
00036 #include "S25FS512.h"
00037 #include "Peripherals.h"
00038 
00039 /// length of flash page as dictated by the device
00040 #define LENGTH_OF_FLASH_PAGE 256 // length of flash page in bytes
00041 /// size in bytes of the external flash device on the HSP platform
00042 #define SIZE_OF_EXTERNAL_FLASH                                                 \
00043   (16777216 / 2) // length of external flash in bytes
00044 /// start page of where the mission is defined
00045 #define MISSION_DEFINITION_START_PAGE 0x00
00046 /// end page of the mission
00047 #define MISSION_DEFINITION_END_PAGE 0x0F
00048 /// page of where the logging data starts
00049 #define LOGGING_START_PAGE 0x12
00050 /// the last logging page
00051 #define LOGGING_END_PAGE (SIZE_OF_EXTERNAL_FLASH / LENGTH_OF_FLASH_PAGE)
00052 
00053 /// static flag to know if logging was started via RPC
00054 static bool startLoggingViaRpc = false;
00055 
00056 extern char missionFileName[32];
00057 
00058 /**
00059 * @brief This will read the mission location and if there is something valid,
00060 * then run the Logging_ProcessMissionCmds()
00061 * @param cmdBuffer buffer
00062 */
00063 uint32_t Logging_IsMissionDefined(uint8_t *cmdBuffer) {
00064   uint32_t valid = 1;
00065   if ((cmdBuffer[0] == 0xFF) || (cmdBuffer[0] == 0x0))
00066     valid = 0;
00067   return valid;
00068 }
00069 
00070 /**
00071 * @brief Read the mission from flash and place in buffer
00072 * @param buffer pointer to byte array that will contain the read results
00073 */
00074 int8_t Logging_ReadMissionFromFlash(uint8_t *buffer) {
00075   return Peripherals::s25FS512()->readPages_Helper(
00076       MISSION_DEFINITION_START_PAGE, MISSION_DEFINITION_END_PAGE, buffer, 0);
00077 }
00078 
00079 /**
00080 * @brief Read the mission from SDCard and place in buffer
00081 * @param buffer pointer to byte array that will contain the read results
00082 */
00083 int8_t Logging_ReadMissionFromSDCard(uint8_t *buffer) {
00084     FILE *fp = NULL;
00085     if (buffer == NULL)
00086         return -1;
00087     fp = fopen(missionFileName, "r");
00088     if (fp != NULL) {
00089         do
00090         {
00091             char c = (char)fgetc(fp);
00092             *buffer++ = c;
00093         } while(!feof(fp));
00094         fclose(fp);
00095     }
00096     else
00097         return -1;
00098     return 0;
00099 }
00100 
00101 //******************************************************************************
00102 // return the page where mission is defined, Mission specific
00103 uint32_t Logging_GetMissionStartPage(void) {
00104   return MISSION_DEFINITION_START_PAGE;
00105 }
00106 
00107 //******************************************************************************
00108 // return the page where the mission definition ends, Mission specific
00109 uint32_t Logging_GetMissionEndPage(void) { return MISSION_DEFINITION_END_PAGE; }
00110 
00111 //******************************************************************************
00112 // Returns the location where the Writing can start from, for data logging...
00113 uint32_t Logging_GetLoggingStartPage(void) { return LOGGING_START_PAGE; }
00114 
00115 //******************************************************************************
00116 // Returns the end location available where the Flash ends essentially.... for
00117 // data logging.
00118 uint32_t Logging_GetLoggingEndPage(void) { return LOGGING_END_PAGE; }
00119 
00120 //******************************************************************************
00121 void Logging_SetStart(bool state) { startLoggingViaRpc = state; }
00122 
00123 //******************************************************************************
00124 bool Logging_GetStart(void) { return startLoggingViaRpc; }
00125 
00126 //******************************************************************************
00127 // for debugging... always say that usb is not connected... for easy bench
00128 // testing
00129 uint32_t Usb_IsConnected(void) { return 0; }
00130