mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Aug 29 17:15:07 2014 +0100
Revision:
304:89b9c3a9a045
Synchronized with git revision 734f365d7da26ef199751f4b0d91611479b495ea

Full URL: https://github.com/mbedmicro/mbed/commit/734f365d7da26ef199751f4b0d91611479b495ea/

1. timestamp_t as an abstraction for time values managed by
Ticker. Using uint64_t for timestamp_t allows a wraparound-free
Ticker. This change forces us to update the definitions of usTicker
for all platforms; but the changes beyond nRF51822 aren't major.

2. reduce power consumption on the nRF51822 by removing the need for
the high-frequency processor timer; and reimplementing it using the
RTC.

I've also replaced high-frequency clock with low-frequency external
clock during system startup of the nRF51822. This brings a major win
in power consumption.

Who changed what in which revision?

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