📄 timer.c
字号:
/********************* SGS-THOMSON MICROELECTRONICS ************************
FILENAME : TIMER.C
VERSION : V1.0
DATE : JAN 1999
AUTHOR(s) : ASHISH RUDOLA / DEEPAK DOSHI
PROCESSOR : ST92195
DESCRIPTION : This module contains functions used for handling software
timers.
MODIFICATIONS:
-
*****************************************************************************/
#include "timer.h"
#include "macro.h"
#include "clock.h"
#include "register.h"
#include "st92196.h"
#include "io.h"
#include "macro.h"
/* Software timers definitions (Keyboard timer, Volume timer...)
These are fast (lower than 5 seconds time-out) and accurate timers.*/
unsigned char fast_timers[NUMBER_OF_FAST_TIMERS];
/* Software timers definitions (Menu timer...)
These are slow timers (from 1 second to less than 5 minutes)*/
unsigned char slow_timers[NUMBER_OF_SLOW_TIMERS];
/*****************************************************************************
INPUTS : none
OUTPUTS : ST9 Slice Timer registers
DESCRIPTION: This function initializes the Slice Timer to provide an
interrupt every 20ms.
1/10Mhz x 4 x 20 x 2500 = 20ms (=1/50Hz, vertical time)
*****************************************************************************/
//void init_slice_timer(void)
//{
/* Select Slice Timer page */
// spp(ST_PG);
/* Set prescaler to 20 */
// ST_PR = 19;
/* Set the 16 bits counter to 4000 (in fact 3999 gives better results) */
// ST_R = 2499; /* Value for 10MHz operation */
/* Select the continuous mode and start the Slice Timer */
// ST_CR = 0x80;
//}
/*================================================================================================
INIT STDT01
--------------------------------------------------------------------------------------------------
FUNCTION : init_STDT01
Input : none
Output : none
DESCRIPTION : initialize standard timer with 1 IT each 0.020s
1/24Mhz x 4 x 2 (ST_PR=0 means no prescaler) x 30000 = 5ms
==================================================================================================*/
void init_STDT01(void)
{
spp(ST_PG); /* set page pointer to standard timer */
ST_PR = 0x01; /* CPU = 24MHz -> STDT is feed with (24/4)/2 = 3 MHz clock*/
ST_HR = 0xEA; /* IT each 0.020s (CPU = 24MHz) */
ST_LR = 0x60;
ST_CR = 0x80; /* start counter, continuous mode, no input, no output */
}
/*****************************************************************************
INPUTS : none
OUTPUTS : see update_clock
see update_fast_timers
ST9 OSD registers
DESCRIPTION: This function services the Slice Timer interrupt. Fast software
and accurate timers are updated every 20ms.
The time of day is also updated here...
*****************************************************************************/
#pragma interrupt(STD_IT)
void STD_IT(void)
{
SAVE_PPR;
/* Force program space in case it has been modified by the OSD module */
/* spm TC */;
/* Enable interrupts to make sure the OSD and IR interrupts will not be
delayed */
asm ("ei");
/* Update fast and accurate timers */
update_fast_timers();
/* Update current time of day */
update_clock();
RESTORE_PPR;
}
/*****************************************************************************
INPUTS : none
OUTPUTS : Software timers
DESCRIPTION: This function updates fast and accurate timers like the clock
timer.
*****************************************************************************/
void update_fast_timers(void)
{
/* Decrement fast software timers up to zero */
asm volatile ("ldw rr0, #%0
ld r2,%1
STI0: cp (rr0),#0
jxz STI1
sub (rr0),#1
STI1: incw rr0
djnz r2,STI0" : : "m"(fast_timers), "i"(NUMBER_OF_FAST_TIMERS));
++count_20ms;
}
/*****************************************************************************
INPUTS : none
OUTPUTS : Software timers
DESCRIPTION: This function updates slow timers and not accurate timers like
status or menu timers.
*****************************************************************************/
void update_slow_timers(void)
{
unsigned char i; /* Temporary storage */
/* Decrement software timers up to zero */
for (i = 0; i < NUMBER_OF_SLOW_TIMERS; i++)
if (slow_timers[i] != 0)
slow_timers[i]--;
}
/*****************************************************************************
INPUTS : timer to check
ONE_SECOND - Set when one second has elapsed
ONE_MINUTE - Set when one minute has elapsed
OUTPUTS : SECOND_TIMER - Reset
ONE_MINUTE - Reset
Return 1 every seconds and minutes. Return 0 otherwise
DESCRIPTION: This function returns 1 every seconds so as to update processes
which require 1 second time base. This function also returns 1
every minutes so as to update preocesses which require 1 minute
time base.
*****************************************************************************/
unsigned char check_time(unsigned char timer_to_check)
{
unsigned char i = 0; /* Temporary storage */
/* if (timer_to_check == CHECK_HALF_SECOND)
{
if (time_flags & HALF_SECOND)
{
time_flags = time_flags & ~HALF_SECOND;
i = 1;
}
}
*/
if (timer_to_check == CHECK_SECOND)
{
if (time_flags & ONE_SECOND)
{
time_flags = time_flags & ~ONE_SECOND;
i = 1;
}
}
if (timer_to_check == CHECK_MINUTE)
{
if (time_flags & ONE_MINUTE)
{
time_flags = time_flags & ~ONE_MINUTE;
i = 1;
}
}
return i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -