Detect the OpenBLT XCP-CONNECT and reset (jump to bootloader)
This allows for firmware updates without power cycling
This commit is contained in:
parent
60499f4ebf
commit
dfb3294ac8
|
@ -5,6 +5,8 @@
|
|||
#include <libcommon/utils.h>
|
||||
#include <libcommon/microvty.h>
|
||||
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
|
||||
/* microVTY - small implementation of a limited feature command line interface
|
||||
* (C) 2019 by Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
|
@ -88,9 +90,30 @@ void microvty_print_prompt(void)
|
|||
printf(g_cmds.prompt);
|
||||
}
|
||||
|
||||
#define HIST_MOD(x) ((x) % 3)
|
||||
/* detect the "matic" "\x02\xff\x00 XCP-CONNECT sequence OpenBLT uses */
|
||||
static bool detect_xcp_connect(int c)
|
||||
{
|
||||
static char history[3];
|
||||
static uint8_t hist_idx;
|
||||
|
||||
hist_idx = HIST_MOD(hist_idx + 1);
|
||||
history[hist_idx] = c;
|
||||
|
||||
if (history[hist_idx] == 0 &&
|
||||
history[HIST_MOD(hist_idx+1)] == 0x02 &&
|
||||
history[HIST_MOD(hist_idx+2)] == 0xff)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool microvty_process_char(int c)
|
||||
{
|
||||
/* if the bootloader entry sequence is detected, reset the system */
|
||||
if (detect_xcp_connect(c))
|
||||
scb_reset_system();
|
||||
|
||||
if (c == '\r' || c == '\n' || g_cmds.buf_idx >= sizeof(g_cmds.buf)-1) {
|
||||
/* skip empty commands */
|
||||
if (g_cmds.buf_idx == 0) {
|
||||
|
|
Loading…
Reference in New Issue