publishing

Dependencies:   USBDevice

Committer:
elouis
Date:
Wed Mar 22 19:42:57 2017 +0000
Revision:
8:9eff4634d9dd
Parent:
0:fd5a76956754
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
asilva14 0:fd5a76956754 1 /*******************************************************************************
asilva14 0:fd5a76956754 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
asilva14 0:fd5a76956754 3 *
asilva14 0:fd5a76956754 4 * Permission is hereby granted, free of charge, to any person obtaining a
asilva14 0:fd5a76956754 5 * copy of this software and associated documentation files (the "Software"),
asilva14 0:fd5a76956754 6 * to deal in the Software without restriction, including without limitation
asilva14 0:fd5a76956754 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
asilva14 0:fd5a76956754 8 * and/or sell copies of the Software, and to permit persons to whom the
asilva14 0:fd5a76956754 9 * Software is furnished to do so, subject to the following conditions:
asilva14 0:fd5a76956754 10 *
asilva14 0:fd5a76956754 11 * The above copyright notice and this permission notice shall be included
asilva14 0:fd5a76956754 12 * in all copies or substantial portions of the Software.
asilva14 0:fd5a76956754 13 *
asilva14 0:fd5a76956754 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
asilva14 0:fd5a76956754 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
asilva14 0:fd5a76956754 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
asilva14 0:fd5a76956754 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
asilva14 0:fd5a76956754 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
asilva14 0:fd5a76956754 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
asilva14 0:fd5a76956754 20 * OTHER DEALINGS IN THE SOFTWARE.
asilva14 0:fd5a76956754 21 *
asilva14 0:fd5a76956754 22 * Except as contained in this notice, the name of Maxim Integrated
asilva14 0:fd5a76956754 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
asilva14 0:fd5a76956754 24 * Products, Inc. Branding Policy.
asilva14 0:fd5a76956754 25 *
asilva14 0:fd5a76956754 26 * The mere transfer of this software does not imply any licenses
asilva14 0:fd5a76956754 27 * of trade secrets, proprietary technology, copyrights, patents,
asilva14 0:fd5a76956754 28 * trademarks, maskwork rights, or any other form of intellectual
asilva14 0:fd5a76956754 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
asilva14 0:fd5a76956754 30 * ownership rights.
asilva14 0:fd5a76956754 31 *******************************************************************************
asilva14 0:fd5a76956754 32 */
asilva14 0:fd5a76956754 33 #include "mbed.h"
asilva14 0:fd5a76956754 34 #include "RpcServer.h"
asilva14 0:fd5a76956754 35 #include "Logging.h"
asilva14 0:fd5a76956754 36 #include "S25FS512.h"
asilva14 0:fd5a76956754 37 #include "Peripherals.h"
asilva14 0:fd5a76956754 38
asilva14 0:fd5a76956754 39 /// length of flash page as dictated by the device
asilva14 0:fd5a76956754 40 #define LENGTH_OF_FLASH_PAGE 256 // length of flash page in bytes
asilva14 0:fd5a76956754 41 /// size in bytes of the external flash device on the HSP platform
asilva14 0:fd5a76956754 42 #define SIZE_OF_EXTERNAL_FLASH \
asilva14 0:fd5a76956754 43 (16777216 / 2) // length of external flash in bytes
asilva14 0:fd5a76956754 44 /// start page of where the mission is defined
asilva14 0:fd5a76956754 45 #define MISSION_DEFINITION_START_PAGE 0x00
asilva14 0:fd5a76956754 46 /// end page of the mission
asilva14 0:fd5a76956754 47 #define MISSION_DEFINITION_END_PAGE 0x0F
asilva14 0:fd5a76956754 48 /// page of where the logging data starts
asilva14 0:fd5a76956754 49 #define LOGGING_START_PAGE 0x12
asilva14 0:fd5a76956754 50 /// the last logging page
asilva14 0:fd5a76956754 51 #define LOGGING_END_PAGE (SIZE_OF_EXTERNAL_FLASH / LENGTH_OF_FLASH_PAGE)
asilva14 0:fd5a76956754 52
asilva14 0:fd5a76956754 53 /// static flag to know if logging was started via RPC
asilva14 0:fd5a76956754 54 static bool startLoggingViaRpc = false;
asilva14 0:fd5a76956754 55
asilva14 0:fd5a76956754 56 /**
asilva14 0:fd5a76956754 57 * @brief This will read the mission location and if there is something valid,
asilva14 0:fd5a76956754 58 * then run the Logging_ProcessMissionCmds()
asilva14 0:fd5a76956754 59 * @param cmdBuffer buffer
asilva14 0:fd5a76956754 60 */
asilva14 0:fd5a76956754 61 uint32_t Logging_IsMissionDefined(uint8_t *cmdBuffer) {
asilva14 0:fd5a76956754 62 uint32_t valid = 1;
asilva14 0:fd5a76956754 63 if ((cmdBuffer[0] == 0xFF) || (cmdBuffer[0] == 0x0))
asilva14 0:fd5a76956754 64 valid = 0;
asilva14 0:fd5a76956754 65 return valid;
asilva14 0:fd5a76956754 66 }
asilva14 0:fd5a76956754 67
asilva14 0:fd5a76956754 68 /**
asilva14 0:fd5a76956754 69 * @brief Read the mission from flash and place in buffer
asilva14 0:fd5a76956754 70 * @param buffer pointer to byte array that will contain the read results
asilva14 0:fd5a76956754 71 */
asilva14 0:fd5a76956754 72 int8_t Logging_ReadMissionFromFlash(uint8_t *buffer) {
asilva14 0:fd5a76956754 73 return Peripherals::s25FS512()->readPages_Helper(
asilva14 0:fd5a76956754 74 MISSION_DEFINITION_START_PAGE, MISSION_DEFINITION_END_PAGE, buffer, 0);
asilva14 0:fd5a76956754 75 }
asilva14 0:fd5a76956754 76
asilva14 0:fd5a76956754 77 //******************************************************************************
asilva14 0:fd5a76956754 78 // return the page where mission is defined, Mission specific
asilva14 0:fd5a76956754 79 uint32_t Logging_GetMissionStartPage(void) {
asilva14 0:fd5a76956754 80 return MISSION_DEFINITION_START_PAGE;
asilva14 0:fd5a76956754 81 }
asilva14 0:fd5a76956754 82
asilva14 0:fd5a76956754 83 //******************************************************************************
asilva14 0:fd5a76956754 84 // return the page where the mission definition ends, Mission specific
asilva14 0:fd5a76956754 85 uint32_t Logging_GetMissionEndPage(void) { return MISSION_DEFINITION_END_PAGE; }
asilva14 0:fd5a76956754 86
asilva14 0:fd5a76956754 87 //******************************************************************************
asilva14 0:fd5a76956754 88 // Returns the location where the Writing can start from, for data logging...
asilva14 0:fd5a76956754 89 uint32_t Logging_GetLoggingStartPage(void) { return LOGGING_START_PAGE; }
asilva14 0:fd5a76956754 90
asilva14 0:fd5a76956754 91 //******************************************************************************
asilva14 0:fd5a76956754 92 // Returns the end location available where the Flash ends essentially.... for
asilva14 0:fd5a76956754 93 // data logging.
asilva14 0:fd5a76956754 94 uint32_t Logging_GetLoggingEndPage(void) { return LOGGING_END_PAGE; }
asilva14 0:fd5a76956754 95
asilva14 0:fd5a76956754 96 //******************************************************************************
asilva14 0:fd5a76956754 97 void Logging_SetStart(bool state) { startLoggingViaRpc = state; }
asilva14 0:fd5a76956754 98
asilva14 0:fd5a76956754 99 //******************************************************************************
asilva14 0:fd5a76956754 100 bool Logging_GetStart(void) { return startLoggingViaRpc; }
asilva14 0:fd5a76956754 101
asilva14 0:fd5a76956754 102 //******************************************************************************
asilva14 0:fd5a76956754 103 // for debugging... always say that usb is not connected... for easy bench
asilva14 0:fd5a76956754 104 // testing
asilva14 0:fd5a76956754 105 uint32_t Usb_IsConnected(void) { return 0; }