Firmware enhancements for HSP_RPC_GUI 3.0.1

Dependencies:   USBDevice

Fork of HSP_RPC_GUI by Maxim Integrated

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  0x2000000 // 33,554,432 Bytes
00043 /// start page of where the mission is defined
00044 #define MISSION_DEFINITION_START_PAGE 0x00
00045 /// end page of the mission
00046 #define MISSION_DEFINITION_END_PAGE 0x0F
00047 /// page of where the logging data starts
00048 #define LOGGING_START_PAGE 0x12
00049 /// the last logging page
00050 #define LOGGING_END_PAGE ((SIZE_OF_EXTERNAL_FLASH / LENGTH_OF_FLASH_PAGE) - 1)
00051 
00052 /// static flag to know if logging was started via RPC
00053 static bool startLoggingViaRpc = false;
00054 
00055 /**
00056 * @brief This will read the mission location and if there is something valid,
00057 * then run the Logging_ProcessMissionCmds()
00058 * @param cmdBuffer buffer
00059 */
00060 uint32_t Logging_IsMissionDefined(uint8_t *cmdBuffer) {
00061   uint32_t valid = 1;
00062   if ((cmdBuffer[0] == 0xFF) || (cmdBuffer[0] == 0x0))
00063     valid = 0;
00064   return valid;
00065 }
00066 
00067 /**
00068 * @brief Read the mission from flash and place in buffer
00069 * @param buffer pointer to byte array that will contain the read results
00070 */
00071 int8_t Logging_ReadMissionFromFlash(uint8_t *buffer) {
00072   return Peripherals::s25FS512()->readPages_Helper(
00073       MISSION_DEFINITION_START_PAGE, MISSION_DEFINITION_END_PAGE, buffer, 0);
00074 }
00075 
00076 //******************************************************************************
00077 // return the page where mission is defined, Mission specific
00078 uint32_t Logging_GetMissionStartPage(void) {
00079   return MISSION_DEFINITION_START_PAGE;
00080 }
00081 
00082 //******************************************************************************
00083 // return the page where the mission definition ends, Mission specific
00084 uint32_t Logging_GetMissionEndPage(void) { return MISSION_DEFINITION_END_PAGE; }
00085 
00086 //******************************************************************************
00087 // Returns the location where the Writing can start from, for data logging...
00088 uint32_t Logging_GetLoggingStartPage(void) { return LOGGING_START_PAGE; }
00089 
00090 //******************************************************************************
00091 // Returns the end location available where the Flash ends essentially.... for
00092 // data logging.
00093 uint32_t Logging_GetLoggingEndPage(void) { return LOGGING_END_PAGE; }
00094 
00095 //******************************************************************************
00096 void Logging_SetStart(bool state) { startLoggingViaRpc = state; }
00097 
00098 //******************************************************************************
00099 bool Logging_GetStart(void) { return startLoggingViaRpc; }
00100 
00101 //******************************************************************************
00102 // for debugging... always say that usb is not connected... for easy bench
00103 // testing
00104 uint32_t Usb_IsConnected(void) { return 0; }