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

📄 0_05_11g.lst

📁 外国人写的时间触发的调度器源码
💻 LST
字号:
C51 COMPILER V6.10  0_05_11G                                                               04/10/2001 11:50:54 PAGE 1   


C51 COMPILER V6.10, COMPILATION OF MODULE 0_05_11G
OBJECT MODULE PLACED IN .\0_05_11g.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\0_05_11g.c OPTIMIZE(6,SIZE) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             0_05_11g.C (v1.00) 
   4          
   5            ------------------------------------------------------------------
   6          
   7             *** THIS IS A SCHEDULER FOR THE STANDARD 8051 ***
   8          
   9             *** Uses T0 for timing, 16-bit, manual reload ***
  10          
  11             *** With 11.059 MHz crystal -> 5ms tick interval ***
  12             --- (see 'reload' function for details) ---
  13          
  14          
  15             COPYRIGHT
  16             ---------
  17          
  18             This code is from the book:
  19          
  20             PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
  21             [Pearson Education, 2001; ISBN: 0-201-33138-1].
  22          
  23             This code is copyright (c) 2001 by Michael J. Pont.
  24           
  25             See book for copyright details and other information.
  26          
  27          -*------------------------------------------------------------------*/
  28          
  29          #include "Main.h"
  30          #include "0_05_11g.h"
  31          
  32          // ------ Public variable declarations -----------------------------
  33          
  34          // The array of tasks (see Sch51.C)
  35          extern sTask SCH_tasks_G[SCH_MAX_TASKS];
  36          
  37          // Used to display the error code
  38          // See Main.H for details of error codes
  39          // See Port.H for details of the error port
  40          extern tByte Error_code_G;
  41          
  42          // ------ Private function prototypes ------------------------------
  43          
  44          static void SCH_Manual_Timer0_Reload(void);
  45          
  46          /*------------------------------------------------------------------*-
  47          
  48            SCH_Init_T0()
  49          
  50            Scheduler initialisation function.  Prepares scheduler
  51            data structures and sets up timer interrupts at required rate.
  52            You must call this function before using the scheduler.  
  53          
  54          -*------------------------------------------------------------------*/
  55          void SCH_Init_T0(void) 
C51 COMPILER V6.10  0_05_11G                                                               04/10/2001 11:50:54 PAGE 2   

  56             {
  57   1         tByte i;
  58   1      
  59   1         for (i = 0; i < SCH_MAX_TASKS; i++) 
  60   1            {
  61   2            SCH_Delete_Task(i);
  62   2            }
  63   1      
  64   1         // Reset the global error variable
  65   1         // - SCH_Delete_Task() will generate an error code, 
  66   1         //   (because the task array is empty)
  67   1         Error_code_G = 0;
  68   1      
  69   1         // Using Timer 0, 16-bit manual reload
  70   1         TMOD &= 0xF0; // Clear all T0 bits (T1 left unchanged)
  71   1         TMOD |= 0x01; // Set required T0 bits (T1 left unchanged) 
  72   1      
  73   1         // Sets up timer reload values
  74   1         SCH_Manual_Timer0_Reload();
  75   1      
  76   1         //  Interrupt Timer 0 enabled
  77   1         ET0  = 1;
  78   1         }
  79          
  80          /*------------------------------------------------------------------*-
  81          
  82            SCH_Start()
  83          
  84            Starts the scheduler, by enabling interrupts.
  85          
  86            NOTE: Usually called after all regular tasks are added,
  87            to keep the tasks synchronised.
  88          
  89            NOTE: ONLY THE SCHEDULER INTERRUPT SHOULD BE ENABLED!!! 
  90           
  91          -*------------------------------------------------------------------*/
  92          void SCH_Start(void) 
  93             {
  94   1         EA = 1;
  95   1         }
  96          
  97          /*------------------------------------------------------------------*-
  98          
  99            SCH_Update
 100          
 101            This is the scheduler ISR.  It is called at a rate 
 102            determined by the timer settings in SCH_Init_T0().
 103            This version is triggered by Timer 0 interrupts.
 104          
 105          -*------------------------------------------------------------------*/
 106          void SCH_Update(void) interrupt INTERRUPT_Timer_0_Overflow 
 107             {
 108   1         tByte Index;
 109   1      
 110   1         // Reload the timer
 111   1         SCH_Manual_Timer0_Reload();
 112   1      
 113   1         // NOTE: calculations are in *TICKS* (not milliseconds)
 114   1         for (Index = 0; Index < SCH_MAX_TASKS; Index++)
 115   1            {
 116   2            // Check if there is a task at this location
 117   2            if (SCH_tasks_G[Index].pTask)
C51 COMPILER V6.10  0_05_11G                                                               04/10/2001 11:50:54 PAGE 3   

 118   2               {
 119   3               if (SCH_tasks_G[Index].Delay == 0)
 120   3                  {
 121   4                  // The task is due to run
 122   4                  SCH_tasks_G[Index].RunMe += 1;  // Inc. the 'Run Me' flag
 123   4      
 124   4                  if (SCH_tasks_G[Index].Period)
 125   4                     {
 126   5                     // Schedule periodic tasks to run again
 127   5                     SCH_tasks_G[Index].Delay = SCH_tasks_G[Index].Period;
 128   5                     }
 129   4                  }
 130   3               else
 131   3                  {
 132   4                  // Not yet ready to run: just decrement the delay 
 133   4                  SCH_tasks_G[Index].Delay -= 1;
 134   4                  }
 135   3               }         
 136   2            }
 137   1         } 
 138          
 139          /*------------------------------------------------------------------*-
 140          
 141            SCH_Manual_Timer0_Reload()
 142          
 143            This scheduler uses a (manually reloaded) 16-bit timer.
 144            The manual reload means that all timings are approximate. 
 145            THIS SCHEDULER IS NOT SUITABLE FOR APPLICATIONS WHERE
 146            ACCURATE TIMING IS REQUIRED!!!
 147            
 148            Timer reload is carried out in this function. 
 149           
 150          -*------------------------------------------------------------------*/
 151          void SCH_Manual_Timer0_Reload()
 152             {
 153   1         // Stop Timer 0
 154   1         TR0 = 0;
 155   1      
 156   1         // Crystal is assumed to be 11.059 MHz
 157   1         // Assume 12 osc cycles per timer increment
 158   1         // -> timer resolution is 0.0000010850694 seconds (1.085 祍)
 159   1         //
 160   1         // The required Timer 0 overflow is 0.005 seconds (5 ms)
 161   1         // - this takes 4608 timer ticks
 162   1         //
 163   1         // Reload value is 65536 - 4608 = 60928 (dec) = 0xEE00
 164   1         TH0  = 0xEE;
 165   1         TL0  = 0x00;
 166   1      
 167   1         //  Start Timer 0
 168   1         TR0  = 1;
 169   1         }
 170          
 171          /*------------------------------------------------------------------*-
 172            ---- END OF FILE -------------------------------------------------
 173          -*------------------------------------------------------------------*/
 174          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    196    ----
   CONSTANT SIZE    =   ----    ----
C51 COMPILER V6.10  0_05_11G                                                               04/10/2001 11:50:54 PAGE 4   

   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       1
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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