-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfaults.h
More file actions
37 lines (28 loc) · 880 Bytes
/
faults.h
File metadata and controls
37 lines (28 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include <ch.h>
#define FAULT_DEFINE_STATIC(HANDLE_NAME, LEVEL, DESCRIPTION) \
static struct fault_s HANDLE_NAME; \
RUN_AFTER(CH_SYS_INIT) { \
fault_register(&HANDLE_NAME, LEVEL, DESCRIPTION); \
}
#ifdef MODULE_PUBSUB_ENABLED
extern struct pubsub_topic_s fault_raised_topic;
#endif
enum fault_level_t {
FAULT_LEVEL_OK,
FAULT_LEVEL_WARNING,
FAULT_LEVEL_ERROR,
FAULT_LEVEL_CRITICAL
};
struct fault_s {
const char* description;
enum fault_level_t level;
systime_t raised_time;
systime_t timeout;
struct fault_s* next;
};
void fault_register(struct fault_s* fault, enum fault_level_t level, const char* description);
void fault_raise(struct fault_s* fault, systime_t timeout);
void fault_clear(struct fault_s* fault);
enum fault_level_t fault_get_level(struct fault_s* fault);
struct fault_s* fault_get_worst_fault(void);