BSPACM  20150113
Board Support Package for ARM Cortex-M Microcontrollers
dietemp.h
Go to the documentation of this file.
1 /* Copyright 2015, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef BSPACM_DEVICE_NRF51_INTERNAL_PERIPH_DIETEMP_H
33 #define BSPACM_DEVICE_NRF51_INTERNAL_PERIPH_DIETEMP_H
34 
35 #include <bspacm/core.h>
36 
53 bool
55 
56 #if (BSPACM_NRF_USE_SD - 0)
57 __STATIC_INLINE
58 #else /* BSPACM_NRF_USE_SD */
59 inline
60 #endif /* BSPACM_NRF_USE_SD */
61 int
62 iBSPACMdietemp_cCel ()
63 {
64  int32_t temp_qCel;
65 #if (BSPACM_NRF_USE_SD - 0)
66  sd_temp_get(&temp_qCel);
67 #else /* BSPACM_NRF_USE_SD */
68  NRF_TEMP->EVENTS_DATARDY = 0;
69 
70  NRF_TEMP->TASKS_START = 1;
71  while (! NRF_TEMP->EVENTS_DATARDY) {
72  }
73  NRF_TEMP->EVENTS_DATARDY = 0;
74 
75  /* PAN-29: STOP task clears TEMP register */
76  uint32_t temp_raw = NRF_TEMP->TEMP;
77 
78  /* PAN-30: TEMP module analog front end does not power down when
79  * DATARDY event occurs */
80  NRF_TEMP->TASKS_STOP = 1;
81 
82  /* PAN-28: Negative measured values are not represented correctly.
83  * Sign extension does not go higher than bit 9.
84  *
85  * Value is 10-bit 2's complement. Convert to 32-bit 2's
86  * complement. */
87  const uint32_t sign_bit = 0x0200;
88  if (temp_raw & sign_bit) {
89  temp_raw |= ~(sign_bit - 1);
90  }
91  temp_qCel = (int32_t)temp_raw;
92 #endif /* BSPACM_NRF_USE_SD */
93 
94  return 25 * (int)temp_qCel;
95 }
96 
97 #endif /* BSPACM_DEVICE_NRF51_INTERNAL_PERIPH_DIETEMP_H */
Common header included by all BSPACM leaf headers.
bool bBSPACMdietempInitialize()