R1 code for micro:bit based train controller code, requires second micro:bit running rx code to operate - see https://meanderingpi.wordpress.com/ for more information

Fork of nrf51-sdk by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nrf_temp.h Source File

nrf_temp.h

00001 /*
00002  * Copyright (c) Nordic Semiconductor ASA
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without modification,
00006  * are permitted provided that the following conditions are met:
00007  *
00008  *   1. Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  *
00011  *   2. Redistributions in binary form must reproduce the above copyright notice, this
00012  *   list of conditions and the following disclaimer in the documentation and/or
00013  *   other materials provided with the distribution.
00014  *
00015  *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
00016  *   contributors to this software may be used to endorse or promote products
00017  *   derived from this software without specific prior written permission.
00018  *
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00024  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00027  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  */
00032 
00033 #ifndef NRF_TEMP_H__
00034 #define NRF_TEMP_H__
00035 
00036 #include "nrf.h"
00037 
00038 /**
00039 * @defgroup nrf_temperature TEMP (temperature) abstraction
00040 * @{
00041 * @ingroup nrf_drivers temperature_example
00042 * @brief Temperature module init and read functions.
00043 *
00044 */
00045 
00046 /**@cond NO_DOXYGEN */
00047 #define MASK_SIGN           (0x00000200UL)
00048 #define MASK_SIGN_EXTENSION (0xFFFFFC00UL)
00049 
00050 /**
00051  * @brief Function for preparing the temp module for temperature measurement.
00052  *
00053  * This function initializes the TEMP module and writes to the hidden configuration register.
00054  */
00055 static __INLINE void nrf_temp_init(void)
00056 {
00057     /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */
00058     *(uint32_t *) 0x4000C504 = 0;
00059 }
00060 
00061 /**
00062  * @brief Function for reading temperature measurement.
00063  *
00064  * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value.
00065  */
00066 static __INLINE int32_t nrf_temp_read(void)
00067 {    
00068     /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */
00069     return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP);    
00070 }
00071 /**@endcond */
00072 
00073 /** @} */
00074 
00075 #endif