Issue #18: Implement writing and reading boot status structure from backup RAM
This commit is contained in:
parent
7434554319
commit
3df0631ffc
@ -52,6 +52,7 @@ struct safety_memory_header {
|
||||
struct safety_memory_boot_status {
|
||||
uint32_t reboot_to_bootloader;
|
||||
uint32_t code_updated;
|
||||
uint32_t reset_from_panic;
|
||||
};
|
||||
|
||||
enum safety_memory_state {
|
||||
@ -67,7 +68,7 @@ enum safety_memory_error_entry_type {
|
||||
|
||||
struct error_memory_entry {
|
||||
enum safety_memory_error_entry_type type;
|
||||
uint16_t flag_num;
|
||||
uint8_t flag_num;
|
||||
};
|
||||
|
||||
enum config_override_entry_type {
|
||||
@ -79,11 +80,11 @@ struct config_override {
|
||||
enum config_override_entry_type type;
|
||||
union {
|
||||
struct {
|
||||
uint16_t flag;
|
||||
uint8_t flag;
|
||||
uint8_t weight;
|
||||
} weight_override;
|
||||
struct {
|
||||
uint16_t flag;
|
||||
uint8_t flag;
|
||||
uint8_t persistance;
|
||||
} persistance_override;
|
||||
} entry;
|
||||
@ -95,6 +96,8 @@ int safety_memory_reinit(enum safety_memory_state *found_state);
|
||||
|
||||
int safety_memory_get_boot_status(struct safety_memory_boot_status *status);
|
||||
|
||||
int safety_memory_set_boot_status(const struct safety_memory_boot_status *status);
|
||||
|
||||
int safety_memory_get_error_entry_count(uint32_t *count);
|
||||
|
||||
int safety_memory_check(void);
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include <reflow-controller/oven-driver.h>
|
||||
#include <reflow-controller/digio.h>
|
||||
#include <reflow-controller/safety/fault.h>
|
||||
#include <reflow-controller/safety/safety-memory.h>
|
||||
#include <helper-macros/helper-macros.h>
|
||||
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
@ -36,6 +38,8 @@ void HardFault_Handler(void)
|
||||
|
||||
void panic_mode(void)
|
||||
{
|
||||
static struct safety_memory_boot_status IN_SECTION(.ccm.bss) boot_status;
|
||||
|
||||
/* Panic mode is esentially the same as a hardfault,
|
||||
* but it can be expected, that more functionality is still usable
|
||||
*/
|
||||
@ -44,6 +48,11 @@ void panic_mode(void)
|
||||
oven_driver_apply_power_level();
|
||||
|
||||
/* TODO: implement panic mode */
|
||||
if (!safety_memory_get_boot_status(&boot_status)) {
|
||||
boot_status.reset_from_panic = 0xFFFFFFFF;
|
||||
(void)safety_memory_set_boot_status(&boot_status);
|
||||
}
|
||||
|
||||
|
||||
while (1);
|
||||
}
|
||||
|
@ -195,7 +195,49 @@ int safety_memory_init(enum safety_memory_state *found_state)
|
||||
return safety_memory_reinit(found_state);
|
||||
}
|
||||
|
||||
int safety_memory_get_boot_status(struct safety_memory_boot_status *status);
|
||||
int safety_memory_get_boot_status(struct safety_memory_boot_status *status)
|
||||
{
|
||||
struct safety_memory_header header;
|
||||
int res;
|
||||
|
||||
if (!status)
|
||||
return -1001;
|
||||
|
||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
||||
return -2000;
|
||||
}
|
||||
|
||||
if (safety_memory_check_crc())
|
||||
return -2001;
|
||||
|
||||
res = backup_ram_get_data(header.boot_status_offset, (uint32_t *)status, wordsize_of(*status));
|
||||
if (res)
|
||||
return -3000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safety_memory_set_boot_status(const struct safety_memory_boot_status *status)
|
||||
{
|
||||
struct safety_memory_header header;
|
||||
int res;
|
||||
|
||||
if (!status)
|
||||
return -1001;
|
||||
|
||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
||||
return -2000;
|
||||
}
|
||||
|
||||
if (safety_memory_check_crc())
|
||||
return -2001;
|
||||
|
||||
res = backup_ram_write_data(header.boot_status_offset, (uint32_t *)status, wordsize_of(*status));
|
||||
res |= safety_memory_gen_crc();
|
||||
if (res)
|
||||
return -3000;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int safety_memory_get_error_entry_count(uint32_t *count);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user