CC26xx Driver Library
[sys_ctrl] System Controller

Functions

static uint32_t SysCtrlClockGet (void)
 Get the CPU core clock frequency. More...
 
static void SysCtrlAonSync (void)
 Sync all accesses to the AON register interface. More...
 
static void SysCtrlAonUpdate (void)
 Update all interfaces to AON. More...
 
void SysCtrlSetRechargeBeforePowerDown (uint32_t xoscPowerMode)
 Set Recharge values before entering Power Down. More...
 
void SysCtrlAdjustRechargeAfterPowerDown (void)
 Adjust Recharge calculations to be used next. More...
 
void SysCtrl_DCDC_VoltageConditionalControl (void)
 Turns DCDC on or off depending of what is considered to be optimal usage. More...
 
uint32_t SysCtrlResetSourceGet (void)
 Returns last reset source (including "wakeup from shutdown"). More...
 
static void SysCtrlSystemReset (void)
 Perform a full system reset. More...
 
static void SysCtrlClockLossResetEnable (void)
 Enables reset if OSC clock loss event is asserted. More...
 
static void SysCtrlClockLossResetDisable (void)
 Disables reset due to OSC clock loss event. More...
 
#define RSTSRC_PWR_ON   (( AON_SYSCTL_RESETCTL_RESET_SRC_PWR_ON ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_PIN_RESET   (( AON_SYSCTL_RESETCTL_RESET_SRC_PIN_RESET ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_VDDS_LOSS   (( AON_SYSCTL_RESETCTL_RESET_SRC_VDDS_LOSS ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_VDD_LOSS   (( AON_SYSCTL_RESETCTL_RESET_SRC_VDD_LOSS ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_VDDR_LOSS   (( AON_SYSCTL_RESETCTL_RESET_SRC_VDDR_LOSS ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_CLK_LOSS   (( AON_SYSCTL_RESETCTL_RESET_SRC_CLK_LOSS ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_SYSRESET   (( AON_SYSCTL_RESETCTL_RESET_SRC_SYSRESET ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_WARMRESET   (( AON_SYSCTL_RESETCTL_RESET_SRC_WARMRESET ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S ))
 
#define RSTSRC_WAKEUP_FROM_SHUTDOWN   ((( AON_SYSCTL_RESETCTL_RESET_SRC_M ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S )) + 1 )
 

Detailed Description

Function Documentation

void SysCtrl_DCDC_VoltageConditionalControl ( void  )

Turns DCDC on or off depending of what is considered to be optimal usage.

This function controls the DCDC only if both the following CCFG settings are true:

  • DCDC is configured to be used.
  • Alternative DCDC settings are defined and enabled.

The DCDC is configured in accordance to the CCFG settings when turned on.

This function should be called periodically.

Returns
None
346 {
347  uint32_t batThreshold ; // Fractional format with 8 fractional bits.
348  uint32_t aonBatmonBat ; // Fractional format with 8 fractional bits.
349  uint32_t ccfg_ModeConfReg ; // Holds a copy of the CCFG_O_MODE_CONF register.
350  uint32_t aonSysctlPwrctl ; // Reflect whats read/written to the AON_SYSCTL_O_PWRCTL register.
351 
352  // We could potentially call this function before any battery voltage measurement
353  // is made/available. In that case we must make sure that we do not turn off the DCDC.
354  // This can be done by doing nothing as long as the battery voltage is 0 (Since the
355  // reset value of the battery voltage register is 0).
356  aonBatmonBat = HWREG( AON_BATMON_BASE + AON_BATMON_O_BAT );
357  if ( aonBatmonBat != 0 ) {
358  // Check if Voltage Conditional Control is enabled
359  // It is enabled if all the following are true:
360  // - DCDC in use (either in active or recharge mode), (in use if one of the corresponding CCFG bits are zero).
361  // - Alternative DCDC settings are enabled ( DIS_ALT_DCDC_SETTING == 0 )
362  // - Not in external regulator mode ( EXT_REG_MODE == 0 )
363  ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
364 
365  if (((( ccfg_ModeConfReg & CCFG_MODE_CONF_DCDC_RECHARGE_M ) == 0 ) ||
366  (( ccfg_ModeConfReg & CCFG_MODE_CONF_DCDC_ACTIVE_M ) == 0 ) ) &&
369  {
370  aonSysctlPwrctl = HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_PWRCTL );
371  batThreshold = (((( HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 ) &
373  CCFG_MODE_CONF_1_ALT_DCDC_VMIN_S ) + 28 ) << 4 );
374 
375  if ( aonSysctlPwrctl & ( AON_SYSCTL_PWRCTL_DCDC_EN_M | AON_SYSCTL_PWRCTL_DCDC_ACTIVE_M )) {
376  // DCDC is ON, check if it should be switched off
377  if ( aonBatmonBat < batThreshold ) {
379 
380  HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_PWRCTL ) = aonSysctlPwrctl;
381  }
382  } else {
383  // DCDC is OFF, check if it should be switched on
384  if ( aonBatmonBat > batThreshold ) {
385  if (( ccfg_ModeConfReg & CCFG_MODE_CONF_DCDC_RECHARGE_M ) == 0 ) aonSysctlPwrctl |= AON_SYSCTL_PWRCTL_DCDC_EN_M ;
386  if (( ccfg_ModeConfReg & CCFG_MODE_CONF_DCDC_ACTIVE_M ) == 0 ) aonSysctlPwrctl |= AON_SYSCTL_PWRCTL_DCDC_ACTIVE_M ;
387 
388  HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_PWRCTL ) = aonSysctlPwrctl;
389  }
390  }
391  }
392  }
393 }
void SysCtrlAdjustRechargeAfterPowerDown ( void  )

Adjust Recharge calculations to be used next.

This function shall be called just after returning from Power Down.

Reads the results from the adaptive recharge controller and current chip temperature. This is used as additional information when calculating optimal recharge controller settings next time (When SysCtrlSetRechargeBeforePowerDown() is called next time).

Note
Special care must be taken to make sure that the AON registers read are updated after the wakeup. Writing to an AON register and then calling SysCtrlAonSync() will handle this.
Returns
None
299 {
300  int32_t curTemp ;
301  uint32_t longestRechargePeriod ;
302  uint32_t deltaTime ;
303  uint32_t newRechargePeriod ;
304 
305  //--- Spec. point 2 ---
306  longestRechargePeriod = ( HWREG( AON_WUC_BASE + AON_WUC_O_RECHARGESTAT ) &
309 
310  if ( longestRechargePeriod != 0 ) {
311  //--- Spec. changed (originaly point 1) ---
312  curTemp = AONBatMonTemperatureGetDegC();
313  if ( curTemp < powerQualGlobals.pdTemp ) {
314  if ( curTemp < -128 ) {
315  curTemp = -128;
316  }
317  powerQualGlobals.pdTemp = curTemp;
318  }
319 
320  //--- Spec. point 4 ---
321  if ( longestRechargePeriod < powerQualGlobals.pdRechargePeriod ) {
322  powerQualGlobals.pdRechargePeriod = longestRechargePeriod;
323  } else {
324  //--- Spec. point 5 ---
325  deltaTime = HWREG( AON_RTC_BASE + AON_RTC_O_SEC ) - powerQualGlobals.pdTime + 2;
326  if ( deltaTime > 31 ) {
327  deltaTime = 31;
328  }
329  newRechargePeriod = powerQualGlobals.pdRechargePeriod + (( longestRechargePeriod - powerQualGlobals.pdRechargePeriod ) >> (deltaTime>>1));
330  if ( newRechargePeriod > 0xFFFF ) {
331  newRechargePeriod = 0xFFFF;
332  }
333  powerQualGlobals.pdRechargePeriod = newRechargePeriod;
334  }
335  }
336 }
int8_t pdTemp
Definition: sys_ctrl.c:80
int32_t AONBatMonTemperatureGetDegC(void)
Get the current temperature measurement as a signed value in Deg Celsius.
Definition: aon_batmon.c:60
static PowerQualGlobals_t powerQualGlobals
Definition: sys_ctrl.c:83
uint32_t pdTime
Definition: sys_ctrl.c:77
uint16_t pdRechargePeriod
Definition: sys_ctrl.c:78

Here is the call graph for this function:

static void SysCtrlAonSync ( void  )
inlinestatic

Sync all accesses to the AON register interface.

When this function returns, all writes to the AON register interface are guaranteed to have propagated to hardware. The function will return immediately if no AON writes are pending; otherwise, it will wait for the next AON clock before returning.

Returns
None
See also
SysCtrlAonUpdate()

Referenced by SetupAfterColdResetWakeupFromShutDownCfg3().

178 {
179  // Sync the AON interface
180  HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
181 }
static void SysCtrlAonUpdate ( void  )
inlinestatic

Update all interfaces to AON.

When this function returns, at least 1 clock cycle has progressed on the AON domain, so that any outstanding updates to and from the AON interface is guaranteed to be in sync.

Note
This function should primarily be used after wakeup from sleep modes, as it will guarantee that all shadow registers on the AON interface are updated before reading any AON registers from the MCU domain. If a write has been done to the AON interface it is sufficient to call the SysCtrlAonSync().
Returns
None
See also
SysCtrlAonSync()
203 {
204  // Force a clock cycle on the AON interface to guarantee all registers are
205  // in sync.
206  HWREG(AON_RTC_BASE + AON_RTC_O_SYNC) = 1;
207  HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
208 }
static uint32_t SysCtrlClockGet ( void  )
inlinestatic

Get the CPU core clock frequency.

Use this function to get the current clock frequency for the CPU.

The CPU can run from 48 MHz and down to 750kHz. The frequency is defined by the combined division factor of the SYSBUS and the CPU clock divider.

Returns
Returns the current CPU core clock frequency.
157 {
158  // Return fixed clock speed
159  return( GET_MCU_CLOCK );
160 }
static void SysCtrlClockLossResetDisable ( void  )
inlinestatic

Disables reset due to OSC clock loss event.

Note
This function shall typically not be called because the clock loss reset functionality is controlled by the boot code (a factory configuration defines whether it is set or not).
Returns
None
See also
SysCtrlClockLossResetEnable()
360 {
361  // Clear clock loss enable bit in AON_SYSCTRL using bit banding
363 }
static void SysCtrlClockLossResetEnable ( void  )
inlinestatic

Enables reset if OSC clock loss event is asserted.

Clock loss circuit in analog domain must be enabled as well in order to actually enable for a clock loss reset to occur OSCClockLossEventEnable().

Note
This function shall typically not be called because the clock loss reset functionality is controlled by the boot code (a factory configuration defines whether it is set or not).
Returns
None
See also
SysCtrlClockLossResetDisable(), OSCClockLossEventEnable()
340 {
341  // Set clock loss enable bit in AON_SYSCTRL using bit banding
343 }
uint32_t SysCtrlResetSourceGet ( void  )

Returns last reset source (including "wakeup from shutdown").

Returns
Returns one of the RSTSRC_ defines.
403 {
405  return ( RSTSRC_WAKEUP_FROM_SHUTDOWN );
406  } else {
407  return (( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
410  }
411 }
#define RSTSRC_WAKEUP_FROM_SHUTDOWN
Definition: sys_ctrl.h:289
void SysCtrlSetRechargeBeforePowerDown ( uint32_t  xoscPowerMode)

Set Recharge values before entering Power Down.

This function shall be called just before entering Power Down. It calculates an optimal and safe recharge setting of the adaptive recharge controller. The results of previous setting are also taken into account.

Note
In order to make sure that the register writes are completed, SysCtrlAonSync() must be called before entering standby/power down. This is not done internally in this function due to two reasons:
  • 1) There might be other register writes that must be synchronized as well.
  • 2) It is possible to save some time by doing other things before calling SysCtrlAonSync() since this call will not return before there are no outstanding write requests between MCU and AON.
Parameters
xoscPowerMode(typically running in XOSC_IN_HIGH_POWER_MODE all the time).
Returns
None
93 {
94  int32_t curTemp ;
95  int32_t shiftedTemp ;
96  int32_t deltaVddrSleepTrim ;
97  int32_t vddrTrimSleep ;
98  int32_t vddrTrimActve ;
99  int32_t diffVddrActiveSleep ;
100  uint32_t ccfg_ModeConfReg ;
101  uint32_t curState ;
102  uint32_t prcmRamRetention ;
103  uint32_t di ;
104  uint32_t dii ;
105  uint32_t ti ;
106  uint32_t cd ;
107  uint32_t cl ;
108  uint32_t load ;
109  uint32_t k ;
110  uint32_t vddrCap ;
111  uint32_t newRechargePeriod ;
112  uint32_t perE ;
113  uint32_t perM ;
114  const uint32_t * pLookupTable ;
115 
116  // If external regulator mode we shall:
117  // - Disable adaptive recharge (bit[31]=0) in AON_WUC_O_RECHARGECFG
118  // - Set recharge period to approximately 500 mS (perM=31, perE=5 => 0xFD)
119  // - Make sure you get a recalculation if leaving external regulator mode by setting powerQualGlobals.pdState accordingly
122  HWREG( AON_WUC_BASE + AON_WUC_O_RECHARGECFG ) = 0x00A4FDFD;
123  return;
124  }
125 
126  //--- Spec. point 1 ---
127  curTemp = AONBatMonTemperatureGetDegC();
128  curState = 0;
129 
130  // read the MODE_CONF register in CCFG
131  ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
132  // Get VDDR_TRIM_SLEEP_DELTA + 1 (sign extended)
133  deltaVddrSleepTrim = ((((int32_t) ccfg_ModeConfReg )
136  // Do temperature compensation if enabled
137  if (( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDR_TRIM_SLEEP_TC ) == 0 ) {
138  int32_t tcDelta = ( 62 - curTemp ) >> 3;
139  if ( tcDelta > 8 ) tcDelta = 8;
140  if ( tcDelta > deltaVddrSleepTrim ) deltaVddrSleepTrim = tcDelta;
141  }
142  {
143  vddrTrimSleep = SetupSignExtendVddrTrimValue((
144  HWREG( FCFG1_BASE + FCFG1_O_LDO_TRIM ) &
147  vddrTrimActve = SetupSignExtendVddrTrimValue((
148  HWREG( FCFG1_BASE + FCFG1_O_SHDW_ANA_TRIM ) &
151  }
152  vddrTrimSleep += deltaVddrSleepTrim;
153  if ( vddrTrimSleep > 21 ) vddrTrimSleep = 21;
154  if ( vddrTrimSleep < -10 ) vddrTrimSleep = -10;
155  // Write adjusted value using MASKED write (MASK8)
156  HWREGH( ADI3_BASE + ADI_O_MASK8B + ( ADI_3_REFSYS_O_DCDCCTL1 * 2 )) = (( ADI_3_REFSYS_DCDCCTL1_VDDR_TRIM_SLEEP_M << 8 ) |
158 
159  prcmRamRetention = HWREG( PRCM_BASE + PRCM_O_RAMRETEN );
160  if ( prcmRamRetention & PRCM_RAMRETEN_VIMS_M ) {
161  curState |= PD_STATE_CACHE_RET;
162  }
163  if ( prcmRamRetention & PRCM_RAMRETEN_RFC ) {
164  curState |= PD_STATE_RFMEM_RET;
165  }
166  if ( xoscPowerMode != XOSC_IN_HIGH_POWER_MODE ) {
167  curState |= PD_STATE_XOSC_LPM;
168  }
169 
170  //--- Spec. point 2 ---
171  if ((( curTemp - powerQualGlobals.pdTemp ) >= 5 ) || ( curState != powerQualGlobals.pdState )) {
172  //--- Spec. point 3 ---
173  shiftedTemp = curTemp - 15;
174 
175  //--- Spec point 4 ---
176  //4. Check for external VDDR load option (may not be supported): ext_load = (VDDR_EXT_LOAD=0 in CCFG)
177  // Currently not implementing external load handling
178  // if ( __ccfg.ulModeConfig & MODE_CONF_VDDR_EXT_LOAD ) {
179  // }
180 
181  pLookupTable = (uint32_t *)( FCFG1_BASE + FCFG1_O_PWD_CURR_20C );
182 
183  //--- Spec point 5 ---
184  di = 0;
185  ti = 0;
186  if ( shiftedTemp >= 0 ) {
187  //--- Spec point 5.a ---
188  shiftedTemp += ( shiftedTemp << 4 );
189 
190  //--- Spec point 5.b ---
191  ti = ( shiftedTemp >> 8 );
192  if ( ti > 7 ) {
193  ti = 7;
194  }
195  dii = ti;
196  if ( dii > 6 ) {
197  dii = 6;
198  }
199 
200  //--- Spec point 5.c ---
201  cd = pLookupTable[ dii + 1 ] - pLookupTable[ dii ];
202 
203  //--- Spec point 5.d ---
204  di = cd & 0xFF;
205 
206  //--- Spec point 5.e ---
207  if ( curState & PD_STATE_XOSC_LPM ) {
208  di += (( cd >> 8 ) & 0xFF );
209  }
210  if ( curState & PD_STATE_RFMEM_RET ) {
211  di += (( cd >> 16 ) & 0xFF );
212  }
213  if ( curState & PD_STATE_CACHE_RET ) {
214  di += (( cd >> 24 ) & 0xFF );
215  }
216 
217  //--- Spec point 5.f ---
218  // Currently not implementing external load handling
219  }
220 
221  //--- Spec. point 6 ---
222  cl = pLookupTable[ ti ];
223 
224  //--- Spec. point 7 ---
225  load = cl & 0xFF;
226 
227  //--- Spec. point 8 ---
228  if ( curState & PD_STATE_XOSC_LPM ) {
229  load += (( cl >> 8 ) & 0xFF );
230  }
231  if ( curState & PD_STATE_RFMEM_RET ) {
232  load += (( cl >> 16 ) & 0xFF );
233  }
234  if ( curState & PD_STATE_CACHE_RET ) {
235  load += (( cl >> 24 ) & 0xFF );
236  }
237 
238  //--- Spec. point 9 ---
239  load += ((( di * ( shiftedTemp - ( ti << 8 ))) + 128 ) >> 8 );
240 
241  // Currently not implementing external load handling
242  // if ( __ccfg.ulModeConfig & MODE_CONF_VDDR_EXT_LOAD ) {
243  //--- Spec. point 10 ---
244  // } else {
245  //--- Spec. point 11 ---
246  diffVddrActiveSleep = ( vddrTrimActve - vddrTrimSleep );
247  if ( diffVddrActiveSleep < 1 ) diffVddrActiveSleep = 1;
248  k = ( diffVddrActiveSleep * 52 );
249  // }
250 
251  //--- Spec. point 12 ---
252 
253  vddrCap = ( ccfg_ModeConfReg & CCFG_MODE_CONF_VDDR_CAP_M ) >> CCFG_MODE_CONF_VDDR_CAP_S;
254  newRechargePeriod = ( vddrCap * k ) / load;
255  if ( newRechargePeriod > 0xFFFF ) {
256  newRechargePeriod = 0xFFFF;
257  }
258  powerQualGlobals.pdRechargePeriod = newRechargePeriod;
259 
260  //--- Spec. point 13 ---
261  if ( curTemp > 127 ) curTemp = 127;
262  if ( curTemp < -128 ) curTemp = -128;
263  powerQualGlobals.pdTemp = curTemp;
264  powerQualGlobals.pdState = curState;
265  }
266 
268 
269  // Calculate PER_E and PER_M (based on powerQualGlobals.pdRechargePeriod)
270  // Round downwards but make sure PER_E=0 and PER_M=1 is the minimum possible setting.
271  // (assuming that powerQualGlobals.pdRechargePeriod always are <= 0xFFFF)
272  perE = 0;
274  if ( perM < 31 ) {
275  perM = 31;
277  }
278  while ( perM > 511 ) {
279  perM >>= 1;
280  perE += 1;
281  }
282  perM = ( perM - 15 ) >> 4;
283 
285  ( 0x80A4E700 ) |
286  ( perM << AON_WUC_RECHARGECFG_PER_M_S ) |
287  ( perE << AON_WUC_RECHARGECFG_PER_E_S ) ;
288  HWREG( AON_WUC_BASE + AON_WUC_O_RECHARGESTAT ) = 0;
289 }
#define XOSC_IN_HIGH_POWER_MODE
Definition: sys_ctrl.h:134
int8_t pdTemp
Definition: sys_ctrl.c:80
int32_t AONBatMonTemperatureGetDegC(void)
Get the current temperature measurement as a signed value in Deg Celsius.
Definition: aon_batmon.c:60
uint8_t pdState
Definition: sys_ctrl.c:79
#define PD_STATE_XOSC_LPM
Definition: sys_ctrl.c:73
#define PD_STATE_CACHE_RET
Definition: sys_ctrl.c:71
#define PD_STATE_EXT_REG_MODE
Definition: sys_ctrl.c:74
static PowerQualGlobals_t powerQualGlobals
Definition: sys_ctrl.c:83
#define PD_STATE_RFMEM_RET
Definition: sys_ctrl.c:72
uint32_t pdTime
Definition: sys_ctrl.c:77
uint16_t pdRechargePeriod
Definition: sys_ctrl.c:78
static int32_t SetupSignExtendVddrTrimValue(uint32_t ui32VddrTrimVal)
Sign extend the VDDR_TRIM setting (special format ranging from -10 to +21)
Definition: setup_rom.h:232

Here is the call graph for this function:

static void SysCtrlSystemReset ( void  )
inlinestatic

Perform a full system reset.

Returns
The chip will reset and hence never return from this call.
310 {
311  // Disable CPU interrupts
312  CPUcpsid();
313  // Write reset register
315  // Finally, wait until the above write propagates
316  while ( 1 ) {
317  // Do nothing, just wait for the reset (and never return from here)
318  }
319 }
uint32_t CPUcpsid(void)
Disable all external interrupts.
Definition: cpu.c:68

Here is the call graph for this function:

Macro Definition Documentation

#define CPU_DEEP_SLEEP   0x00000002
#define CPU_RUN   0x00000000
#define CPU_SLEEP   0x00000001
#define RSTSRC_WAKEUP_FROM_SHUTDOWN   ((( AON_SYSCTL_RESETCTL_RESET_SRC_M ) >> ( AON_SYSCTL_RESETCTL_RESET_SRC_S )) + 1 )

Referenced by SysCtrlResetSourceGet().

#define SYSCTRL_SYSBUS_OFF   0x00000000
#define SYSCTRL_SYSBUS_ON   0x00000001
#define XOSC_IN_HIGH_POWER_MODE   0
#define XOSC_IN_LOW_POWER_MODE   1