CC13xx Driver Library
[aon_batmon.h] AON Battery Monitor

Functions

static void AONBatMonEnable (void)
 Enable the temperature and battery monitoring. More...
 
static void AONBatMonDisable (void)
 Disable the temperature and battery monitoring. More...
 
int32_t AONBatMonTemperatureGetDegC (void)
 Get the current temperature measurement as a signed value in Deg Celsius. More...
 
static uint32_t AONBatMonBatteryVoltageGet (void)
 Get the battery monitor measurement. More...
 
static bool AONBatMonNewBatteryMeasureReady (void)
 Check if battery monitor measurement has changed. More...
 
static bool AONBatMonNewTempMeasureReady (void)
 Check if temperature monitor measurement has changed. More...
 

Detailed Description

Function Documentation

static uint32_t AONBatMonBatteryVoltageGet ( void  )
inlinestatic

Get the battery monitor measurement.

This function will return the current battery monitor measurement. The battery voltage measurements are updated every cycle.

Note
The returned value is NOT sign-extended!
Use the function AONBatMonNewBatteryMeasureReady() to test for a change in measurement.
Returns
Returns the current battery monitor value of the battery voltage measurement in a <int.frac> format size <3.8> in units of volt.
See also
AONBatMonNewBatteryMeasureReady()
188 {
189  uint32_t ui32CurrentBattery;
190 
191  ui32CurrentBattery = HWREG(AON_BATMON_BASE + AON_BATMON_O_BAT);
192 
193  // Return the current battery voltage measurement.
194  return (ui32CurrentBattery >> AON_BATMON_BAT_FRAC_S);
195 }
static void AONBatMonDisable ( void  )
inlinestatic

Disable the temperature and battery monitoring.

This function will disable the measurements of the temperature and the battery voltage.

Returns
None
143 {
144  // Disable the measurements.
145  HWREG(AON_BATMON_BASE + AON_BATMON_O_CTL) = 0;
146 }
static void AONBatMonEnable ( void  )
inlinestatic

Enable the temperature and battery monitoring.

This function will enable the measurements of the temperature and the battery voltage.

To speed up the measurement of the levels the measurement can be enabled before configuring the battery and temperature settings. When all of the AON_BATMON registers are configured, the calculation of the voltage and temperature values can be enabled (the measurement will now take effect/propagate to other blocks).

It is possible to enable both at the same time, after the AON_BATMON registers are configured, but then the first values will be ready at a later point compared to the scenario above.

Note
Temperature and battery voltage measurements are not done in parallel. The measurement cycle is controlled by a hardware Finite State Machine. First the temperature and then the battery voltage each taking one cycle to complete. However, if the comparator measuring the battery voltage detects a change on the reference value, a new measurement of the battery voltage only is performed immediately after. This has no impact on the cycle count.
Returns
None
124 {
125  // Enable the measurements.
129 }
static bool AONBatMonNewBatteryMeasureReady ( void  )
inlinestatic

Check if battery monitor measurement has changed.

This function checks if a new battery monitor value is available. If the measurement value has changed since last clear the function returns true.

If the measurement has changed the function will automatically clear the status bit.

Note
It is always possible to read out the current value of the battery level using AONBatMonBatteryVoltageGet() but this function can be used to check if the measurement has changed.
Returns
Returns true if the measurement value has changed and false otherwise.
See also
AONBatMonNewTempMeasureReady(), AONBatMonBatteryVoltageGet()
219 {
220  bool bStatus;
221 
222  // Check the status bit.
223  bStatus = HWREG(AON_BATMON_BASE + AON_BATMON_O_BATUPD) &
224  AON_BATMON_BATUPD_STAT ? true : false;
225 
226  // Clear status bit if set.
227  if(bStatus)
228  {
230  }
231 
232  // Return status.
233  return (bStatus);
234 }
static bool AONBatMonNewTempMeasureReady ( void  )
inlinestatic

Check if temperature monitor measurement has changed.

This function checks if a new temperature value is available. If the measurement value has changed since last clear the function returns true.

If the measurement has changed the function will automatically clear the status bit.

Note
It is always possible to read out the current value of the temperature using AONBatMonTemperatureGetDegC() but this function can be used to check if the measurement has changed.
Returns
Returns true if the measurement value has changed and false otherwise.
See also
AONBatMonNewBatteryMeasureReady(), AONBatMonTemperatureGetDegC()
258 {
259  bool bStatus;
260 
261  // Check the status bit.
262  bStatus = HWREG(AON_BATMON_BASE + AON_BATMON_O_TEMPUPD) &
263  AON_BATMON_TEMPUPD_STAT ? true : false;
264 
265  // Clear status bit if set.
266  if(bStatus)
267  {
269  }
270 
271  // Return status.
272  return (bStatus);
273 }
int32_t AONBatMonTemperatureGetDegC ( void  )

Get the current temperature measurement as a signed value in Deg Celsius.

This function returns an calibrated and rounded value in degree Celsius. The temperature measurements are updated every cycle.

Note
The temperature drifts slightly depending on the battery voltage. This function compensates for this drift and returns a calibrated temperature.
Use the function AONBatMonNewTempMeasureReady() to test for a new measurement.
Returns
Returns signed integer part of temperature in Deg C (-256 .. +255)
See also
AONBatMonNewTempMeasureReady()

Referenced by OSCHF_GetStartupTime(), OSCHF_SwitchToRcOscTurnOffXosc(), SysCtrlAdjustRechargeAfterPowerDown(), and SysCtrlSetRechargeBeforePowerDown().

61 {
62  int32_t signedTemp ; // Signed extended temperature with 8 fractional bits
63  int32_t tempCorrection ; // Voltage dependent temp correction with 8 fractional bits
64  int8_t voltageSlope ; // Signed byte value representing the TEMP slope with battery voltage, in degrees C/V, with 4 fractional bits.
65 
66  // Shift left then right to sign extend the BATMON_TEMP field
67  signedTemp = ((((int32_t)HWREG( AON_BATMON_BASE + AON_BATMON_O_TEMP ))
70 
71  // Typecasting voltageSlope to int8_t prior to assignment in order to make sure sign extension works properly
72  // Using byte read (HWREGB) in order to make more efficient code since voltageSlope is assigned to bits[7:0] of FCFG1_O_MISC_TRIM
73  voltageSlope = ((int8_t)HWREGB( FCFG1_BASE + FCFG1_O_MISC_TRIM ));
74  tempCorrection = (( voltageSlope * (((int32_t)HWREG( AON_BATMON_BASE + AON_BATMON_O_BAT )) - 0x300 )) >> 4 );
75 
76  return ((( signedTemp - tempCorrection ) + 0x80 ) >> 8 );
77 }