konashi/SBBLEのテスト

Dependencies:   BLE_API mbed

Fork of BLE_LoopbackUART by Bluetooth Low Energy

Committer:
robo8080
Date:
Sun Aug 17 00:53:23 2014 +0000
Revision:
8:a62b8f7d5dcf
Parent:
5:61109bce11fe
DeviceName??

Who changed what in which revision?

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