123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- #ifndef APP_UTIL_PLATFORM_H__
- #define APP_UTIL_PLATFORM_H__
- #include <stdint.h>
- #include "compiler_abstraction.h"
- #include "nrf.h"
- #ifdef SOFTDEVICE_PRESENT
- #include "nrf_soc.h"
- #include "nrf_nvic.h"
- #endif
- #include "nrf_assert.h"
- #include "app_error.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if __CORTEX_M == (0x00U)
- #define _PRIO_SD_HIGH 0
- #define _PRIO_APP_HIGH 1
- #define _PRIO_APP_MID 1
- #define _PRIO_SD_LOW 2
- #define _PRIO_APP_LOW_MID 3
- #define _PRIO_APP_LOW 3
- #define _PRIO_APP_LOWEST 3
- #define _PRIO_THREAD 4
- #elif __CORTEX_M >= (0x04U)
- #define _PRIO_SD_HIGH 0
- #define _PRIO_SD_MID 1
- #define _PRIO_APP_HIGH 2
- #define _PRIO_APP_MID 3
- #define _PRIO_SD_LOW 4
- #define _PRIO_APP_LOW_MID 5
- #define _PRIO_APP_LOW 6
- #define _PRIO_APP_LOWEST 7
- #define _PRIO_THREAD 15
- #else
- #error "No platform defined"
- #endif
- typedef enum
- {
- #ifndef SOFTDEVICE_PRESENT
- APP_IRQ_PRIORITY_HIGHEST = _PRIO_SD_HIGH,
- #else
- APP_IRQ_PRIORITY_HIGHEST = _PRIO_APP_HIGH,
- #endif
- APP_IRQ_PRIORITY_HIGH = _PRIO_APP_HIGH,
- #ifndef SOFTDEVICE_PRESENT
- APP_IRQ_PRIORITY_MID = _PRIO_SD_LOW,
- #else
- APP_IRQ_PRIORITY_MID = _PRIO_APP_MID,
- #endif
- APP_IRQ_PRIORITY_LOW_MID = _PRIO_APP_LOW_MID,
- APP_IRQ_PRIORITY_LOW = _PRIO_APP_LOW,
- APP_IRQ_PRIORITY_LOWEST = _PRIO_APP_LOWEST,
- APP_IRQ_PRIORITY_THREAD = _PRIO_THREAD
- } app_irq_priority_t;
- typedef enum
- {
- APP_LEVEL_UNPRIVILEGED,
- APP_LEVEL_PRIVILEGED
- } app_level_t;
- #define EXTERNAL_INT_VECTOR_OFFSET 16
- #if defined(__GNUC__)
- #define NRF_BREAKPOINT __asm__("BKPT 0");
- #else
- #define NRF_BREAKPOINT __BKPT(0)
- #endif
- #if __CORTEX_M == 0x04
- #define NRF_BREAKPOINT_COND do { \
- \
- if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) \
- { \
- \
- NRF_BREAKPOINT; \
- } \
- }while (0)
- #else
- #define NRF_BREAKPOINT_COND NRF_BREAKPOINT
- #endif
- #if defined ( __CC_ARM )
- #define PACKED(TYPE) __packed TYPE
- #define PACKED_STRUCT PACKED(struct)
- #elif defined ( __GNUC__ )
- #define PACKED __attribute__((packed))
- #define PACKED_STRUCT struct PACKED
- #elif defined (__ICCARM__)
- #define PACKED_STRUCT __packed struct
- #endif
- #if defined ( __CC_ARM )
- #define PRAGMA_OPTIMIZATION_FORCE_START _Pragma ("push") \
- _Pragma ("O3")
- #define PRAGMA_OPTIMIZATION_FORCE_END _Pragma ("pop")
- #elif defined ( __GNUC__ )
- #define PRAGMA_OPTIMIZATION_FORCE_START _Pragma("GCC push_options") \
- _Pragma ("GCC optimize (\"Os\")")
- #define PRAGMA_OPTIMIZATION_FORCE_END _Pragma ("GCC pop_options")
- #elif defined (__ICCARM__)
- #define PRAGMA_OPTIMIZATION_FORCE_START _Pragma ("optimize=high z")
- #define PRAGMA_OPTIMIZATION_FORCE_END
- #endif
- void app_util_critical_region_enter (uint8_t *p_nested);
- void app_util_critical_region_exit (uint8_t nested);
- #ifdef SOFTDEVICE_PRESENT
- #define CRITICAL_REGION_ENTER() \
- { \
- uint8_t __CR_NESTED = 0; \
- app_util_critical_region_enter(&__CR_NESTED);
- #else
- #define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
- #endif
- #ifdef SOFTDEVICE_PRESENT
- #define CRITICAL_REGION_EXIT() \
- app_util_critical_region_exit(__CR_NESTED); \
- }
- #else
- #define CRITICAL_REGION_EXIT() app_util_critical_region_exit(0)
- #endif
- #ifndef IPSR_ISR_Msk
- #define IPSR_ISR_Msk (0x1FFUL )
- #endif
- #if defined(__CC_ARM)
- #define ANON_UNIONS_ENABLE _Pragma("push") \
- _Pragma("anon_unions") \
- struct semicolon_swallower
- #elif defined(__ICCARM__)
- #define ANON_UNIONS_ENABLE _Pragma("language=extended") \
- struct semicolon_swallower
- #else
- #define ANON_UNIONS_ENABLE struct semicolon_swallower
-
-
- #endif
- #if defined(__CC_ARM)
- #define ANON_UNIONS_DISABLE _Pragma("pop") \
- struct semicolon_swallower
- #elif defined(__ICCARM__)
- #define ANON_UNIONS_DISABLE struct semicolon_swallower
-
- #else
- #define ANON_UNIONS_DISABLE struct semicolon_swallower
-
-
- #endif
- #ifdef __GNUC__
- #define GCC_PRAGMA(v) _Pragma(v)
- #else
- #define GCC_PRAGMA(v)
- #endif
- #ifndef CONTROL_nPRIV_Msk
- #define CONTROL_nPRIV_Msk (1UL )
- #endif
- uint8_t current_int_priority_get(void);
- uint8_t privilege_level_get(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|