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

📄 0_01_12g.lst

📁 调度器内核
💻 LST
字号:
C51 COMPILER V8.05a   0_01_12G                                                             04/02/2007 21:08:48 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE 0_01_12G
OBJECT MODULE PLACED IN 0_01_12g.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 0_01_12g.c OPTIMIZE(6,SIZE) BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*------------------------------------------------------------------*-
   2          
   3             0_01_12g.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 12MHz crystal -> 1ms 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_01_12g.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            Must call this function before using the scheduler.  
  53          
  54          -*------------------------------------------------------------------*/
  55          void SCH_Init_T0(void) 
C51 COMPILER V8.05a   0_01_12G                                                             04/02/2007 21:08:48 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 V8.05a   0_01_12G                                                             04/02/2007 21:08:48 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            Timer reload is carried out in this function. 
 148           
 149          -*------------------------------------------------------------------*/
 150          void SCH_Manual_Timer0_Reload()
 151             {
 152   1         // Stop Timer 0
 153   1         TR0 = 0;
 154   1      
 155   1         // 8051, 12 MHz
 156   1         // The Timer 0 resolution is 1.000 祍
 157   1         // We set the timer at 64336 to generate interrupt after 1 ms
 158   1         // -> we are generating timer ticks at ~1 ms intervals
 159   1         TL0  = 0x18;
 160   1         TH0  = 0xFC;
 161   1      
 162   1         //  Start Timer 0
 163   1         TR0  = 1;
 164   1         }
 165          
 166          /*------------------------------------------------------------------*-
 167            ---- END OF FILE -------------------------------------------------
 168          -*------------------------------------------------------------------*/
 169          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    196    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       1
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
C51 COMPILER V8.05a   0_01_12G                                                             04/02/2007 21:08:48 PAGE 4   

END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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