Wilson Tang
/
HSP_RPC_GUI
Fork of the offical HSP_RPC_GUI firmware
Fork of MAXREFDES100 firmware for MAX32620HSP
HSP/LoggingService/Logging.cpp@4:18155622d30a, 2020-01-28 (annotated)
- Committer:
- wt8008
- Date:
- Tue Jan 28 20:22:16 2020 +0000
- Revision:
- 4:18155622d30a
- Parent:
- 1:9490836294ea
Update Maxim's USBDevice project to the latest version
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 "mbed.h" |
jbradshaw | 0:e4a10ed6eb92 | 34 | #include "RpcServer.h" |
jbradshaw | 0:e4a10ed6eb92 | 35 | #include "Logging.h" |
jbradshaw | 0:e4a10ed6eb92 | 36 | #include "S25FS512.h" |
jbradshaw | 0:e4a10ed6eb92 | 37 | #include "Peripherals.h" |
jbradshaw | 0:e4a10ed6eb92 | 38 | |
jbradshaw | 0:e4a10ed6eb92 | 39 | /// length of flash page as dictated by the device |
jbradshaw | 0:e4a10ed6eb92 | 40 | #define LENGTH_OF_FLASH_PAGE 256 // length of flash page in bytes |
jbradshaw | 0:e4a10ed6eb92 | 41 | /// size in bytes of the external flash device on the HSP platform |
jbradshaw | 1:9490836294ea | 42 | #define SIZE_OF_EXTERNAL_FLASH 0x2000000 // 33,554,432 Bytes |
jbradshaw | 0:e4a10ed6eb92 | 43 | /// start page of where the mission is defined |
jbradshaw | 0:e4a10ed6eb92 | 44 | #define MISSION_DEFINITION_START_PAGE 0x00 |
jbradshaw | 0:e4a10ed6eb92 | 45 | /// end page of the mission |
jbradshaw | 0:e4a10ed6eb92 | 46 | #define MISSION_DEFINITION_END_PAGE 0x0F |
jbradshaw | 0:e4a10ed6eb92 | 47 | /// page of where the logging data starts |
jbradshaw | 0:e4a10ed6eb92 | 48 | #define LOGGING_START_PAGE 0x12 |
jbradshaw | 0:e4a10ed6eb92 | 49 | /// the last logging page |
jbradshaw | 1:9490836294ea | 50 | #define LOGGING_END_PAGE ((SIZE_OF_EXTERNAL_FLASH / LENGTH_OF_FLASH_PAGE) - 1) |
jbradshaw | 0:e4a10ed6eb92 | 51 | |
jbradshaw | 0:e4a10ed6eb92 | 52 | /// static flag to know if logging was started via RPC |
jbradshaw | 0:e4a10ed6eb92 | 53 | static bool startLoggingViaRpc = false; |
jbradshaw | 0:e4a10ed6eb92 | 54 | |
jbradshaw | 0:e4a10ed6eb92 | 55 | /** |
jbradshaw | 0:e4a10ed6eb92 | 56 | * @brief This will read the mission location and if there is something valid, |
jbradshaw | 0:e4a10ed6eb92 | 57 | * then run the Logging_ProcessMissionCmds() |
jbradshaw | 0:e4a10ed6eb92 | 58 | * @param cmdBuffer buffer |
jbradshaw | 0:e4a10ed6eb92 | 59 | */ |
jbradshaw | 0:e4a10ed6eb92 | 60 | uint32_t Logging_IsMissionDefined(uint8_t *cmdBuffer) { |
jbradshaw | 0:e4a10ed6eb92 | 61 | uint32_t valid = 1; |
jbradshaw | 0:e4a10ed6eb92 | 62 | if ((cmdBuffer[0] == 0xFF) || (cmdBuffer[0] == 0x0)) |
jbradshaw | 0:e4a10ed6eb92 | 63 | valid = 0; |
jbradshaw | 0:e4a10ed6eb92 | 64 | return valid; |
jbradshaw | 0:e4a10ed6eb92 | 65 | } |
jbradshaw | 0:e4a10ed6eb92 | 66 | |
jbradshaw | 0:e4a10ed6eb92 | 67 | /** |
jbradshaw | 0:e4a10ed6eb92 | 68 | * @brief Read the mission from flash and place in buffer |
jbradshaw | 0:e4a10ed6eb92 | 69 | * @param buffer pointer to byte array that will contain the read results |
jbradshaw | 0:e4a10ed6eb92 | 70 | */ |
jbradshaw | 0:e4a10ed6eb92 | 71 | int8_t Logging_ReadMissionFromFlash(uint8_t *buffer) { |
jbradshaw | 0:e4a10ed6eb92 | 72 | return Peripherals::s25FS512()->readPages_Helper( |
jbradshaw | 0:e4a10ed6eb92 | 73 | MISSION_DEFINITION_START_PAGE, MISSION_DEFINITION_END_PAGE, buffer, 0); |
jbradshaw | 0:e4a10ed6eb92 | 74 | } |
jbradshaw | 0:e4a10ed6eb92 | 75 | |
jbradshaw | 0:e4a10ed6eb92 | 76 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 77 | // return the page where mission is defined, Mission specific |
jbradshaw | 0:e4a10ed6eb92 | 78 | uint32_t Logging_GetMissionStartPage(void) { |
jbradshaw | 0:e4a10ed6eb92 | 79 | return MISSION_DEFINITION_START_PAGE; |
jbradshaw | 0:e4a10ed6eb92 | 80 | } |
jbradshaw | 0:e4a10ed6eb92 | 81 | |
jbradshaw | 0:e4a10ed6eb92 | 82 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 83 | // return the page where the mission definition ends, Mission specific |
jbradshaw | 0:e4a10ed6eb92 | 84 | uint32_t Logging_GetMissionEndPage(void) { return MISSION_DEFINITION_END_PAGE; } |
jbradshaw | 0:e4a10ed6eb92 | 85 | |
jbradshaw | 0:e4a10ed6eb92 | 86 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 87 | // Returns the location where the Writing can start from, for data logging... |
jbradshaw | 0:e4a10ed6eb92 | 88 | uint32_t Logging_GetLoggingStartPage(void) { return LOGGING_START_PAGE; } |
jbradshaw | 0:e4a10ed6eb92 | 89 | |
jbradshaw | 0:e4a10ed6eb92 | 90 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 91 | // Returns the end location available where the Flash ends essentially.... for |
jbradshaw | 0:e4a10ed6eb92 | 92 | // data logging. |
jbradshaw | 0:e4a10ed6eb92 | 93 | uint32_t Logging_GetLoggingEndPage(void) { return LOGGING_END_PAGE; } |
jbradshaw | 0:e4a10ed6eb92 | 94 | |
jbradshaw | 0:e4a10ed6eb92 | 95 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 96 | void Logging_SetStart(bool state) { startLoggingViaRpc = state; } |
jbradshaw | 0:e4a10ed6eb92 | 97 | |
jbradshaw | 0:e4a10ed6eb92 | 98 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 99 | bool Logging_GetStart(void) { return startLoggingViaRpc; } |
jbradshaw | 0:e4a10ed6eb92 | 100 | |
jbradshaw | 0:e4a10ed6eb92 | 101 | //****************************************************************************** |
jbradshaw | 0:e4a10ed6eb92 | 102 | // for debugging... always say that usb is not connected... for easy bench |
jbradshaw | 0:e4a10ed6eb92 | 103 | // testing |
jbradshaw | 0:e4a10ed6eb92 | 104 | uint32_t Usb_IsConnected(void) { return 0; } |