UG-1262
Rev. B | Page 27 of 312
CODE EXAMPLES
Enter Power Saving Mode
The following function configures the analog die operating mode:
uint32_t AfePwrCfg(uint16_t iMode)
{
// PSWFULLCON[14:13]= [11]b
//Close switches NL and NL2. PSWFULLCON[11:10]= [11]b
pADI_AFE-> PSWFULLCON|=0x6C00; // Close PL2, PL1, P12, P11 switches to tie HSTIA N and D
//terminals to 1.8 V LDO
pADI_ALLON->PWRKEY = 0x4859;
pADI_ALLON->PWRKEY = 0xF27B;
pADI_ALLON->PWRMOD = (pADI_ALLON->PWRMOD&(~BITM_ALLON_PWRMOD_PWRMOD))|iMode;
//=========================================
// IMPORTANT
// If Chip is going into hibernate mode, you
// cannot read PWRMOD after configuring it.
// For safety reasons, return value set
// to 0 directly.
//=========================================
//return pADI_ALLON->PWRMOD;
return 0;
}
The following function configures the digital die operating mode:
int PwrCfg(int iMode,int iMonVbBat,int iSramRet)
{
int32_t index = 0;
uint32_t savedWDT;
savedWDT = pADI_WDT0->CTL; //None of the watchdog timer registers are retained in hibernate
mode
if (iMode > 3)
// Check for invalid sleep mode value
{
iMode = 0;
return 1;
}
if ((iMode == 2) || (iMode == 3))
{
SCB->SCR = 0x04; // sleepdeep mode - write to the Cortex-m3 System Control register bit2
}
pADI_PMG0->PWRKEY = 0x4859;
// key1
pADI_PMG0->PWRMOD = iMode|iMonVbBat;
for (index=0;index<2;index++);
__WFI();
for (index=0;index<2;index++);
pADI_WDT0->CTL = savedWDT; //restore WDT control register.
return 1;
}