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