From 69734d2e9c22d923860e3c0348da25440fd66e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 31 Jan 2017 14:25:32 +0000 Subject: [PATCH] Add Monitor_Reboot command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - this is for ChibiOS reference implementation (nanoBooter only) Signed-off-by: José Simões --- .../WireProtocol_MonitorCommands.c | 7 ++++++ .../WireProtocol_MonitorCommands.h | 19 +++++++++++++++ .../nanoBooter/WireProtocol_App_Interface.c | 2 +- .../nanoBooter/WireProtocol_MonitorCommands.c | 24 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c index 32faca7775..7fc838be28 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c @@ -27,3 +27,10 @@ __attribute__((weak)) bool Monitor_WriteMemory(WP_Message* message) // default to false return false; } + +// provided as weak to be replaced by actual implementation by application +__attribute__((weak)) bool Monitor_Reboot(WP_Message* message) +{ + // default to false + return false; +} diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.h b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.h index 8d7871b027..70c2687eeb 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.h +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.h @@ -10,6 +10,19 @@ #include "WireProtocol.h" #include "WireProtocol_Message.h" +////////////////////////////////////////// +// enums + +// structure for Monitor Reboot options +// backwards compatible with .NETMF +typedef enum Monitor_Reboot_Options +{ + Monitor_Reboot_c_NormalReboot = 0, + Monitor_Reboot_c_EnterBootloader = 1, + Monitor_Reboot_c_ClrRebootOnly = 2, + Monitor_Reboot_c_ClrStopDebugger = 4 +}Monitor_Reboot_Options; + ////////////////////////////////////////// // typedefs @@ -37,6 +50,11 @@ typedef struct CLR_DBG_Commands_Monitor_WriteMemory }CLR_DBG_Commands_Monitor_WriteMemory; +typedef struct Monitor_Reboot_Command +{ + uint32_t m_flags; + +}Monitor_Reboot_Command; ////////////////////////////////////////// // function declarations (commands) @@ -44,5 +62,6 @@ typedef struct CLR_DBG_Commands_Monitor_WriteMemory bool Monitor_Ping(WP_Message* message); bool Monitor_OemInfo(WP_Message* message); bool Monitor_WriteMemory(WP_Message* message); +bool Monitor_Reboot(WP_Message* message); #endif //_WIREPROTOCOL_COMMANDS_H_ diff --git a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c index 08d4783420..06666bb3f6 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c +++ b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_App_Interface.c @@ -17,7 +17,7 @@ static const CommandHandlerLookup c_Lookup_Request[] = /*******************************************************************************************************************************************************************/ #define DEFINE_CMD(cmd) { CLR_DBG_Commands_c_Monitor_##cmd, &Monitor_##cmd } DEFINE_CMD(Ping ), - // DEFINE_CMD(Reboot ), + DEFINE_CMD(Reboot ), // // // DEFINE_CMD(ReadMemory ), DEFINE_CMD(WriteMemory), diff --git a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c index 2c43addb41..b13ad5a692 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c +++ b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c @@ -4,6 +4,8 @@ // See LICENSE file in the project root for full license information. // +#include + #include #include @@ -88,3 +90,25 @@ bool Monitor_WriteMemory(WP_Message* message) return ret; } + +bool Monitor_Reboot(WP_Message* message) +{ + Monitor_Reboot_Command* cmd = (Monitor_Reboot_Command*)message->m_payload; + + ReplyToCommand(message, true, false, NULL, 0); + + if(cmd != NULL) + { + // only reset if we are not trying to get into the bootloader + if((cmd->m_flags & Monitor_Reboot_c_EnterBootloader) != Monitor_Reboot_c_EnterBootloader) + { + // UNDONE: FIXME: Events_WaitForEvents( 0, 100 ); + + // RESET CPU + // because ChibiOS relies on CMSIS it's recommended to make use of the CMSIS API + NVIC_SystemReset(); + } + } + + return true; +}