hello,
my following methods seem work without "timers" :smileywink:
/************************************************************************
* enable 32khz clock before entering stop3 mode
*
************************************************************************/
void RTC_AllowStop3ExitIcs32K(TByte ics32kValueArg)
{
// Setup RTC peripheral to generate a 100ms period interrupt ; clock source : ICS 32 kHz internal
// CAUTION !! Setup RTC clock BEFORE setup RTC module itself !!
ICSC1_IRCLKEN = 1; // Activates internal 32 kHz clock
ICSC1_IREFSTEN = 1; // Allow internal 32 kHz clock to continue running during stop3 mode
SCGC2_RTC = 1; // Gates IRCLK clock to RTC peripheral
RTCMOD = 0x00;
RTCSC= (0x00 | RTCSC_RTIF_MASK );// Remove a potential spurious interrupt
//code factorization for RTCLKS MASK (the same for the 2 RTC values)
switch ( ics32kValueArg )
{
default:
DEV_ASSERT(FALSE);
break;
case E_RTC_4MS:
RTCSC |= (RTCSC_RTCLKS1_MASK | VALUE_ICS32K_4MS );
break;
case E_RTC_64MS:
RTCSC |= (RTCSC_RTCLKS1_MASK | RTCSC_RTCLKS0_MASK | VALUE_ICS32K_64MS );
break;
case E_RTC_16MS:
RTCSC |= (RTCSC_RTCLKS1_MASK | VALUE_ICS32K_16MS );
break;
case E_RTC_8MS:
RTCSC |= (RTCSC_RTCLKS1_MASK | VALUE_ICS32K_8MS );
break;
}
RTCSC_RTIE = 1; // Enable RTC interrupt
}
/************************************************************************
* enable lpo 1khz clock before entering stop3 mode
*
************************************************************************/
void RTC_AllowStop3ExitLpo1K(TByte lpo1kValueArg)
{
// Setup RTC peripheral to generate a 1s period interrupt ; clock source : LPO 1 kHz internal
// This seems to be useles according spec chap 5.8.11 ; but RTC does not generate interrupts if this line is removed
// Confirmed by Freescale on 20/3/2008 : enable bus clock to RTC peripheral, even if RTC is clocke by LPO
SCGC2_RTC = 1;
RTCMOD = 2-1; //2s period
RTCSC= (0x00 | RTCSC_RTIF_MASK);// Remove a potential spurious interrupt
switch ( lpo1kValueArg )
{
default:
DEV_ASSERT(FALSE);
break;
case E_LPO_2S:
RTCSC |= VALUE_LPO1K_1S;
break;
}
RTCSC_RTIE = 1; // Enable RTC interrupt
}
/************************************************************************
*Called from ISR
*
************************************************************************/
void RTC_SetupDisable(void)
{
// Disable wake-up on RTC (case : "MCU goes out of STOP3 mode")
RTCSC = ( 0x00
// | RTCSC_RTIF_MASK
// | RTCSC_RTCLKS1_MASK
// | RTCSC_RTCLKS0_MASK
// | RTCSC_RTIE_MASK // Disable RTC interrupt
// | RTCSC_RTCPS3_MASK // 0000 => RTC off
// | RTCSC_RTCPS2_MASK
// | RTCSC_RTCPS1_MASK
// | RTCSC_RTCPS0_MASK
);
//***************************************************************************
//WARNING BUG !!!!
//WARNING BUG !!!!
//DON'T USE THE LINE BELOW
//ICSC1_IRCLKEN = 0; // Deactivates internal 32 kHz clock
//***************************************************************************
//ONLY DISABLED IN STOP MODE (FOR NEXT LPO STOP)
ICSC1_IREFSTEN= 0;
SCGC2_RTC = 0; // Deactivate clock for RTC peripheral
/*
AN3460 :
The clock is gated on or off immediately after the register is written. Be careful when using this feature.
=> After a reset all the clocks are gated on. To keep power consumption down, the clocks should be
gated off as soon as possible.
=> Writes to registers associated with a gated off module have no effect (e.g. writing to the Modulo of
the RTC module if the SCGC2_RTC bit is 1 will not cause the register value to change).
=> To avoid errors, disable the module before gating it off and re-initializing the register when the
module is gated back on.
*/
}
/************************************************************************
* ISR !!!
*
************************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
__interrupt void RTC_ISR_Handler(void)
{
//--------------------------------------------
// First thing a interrupt must do (in most cases)
// Here it is needed because it includes calls to K_Event_Signal() & K_OS_Tick_Update()
//--------------------------------------------
K_OS_Intrp_Entry();
// !! This interrupt should be called only to exit STOP3 mode !!
RTCSC_RTIF = 1; // Acknowledge interrupt
RTCSC_RTIE = 0; // Disable RTC interrupt
RTC_SetupDisable();
//--------------------------------------------
// Last thing an interrupt must do (if K_OS_Intrp_Entry called)
//--------------------------------------------
K_OS_Intrp_Exit();
}
#pragma CODE_SEG DEFAULT_ROM
Message Edited by goiz74 on 2009-12-21 08:32 AM