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

📄 scheduler.c

📁 ATMEL公司AT89C51SND1为主控制器MP3源代码
💻 C
字号:
/*C**************************************************************************
* NAME:         scheduler.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-4_0_3      
* REVISION:     1.8     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the scheduler routines
*
* NOTES:
* Configuration:
*   - SCH_TYPE in scheduler.h header file
*   - SCH_TIMER in scheduler.h header file
* Global Variables:
*   - gl_cpt_tick: byte in data space
*   - gl_kbd_tick: byte in data space
*   - gl_mem_tick: byte in data space
*
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/

#include "config.h"                         /* system definition */
#include "lib_mcu\timer\timer_drv.h"        /* timer definition */
#include "scheduler.h"                      /* scheduler definition */


/*_____ M A C R O S ________________________________________________________*/


/*_____ D E F I N I T I O N ________________________________________________*/

extern  data    Byte    gl_cpt_tick;        /* general tick counter */
extern  data    Byte    gl_kbd_tick;        /* keypad tick counter */
extern  data    Byte    gl_mem_tick;        /* memory tick counter */
extern  data    Byte    gl_led_tick;        /* led tick counter */
extern  idata   Uint16  gl_act_tick;        /* led tick counter */

#if (SCH_TYPE != SCH_FREE)
  bit   sch_tick_flag;
#endif


/*_____ D E C L A R A T I O N ______________________________________________*/

static  void sch_time_init (void);


/*F**************************************************************************
* NAME:     sch_scheduler_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Scheduler initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   Task_x_init() and Task_x_fct() are defined in scheduler.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void sch_scheduler_init (void)
{
  Task_1_init();  
  Task_2_init();  
  Task_3_init();  
  Task_4_init();  
  Task_5_init();  
  Task_6_init();  
  Task_7_init();  
  Task_8_init();  
  Task_9_init();  
  Task_10_init();
#if (SCH_TYPE != SCH_FREE)
  sch_tick_flag = FALSE;
#endif
  sch_time_init();                /* start time base */
}


/*F**************************************************************************
* NAME:     sch_scheduler
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Task execution scheduler 
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void sch_scheduler (void)
{
  while (1)
  {
    Task_1_fct();
    Sch_call_next_task();

    Task_2_fct();
    Sch_call_next_task();

    Task_3_fct();
    Sch_call_next_task();
  
    Task_4_fct();
    Sch_call_next_task();
  
    Task_5_fct();
    Sch_call_next_task();
  
    Task_6_fct();
    Sch_call_next_task();
  
    Task_7_fct();
    Sch_call_next_task();
  
    Task_8_fct();
    Sch_call_next_task();
  
    Task_9_fct();
    Sch_call_next_task();
  
    Task_10_fct();
    Sch_call_next_task();

    Sch_new_schedule();
  }
}


/*F**************************************************************************
* NAME:    sch_default_fct
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   This function does nothing 
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void sch_default_fct (void)
{
}


#if (SCH_TIMER == SCH_TIMER0)
/*F**************************************************************************
* NAME:     sch_time_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Scheduler time base (timer 0) initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   mode 16-bit Timer, Time counter
*   T0_PRIO to be defined in config.h
*   TIM_LOW & TIM_HIGH defined in scheduler.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void sch_time_init (void)
{
  T0_init(T0_NOT_GATED, T0_TIMER, T0_MODE_1);
  TL0 = TIM_LOW;
  TH0 = TIM_HIGH;
  t0_set_prio(T0_PRIO);         /* set-up priority */
  T0_enable_int();              /* enable interrupt */
  T0_start();                   /* start time base */
}

/*F**************************************************************************
* NAME:     sch_timer_int
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Timer 0 interrupt function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   IRQ_T0 defined in extsnd1.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
******************************************************************************/
Interrupt (sch_timer_int(void), IRQ_T0) 
{
//  T0_stop();                    /* stop timer */
  TL0 = TIM_LOW;                /* reload timer */ 
  TH0 = TIM_HIGH;
//  T0_start();                   /* restart timer */

#if (SCH_TYPE != SCH_FREE)
  sch_tick_flag = TRUE;
#endif
  /* increment task tick counters */
  gl_cpt_tick++;                /* general timer */
  gl_kbd_tick++;                /* keyboard timer */
  gl_mem_tick++;                /* memory timer */
  gl_led_tick++;                /* LED timer */
  gl_act_tick++;				/* Inactivity TIMER */


}


#elif (SCH_TIMER == SCH_TIMER1)
/*F**************************************************************************
* NAME:     sch_time_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Scheduler time base (timer 1) initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   mode 16-bit Timer, Time counter
*   T1_PRIO to be defined in config.h
*   TIM_LOW & TIM_HIGH defined in scheduler.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void sch_time_init (void)
{
  T1_init(T1_NOT_GATED, T1_TIMER, T1_MODE_1);
  TL1 = TIM_LOW;
  TH1 = TIM_HIGH;
  t1_set_prio(T1_PRIO);         /* set-up priority */
  T1_enable_int();              /* enable interrupt */
  T1_start();                   /* start time base */
}

/*F**************************************************************************
* NAME:     sch_timer_int
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Timer 1 interrupt function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   IRQ_T1 defined in extsnd1.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
Interrupt (sch_timer_int(void), IRQ_T1) 
{
//  T1_stop();                    /* stop timer */
  TL1 = TIM_LOW;                /* reload timer */ 
  TH1 = TIM_HIGH;
//  T1_start();                   /* restart timer */

#if (SCH_TYPE != SCH_FREE)
  sch_tick_flag = TRUE;
#endif

  gl_cpt_tick++;
}


#elif (SCH_TIMER == SCH_TIMER2)
/*F**************************************************************************
* NAME:     sch_time_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Scheduler time base (timer 2) initialization
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   mode 16-bit auto-reload
*   T2_PRIO to be defined in config.h
*   TIM_LOW & TIM_HIGH defined in scheduler.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
*****************************************************************************/
void sch_time_init (void)
{
  T2_init(T2_AUTO_RELOAD, T2_TIMER, T2_NOT_GATED);
  RCAP2L = TIM_LOW;
  RCAP2H = TIM_HIGH;
  t2_set_prio(T2_PRIO);         /* set-up priority */
  T2_enable_int();              /* enable interrupt */
  T2_start();                   /* start time base */
}

/*F**************************************************************************
* NAME:     sch_timer_int
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE:
*   Timer 2 interrupt function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   IRQ_T2 defined in extsnd1.h
*----------------------------------------------------------------------------
* REQUIREMENTS:
******************************************************************************/
Interrupt (sch_timer_int(void), IRQ_T2) 
{
  TF2 = 0;                      /* ack interrupt */

#if (SCH_TYPE != SCH_FREE)
  sch_tick_flag = TRUE;
#endif
  gl_cpt_tick++;
}
#endif


⌨️ 快捷键说明

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