-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.c
168 lines (144 loc) · 3.72 KB
/
error.c
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* mµOS - my micro OS
*
* Copyright (C)
* 2015 Christian Thäter <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <muos/muos.h>
#include <muos/error.h>
#include <stddef.h>
//PLANNED: counters per error class, configurable
volatile uint8_t muos_errors_pending_;
volatile MUOS_BARRAY(muos_errors_, muos_errors_end);
#ifdef MUOS_ERROR_CTX
static const char __flash empty[] = "";
static uint16_t ctx_line;
static const char __flash* ctx_file = empty;
uint16_t
muos_error_ctx_line (void)
{
return ctx_line;
}
const char __flash*
muos_error_ctx_file (void)
{
return ctx_file;
}
#endif
#ifdef MUOS_ERROR_STR
#define MUOS_INFO(name, ...) static const char __flash muos_info_##name##_str[] = #name;
#define MUOS_WARN(name, ...) static const char __flash muos_warn_##name##_str[] = #name;
#define MUOS_ERROR(name, ...) static const char __flash muos_error_##name##_str[] = #name;
#define MUOS_FATAL(name, ...) static const char __flash muos_fatal_##name##_str[] = #name;
static const char __flash muos_success_str[] = "muos_success";
MUOS_ERRORS
#undef MUOS_INFO
#undef MUOS_WARN
#undef MUOS_ERROR
#undef MUOS_FATAL
static
const char __flash * const __flash muos_error_names[] =
{
muos_success_str,
#define MUOS_INFO(name, ...) muos_info_##name##_str,
#define MUOS_WARN(...)
#define MUOS_ERROR(...)
#define MUOS_FATAL(...)
MUOS_ERRORS
#undef MUOS_INFO
#define MUOS_INFO(...)
#undef MUOS_WARN
#define MUOS_WARN(name, ...) muos_warn_##name##_str,
MUOS_ERRORS
#undef MUOS_WARN
#define MUOS_WARN(...)
#undef MUOS_ERROR
#define MUOS_ERROR(name, ...) muos_error_##name##_str,
MUOS_ERRORS
#undef MUOS_ERROR
#define MUOS_ERROR(...)
#undef MUOS_FATAL
#define MUOS_FATAL(name, ...) muos_fatal_##name##_str,
MUOS_ERRORS
#undef MUOS_INFO
#undef MUOS_WARN
#undef MUOS_ERROR
#undef MUOS_FATAL
};
const char __flash*
muos_error_str (muos_error err)
{
if (err >= muos_errors_end)
return muos_fatal_error_str;
return muos_error_names[err];
}
#endif
#ifdef MUOS_ERROR_CTX
muos_error
muos_error_set_isr_ (muos_error err, uint16_t line, const char __flash* file)
{
if (err && !(muos_errors_[err/8] & 1<<(err%8)))
{
MUOS_DEBUG_ERROR_ON;
muos_barray_setbit (muos_errors_, err);
++muos_errors_pending_;
ctx_line = line;
ctx_file = file;
}
return err;
}
#else
muos_error
muos_error_set_isr_ (muos_error err)
{
if (err && !(muos_errors_[err/8] & 1<<(err%8)))
{
MUOS_DEBUG_ERROR_ON;
muos_barray_setbit (muos_errors_, err);
++muos_errors_pending_;
}
return err;
}
#endif
bool
muos_error_check_isr (muos_error err)
{
bool ret = false;
if (muos_errors_pending_)
{
ret = muos_error_peek (err);
if (ret)
{
muos_barray_clearbit (muos_errors_, err);
--muos_errors_pending_;
}
#ifdef MUOS_DEBUG_ERROR
if (!muos_errors_pending_)
{
MUOS_DEBUG_ERROR_OFF;
}
#endif
}
return ret;
}
void
muos_error_clearall_isr (void)
{
muos_barray_clear(muos_errors_);
muos_errors_pending_ = 0;
MUOS_DEBUG_ERROR_OFF;
}