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