143 lines
4.2 KiB
C
143 lines
4.2 KiB
C
/* Reflow Oven Controller
|
|
*
|
|
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
*
|
|
* This file is part of the Reflow Oven Controller Project.
|
|
*
|
|
* The reflow oven controller is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with the reflow oven controller project.
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef __SAFETY_MEMORY_H__
|
|
#define __SAFETY_MEMORY_H__
|
|
|
|
#include <stdint.h>
|
|
|
|
/**
|
|
* @brief Magic number to signal a valid safety memory header.
|
|
*/
|
|
#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.
|
|
*/
|
|
#define SAFETY_MEMORY_HEADER_ADDRESS 0UL
|
|
|
|
#define SAFETY_MEMORY_CONFIG_OVERRIDE_COUNT 32UL
|
|
|
|
/**
|
|
* @brief Safety memory header
|
|
*/
|
|
struct safety_memory_header {
|
|
uint32_t magic; /**< @brief Magic. Set to @ref SAFETY_MEMORY_MAGIC */
|
|
uint32_t boot_status_offset; /**< @brief Offset of the safety_memory_boot_status struct (in 32 bit words)*/
|
|
uint32_t config_overrides_offset; /**< @brief Offset address of override entries */
|
|
uint32_t config_overrides_len; /**< @brief Length of override entries in words */
|
|
uint32_t err_memory_offset; /**< @brief Offset of the error memory */
|
|
uint32_t err_memory_end; /**< @brief End of the error memory. This points to the word after the error memory, containing the CRC of the whole backup RAM. */
|
|
uint32_t magic_i; /**< @brief Invers Magic. Set to the bitwise inverse of @ref SAFETY_MEMORY_MAGIC */
|
|
};
|
|
|
|
struct safety_memory_boot_status {
|
|
/**
|
|
* @brief Reboot into the bootloader
|
|
*
|
|
* When this flag is set, the controller will load the bootloader to
|
|
* memory and execute it.
|
|
*/
|
|
uint32_t reboot_to_bootloader;
|
|
|
|
/**
|
|
* @brief Bootloader has updated the code
|
|
*
|
|
* This flag is set, if the firmware ahs been updated successfully
|
|
*/
|
|
uint32_t code_updated;
|
|
|
|
/**
|
|
* @brief reset_from_panic
|
|
*
|
|
* This flag is set, when entering the panic mode.
|
|
* Because the panic mode is reset by a watchdog reset,
|
|
* this flag is needed, in order to ensure, that the panic is handled correcly after
|
|
* the watchdog reset.
|
|
*/
|
|
uint32_t reset_from_panic;
|
|
};
|
|
|
|
enum safety_memory_state {
|
|
SAFETY_MEMORY_INIT_FRESH = 0,
|
|
SAFETY_MEMORY_INIT_CORRUPTED = 1,
|
|
SAFETY_MEMORY_INIT_VALID_MEMORY = 2,
|
|
};
|
|
|
|
enum safety_memory_error_entry_type {
|
|
SAFETY_MEMORY_ERR_ENTRY_FLAG = 1,
|
|
SAFETY_MEMORY_ERR_ENTRY_NOP = 2,
|
|
};
|
|
|
|
struct error_memory_entry {
|
|
enum safety_memory_error_entry_type type;
|
|
uint8_t flag_num;
|
|
uint16_t counter;
|
|
};
|
|
|
|
enum config_override_entry_type {
|
|
SAFETY_MEMORY_CONFIG_OVERRIDE_WEIGHT = 1,
|
|
SAFETY_MEMORY_CONFIG_OVERRIDE_PERSISTANCE = 2,
|
|
};
|
|
|
|
struct config_override {
|
|
enum config_override_entry_type type;
|
|
union {
|
|
struct {
|
|
uint8_t flag;
|
|
uint8_t weight;
|
|
} weight_override;
|
|
struct {
|
|
uint8_t flag;
|
|
uint8_t persistance;
|
|
} persistance_override;
|
|
} entry;
|
|
};
|
|
|
|
int safety_memory_init(enum safety_memory_state *found_state);
|
|
|
|
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);
|
|
|
|
int safety_memory_get_error_entry(uint32_t idx, struct error_memory_entry *entry);
|
|
|
|
int safety_memory_insert_error_entry(struct error_memory_entry *entry);
|
|
|
|
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);
|
|
|
|
#endif /* __SAFETY_MEMORY_H__ */
|