Program Listing for File error.h¶
↰ Return to documentation for file (mainboard/Inc/error/error.h
)
#ifndef ERROR_H
#define ERROR_H
#include "../../lib/can/naked_generator/Primary/c/Primary.h"
#include "llist.h"
#include <inttypes.h>
#include <stdbool.h>
#define error_toggle_check(condition, error_type, index) \
if ((condition)) { \
error_set((error_type), (index), HAL_GetTick()); \
} else { \
error_reset((error_type), (index)); \
}
typedef enum {
ERROR_CELL_LOW_VOLTAGE,
ERROR_CELL_UNDER_VOLTAGE,
ERROR_CELL_OVER_VOLTAGE,
ERROR_CELL_OVER_TEMPERATURE,
ERROR_CELL_HIGH_TEMPERATURE,
ERROR_OVER_CURRENT,
ERROR_CAN,
ERROR_ADC_INIT,
ERROR_ADC_TIMEOUT,
ERROR_INT_VOLTAGE_MISMATCH,
ERROR_CELLBOARD_COMM,
ERROR_CELLBOARD_INTERNAL,
ERROR_FEEDBACK,
ERROR_EEPROM_COMM,
ERROR_EEPROM_WRITE,
ERROR_NUM_ERRORS
} __attribute__((__packed__)) error_id;
typedef enum { SOFT = UINT32_MAX, SHORT = 500, REGULAR = 1000, INSTANT = 0 } __attribute__((__packed__)) error_timeout;
typedef enum { STATE_WARNING, STATE_FATAL } __attribute__((__packed__)) error_state;
typedef struct {
error_id id; /* Defines the type of error */
uint8_t offset; /* Identifies different instances of a type */
error_state state;
uint32_t timestamp; /* Last time the error activated */
} error_t;
extern llist er_list;
void error_init();
void error_init_error(error_t *error, error_id id, uint8_t offset, uint32_t timestamp);
bool error_set(error_id type, uint8_t offset, uint32_t now);
error_t *error_get_top();
bool error_set_fatal(error_t *error);
bool error_reset(error_id type, uint8_t offset);
size_t error_get_fatal();
size_t error_count();
void error_dump(error_t errors[]);
bool compare_timeouts(error_t *a, error_t *b);
#endif /* ERROR_H_ */