| SX126x-Arduino 2.0.1

app_util.h
Go to the documentation of this file.
1
48 #ifdef NRF52_SERIES
49 #ifndef APP_UTIL_PLATFORM_H__
50 #define APP_UTIL_PLATFORM_H__
51
52 #include <stdint.h>
53 #include "compiler_abstraction.h"
54 #include "nrf.h"
55 #ifdef SOFTDEVICE_PRESENT
56 #include "nrf_soc.h"
57 #include "nrf_nvic.h"
58 #endif
59 // #include "nrf_assert.h"
60 // #include "app_error.h"
61
62 #ifdef __cplusplus
63 extern "C"
64 {
65 #endif
66
67 #if __CORTEX_M == (0x00U)
68 #define _PRIO_SD_HIGH 0
69 #define _PRIO_APP_HIGH 1
70 #define _PRIO_APP_MID 1
71 #define _PRIO_SD_LOW 2
72 #define _PRIO_APP_LOW 3
73 #define _PRIO_APP_LOWEST 3
74 #define _PRIO_THREAD 4
75 #elif __CORTEX_M == (0x04U)
76 #define _PRIO_SD_HIGH 0
77 #define _PRIO_SD_MID 1
78 #define _PRIO_APP_HIGH 2
79 #define _PRIO_APP_MID 3
80 #define _PRIO_SD_LOW 4
81 #define _PRIO_SD_LOWEST 5
82 #define _PRIO_APP_LOW 6
83 #define _PRIO_APP_LOWEST 7
84 #define _PRIO_THREAD 15
85 #else
86 #error "No platform defined"
87 #endif
88
89 //lint -save -e113 -e452
91 typedef enum
92 {
93 #ifndef SOFTDEVICE_PRESENT
94 APP_IRQ_PRIORITY_HIGHEST = _PRIO_SD_HIGH,
95 #else
96 APP_IRQ_PRIORITY_HIGHEST = _PRIO_APP_HIGH,
97 #endif
98 APP_IRQ_PRIORITY_HIGH = _PRIO_APP_HIGH,
99 #ifndef SOFTDEVICE_PRESENT
100 APP_IRQ_PRIORITY_MID = _PRIO_SD_LOW,
101 #else
102 APP_IRQ_PRIORITY_MID = _PRIO_APP_MID,
103 #endif
104 APP_IRQ_PRIORITY_LOW = _PRIO_APP_LOW,
105 APP_IRQ_PRIORITY_LOWEST = _PRIO_APP_LOWEST,
106 APP_IRQ_PRIORITY_THREAD = _PRIO_THREAD
107 } app_irq_priority_t;
108 //lint -restore
109
110 /*@brief The privilege levels available to applications in Thread Mode */
111 typedef enum
112 {
113 APP_LEVEL_UNPRIVILEGED,
114 APP_LEVEL_PRIVILEGED
115 } app_level_t;
116
118 #define EXTERNAL_INT_VECTOR_OFFSET 16
119
123 #if defined(__GNUC__)
124 #define NRF_BREAKPOINT __builtin_trap()
125 #else
126 #define NRF_BREAKPOINT __BKPT(0)
127 #endif
128
134 #if __CORTEX_M == 0x04
135 #define NRF_BREAKPOINT_COND \
136 do \
137 { \
138 /* C_DEBUGEN == 1 -> Debugger Connected */ \
139 if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) \
140 { \
141 /* Generate breakpoint if debugger is connected */ \
142 NRF_BREAKPOINT; \
143 } \
144 } while (0)
145 #else
146 #define NRF_BREAKPOINT_COND NRF_BREAKPOINT
147 #endif // __CORTEX_M == 0x04
148
149 #if defined(__CC_ARM)
150 #define PACKED(TYPE) __packed TYPE
151 #define PACKED_STRUCT PACKED(struct)
152 #elif defined(__GNUC__)
153 #define PACKED __attribute__((packed))
154 #define PACKED_STRUCT struct PACKED
155 #elif defined(__ICCARM__)
156 #define PACKED_STRUCT __packed struct
157 #endif
158
159 void app_util_critical_region_enter(uint8_t *p_nested);
160 void app_util_critical_region_exit(uint8_t nested);
161
168 #ifdef SOFTDEVICE_PRESENT
169 #define CRITICAL_REGION_ENTER() \
170 { \
171 uint8_t __CR_NESTED = 0; \
172 app_util_critical_region_enter(&__CR_NESTED);
173 #else
174 #define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
175 #endif
176
183 #ifdef SOFTDEVICE_PRESENT
184 #define CRITICAL_REGION_EXIT() \
185 app_util_critical_region_exit(__CR_NESTED); \
186 }
187 #else
188 #define CRITICAL_REGION_EXIT() app_util_critical_region_exit(0)
189 #endif
190
191 /* Workaround for Keil 4 */
192 #ifndef IPSR_ISR_Msk
193 #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/)
194 #endif
195
198 #if defined(__CC_ARM)
199 #define ANON_UNIONS_ENABLE _Pragma("push") \
200 _Pragma("anon_unions")
201 #elif defined(__ICCARM__)
202 #define ANON_UNIONS_ENABLE _Pragma("language=extended")
203 #else
204 #define ANON_UNIONS_ENABLE
205 // No action will be taken.
206 // For GCC anonymous unions are enabled by default.
207 #endif
208
212 #if defined(__CC_ARM)
213 #define ANON_UNIONS_DISABLE _Pragma("pop")
214 #elif defined(__ICCARM__)
215 #define ANON_UNIONS_DISABLE
216 // for IAR leave anonymous unions enabled
217 #else
218 #define ANON_UNIONS_DISABLE
219 // No action will be taken.
220 // For GCC anonymous unions are enabled by default.
221 #endif
222
225 #ifdef __GNUC__
226 #define GCC_PRAGMA(v) _Pragma(v)
227 #else
228 #define GCC_PRAGMA(v)
229 #endif
230
231 /* Workaround for Keil 4 */
232 #ifndef CONTROL_nPRIV_Msk
233 #define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/)
234 #endif
235
243 uint8_t current_int_priority_get(void);
244
251 uint8_t privilege_level_get(void);
252
253 #ifdef __cplusplus
254 }
255 #endif
256
257 #endif // APP_UTIL_PLATFORM_H__
258 #endif
259