Download Embedded Multitasking with small - innovated

Transcript
304
Chapter 5
Other variations of skip timer may also require an external event in
conjunction with the skip timer timeout, or in place of the skip timer
timeout. One such skip timer is the timebase task in our alarm clock
example. In this case, a trigger from the external 60-Hz timebase is
supposed to trigger an increment of the current time. However, if five
consecutive pulses from the 60-Hz timebase are missed, then the system
will switch over to an internal timebase. To implement this type of system, a more complex function is required. The following is an example
of how this system could be implemented:
Code Snippet 5.12
if (60Hz_pulse == true)
{
if (system_mode!=Power_fail_mode) //normal operating modes for the system
{
//use a short timeout = to 60Hz period + 1
timebase_task_skptmr = (timebase_task_reloadvalue/60)+1;
if (--60Hz_postscaler == 0)
{
//the postscaler sets the goflags every 60
60Hz_postscaler = 60;
timebase_task_goflag = true;
time_increment = true;
}
}
else
//60Hz pulses have resumed after power fail
{
if (--missed_60Hzpulse_counter == 0) system_mode = determine_sys_mode();
timebase_task_skptmr = (timebase_task_reloadvalue/60)+1;
}
}
If (--timebase_task_skptmr == 0)
//skiptimer timeout, missed pulse, powerfail
{
if (system_mode == Power_fail_mode) //power fail, do goflags & set 1sec timeout
{
timebase_task_skptmr = timebase_task_reloadvalue;
timebase_task_goflag = true;
time_increment = true;
}
else
//missing pulse, count & reload skiptimer
{
timebase_task_skptmr = (timebase_task_reloadvalue/60)+1;
if (++missed_60Hzpulse_counter > 4)
{
//5th missing pulse, change mode & timeout
missed_60Hzpulse_counter = 5;
system_mode = Power_fail_mode;
timebase_task_skptmr = timebase_task_reloadvalue;
}
}
}