Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:56 2016 +0100
Revision:
28:041dac1366b2
Parent:
20:a90c48eb1d30
Child:
29:286940b7ee5a
Synchronized with git rev 012b8118
Author: Liyou Zhou
Pull in files from sdk 10.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vcoubard 28:041dac1366b2 1 /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
vcoubard 28:041dac1366b2 2 *
vcoubard 28:041dac1366b2 3 * The information contained herein is property of Nordic Semiconductor ASA.
vcoubard 28:041dac1366b2 4 * Terms and conditions of usage are described in detail in NORDIC
vcoubard 28:041dac1366b2 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
vcoubard 28:041dac1366b2 6 *
vcoubard 28:041dac1366b2 7 * Licensees are granted free, non-transferable use of the information. NO
vcoubard 28:041dac1366b2 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
vcoubard 28:041dac1366b2 9 * the file.
vcoubard 28:041dac1366b2 10 *
Vincent Coubard 0:f2542974c862 11 */
Vincent Coubard 0:f2542974c862 12
Vincent Coubard 0:f2542974c862 13 /**@file
Vincent Coubard 0:f2542974c862 14 *
Vincent Coubard 0:f2542974c862 15 * @defgroup app_util_platform Utility Functions and Definitions (Platform)
Vincent Coubard 0:f2542974c862 16 * @{
Vincent Coubard 0:f2542974c862 17 * @ingroup app_common
Vincent Coubard 0:f2542974c862 18 *
Vincent Coubard 0:f2542974c862 19 * @brief Various types and definitions available to all applications when using SoftDevice.
Vincent Coubard 0:f2542974c862 20 */
Vincent Coubard 0:f2542974c862 21
Vincent Coubard 0:f2542974c862 22 #ifndef APP_UTIL_PLATFORM_H__
Vincent Coubard 0:f2542974c862 23 #define APP_UTIL_PLATFORM_H__
Vincent Coubard 0:f2542974c862 24
Vincent Coubard 0:f2542974c862 25 #include <stdint.h>
Vincent Coubard 0:f2542974c862 26 #include "compiler_abstraction.h"
vcoubard 28:041dac1366b2 27 #include "nrf.h"
Vincent Coubard 0:f2542974c862 28 #ifdef SOFTDEVICE_PRESENT
Vincent Coubard 0:f2542974c862 29 #include "nrf_soc.h"
Vincent Coubard 0:f2542974c862 30 #include "app_error.h"
Vincent Coubard 0:f2542974c862 31 #endif
Vincent Coubard 0:f2542974c862 32 /**@brief The interrupt priorities available to the application while the SoftDevice is active. */
Vincent Coubard 0:f2542974c862 33 typedef enum
Vincent Coubard 0:f2542974c862 34 {
Vincent Coubard 0:f2542974c862 35 #ifndef SOFTDEVICE_PRESENT
Vincent Coubard 0:f2542974c862 36 APP_IRQ_PRIORITY_HIGHEST = 0,
Vincent Coubard 0:f2542974c862 37 #endif
Vincent Coubard 0:f2542974c862 38 APP_IRQ_PRIORITY_HIGH = 1,
Vincent Coubard 0:f2542974c862 39 #ifndef SOFTDEVICE_PRESENT
Vincent Coubard 0:f2542974c862 40 APP_IRQ_PRIORITY_MID = 2,
Vincent Coubard 0:f2542974c862 41 #endif
Vincent Coubard 0:f2542974c862 42 APP_IRQ_PRIORITY_LOW = 3
Vincent Coubard 0:f2542974c862 43 } app_irq_priority_t;
Vincent Coubard 0:f2542974c862 44
Vincent Coubard 0:f2542974c862 45 #define NRF_APP_PRIORITY_THREAD 4 /**< "Interrupt level" when running in Thread Mode. */
Vincent Coubard 0:f2542974c862 46
Vincent Coubard 0:f2542974c862 47 /**@cond NO_DOXYGEN */
Vincent Coubard 0:f2542974c862 48 #define EXTERNAL_INT_VECTOR_OFFSET 16
Vincent Coubard 0:f2542974c862 49 /**@endcond */
Vincent Coubard 0:f2542974c862 50
Vincent Coubard 0:f2542974c862 51 #define PACKED(TYPE) __packed TYPE
Vincent Coubard 0:f2542974c862 52
Vincent Coubard 0:f2542974c862 53 void critical_region_enter (void);
Vincent Coubard 0:f2542974c862 54 void critical_region_exit (void);
Vincent Coubard 0:f2542974c862 55
Vincent Coubard 0:f2542974c862 56 /**@brief Macro for entering a critical region.
Vincent Coubard 0:f2542974c862 57 *
Vincent Coubard 0:f2542974c862 58 * @note Due to implementation details, there must exist one and only one call to
Vincent Coubard 0:f2542974c862 59 * CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
Vincent Coubard 0:f2542974c862 60 * in the same scope.
Vincent Coubard 0:f2542974c862 61 */
Vincent Coubard 0:f2542974c862 62 #ifdef SOFTDEVICE_PRESENT
Vincent Coubard 0:f2542974c862 63 #define CRITICAL_REGION_ENTER() \
Vincent Coubard 0:f2542974c862 64 { \
Vincent Coubard 0:f2542974c862 65 uint8_t IS_NESTED_CRITICAL_REGION = 0; \
Vincent Coubard 0:f2542974c862 66 uint32_t CURRENT_INT_PRI = current_int_priority_get(); \
Vincent Coubard 0:f2542974c862 67 if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH) \
Vincent Coubard 0:f2542974c862 68 { \
Vincent Coubard 0:f2542974c862 69 uint32_t ERR_CODE = sd_nvic_critical_region_enter(&IS_NESTED_CRITICAL_REGION); \
Vincent Coubard 0:f2542974c862 70 if (ERR_CODE == NRF_ERROR_SOFTDEVICE_NOT_ENABLED) \
Vincent Coubard 0:f2542974c862 71 { \
Vincent Coubard 0:f2542974c862 72 __disable_irq(); \
Vincent Coubard 0:f2542974c862 73 } \
Vincent Coubard 0:f2542974c862 74 else \
Vincent Coubard 0:f2542974c862 75 { \
Vincent Coubard 0:f2542974c862 76 APP_ERROR_CHECK(ERR_CODE); \
Vincent Coubard 0:f2542974c862 77 } \
Vincent Coubard 0:f2542974c862 78 }
Vincent Coubard 0:f2542974c862 79 #else
Vincent Coubard 0:f2542974c862 80 #define CRITICAL_REGION_ENTER() critical_region_enter()
Vincent Coubard 0:f2542974c862 81 #endif
Vincent Coubard 0:f2542974c862 82
Vincent Coubard 0:f2542974c862 83 /**@brief Macro for leaving a critical region.
Vincent Coubard 0:f2542974c862 84 *
Vincent Coubard 0:f2542974c862 85 * @note Due to implementation details, there must exist one and only one call to
Vincent Coubard 0:f2542974c862 86 * CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
Vincent Coubard 0:f2542974c862 87 * in the same scope.
Vincent Coubard 0:f2542974c862 88 */
Vincent Coubard 0:f2542974c862 89 #ifdef SOFTDEVICE_PRESENT
Vincent Coubard 0:f2542974c862 90 #define CRITICAL_REGION_EXIT() \
Vincent Coubard 0:f2542974c862 91 if (CURRENT_INT_PRI != APP_IRQ_PRIORITY_HIGH) \
Vincent Coubard 0:f2542974c862 92 { \
Vincent Coubard 0:f2542974c862 93 uint32_t ERR_CODE; \
Vincent Coubard 0:f2542974c862 94 __enable_irq(); \
Vincent Coubard 0:f2542974c862 95 ERR_CODE = sd_nvic_critical_region_exit(IS_NESTED_CRITICAL_REGION); \
Vincent Coubard 0:f2542974c862 96 if (ERR_CODE != NRF_ERROR_SOFTDEVICE_NOT_ENABLED) \
Vincent Coubard 0:f2542974c862 97 { \
Vincent Coubard 0:f2542974c862 98 APP_ERROR_CHECK(ERR_CODE); \
Vincent Coubard 0:f2542974c862 99 } \
Vincent Coubard 0:f2542974c862 100 } \
Vincent Coubard 0:f2542974c862 101 }
Vincent Coubard 0:f2542974c862 102 #else
Vincent Coubard 0:f2542974c862 103 #define CRITICAL_REGION_EXIT() critical_region_exit()
Vincent Coubard 0:f2542974c862 104 #endif
Vincent Coubard 0:f2542974c862 105
Vincent Coubard 0:f2542974c862 106 /**@brief Function for finding the current interrupt level.
Vincent Coubard 0:f2542974c862 107 *
Vincent Coubard 0:f2542974c862 108 * @return Current interrupt level.
Vincent Coubard 0:f2542974c862 109 * @retval APP_IRQ_PRIORITY_HIGH We are running in Application High interrupt level.
Vincent Coubard 0:f2542974c862 110 * @retval APP_IRQ_PRIORITY_LOW We are running in Application Low interrupt level.
Vincent Coubard 0:f2542974c862 111 * @retval APP_IRQ_PRIORITY_THREAD We are running in Thread Mode.
Vincent Coubard 0:f2542974c862 112 */
Vincent Coubard 0:f2542974c862 113 static __INLINE uint8_t current_int_priority_get(void)
Vincent Coubard 0:f2542974c862 114 {
Vincent Coubard 0:f2542974c862 115 uint32_t isr_vector_num = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk);
Vincent Coubard 0:f2542974c862 116 if (isr_vector_num > 0)
Vincent Coubard 0:f2542974c862 117 {
Vincent Coubard 0:f2542974c862 118 int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET);
Vincent Coubard 0:f2542974c862 119 return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF);
Vincent Coubard 0:f2542974c862 120 }
Vincent Coubard 0:f2542974c862 121 else
Vincent Coubard 0:f2542974c862 122 {
Vincent Coubard 0:f2542974c862 123 return NRF_APP_PRIORITY_THREAD;
Vincent Coubard 0:f2542974c862 124 }
Vincent Coubard 0:f2542974c862 125 }
Vincent Coubard 0:f2542974c862 126
Vincent Coubard 0:f2542974c862 127 #endif // APP_UTIL_PLATFORM_H__
Vincent Coubard 0:f2542974c862 128
vcoubard 1:ebc0e0ef0a11 129 /** @} */