Smart Remote 3 nRF52 v1.2
app_util_platform.h
1 /*$$$LICENCE_NORDIC_STANDARD<2014>$$$*/
11 #ifndef APP_UTIL_PLATFORM_H__
12 #define APP_UTIL_PLATFORM_H__
13 
14 #include <stdint.h>
15 #include "compiler_abstraction.h"
16 #include "nrf.h"
17 #ifdef SOFTDEVICE_PRESENT
18 #include "nrf_soc.h"
19 #include "nrf_nvic.h"
20 #endif
21 #include "nrf_assert.h"
22 #include "app_error.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #if __CORTEX_M == (0x00U)
29 #define _PRIO_SD_HIGH 0
30 #define _PRIO_APP_HIGH 1
31 #define _PRIO_APP_MID 1
32 #define _PRIO_SD_LOW 2
33 #define _PRIO_APP_LOW 3
34 #define _PRIO_APP_LOWEST 3
35 #define _PRIO_THREAD 4
36 #elif __CORTEX_M == (0x04U) && !defined(S1XX)
37 #define _PRIO_SD_HIGH 0
38 #define _PRIO_SD_MID 1
39 #define _PRIO_APP_HIGH 2
40 #define _PRIO_APP_MID 3
41 #define _PRIO_SD_LOW 4
42 #define _PRIO_SD_LOWEST 5
43 #define _PRIO_APP_LOW 6
44 #define _PRIO_APP_LOWEST 7
45 #define _PRIO_THREAD 15
46 #elif defined(S1XX)
47 #define _PRIO_SD_HIGH 0
48 #define _PRIO_APP_HIGH 1
49 #define _PRIO_APP_MID 1
50 #define _PRIO_SD_LOW 2
51 #define _PRIO_APP_LOW 3
52 #define _PRIO_APP_LOWEST 3
53 #define _PRIO_THREAD 4
54 #else
55  #error "No platform defined"
56 #endif
57 
58 
59 //lint -save -e113 -e452
61 typedef enum
62 {
63 #ifndef SOFTDEVICE_PRESENT
64  APP_IRQ_PRIORITY_HIGHEST = _PRIO_SD_HIGH,
65 #else
66  APP_IRQ_PRIORITY_HIGHEST = _PRIO_APP_HIGH,
67 #endif
68  APP_IRQ_PRIORITY_HIGH = _PRIO_APP_HIGH,
69 #ifndef SOFTDEVICE_PRESENT
70  APP_IRQ_PRIORITY_MID = _PRIO_SD_LOW,
71 #else
72  APP_IRQ_PRIORITY_MID = _PRIO_APP_MID,
73 #endif
74  APP_IRQ_PRIORITY_LOW = _PRIO_APP_LOW,
75  APP_IRQ_PRIORITY_LOWEST = _PRIO_APP_LOWEST,
76  APP_IRQ_PRIORITY_THREAD = _PRIO_THREAD
78 //lint -restore
79 
80 
81 /*@brief The privilege levels available to applications in Thread Mode */
82 typedef enum
83 {
84  APP_LEVEL_UNPRIVILEGED,
85  APP_LEVEL_PRIVILEGED
86 } app_level_t;
87 
89 #define EXTERNAL_INT_VECTOR_OFFSET 16
90 
94 #if defined(__GNUC__)
95 #define NRF_BREAKPOINT __builtin_trap()
96 #else
97 #define NRF_BREAKPOINT __BKPT(0)
98 #endif
99 
105 #if __CORTEX_M == 0x04
106 #define NRF_BREAKPOINT_COND do { \
107  /* C_DEBUGEN == 1 -> Debugger Connected */ \
108  if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) \
109  { \
110  /* Generate breakpoint if debugger is connected */ \
111  NRF_BREAKPOINT; \
112  } \
113  }while (0)
114 #else
115 #define NRF_BREAKPOINT_COND NRF_BREAKPOINT
116 #endif // __CORTEX_M == 0x04
117 
118 #if defined ( __CC_ARM )
119 #define PACKED(TYPE) __packed TYPE
120 #define PACKED_STRUCT PACKED(struct)
121 #elif defined ( __GNUC__ )
122 #define PACKED __attribute__((packed))
123 #define PACKED_STRUCT struct PACKED
124 #elif defined (__ICCARM__)
125 #define PACKED_STRUCT __packed struct
126 #endif
127 
128 void app_util_critical_region_enter (uint8_t *p_nested);
129 void app_util_critical_region_exit (uint8_t nested);
130 
137 #ifdef SOFTDEVICE_PRESENT
138 #define CRITICAL_REGION_ENTER() \
139  { \
140  uint8_t __CR_NESTED = 0; \
141  app_util_critical_region_enter(&__CR_NESTED);
142 #else
143 #define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
144 #endif
145 
152 #ifdef SOFTDEVICE_PRESENT
153 #define CRITICAL_REGION_EXIT() \
154  app_util_critical_region_exit(__CR_NESTED); \
155  }
156 #else
157 #define CRITICAL_REGION_EXIT() app_util_critical_region_exit(0)
158 #endif
159 
160 /* Workaround for Keil 4 */
161 #ifndef IPSR_ISR_Msk
162 #define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/)
163 #endif
164 
165 
166 
169 #if defined(__CC_ARM)
170  #define ANON_UNIONS_ENABLE _Pragma("push") \
171  _Pragma("anon_unions")
172 #elif defined(__ICCARM__)
173  #define ANON_UNIONS_ENABLE _Pragma("language=extended")
174 #else
175  #define ANON_UNIONS_ENABLE
176  // No action will be taken.
177  // For GCC anonymous unions are enabled by default.
178 #endif
179 
183 #if defined(__CC_ARM)
184  #define ANON_UNIONS_DISABLE _Pragma("pop")
185 #elif defined(__ICCARM__)
186  #define ANON_UNIONS_DISABLE
187  // for IAR leave anonymous unions enabled
188 #else
189  #define ANON_UNIONS_DISABLE
190  // No action will be taken.
191  // For GCC anonymous unions are enabled by default.
192 #endif
193 
196 #ifdef __GNUC__
197 #define GCC_PRAGMA(v) _Pragma(v)
198 #else
199 #define GCC_PRAGMA(v)
200 #endif
201 
202 /* Workaround for Keil 4 */
203 #ifndef CONTROL_nPRIV_Msk
204 #define CONTROL_nPRIV_Msk (1UL /*<< CONTROL_nPRIV_Pos*/)
205 #endif
206 
214 uint8_t current_int_priority_get(void);
215 
216 
223 uint8_t privilege_level_get(void);
224 
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 #endif // APP_UTIL_PLATFORM_H__
231 

Documentation feedback | Developer Zone | Subscribe | Updated