From ab3d148449a89e285d313b2be9b95b69921548b8 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Tue, 22 Mar 2022 15:10:52 +0100 Subject: [PATCH] Implemented activation of external flash backup and restore via menu entries --- meson.build | 9 +++-- openrtx/include/core/state.h | 1 + openrtx/include/core/xmodem.h | 1 + openrtx/src/core/state.c | 1 + openrtx/src/core/threads.c | 12 +++++++ openrtx/src/core/xmodem.c | 2 +- openrtx/src/ui/ui_menu.c | 55 +++++++++++++++++++++++----- tests/platform/xmodem_flash_dump.c | 57 ------------------------------ 8 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 tests/platform/xmodem_flash_dump.c diff --git a/meson.build b/meson.build index 9343c478..482e3498 100644 --- a/meson.build +++ b/meson.build @@ -31,7 +31,6 @@ openrtx_src = ['openrtx/src/core/state.c', 'openrtx/src/core/dsp.cpp', 'openrtx/src/core/cps.c', 'openrtx/src/core/crc.c', - 'openrtx/src/core/xmodem.c', 'openrtx/src/core/memory_profiling.cpp', 'openrtx/src/ui/ui.c', 'openrtx/src/ui/ui_main.c', @@ -124,7 +123,9 @@ def = def + {'GIT_VERSION': git_version} ## TYT MDx family ## -mdx_src = ['platform/drivers/ADC/ADC1_MDx.c', +mdx_src = ['openrtx/src/core/xmodem.c', + 'openrtx/src/core/backup.c', + 'platform/drivers/ADC/ADC1_MDx.c', 'platform/drivers/GPS/GPS_MDx.cpp', 'platform/drivers/NVM/W25Qx.c', 'platform/drivers/NVM/nvmem_settings_MDx.c', @@ -140,7 +141,9 @@ mdx_src = ['platform/drivers/ADC/ADC1_MDx.c', ## GDx family: Radioddity GD-77 and Baofeng DM-1801 ## -gdx_src = ['platform/drivers/NVM/W25Qx.c', +gdx_src = ['openrtx/src/core/xmodem.c', + 'openrtx/src/core/backup.c', + 'platform/drivers/NVM/W25Qx.c', 'platform/drivers/NVM/AT24Cx_GDx.c', 'platform/drivers/NVM/spiFlash_GDx.c', 'platform/drivers/NVM/nvmem_GDx.c', diff --git a/openrtx/include/core/state.h b/openrtx/include/core/state.h index 32162d99..c61a6b05 100644 --- a/openrtx/include/core/state.h +++ b/openrtx/include/core/state.h @@ -97,6 +97,7 @@ typedef struct bool zone_enabled; zone_t zone; uint8_t rtxStatus; + bool rtxShutdown; bool emergency; settings_t settings; diff --git a/openrtx/include/core/xmodem.h b/openrtx/include/core/xmodem.h index 0ab6609e..8f77270d 100644 --- a/openrtx/include/core/xmodem.h +++ b/openrtx/include/core/xmodem.h @@ -21,6 +21,7 @@ #ifndef XMODEM_H #define XMODEM_H +#include #include #include diff --git a/openrtx/src/core/state.c b/openrtx/src/core/state.c index 4c19bcc6..59b9da67 100644 --- a/openrtx/src/core/state.c +++ b/openrtx/src/core/state.c @@ -75,6 +75,7 @@ void state_init() state.channel_index = 1; // Set default channel index (it is 1-based) state.zone_enabled = false; state.rtxStatus = RTX_OFF; + state.rtxShutdown = false; state.emergency = false; // Force brightness field to be in range 0 - 100 diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index dac954e4..9cc9057d 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -251,7 +252,18 @@ void *rtx_task(void *arg) while(1) { rtx_taskFunc(); + + // TODO: implement a cleaner shutdown procedure + if(state.rtxShutdown == true) + { + radio_disableRtx(); + platform_ledOff(RED); + platform_ledOff(GREEN); + break; + } } + + return NULL; } #if defined(HAS_GPS) && !defined(MD3x0_ENABLE_DBG) diff --git a/openrtx/src/core/xmodem.c b/openrtx/src/core/xmodem.c index c2fdbcb4..8627f12a 100644 --- a/openrtx/src/core/xmodem.c +++ b/openrtx/src/core/xmodem.c @@ -118,7 +118,7 @@ size_t xmodem_receivePacket(void* data, uint8_t expectedBlockNum) return blockSize; } -ssize_t xmodem_sendData(size_t size, ssize_t (*callback)(uint8_t *, size_t)) +ssize_t xmodem_sendData(size_t size, int (*callback)(uint8_t *, size_t)) { // Wait for the start command from the receiver, only CRC mode is supported. uint8_t cmd = 0; diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index d2d66775..9fa77ac5 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -443,30 +444,68 @@ void _ui_drawMenuBackupRestore(ui_state_t* ui_state) void _ui_drawMenuBackup(ui_state_t* ui_state) { + (void) ui_state; + gfx_clearScreen(); // Print "Flash Backup" on top bar gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, color_white, "Flash Backup"); // Print backup message - gfx_print(layout.line2_pos, layout.line2_font, TEXT_ALIGN_CENTER, + point_t line = layout.line2_pos; + gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, color_white, "Connect to RTXTool"); - gfx_print(layout.line3_pos, layout.line2_font, TEXT_ALIGN_CENTER, - color_white, "to backup flash."); - // TODO: Add call to xmodem send function + line.y += 18; + gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, + color_white, "to backup flash and"); + line.y += 18; + gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, + color_white, "press PTT to start."); + + // Shutdown RF stage + state.rtxShutdown = true; + + #ifndef PLATFORM_LINUX + if(platform_getPttStatus() == 1) + { + platform_ledOn(GREEN); + eflash_dump(); + platform_terminate(); + NVIC_SystemReset(); + } + #endif } void _ui_drawMenuRestore(ui_state_t* ui_state) { + (void) ui_state; + gfx_clearScreen(); // Print "Flash Backup" on top bar gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, color_white, "Flash Restore"); // Print backup message - gfx_print(layout.line2_pos, layout.line2_font, TEXT_ALIGN_CENTER, + point_t line = layout.line2_pos; + gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, color_white, "Connect to RTXTool"); - gfx_print(layout.line3_pos, layout.line2_font, TEXT_ALIGN_CENTER, - color_white, "to restore flash."); - // TODO: Add call to xmodem receive function + line.y += 18; + gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, + color_white, "to restore flash and"); + line.y += 18; + gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, + color_white, "press PTT to start."); + + // Shutdown RF stage + state.rtxShutdown = true; + + #ifndef PLATFORM_LINUX + if(platform_getPttStatus() == 1) + { + platform_ledOn(GREEN); + eflash_restore(); + platform_terminate(); + NVIC_SystemReset(); + } + #endif } void _ui_drawMenuInfo(ui_state_t* ui_state) diff --git a/tests/platform/xmodem_flash_dump.c b/tests/platform/xmodem_flash_dump.c deleted file mode 100644 index 1c78662f..00000000 --- a/tests/platform/xmodem_flash_dump.c +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2022 by Federico Amedeo Izzo IU2NUO, * - * Niccolò Izzo IU2KIN, * - * Frederik Saraci IU2NRO, * - * Silvano Seva IU2KWO * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include "W25Qx.h" - -static const size_t FLASH_SIZE = 16*1024*1024; /* 16MB */ -size_t addr = 0; - -int callback(uint8_t *ptr, size_t size) -{ - if((addr + size) > FLASH_SIZE) return -1; - W25Qx_readData(addr, ptr, size); - addr += size; - return 0; -} - - -int main() -{ - platform_init(); - W25Qx_init(); - W25Qx_wakeup(); - - xmodem_sendData(FLASH_SIZE, callback); - - while(1) - { - platform_ledOn(GREEN); - sleepFor(1,0); - platform_ledOff(GREEN); - sleepFor(1,0); - } - - return 0; -}