BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

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