Skip to content

Commit

Permalink
Merge pull request #100 from Eclo/add-monitor-reboot-command
Browse files Browse the repository at this point in the history
Add Monitor_Reboot command
  • Loading branch information
cw2 authored Jan 31, 2017
2 parents 218b10b + 69734d2 commit 86ad17d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/CLR/WireProtocol/WireProtocol_MonitorCommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
19 changes: 19 additions & 0 deletions src/CLR/WireProtocol/WireProtocol_MonitorCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -37,12 +50,18 @@ 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)

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_
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
24 changes: 24 additions & 0 deletions targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// See LICENSE file in the project root for full license information.
//

#include <cmsis_os.h>

#include <WireProtocol.h>
#include <WireProtocol_MonitorCommands.h>

Expand Down Expand Up @@ -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;
}

0 comments on commit 86ad17d

Please sign in to comment.