Implement saftey memory dump feature and increase heap space

This commit is contained in:
Mario Hüttel 2020-11-01 20:43:59 +01:00
parent 10596cdbf0
commit 7aa0b62012
7 changed files with 121 additions and 2 deletions

View File

@ -54,6 +54,8 @@ INCLUDEPATH += -Iconfig-parser/include
CFILES += base64-lib/src/base64-lib.c
INCLUDEPATH += -Ibase64-lib/include
DEFINES += -DBASE64_LOOKUP_TABLE_SECTION="\".ccm.bss\""
DEBUG_DEFINES = -DDEBUGBUILD
RELEASE_DEFINES =

View File

@ -22,6 +22,7 @@
#define __SAFETY_MEMORY_H__
#include <stdint.h>
#include <stddef.h>
/** @addtogroup safety-memory
* @{
@ -245,6 +246,15 @@ int safety_memory_get_config_override_count(uint32_t *count);
*/
int safety_memory_get_config_override(uint32_t idx, struct config_override *config_override);
/**
* @brief Get a base64 dump of the whole safety memory.
* @param[out] buffer Buffer to write the base 64 dump into.
* @param buffsize Size of buffer. Must be large enough to hold the data plus a '\0' terminator
* @param[out] used_size Number of written bytes including the '\0' terminator. May be NULL.
* @return 0 if successful
*/
int safety_memory_dump_base64(char *buffer, size_t buffsize, size_t *used_size);
#endif /* __SAFETY_MEMORY_H__ */
/** @} */

View File

@ -55,3 +55,5 @@ int backup_ram_get_data(uint32_t addr, uint32_t *data, uint32_t count);
int backup_ram_write_data(uint32_t addr, const uint32_t *data, uint32_t count);
uint32_t backup_ram_get_size_in_words(void);
volatile void *backup_ram_get_base_ptr(void);

View File

@ -22,6 +22,7 @@
#include <helper-macros/helper-macros.h>
#include <stm-periph/crc-unit.h>
#include <stm-periph/backup-ram.h>
#include <base64-lib/base64-lib.h>
static int word_to_error_memory_entry(uint32_t entry_data, struct error_memory_entry *out)
{
@ -481,3 +482,29 @@ int safety_memory_insert_config_override(struct config_override *config_override
int safety_memory_get_config_override_count(uint32_t *count);
int safety_memory_get_config_override(uint32_t idx, struct config_override *config_override);
int safety_memory_dump_base64(char *buffer, size_t buffsize, size_t *used_size)
{
uint32_t safety_mem_size;
size_t output_size;
const char *backup_mem_ptr;
int res;
if (!buffer)
return -1000;
safety_mem_size = backup_ram_get_size_in_words() * 4U;
output_size = base64_calculate_encoded_size(safety_mem_size);
if (output_size + 1 > buffsize)
return -1001;
backup_mem_ptr = (const char *)backup_ram_get_base_ptr();
res = base64_encode(backup_mem_ptr, buffer, safety_mem_size, buffsize, &output_size);
if (res)
return -1;
buffer[output_size] = '\0';
if (used_size)
*used_size = output_size + 1u;
return 0;
}

View File

@ -39,6 +39,7 @@
#include <reflow-controller/settings/settings.h>
#include <reflow-controller/button.h>
#include <reflow-controller/safety/fault.h>
#include <reflow-controller/safety/safety-memory.h>
#ifndef GIT_VER
#define GIT_VER "VERSION NOT SET"
@ -546,6 +547,70 @@ static shellmatta_retCode_t shell_cmd_panic(const shellmatta_handle_t handle, co
return SHELLMATTA_OK;
}
static char *get_safety_mem_dump(size_t *used_bytes)
{
char *buffer;
int res;
buffer = (char *)malloc(5470);
res = safety_memory_dump_base64(buffer, 5470UL, used_bytes);
if (res) {
if (buffer)
free(buffer);
buffer = NULL;
}
return buffer;
}
static shellmatta_retCode_t shell_cmd_dump_safety_mem(const shellmatta_handle_t handle, const char *arguments,
uint32_t length)
{
(void)arguments;
(void)length;
static char *buffer;
static const char *ptr;
size_t used_bytes;
static size_t full_lines = 0;
static size_t current_line;
size_t remainder;
static const char *hline = "----------------------------------------------------------------";
if (full_lines == 0) {
shellmatta_printf(handle, "Safety memory content\r\n%s\r\n", hline);
buffer = get_safety_mem_dump(&used_bytes);
if (!buffer) {
shellmatta_printf(handle, "Error dumping memory!\r\n");
return SHELLMATTA_OK;
}
full_lines = (used_bytes - 1) / 64;
remainder = (used_bytes - 1) % 64;
if (remainder)
full_lines++;
ptr = buffer;
current_line = 0;
return SHELLMATTA_BUSY;
} else {
if (current_line < full_lines) {
shellmatta_printf(handle, "%.64s\r\n", ptr);
ptr += 64;
current_line++;
} else {
shellmatta_printf(handle, "%s\r\n", hline);
full_lines = 0;
if (buffer)
free(buffer);
buffer = NULL;
return SHELLMATTA_OK;
}
}
return SHELLMATTA_BUSY;
}
//typedef struct shellmatta_cmd
//{
// char *cmd; /**< command name */
@ -555,7 +620,7 @@ static shellmatta_retCode_t shell_cmd_panic(const shellmatta_handle_t handle, co
// 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[17] = {
static shellmatta_cmd_t cmd[18] = {
{
.cmd = "version",
.cmdAlias = "ver",
@ -690,6 +755,14 @@ static shellmatta_cmd_t cmd[17] = {
.helpText = "Panic Mode!",
.usageText = "",
.cmdFct = shell_cmd_panic,
.next = &cmd[17],
},
{
.cmd = "safety-mem-dump",
.cmdAlias = NULL,
.helpText = "",
.usageText = "",
.cmdFct = shell_cmd_dump_safety_mem,
.next = NULL,
},
};

View File

@ -107,3 +107,8 @@ uint32_t backup_ram_get_size_in_words(void)
{
return (uint32_t)BACKUP_RAM_SIZE_WORDS;
}
volatile void *backup_ram_get_base_ptr(void)
{
return backup_ram;
}

View File

@ -24,7 +24,7 @@
/* USER PARAMETERS */
__ld_stack_size = 0x3000;
__ld_heap_size = 0x2100;
__ld_heap_size = 0x4200;
__stack_corruption_area_size = 128;
/* END OF USER PARAMETERS */