📄 timer_test.c
字号:
/*************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* timer_test.c KS32C5000, KS32C50100 : version 1.0 */
/* */
/* COMPONENT */
/* */
/* */
/* DESCRIPTION */
/* */
/* */
/* AUTHOR */
/* */
/* Young Sun KIM, Samsung Electronics, Inc. */
/* */
/* DATA STRUCTURES */
/* */
/* */
/* FUNCTIONS */
/* */
/* The functions in this file are: */
/* */
/* TimerTest Top module for timer function evaluations */
/* rtc_run Timer0 or timer1 run test */
/* TimerStartUpDiaglog Start-up dialog for to configure the timer */
/* tmConfig Monitoring the timer related registers */
/* */
/* DEPENDENCIES */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 09-15-1998 Created initial version 1.0 */
/* */
/*************************************************************************/
#include <stdio.h>
#include "snds.h"
#include "uart.h"
#include "isr.h"
#include "timer.h"
#include "pollio.h"
#include "sysconf.h"
/*************************************************************************/
/* */
/* NAME : TimerTest() */
/* */
/* FUNCTIONS : Top module for timer test. */
/* */
/* EXAMPLES : */
/* */
/* VARIABLES USED */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 06-07-1999 Created initial version 1.0 */
/* */
/*************************************************************************/
void TimerTest(void)
{
U8 items;
do {
TimerTestItem(); // Main memu for cache test
do {
Print("\rSelect Number?_");
items = get_byte();
}while(is_space(items));
if(is_xdigit(to_upper(items))) {
switch(to_upper(items)) {
case '1': rtc_run(); break;
case '2': WatchDogTest(); break;
case '3': tmConfig(); break;
default : break;
}
}
Print("\rPress any key to continue.\r");
while(!is_space(get_byte()));
} while((items!='q')&&(items!='Q'));
}
void TimerTestItem()
{
Print("\r\r>> TIMER TEST ITEMS <<\r\r");
Print("======================================\r");
Print("1. Running Timer 0,1 \r");
Print("2. Watchdog Timer function(Timer1) Test.\r");
Print("3. View the timer configurations. \r");
Print("Q. Type Q for exit timer test. \r");
Print("======================================\r");
}
/*************************************************************************/
/* */
/* NAME : rtc_run() */
/* */
/* FUNCTIONS : timer0 or 1 run test function. */
/* */
/* EXAMPLES : */
/* */
/* VARIABLES USED */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 06-07-1999 Created initial version 1.0 */
/* */
/*************************************************************************/
void rtc_run()
{
uint8 ch; /* variable for io consol */
uint8 dev; /* for to select timer device 0,1 */
/* Select timer device. Timer0 or Timer 1 */
do {
Print("\r\r$ Select timer[0/1]_");
dev = get_byte();
} while(dev != '1' && dev != '0');
Print("\n*****************************************\r");
Print(">> You select timer default value for test <<\r");
Print("*****************************************\r\r");
if(dev=='1') {
tm_init(TIMER_DEV1,(ONE_SECOND/TICKS_PER_SECOND));
TimerStart(TIMER_DEV1);
}
else {
tm_init(TIMER_DEV0,(ONE_SECOND/TICKS_PER_SECOND));
TimerStart(TIMER_DEV0);
}
/* -------------------------*/
/* Now Start timer for test */
/* -------------------------*/
Print("\rTo exit, enter the Esc key on keyboard.\r");
Print("\r\r>> Now, the timer is Running......\r\r");
IOPDATA = 0xff; // All LED OFF
while(1)
{
if(dev == '1') PrtSysTime(TIMER_DEV1,"[TIMER1] Current time");
else PrtSysTime(TIMER_DEV0,"[TIMER0] Current time");
}
}
/*************************************************************************/
/* */
/* NAME : WatchDogTest() */
/* */
/* FUNCTIONS : Watchdog timer function test. */
/* */
/* EXAMPLES : */
/* */
/* VARIABLES USED */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 06-07-1999 Created initial version 1.0 */
/* */
/*************************************************************************/
void WatchDogTest()
{
uint8 ch;
Print("\r\rWatchDog Timer function test.\r\r");
Print("Timer0 used as system timer.\r");
Print("Timer1 used as watchdog timer.\r");
Print("Watchdog timer counter value will be initialized at \r");
Print("system timer interrupt service routine repeatedly. \r");
Print("If you want to make the system hangup situation,\r");
Print("\rEnter the character 'R'.\r");
WatchDogFunc(0);
Print("\r\r Now, watchdog & system timer is running.....\r");
while(1)
{
ch = get_byte(); put_byte(ch); /* for echo */
if(ch != 'r')
{
Print("\rTIMER0 reconfigured with no watchdog Init function.\r");
/* TIMER 0 re-configured with no watchdog Initialize function */
WatchDogFunc(1);
Print("\rNow, wathdog timer interrupt occurred...\r");
}
}
}
/*************************************************************************/
/* */
/* NAME : tmConfig() */
/* */
/* FUNCTIONS : Monitoring the timer related system registers. */
/* and start & stop timer control. */
/* */
/* EXAMPLES : */
/* */
/* VARIABLES USED */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* in4maker 06-07-1999 Created initial version 1.0 */
/* */
/*************************************************************************/
void tmConfig(void)
{
Print("\r<<---------- TIMER 0 STATUS ----------->>\r");
if(TMOD & TM0_RUN)
Print(">>TMOD[0]: Timer0,Start enabled.\r");
else
Print(">>TMOD[0]: Timer0,Disabled.\r");
if(TMOD & TM0_TOGGLE)
Print(">>TMOD[1]: Timer0,Toggle mode.\r");
else
Print(">>TMOD[1]: Timer0,Interval mode.\r");
if(TMOD & TM0_OUT_1)
Print(">>TMOD[2]: Timer0,Initial TOUT0 is 1.\r");
else
Print(">>TMOD[2]: Timer0,Initial TOUT0 is 0.\r");
Print(">>TDATA0 = 0x%08x\r",TDATA0);
Print(">>TCNT0= 0x%08x \r",TCNT0);
if((IOPCON & 0x40000000) && (IOPMOD & 0x10000))
Print(">>Timer0,TOUT0 will be monitored at PORT16.\r");
else
Print(">>Timer0,TOUT0 output disabled.\r");
if(INTMODE & TIMER0_INT)
Print(">>Timer0 is in FIQ mode.\r");
else
Print(">>Timer0 is in IRQ mode.\r");
if(~INTMASK & TIMER0_INT)
Print(">>Timer0 interrupt enabled.\r");
else
Print(">>Timer0 interrupt disabled.\r");
Print("-----------------------------------------\r");
Print("\r<<---------- TIMER 1 STATUS ----------->>\r");
if(TMOD & TM1_RUN)
Print(">>TMOD[1]: Timer1,Start enabled.\r");
else
Print(">>TMOD[1]: Timer1,Disabled.\r");
if(TMOD & TM1_TOGGLE)
Print(">>TMOD[1]: Timer1,Toggle mode.\r");
else
Print(">>TMOD[1] Timer1,Interval mode.\r");
if(TMOD & TM1_OUT_1)
Print(">>TMOD[2]: Timer1,Initial TOUT1 is 1.\r");
else
Print(">>TMOD[2]: Timer1,Initial TOUT1 is 0.\r");
Print(">>TDATA1 = 0x%08x\r",TDATA1);
Print(">>TCNT1= 0x%08x\r",TCNT1);
if((IOPCON & 0x80000000) && (IOPMOD & 0x20000))
Print(">>Timer1,TOUT1 will be monitored at PORT17.\r");
else
Print(">>Timer1,TOUT1 output disabled.\r");
if(INTMODE & TIMER1_INT)
Print(">>Timer1 is in FIQ mode.\r");
else
Print(">>Timer1 is in IRQ mode.\r");
if(~INTMASK & TIMER1_INT)
Print(">>Timer1 interrupt enabled.\r");
else
Print(">>Timer1 interrupt disabled.\r");
Print("-----------------------------------------\r\r");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -