#ifndef _SAFETY_MEM_TYPES_H_
#define _SAFETY_MEM_TYPES_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 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 crc;		/**< @brief  CRC of the header */
};

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;
};


#endif /* _SAFETY_MEM_TYPES_H_ */
