project for nrf51822 qfab
Dependencies: eddystone_URL mbed
Fork of eddystone_URL by
nRF51822/nordic/nrf-sdk/nrf_temp.h@5:267bdacf5508, 2017-11-23 (annotated)
- Committer:
- tridung141196
- Date:
- Thu Nov 23 15:38:48 2017 +0000
- Revision:
- 5:267bdacf5508
- Parent:
- 0:76dfa9657d9d
ibeacon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:76dfa9657d9d | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
jksoft | 0:76dfa9657d9d | 2 | * |
jksoft | 0:76dfa9657d9d | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
jksoft | 0:76dfa9657d9d | 4 | * Terms and conditions of usage are described in detail in NORDIC |
jksoft | 0:76dfa9657d9d | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
jksoft | 0:76dfa9657d9d | 6 | * |
jksoft | 0:76dfa9657d9d | 7 | * Licensees are granted free, non-transferable use of the information. NO |
jksoft | 0:76dfa9657d9d | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
jksoft | 0:76dfa9657d9d | 9 | * the file. |
jksoft | 0:76dfa9657d9d | 10 | * |
jksoft | 0:76dfa9657d9d | 11 | */ |
jksoft | 0:76dfa9657d9d | 12 | |
jksoft | 0:76dfa9657d9d | 13 | #ifndef NRF_TEMP_H__ |
jksoft | 0:76dfa9657d9d | 14 | #define NRF_TEMP_H__ |
jksoft | 0:76dfa9657d9d | 15 | |
jksoft | 0:76dfa9657d9d | 16 | #include "nrf51.h" |
jksoft | 0:76dfa9657d9d | 17 | |
jksoft | 0:76dfa9657d9d | 18 | /** |
jksoft | 0:76dfa9657d9d | 19 | * @defgroup nrf_temperature TEMP (temperature) abstraction |
jksoft | 0:76dfa9657d9d | 20 | * @{ |
jksoft | 0:76dfa9657d9d | 21 | * @ingroup nrf_drivers temperature_example |
jksoft | 0:76dfa9657d9d | 22 | * @brief Temperature module init and read functions. |
jksoft | 0:76dfa9657d9d | 23 | * |
jksoft | 0:76dfa9657d9d | 24 | */ |
jksoft | 0:76dfa9657d9d | 25 | |
jksoft | 0:76dfa9657d9d | 26 | |
jksoft | 0:76dfa9657d9d | 27 | |
jksoft | 0:76dfa9657d9d | 28 | /** |
jksoft | 0:76dfa9657d9d | 29 | * @brief Function for preparing the temp module for temperature measurement. |
jksoft | 0:76dfa9657d9d | 30 | * |
jksoft | 0:76dfa9657d9d | 31 | * This function initializes the TEMP module and writes to the hidden configuration register. |
jksoft | 0:76dfa9657d9d | 32 | * |
jksoft | 0:76dfa9657d9d | 33 | * @param none |
jksoft | 0:76dfa9657d9d | 34 | */ |
jksoft | 0:76dfa9657d9d | 35 | static __INLINE void nrf_temp_init(void) |
jksoft | 0:76dfa9657d9d | 36 | { |
jksoft | 0:76dfa9657d9d | 37 | /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */ |
jksoft | 0:76dfa9657d9d | 38 | *(uint32_t *) 0x4000C504 = 0; |
jksoft | 0:76dfa9657d9d | 39 | } |
jksoft | 0:76dfa9657d9d | 40 | |
jksoft | 0:76dfa9657d9d | 41 | |
jksoft | 0:76dfa9657d9d | 42 | |
jksoft | 0:76dfa9657d9d | 43 | #define MASK_SIGN (0x00000200UL) |
jksoft | 0:76dfa9657d9d | 44 | #define MASK_SIGN_EXTENSION (0xFFFFFC00UL) |
jksoft | 0:76dfa9657d9d | 45 | |
jksoft | 0:76dfa9657d9d | 46 | /** |
jksoft | 0:76dfa9657d9d | 47 | * @brief Function for reading temperature measurement. |
jksoft | 0:76dfa9657d9d | 48 | * |
jksoft | 0:76dfa9657d9d | 49 | * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value. |
jksoft | 0:76dfa9657d9d | 50 | * |
jksoft | 0:76dfa9657d9d | 51 | * @param none |
jksoft | 0:76dfa9657d9d | 52 | */ |
jksoft | 0:76dfa9657d9d | 53 | static __INLINE int32_t nrf_temp_read(void) |
jksoft | 0:76dfa9657d9d | 54 | { |
jksoft | 0:76dfa9657d9d | 55 | /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */ |
jksoft | 0:76dfa9657d9d | 56 | return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP); |
jksoft | 0:76dfa9657d9d | 57 | } |
jksoft | 0:76dfa9657d9d | 58 | |
jksoft | 0:76dfa9657d9d | 59 | /** @} */ |
jksoft | 0:76dfa9657d9d | 60 | |
jksoft | 0:76dfa9657d9d | 61 | #endif |