-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.h
185 lines (163 loc) · 5.63 KB
/
debug.h
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* mµOS - my micro OS
*
* Copyright (C)
* 2016 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/>.
*/
#ifndef MUOS_DEBUG_H
#define MUOS_DEBUG_H
//debug_api:
//: .Debug GPIO Macros
//: ----
//: MUOS_DEBUG_Cx_ON
//: MUOS_DEBUG_Cx_OFF
//: MUOS_DEBUG_Cx_TOGGLE
//: ----
//:
//: +x+::
//: Debug channel (1-4)
//:
//: Sets the debug channel to the given state.
//:
//: ----
//: MUOS_DEBUG_INTR_ON
//: MUOS_DEBUG_INTR_OFF
//: ----
//:
//: MµOS Interrupt debug channel. User defined interrupts should turn
//: the GPIO on right at the start and off when done.
//:
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_BUSY)
#define MUOS_DEBUG_BUSY_ON MUOS_GPIO_SET_(MUOS_DEBUG_BUSY)
#define MUOS_DEBUG_BUSY_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_BUSY)
#else
#define MUOS_DEBUG_BUSY_ON
#define MUOS_DEBUG_BUSY_OFF
#endif
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_INTR)
#define MUOS_DEBUG_INTR_ON MUOS_GPIO_SET_(MUOS_DEBUG_INTR)
#define MUOS_DEBUG_INTR_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_INTR)
#else
#define MUOS_DEBUG_INTR_ON
#define MUOS_DEBUG_INTR_OFF
#endif
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_ERROR)
#define MUOS_DEBUG_ERROR_ON MUOS_GPIO_SET_(MUOS_DEBUG_ERROR)
#define MUOS_DEBUG_ERROR_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_ERROR)
#define MUOS_DEBUG_ERROR_TOGGLE MUOS_GPIO_TOGGLE_(MUOS_DEBUG_ERROR)
#else
#define MUOS_DEBUG_ERROR_ON
#define MUOS_DEBUG_ERROR_OFF
#define MUOS_DEBUG_ERROR_TOGGLE
#endif
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_SWITCH)
#define MUOS_DEBUG_SWITCH_ON MUOS_GPIO_SET_(MUOS_DEBUG_SWITCH)
#define MUOS_DEBUG_SWITCH_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_SWITCH)
#define MUOS_DEBUG_SWITCH_TOGGLE MUOS_GPIO_TOGGLE_(MUOS_DEBUG_SWITCH)
#else
#define MUOS_DEBUG_SWITCH_ON
#define MUOS_DEBUG_SWITCH_OFF
#define MUOS_DEBUG_SWITCH_TOGGLE
#endif
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_C1)
#define MUOS_DEBUG_C1_ON MUOS_GPIO_SET_(MUOS_DEBUG_C1)
#define MUOS_DEBUG_C1_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_C1)
#define MUOS_DEBUG_C1_TOGGLE MUOS_GPIO_TOGGLE_(MUOS_DEBUG_C1)
#else
#define MUOS_DEBUG_C1_ON
#define MUOS_DEBUG_C1_OFF
#define MUOS_DEBUG_C1_TOGGLE
#endif
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_C2)
#define MUOS_DEBUG_C2_ON MUOS_GPIO_SET_(MUOS_DEBUG_C2)
#define MUOS_DEBUG_C2_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_C2)
#define MUOS_DEBUG_C2_TOGGLE MUOS_GPIO_TOGGLE_(MUOS_DEBUG_C2)
#else
#define MUOS_DEBUG_C2_ON
#define MUOS_DEBUG_C2_OFF
#define MUOS_DEBUG_C2_TOGGLE
#endif
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_C3)
#define MUOS_DEBUG_C3_ON MUOS_GPIO_SET_(MUOS_DEBUG_C3)
#define MUOS_DEBUG_C3_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_C3)
#define MUOS_DEBUG_C3_TOGGLE MUOS_GPIO_TOGGLE_(MUOS_DEBUG_C3)
#else
#define MUOS_DEBUG_C3_ON
#define MUOS_DEBUG_C3_OFF
#define MUOS_DEBUG_C3_TOGGLE
#endif
#if defined(MUOS_DEBUG) && defined(MUOS_DEBUG_C4)
#define MUOS_DEBUG_C4_ON MUOS_GPIO_SET_(MUOS_DEBUG_C4)
#define MUOS_DEBUG_C4_OFF MUOS_GPIO_CLEAR_(MUOS_DEBUG_C4)
#define MUOS_DEBUG_C4_TOGGLE MUOS_GPIO_TOGGLE_(MUOS_DEBUG_C4)
#else
#define MUOS_DEBUG_C4_ON
#define MUOS_DEBUG_C4_OFF
#define MUOS_DEBUG_C4_TOGGLE
#endif
void
muos_hw_debug_init (void);
//debug_api:
//: .Assertions
//: ----
//: MUOS_ASSERT(flag, pred)
//: MUOS_ASSERT_ISR(flag, pred)
//: MUOS_ASSURE(flag, expr, expect)
//: MUOS_ASSURE_ISR(flag, expr, expect)
//: ----
//:
//: +flag+::
//: Flag to turn assertion on
//: +pred+::
//: predicate to check
//: +expr+::
//: expression to evaluate
//: +expect+::
//: comparison that should yield true from 'expr'
//:
//: 'MUOS_ASSERT()'/'MUOS_ASSERT_ISR()'::
//: When MUOS_DEBUG_ASSERTIONS are enabled and 'flag' is true then
//: these macros check 'pred', when it evaluates to 'false' then
//: 'muos_fatal_assert' is set. 'pred' must be side effect free.
//:
//: 'flag' is ideally an constant expression then the compiler can
//: optimize unused assertions completely out.
//:
//: 'MUOS_ASSURE()'/'MUOS_ASSURE_ISR()'::
//: Evaluate 'expr'. When MUOS_DEBUG_ASSERTIONS is enabled and 'flag' ist true,
//: then compare the result with 'expect' and set 'muos_fatal_assert' when false.
//:
//: When MUOS_DEBUG_ASSERTS are disabled or 'flag' is false, 'expr' is still
//: evaluated but no error is set.
//:
//: Asssure does not yield a result, assignments should be written within the +expr+.
//:
//: 'expect' should include an comparison operator eg.:
//:
//: MUOS_ASSURE (true, foo = something(), > 0);
//:
#ifdef MUOS_DEBUG_ASSERTIONS
#define MUOS_ASSERT(flag, pred) do {if ((flag) && !(pred)){muos_error_set (muos_fatal_assert);}}while(0)
#define MUOS_ASSERT_ISR(flag, pred) do {if ((flag) && !(pred)){muos_error_set_isr (muos_fatal_assert);}}while(0)
#define MUOS_ASSURE(flag, expr, expect) do {if (!((expr) expect) && flag){muos_error_set (muos_fatal_assert);}}while(0)
#define MUOS_ASSURE_ISR(flag, expr, expect) do {if (!((expr) expect) && flag){muos_error_set_isr (muos_fatal_assert);}}while(0)
#else
#define MUOS_ASSERT(flag, pred)
#define MUOS_ASSERT_ISR(flag, pred)
#define MUOS_ASSURE(flag, expr, expect) do { expr; }while(0)
#define MUOS_ASSURE_ISR(flag, expr, expect) do { expr; }while(0)
#endif
#endif