Separate flash CRC checker from safety controller and implement shell command to calculate CRCs
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include <stm-periph/option-bytes.h>
|
||||
#include <reflow-controller/ui/gui.h>
|
||||
#include <reflow-controller/ui/shell-uart.h>
|
||||
#include <reflow-controller/safety/flash-crc.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1020,6 +1021,53 @@ shellmatta_retCode_t shell_cmd_set_baud(const shellmatta_handle_t handle, const
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
static void shell_print_crc_line(const shellmatta_handle_t handle, const char *name,
|
||||
uint32_t crc, uint32_t crc_expected)
|
||||
{
|
||||
shellmatta_printf(handle, "%-15s0x%08x 0x%08x [%s]\r\n",
|
||||
name,
|
||||
crc,
|
||||
crc_expected,
|
||||
crc != crc_expected ? "\e[1;31mERR\e[m" : "\e[32mOK\e[m");
|
||||
}
|
||||
|
||||
shellmatta_retCode_t shell_cmd_flash_crc(const shellmatta_handle_t handle, const char *args, uint32_t len)
|
||||
{
|
||||
(void)args;
|
||||
(void)len;
|
||||
uint32_t crc = 0;
|
||||
uint32_t crc_expected = 0;
|
||||
int res;
|
||||
|
||||
shellmatta_printf(handle, " Calculated Expected State\r\n\r\n");
|
||||
|
||||
res = flash_crc_calc_section(FLASH_CRC_VECTOR, &crc);
|
||||
crc_expected = flash_crc_get_expected_crc(FLASH_CRC_VECTOR);
|
||||
if (res)
|
||||
shellmatta_printf(handle, "Error during calculation!\r\n");
|
||||
shell_print_crc_line(handle, "Vector CRC:", crc, crc_expected);
|
||||
|
||||
res = flash_crc_calc_section(FLASH_CRC_TEXT, &crc);
|
||||
crc_expected = flash_crc_get_expected_crc(FLASH_CRC_TEXT);
|
||||
if (res)
|
||||
shellmatta_printf(handle, "Error during calculation!\r\n");
|
||||
shell_print_crc_line(handle, "Code CRC:", crc, crc_expected);
|
||||
|
||||
res = flash_crc_calc_section(FLASH_CRC_DATA, &crc);
|
||||
crc_expected = flash_crc_get_expected_crc(FLASH_CRC_DATA);
|
||||
if (res)
|
||||
shellmatta_printf(handle, "Error during calculation!\r\n");
|
||||
shell_print_crc_line(handle, "Data CRC:", crc, crc_expected);
|
||||
|
||||
res = flash_crc_calc_section(FLASH_CRC_CCMDATA, &crc);
|
||||
crc_expected = flash_crc_get_expected_crc(FLASH_CRC_CCMDATA);
|
||||
if (res)
|
||||
shellmatta_printf(handle, "Error during calculation!\r\n");
|
||||
shell_print_crc_line(handle, "CCM Data CRC:", crc, crc_expected);
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
//typedef struct shellmatta_cmd
|
||||
//{
|
||||
// char *cmd; /**< command name */
|
||||
@@ -1029,7 +1077,7 @@ shellmatta_retCode_t shell_cmd_set_baud(const shellmatta_handle_t handle, const
|
||||
// shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
|
||||
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
||||
//} shellmatta_cmd_t;
|
||||
static shellmatta_cmd_t cmd[25] = {
|
||||
static shellmatta_cmd_t cmd[26] = {
|
||||
{
|
||||
.cmd = "version",
|
||||
.cmdAlias = "ver",
|
||||
@@ -1229,6 +1277,14 @@ static shellmatta_cmd_t cmd[25] = {
|
||||
.helpText = "Set a new temporary baudrate for the UART",
|
||||
.usageText = "baudrate <new baud>",
|
||||
.cmdFct = shell_cmd_set_baud,
|
||||
.next = &cmd[25],
|
||||
},
|
||||
{
|
||||
.cmd = "flashcrc",
|
||||
.cmdAlias = "fcrc",
|
||||
.helpText = "Calculate the Flash CRCs",
|
||||
.usageText = "flashcrc",
|
||||
.cmdFct = shell_cmd_flash_crc,
|
||||
.next = NULL,
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user