Hi @Q_man ,
please see the code as below:
extern void ApiPowerEnterStopMode()
{
u8 CAN_status[3];
u16 timeout = 10000;
CAN_STDBY(STANDBYMODE);
DelayMs();
Sleep_CAN(CAN0, CMPTX); // request CAN channel 0 go to sleep with completing transmission scheduled
do {
Check_CAN_Status(CAN0, CAN_status); // read the channel 0 status
} while (!(CAN_status[1] & SLPAK) && timeout--); // wait till SLPAK bit set
B_PCR_WUEH_WUPTB4 = 1; // enable PTB4 wakeup
B_GPIO_TSENSE = 0;
B_GPIO_VSENSE = 0;
ADCDisable();
TsenseDisable();
PCREnterStopMode();
ApiPowerRecoverFromStop();
//PCREnterSleepMode();
// .....zzzzzzzzzzz (stop mode)
// after wakeup the code continues to run here....
// but first the D2D Interrupt service routine will be run
VsenseInit();
CsenseInit();
TsenseInit();
.....
}
static void ApiPowerRecoverFromStop(void)
{
u16 timeout = 1u;
B_PCR_CTL = 0x0300; // Go to normal mode
while(timeout--)
{
Nop();
}
while (!(B_PCR_SRH&0x01)) DO_NOTHING; // Wait for Clock Domain Change
u16gPowerRstReason = B_PCR_SR;
B_PCR_SR = 0xFFFF;
B_WD_CTL = 0x0700; // disable Watchdog after wake up
}
void PCREnterStopMode(void) {
u16 timeout = 1; //100us
IrqDisable();
B_INT_MSK = 0xFF3F; // disable all Analog Interrupts
B_ACQ_SRH = 0xFF; // Clear pending Flags
B_INT_MSK = 0xFF00; // enable all Analog Interrupts
B_PCR_SR = 0xFFFF; // Clear Flags
B_PCR_CTL = OPM_SET_STOP; // Goto Stop Mode
while(timeout--)
{
Nop();
}
StopEnable();
Nop();
StopEnter();
}