Issue #18: Check error memory entries at safety ram init
This commit is contained in:
		@@ -28,6 +28,11 @@
 | 
			
		||||
 */
 | 
			
		||||
#define SAFETY_MEMORY_MAGIC 0x12AA5CB7
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Error memory NOP entry
 | 
			
		||||
 */
 | 
			
		||||
#define SAFETY_MEMORY_NOP_ENTRY 0xC1AA1222
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Offset address for the safety_memory_header.
 | 
			
		||||
 * @note Any other value than 0UL doesn't really make sense. Therfore, this should not be changed.
 | 
			
		||||
 
 | 
			
		||||
@@ -154,14 +154,12 @@ static inline void setup_system(void)
 | 
			
		||||
	setup_nvic_priorities();
 | 
			
		||||
	systick_setup();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	oven_driver_init();
 | 
			
		||||
	digio_setup_default_all();
 | 
			
		||||
	led_setup();
 | 
			
		||||
	loudspeaker_setup();
 | 
			
		||||
	reflow_menu_init();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	uart_gpio_config();
 | 
			
		||||
	setup_shell_uart(&shell_uart);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -239,6 +239,35 @@ int safety_memory_set_boot_status(const struct safety_memory_boot_status *status
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int safety_memory_check_error_entries()
 | 
			
		||||
{
 | 
			
		||||
	struct safety_memory_header header;
 | 
			
		||||
	uint32_t addr;
 | 
			
		||||
	uint32_t data;
 | 
			
		||||
	int ret = 0;
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
 | 
			
		||||
		return -2000;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for (addr = header.err_memory_offset; addr < header.err_memory_end; addr++) {
 | 
			
		||||
		res = backup_ram_get_data(addr, &data, 1UL);
 | 
			
		||||
		if (res)
 | 
			
		||||
			return -100;
 | 
			
		||||
 | 
			
		||||
		/* Valid flag entry */
 | 
			
		||||
		if ((data & 0xFF) == 0x51)
 | 
			
		||||
			continue;
 | 
			
		||||
		if (data == SAFETY_MEMORY_NOP_ENTRY)
 | 
			
		||||
			continue;
 | 
			
		||||
 | 
			
		||||
		ret--;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int safety_memory_get_error_entry_count(uint32_t *count);
 | 
			
		||||
 | 
			
		||||
int safety_memory_check(void)
 | 
			
		||||
@@ -246,6 +275,10 @@ int safety_memory_check(void)
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	res = safety_memory_check_crc();
 | 
			
		||||
	if (!res) {
 | 
			
		||||
		res |= safety_memory_check_error_entries();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return -!!res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user