CC26xx Driver Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
aon_batmon.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: aon_batmon.h
3 * Revised: 2015-01-14 12:12:44 +0100 (on, 14 jan 2015)
4 * Revision: 42373
5 *
6 * Description: Defines and prototypes for the AON Battery and Temperature
7 * Monitor
8 *
9 * Copyright (c) 2015, Texas Instruments Incorporated
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1) Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 *
18 * 2) Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 *
22 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
23 * be used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 ******************************************************************************/
39 
40 //*****************************************************************************
41 //
44 //
45 //*****************************************************************************
46 
47 #ifndef __AON_BATMON_H__
48 #define __AON_BATMON_H__
49 
50 //*****************************************************************************
51 //
52 // If building with a C++ compiler, make all of the definitions in this header
53 // have a C binding.
54 //
55 //*****************************************************************************
56 #ifdef __cplusplus
57 extern "C"
58 {
59 #endif
60 
61 #include <stdbool.h>
62 #include <stdint.h>
63 #include <inc/hw_types.h>
64 #include <inc/hw_memmap.h>
65 #include <inc/hw_aon_batmon.h>
66 #include <driverlib/debug.h>
67 
68 //*****************************************************************************
69 //
70 // Values that can be passed to the AONBatMonMeasurementCycleSet() for setting
71 // the measurement cycle.
72 //
73 //*****************************************************************************
74 #define AON_BATMON_CYCLE_32 AON_BATMON_MEASCFG_PER_32CYC // 32 Clock cycles between
75  // each measurement.
76 #define AON_BATMON_CYCLE_16 AON_BATMON_MEASCFG_PER_16CYC // 16 Clock cycles between
77  // each measurement.
78 #define AON_BATMON_CYCLE_8 AON_BATMON_MEASCFG_PER_8CYC // 8 Clock cycles between
79  // each measurement.
80 #define AON_BATMON_CYCLE_CONT AON_BATMON_MEASCFG_PER_CONT // Continouos measurement
81 
82 //*****************************************************************************
83 //
84 // API Functions and prototypes
85 //
86 //*****************************************************************************
87 
88 //*****************************************************************************
89 //
114 //
115 //*****************************************************************************
116 __STATIC_INLINE void
118 {
119  //
120  // Enable the measurements.
121  //
125 }
126 
127 //*****************************************************************************
128 //
135 //
136 //*****************************************************************************
137 __STATIC_INLINE void
139 {
140  //
141  // Disable the measurements.
142  //
143  HWREG(AON_BATMON_BASE + AON_BATMON_O_CTL) = 0;
144 }
145 
146 //*****************************************************************************
147 //
164 //
165 //*****************************************************************************
166 __STATIC_INLINE void
167 AONBatMonMeasurementCycleSet(uint32_t ui32Cycle)
168 {
169  //
170  // Check the arguments.
171  //
172  ASSERT(ui32Cycle == AON_BATMON_CYCLE_32 ||
173  ui32Cycle == AON_BATMON_CYCLE_16 ||
174  ui32Cycle == AON_BATMON_CYCLE_8 ||
175  ui32Cycle == AON_BATMON_CYCLE_CONT);
176 
177  //
178  // Set the measurement cycle.
179  //
180  HWREG(AON_BATMON_BASE + AON_BATMON_O_MEASCFG) = ui32Cycle;
181 }
182 
183 //*****************************************************************************
184 //
193 //
194 //*****************************************************************************
195 __STATIC_INLINE uint32_t
197 {
198  //
199  // Return the current measurement cycle.
200  //
201  return (HWREG(AON_BATMON_BASE + AON_BATMON_O_MEASCFG));
202 }
203 
204 //*****************************************************************************
205 //
213 
220 //
228 //*****************************************************************************
229 __STATIC_INLINE void
230 AONBatMonBatteryTrimSet(uint32_t ui32TrimP0, uint32_t ui32TrimP1)
231 {
232  //
233  // Check the arguments.
234  //
235  ASSERT(ui32TrimP0 <= AON_BATMON_BATMONP0_CFG_M ||
236  ui32TrimP1 <= AON_BATMON_BATMONP1_CFG_M);
237 
238  //
239  // Set the trim values.
240  //
241  HWREG(AON_BATMON_BASE + AON_BATMON_O_BATMONP0) = ui32TrimP0;
242  HWREG(AON_BATMON_BASE + AON_BATMON_O_BATMONP1) = ui32TrimP1;
243 }
244 
245 //*****************************************************************************
246 //
255 
262 //
271 //*****************************************************************************
272 __STATIC_INLINE void
273 AONBatMonTemperatureTrimSet(uint32_t ui32TrimP0, uint32_t ui32TrimP1,
274  uint32_t ui32TrimP2)
275 {
276  //
277  // Check the arguments.
278  //
279  ASSERT(ui32TrimP0 < AON_BATMON_TEMPP0_CFG_M ||
280  ui32TrimP1 < AON_BATMON_TEMPP1_CFG_M ||
281  ui32TrimP2 < AON_BATMON_TEMPP2_CFG_M);
282 
283  //
284  // Set the trim values
285  //
286  HWREG(AON_BATMON_BASE + AON_BATMON_O_TEMPP0) = ui32TrimP0;
287  HWREG(AON_BATMON_BASE + AON_BATMON_O_TEMPP1) = ui32TrimP1;
288  HWREG(AON_BATMON_BASE + AON_BATMON_O_TEMPP2) = ui32TrimP2;
289 }
290 
291 //*****************************************************************************
292 //
312 //
313 //*****************************************************************************
314 __STATIC_INLINE uint32_t
316 {
317  uint32_t ui32CurrentTemp;
318 
319  ui32CurrentTemp = HWREG(AON_BATMON_BASE + AON_BATMON_O_TEMP);
320 
321  //
322  // Return the current temperature measurement.
323  //
324  return (ui32CurrentTemp >> AON_BATMON_TEMP_FRAC_S);
325 }
326 
327 //*****************************************************************************
328 //
342 //
343 //*****************************************************************************
344 int32_t
345 AON_BatmonTempGetDegC( void );
346 
347 //*****************************************************************************
348 //
364 //
365 //*****************************************************************************
366 __STATIC_INLINE uint32_t
368 {
369  uint32_t ui32CurrentBattery;
370 
371  ui32CurrentBattery = HWREG(AON_BATMON_BASE + AON_BATMON_O_BAT);
372 
373  //
374  // Return the current battery voltage measurement.
375  //
376  return (ui32CurrentBattery >> AON_BATMON_BAT_FRAC_S);
377 }
378 
379 //*****************************************************************************
380 //
397 //
398 //*****************************************************************************
399 __STATIC_INLINE bool
401 {
402  bool bStatus;
403 
404  //
405  // Check the status bit.
406  //
407  bStatus = HWREG(AON_BATMON_BASE + AON_BATMON_O_BATUPD) &
408  AON_BATMON_BATUPD_STAT ? true : false;
409 
410  //
411  // Clear status bit if set.
412  //
413  if(bStatus)
414  {
416  }
417 
418  //
419  // Return status.
420  //
421  return (bStatus);
422 }
423 
424 //*****************************************************************************
425 //
442 //
443 //*****************************************************************************
444 __STATIC_INLINE bool
446 {
447  bool bStatus;
448 
449  //
450  // Check the status bit.
451  //
452  bStatus = HWREG(AON_BATMON_BASE + AON_BATMON_O_TEMPUPD) &
453  AON_BATMON_TEMPUPD_STAT ? true : false;
454 
455  //
456  // Clear status bit if set.
457  //
458  if(bStatus)
459  {
461  }
462 
463  //
464  // Return status.
465  //
466  return (bStatus);
467 }
468 
469 //*****************************************************************************
470 //
471 // Mark the end of the C bindings section for C++ compilers.
472 //
473 //*****************************************************************************
474 #ifdef __cplusplus
475 }
476 #endif
477 
478 #endif // __AON_BATMON_H__
479 
480 //*****************************************************************************
481 //
484 //
485 //*****************************************************************************
__STATIC_INLINE uint32_t AONBatMonTemperatureGet(void)
Get the current temperature measurement.
Definition: aon_batmon.h:315
__STATIC_INLINE uint32_t AONBatMonMeasurementCycleGet(void)
Get the measurement cycle for the temperature and the battery voltage.
Definition: aon_batmon.h:196
#define AON_BATMON_CYCLE_32
Definition: aon_batmon.h:74
#define ASSERT(expr)
Definition: debug.h:65
__STATIC_INLINE void AONBatMonDisable(void)
Disable the temperatur and battery monitoring.
Definition: aon_batmon.h:138
#define AON_BATMON_CYCLE_16
Definition: aon_batmon.h:76
int32_t AON_BatmonTempGetDegC(void)
Get the current temperature measurement as a signed value in Deg Celsius.
Definition: aon_batmon.c:55
__STATIC_INLINE void AONBatMonBatteryTrimSet(uint32_t ui32TrimP0, uint32_t ui32TrimP1)
Set the trim values for the battery voltage calculation.
Definition: aon_batmon.h:230
__STATIC_INLINE bool AONBatMonNewTempMeasureReady(void)
Check if temperature monitor measurement has changed.
Definition: aon_batmon.h:445
__STATIC_INLINE void AONBatMonEnable(void)
Enable the temperatur and battery monitoring.
Definition: aon_batmon.h:117
__STATIC_INLINE bool AONBatMonNewBatteryMeasureReady(void)
Check if battery monitor measurement has changed.
Definition: aon_batmon.h:400
#define AON_BATMON_CYCLE_8
Definition: aon_batmon.h:78
__STATIC_INLINE void AONBatMonMeasurementCycleSet(uint32_t ui32Cycle)
Adjust the measurement cycle for the temperature and the battery voltage.
Definition: aon_batmon.h:167
__STATIC_INLINE void AONBatMonTemperatureTrimSet(uint32_t ui32TrimP0, uint32_t ui32TrimP1, uint32_t ui32TrimP2)
Set the trim values for the temperature calculation.
Definition: aon_batmon.h:273
__STATIC_INLINE uint32_t AONBatMonBatteryVoltageGet(void)
Get the battery monitor measurement.
Definition: aon_batmon.h:367
#define AON_BATMON_CYCLE_CONT
Definition: aon_batmon.h:80