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

📄 timer.c

📁 4510 study
💻 C
📖 第 1 页 / 共 3 页
字号:
/*                                                                       */
/*   Watchdog timer functions:                                           */
/*                                                                       */
/*   WatchDogFunc    Test function for watchdog                          */
/*   WatchDogStart   WatchDog timer(timer1) will be initialized and      */
/*                   start.                                              */
/*   WatchDogReload  This function is called by timer0 for reload watch  */
/*                   dog timer counte value.                             */
/*   WatchDog0Lisr   Timer0 interrupt service routine for system timer   */
/*   WatchDog1Lisr   Timer1 interrupt service routine for watchdog timer */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      09-15-1998      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
/*************************************************************************/
/*                                                                       */
/* 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      */
/*                                                                       */
/*************************************************************************/
/*
void WatchDogFunc(int reconf)
{
     Disable_Int(nTIMER0_INT);    
     Disable_Int(nTIMER1_INT);    

     if(reconf) // timer0 reconfiguration 
          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);  
     TCNT0 = 0x0;
     TMOD  = 0;        


     // TIMER 1 used to system watchdog timer 
     WatchDogSetup();

     Enable_Int(nTIMER0_INT);  // Timer0 interrupt enable 
     Enable_Int(nTIMER1_INT);  // Timer1 interrupt enable 

     // TIMER RUN enable 
     TimerStart(TIMER_DEV0);
     TimerStart(TIMER_DEV1);

}
*/

/*************************************************************************/
/*                                                                       */
/* NAME : WatchDogStart()                                                */
/*                                                                       */
/* FUNCTIONS : TIMER1 will be initialized for watchdog functions         */
/*             if the counter value(3sec) counted out, the SNDS100       */
/*             will be reset by software or hardware method.             */
/*                                                                       */
/* EXAMPLES :                                                            */
/*                                                                       */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
/*
// Watchdog timer start 
void WatchDogSetup(void) 
{ 
     IOPDATA &= ~(1<<17);                    // Output 0 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);       // Set watchdog time to 3sec 
     TMOD   = 0;                              // Set timer mode : 
                                             //   Interval mode,timer start 
     //IOPCON = (1<<31);                     // Timer1 output(TOUT1)enable  
     WatchDogStatus = 0;
}
*/

/*************************************************************************/
/*                                                                       */
/* NAME : WatchDogReload()                                               */
/*                                                                       */
/* FUNCTIONS : This function is called at timer0 interrupt servive       */
/*             routine for reload watchdog timer count value to avoid    */
/*             system reset by watchdog timer1.                          */
/*                                                                       */
/* EXAMPLES :                                                            */
/*                                                                       */
/*                                                                       */
/* VARIABLES USED                                                        */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*        in4maker      06-07-1999      Created initial version 1.0      */
/*                                                                       */
/*************************************************************************/
/*
void WatchDogReload(void)
{
     TimerStop(TIMER_DEV1);
     Disable_Int(nTIMER1_INT);    
     TDATA1 = t_data_ms(3*ONE_SECOND); // Set watchdog time to 3sec 
     WatchDogStatus = 0;
     Enable_Int(nTIMER1_INT);  // Timer0 interrupt enable 
     TimerStart(TIMER_DEV1);
}
*/

/*************************************************************************/
/*                                                                       */
/* 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      */
/*                                                                       */
/*************************************************************************/
/*
void WatchDog1Lisr(void)
{

#ifdef WDT_HW_RESET

     Print("\r\r@@System hardware reset.\r");
     Print("Reset signal came from TOUT1 as reset input\r");

     // 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("\r\r@@System software reset.\r");
     Print("System will be reboot by boot ROM.\r");
     //Reset_Boot_Rom() ;  // If ROM at address zero 
     //StartUserPgm();
     Reset_Handler();
     //C_Entry();  
     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      */
/*                                                                       */
/*************************************************************************/
/*
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++;
                           }
                       }
                  }
              }
          }
          // 4 means digit number for LED display 
          IOPDATA = ~(1<<tm0.tm_sec%4); 
    }  
    WatchDogReload();  // WatchDog timer value will be re-loaded 
}

*/

⌨️ 快捷键说明

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