テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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