⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 本source code 為s3c4510的bootloader
💻 C
📖 第 1 页 / 共 3 页
字号:
/* FUNCTIONS : Timer1 interrupt service routine.                         *//*                                                                       *//* EXAMPLES :                                                            *//*                                                                       *//*       SysSetInterrupt(nTIMER1_INT, tm1isr);                           *//*                                                                       *//* VARIABLES USED                                                        *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         NAME            DATE                    REMARKS               *//*                                                                       *//*        in4maker      06-07-1999      Created initial version 1.0      *//*                                                                       *//*************************************************************************/void tm1isr(void){ clk_tick1++;   if(clk_tick1 >= TICKS_PER_SECOND)   {   clk_tick1 = 0;   if(tm1.tm_sec++ > 59)     {      tm1.tm_sec = 0;     if(tm1.tm_min++ > 59)       {         tm1.tm_min = 0;       if(tm1.tm_hour++ > 23)         {         tm1.tm_hour = 0;         if(tm1.tm_mday++ > 30)           {           tm1.tm_mday = 0;           if(tm1.tm_mon++ > 11)             {              tm1.tm_mon = 0;              tm1.tm_year++;            }          }        }      }    }  }  }/*************************************************************************//*                                                                       *//* NAME : WatchDog1Lisr()                                                *//*                                                                       *//* FUNCTIONS : This function will be served when the watchdog timer      *//*             count value is counted out.                               *//*             If TOUT1(P17) merged to System reset input(nRESET),       *//*             The system will be reset by the input signal from TOUT1.  *//*             Any other case, rebooted by boot ROM.                     *//*                                                                       *//* EXAMPLES :                                                            *//*                                                                       *//*                                                                       *//* VARIABLES USED                                                        *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         NAME            DATE                    REMARKS               *//*                                                                       *//*        in4maker      06-07-1999      Created initial version 1.0      *//*                                                                       *//*************************************************************************/#define WDT_HW_RESETstatic void WatchDog1Lisr(void){#ifdef WDT_HW_RESET Print("\n\nSystem hardware reset.\n"); Print("Reset signal came from TOUT1 as reset input\n");/* This for the System hardware reset *//* P17 have been merged system reset input pin */ IOPDATA &= ~(1<<17);  				/* Output 0 to P17(TOUT1) */ IOPMOD  |=  (1<<17);    			/* P17 output mode enable */#else Print("\nSystem software reset.\n"); Print("System will be reboot by boot ROM.\n"); return;#endif      WatchDogStatus = 1;}/*************************************************************************//*                                                                       *//* NAME : WatchDog0Lisr()                                                *//*                                                                       *//* FUNCTIONS : Basic system timer using timer0.                          *//*                                                                       *//* EXAMPLES :                                                            *//*                                                                       *//*                                                                       *//* VARIABLES USED                                                        *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         NAME            DATE                    REMARKS               *//*                                                                       *//*        in4maker      06-07-1999      Created initial version 1.0      *//*                                                                       *//*************************************************************************/static void WatchDog0Lisr(void){ clk_tick0++;   if(clk_tick0 == TICKS_PER_SECOND)   {   clk_tick0 = 0;   if(tm0.tm_sec++ > 59)     {      tm0.tm_sec = 0;     if(tm0.tm_min++ > 59)       {         tm0.tm_min = 0;       if(tm0.tm_hour++ > 23)         {         tm0.tm_hour = 0;         if(tm0.tm_mday++ > 30)           {           tm0.tm_mday = 0;           if(tm0.tm_mon++ > 11)             {              tm0.tm_mon = 0;              tm0.tm_year++;            }          }        }      }    }  }   Disable_Int(nGLOBAL_INT);  		 Disable_Int(nTIMER1_INT);    		/* Disable TIMER1 interrupt source */ TimerStop(1);				/* Stop TIMER 1 */  TDATA1 = t_data_ms(3*ONE_SECOND/TICKS_PER_SECOND); 	/* Set watchdog time to 3sec */ WatchDogStatus = 0;			/* Clear WatchDog Status */ Enable_Int(nTIMER1_INT);  		/* Timer1 interrupt source enable */ Enable_Int(nGLOBAL_INT);  			/* Timer1 interrupt enable */ TimerStart(1);				/* start timer 1 */}/*************************************************************************//*                                                                       *//* NAME : WatchDogFunc()                                                 *//*                                                                       *//* FUNCTIONS : Watchdog timer functions.                                 *//*             TIMER0 used to basic system timer.                        *//*             TIMER1 used to watchdog timer.                            *//*                                                                       *//*             Whenever the system timer0 interrupt occurred, the watch  *//*             dog timer(timer1) count value will be reloaded at timer0  *//*             interrupt service routine as call WatchDogReload().       *//*                                                                       *//* EXAMPLES :                                                            *//*                                                                       *//*                                                                       *//* VARIABLES USED                                                        *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         NAME            DATE                    REMARKS               *//*                                                                       *//*        in4maker      06-07-1999      Created initial version 1.0      *//*                                                                       *//*************************************************************************/static void WatchDogInit(int reconf){ Disable_Int(nGLOBAL_INT);  			 Disable_Int(nTIMER0_INT);    			/* Disable TIMER0 interrupt */  Disable_Int(nTIMER1_INT);    			/* Disable TIMER1 interrupt */ if(reconf) 					/* timer0 reconfiguration */  {/* restore TIMER 0 ISR, without WatchDog reload	*/    SysSetInterrupt(nTIMER0_INT, tm0isr);  } else   {   SysSetInterrupt(nTIMER0_INT, WatchDog0Lisr);  }   SysSetInterrupt(nTIMER1_INT, WatchDog1Lisr);/* TIMER 0 used to system basic timer */ TDATA0 = t_data_ms(ONE_SECOND/TICKS_PER_SECOND); /* timer 0 period 10 ms */ 	   TCNT0 = 0x0;					/* timer0 counter */  TMOD  = 0;        				/* Timer 0/1 mode register *//* TIMER 1 used to system watchdog timer *//* Watchdog timer start *//* WARNING ! Check 74HCT125, pin 4 active 0 ? */ IOPDATA |= (1<<17);  		       		/* Output 1 to P17(TOUT1) */ IOPMOD  |= (1<<17);                		/* Enable P17 to output port */                                            	/* TOUT1 will be cleared */ TCNT1  = 0;                          		/* Clear timer counter register */ TDATA1 = t_data_ms(3*ONE_SECOND/TICKS_PER_SECOND); /* Set watchdog time to 3sec */                                   		/* Interval mode,timer start */ WatchDogStatus = 0;/* Enable TIMER0/1 interrupts */   Enable_Int(nTIMER0_INT);  			/* Timer0 interrupt enable */ Enable_Int(nTIMER1_INT);  			/* Timer1 interrupt enable */ Enable_Int(nGLOBAL_INT);  			/* Timer1 interrupt enable *//* TIMER RUN enable */ TimerStart(0);			/* Start TIMER 0 */ TimerStart(1);			/* Start TIMER 1 */}/*************************************************************************//*                                                                       *//* NAME : WatchDogTest()                                                 *//*                                                                       *//* FUNCTIONS : Watchdog timer function test.                             *//*                                                                       *//* EXAMPLES :                                                            *//*                                                                       *//* VARIABLES USED                                                        *//*                                                                       *//*                                                                       *//* HISTORY                                                               *//*                                                                       *//*         NAME            DATE                    REMARKS               *//*                                                                       *//*        in4maker      06-07-1999      Created initial version 1.0      *//*                                                                       *//*************************************************************************/static void WatchDogTest(void){ U8 ch; Print("\n\nWatchDog Timer function test."); Print("\nTimer0 used as system timer."); Print("\nTimer1 used as watchdog timer."); Print("\nWatchdog timer counter value will be initialized at");    Print("\nsystem timer interrupt service routine repeatedly.");    Print("\nIf you want to make the system hangup situation,"); Print("\nEnter the character 'R'.\n"); WatchDogInit(0); Print("\n\n Now, watchdog & system timer is running.....\n"); while(1)   {   ch = get_upper(); 			/* get byte from console */   if(ch == 'R')    {     Print("\nTIMER0 reconfigured with no watchdog Init function.\n");/* TIMER 0 re-configured with no watchdog Initialize function */     WatchDogInit(1);     Print("\nNow, wathdog timer interrupt occurred...\n");    }  }}////////////////////////////////////////////////////////////////////////////////// timer test top function /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////void TimerTest(void){ U8 it; while(1)   {   Print("\n\nTIMER TEST");    Print("\n[R] Running Timer 0,1.");    Print("\n[W] Watchdog Timer function(Timer1) Test.");   Print("\n[V] View the timer configurations.");   Print("\n[Q] Type Q for exit timer test.");   Print("\nSelect Test Item: ");   it = get_upper();   switch(it)     {     case 'R' : rtc_run();  break;	  	/* TIMER0/TIMER1 test */     case 'W' : WatchDogTest();  break;   	/* WatchDog Test */	     case 'V' : TimerConfigView();  break; 	/* show timer0/timer1 configuration */     case 'Q' : return;     default  : break;    }   Print("\nPress any key to continue.");   it = get_upper();   if(it == 'Q')    {     break;    }   } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -