To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

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