bugfix for duplicate symbol

Fork of nRF51822 by Nordic Semiconductor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers app_util_platform.h Source File

app_util_platform.h

Go to the documentation of this file.
00001 /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is property of Nordic Semiconductor ASA.
00004  * Terms and conditions of usage are described in detail in NORDIC
00005  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *
00011  */
00012 
00013 /**@file
00014  *
00015  * @defgroup app_util_platform Utility Functions and Definitions (Platform)
00016  * @{
00017  * @ingroup app_common
00018  *
00019  * @brief Various types and definitions available to all applications when using SoftDevice.
00020  */
00021 
00022 #ifndef APP_UTIL_PLATFORM_H__
00023 #define APP_UTIL_PLATFORM_H__
00024 
00025 #include <stdint.h>
00026 #include "compiler_abstraction.h"
00027 #include "nrf51.h"
00028 #ifdef SOFTDEVICE_PRESENT
00029 #include "nrf_soc.h"
00030 #include "app_error.h "
00031 #endif
00032 /**@brief The interrupt priorities available to the application while the SoftDevice is active. */
00033 typedef enum
00034 {
00035     APP_IRQ_PRIORITY_HIGH = 1,
00036 #ifndef SOFTDEVICE_PRESENT
00037     APP_IRQ_PRIORITY_MID  = 2,
00038 #endif
00039     APP_IRQ_PRIORITY_LOW  = 3
00040 } app_irq_priority_t;
00041 
00042 #define NRF_APP_PRIORITY_THREAD    4                    /**< "Interrupt level" when running in Thread Mode. */
00043 
00044 /**@cond NO_DOXYGEN */
00045 #define EXTERNAL_INT_VECTOR_OFFSET 16
00046 /**@endcond */
00047 
00048 #define PACKED(TYPE) __packed TYPE
00049 
00050 void critical_region_enter (void);
00051 void critical_region_exit (void);
00052 
00053 /**@brief Macro for entering a critical region.
00054  *
00055  * @note Due to implementation details, there must exist one and only one call to
00056  *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
00057  *       in the same scope.
00058  */
00059 #ifdef SOFTDEVICE_PRESENT
00060 #define CRITICAL_REGION_ENTER()                                                             \
00061     {                                                                                       \
00062         uint8_t IS_NESTED_CRITICAL_REGION = 0;                                              \
00063         uint32_t CURRENT_INT_PRI = current_int_priority_get();                              \
00064         if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH)                                       \
00065         {                                                                                   \
00066             uint32_t ERR_CODE = sd_nvic_critical_region_enter(&IS_NESTED_CRITICAL_REGION);  \
00067             if (ERR_CODE == NRF_ERROR_SOFTDEVICE_NOT_ENABLED)                               \
00068             {                                                                               \
00069                 __disable_irq();                                                            \
00070             }                                                                               \
00071             else                                                                            \
00072             {                                                                               \
00073                 APP_ERROR_CHECK(ERR_CODE);                                                  \
00074             }                                                                               \
00075         }        
00076 #else
00077 #define CRITICAL_REGION_ENTER() critical_region_enter()
00078 #endif
00079 
00080 /**@brief Macro for leaving a critical region.
00081  *
00082  * @note Due to implementation details, there must exist one and only one call to
00083  *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
00084  *       in the same scope.
00085  */
00086 #ifdef SOFTDEVICE_PRESENT
00087 #define CRITICAL_REGION_EXIT()                                                              \
00088         if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH)                                       \
00089         {                                                                                   \
00090             uint32_t ERR_CODE;                                                              \
00091             __enable_irq();                                                                 \
00092             ERR_CODE = sd_nvic_critical_region_exit(IS_NESTED_CRITICAL_REGION);             \
00093             if (ERR_CODE != NRF_ERROR_SOFTDEVICE_NOT_ENABLED)                               \
00094             {                                                                               \
00095                 APP_ERROR_CHECK(ERR_CODE);                                                  \
00096             }                                                                               \
00097         }                                                                                   \
00098     }
00099 #else
00100 #define CRITICAL_REGION_EXIT() critical_region_exit()
00101 #endif 
00102        
00103 /**@brief Function for finding the current interrupt level.
00104  *
00105  * @return   Current interrupt level.
00106  * @retval   APP_IRQ_PRIORITY_HIGH    We are running in Application High interrupt level.
00107  * @retval   APP_IRQ_PRIORITY_LOW     We are running in Application Low interrupt level.
00108  * @retval   APP_IRQ_PRIORITY_THREAD  We are running in Thread Mode.
00109  */
00110 static __INLINE uint8_t current_int_priority_get(void)
00111 {
00112     uint32_t isr_vector_num = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk);
00113     if (isr_vector_num > 0)
00114     {
00115         int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
00116         return (NVIC_GetPriority((IRQn_Type )irq_type) & 0xFF);
00117     }
00118     else
00119     {
00120         return NRF_APP_PRIORITY_THREAD;
00121     }
00122 }
00123 
00124 #endif // APP_UTIL_PLATFORM_H__
00125 
00126 /** @} */