shuiqinghan2012的个人空间 https://bbs.21ic.com/?875044 [收藏] [复制] [RSS]

日志

调度器学习

已有 234 次阅读2018-10-2 16:24 |个人分类:STC51单片机|系统分类:兴趣爱好

        时间触发嵌入式系统设计模式——8051系列微控制器开发可靠应用
        13,14章 合作式调度器学习记录
       
        翻出之前找的一本书--时间触发嵌入式系统设计模式——8051系列微控制器开发可靠应用--学习了一下合作式调度器
        这次主要是看了相关的例程代码,总体有了一部分感觉,但整体看,可以满足大部分单片机程序的应用,任务数小于10,但实时性应该不会很强,因为,删除,创建,或者便利任务都是在用for循环查找,时间确定性应该不是很高。
       
        重点看了如下这些函数
        14例程中解释如下,所以2_01_12g (T2定时器作为调度器,1mS调度一次,12Mhz 通用51处理器)这个例程可以直接用于大部分的51处理器。

The sub-directory 'Func_Ptr' contains the function pointer example 
(Listing 14.1 and 14.2).

The remaining sub-directories contain a number of complete scheduler examples. 
These projects (and sub-directories) are named as follows:

  TIMER_TICK_OSCILLATOR 

For example, the scheduler in sub-directory 0_01_12 has the following features:
- The scheduler is driven by Timer 0;
- The scheduler has a 1 millisecond tick interval;
- The scheduler code assumes use of a 12 MHz oscillator.

Most of the examples are 'generic' and have a 'g' suffix (e.g. 0_01_12g).  
These examples can be adapted without difficulty for use with a wide range
of 8051 devices.  

Two of the examples (with an 'i' suffix; e.g. 2_01_10i) are adapted for
use with the Infineon family of microcontrollers.

All of the examples may be easily adapted (for example, to generate different 
tick intervals or for use with different oscillators).

2_01_12g 说明如下:
Generic 16-bit auto-reload scheduler (using T2).

   Assumes 12 MHz oscillator (-> 01 ms tick interval).

   *** All timing is in TICKS (not milliseconds) ***

任务核心代码为任务数据结构体,之后建立了结构体数组组着成任务队列
_SCH51_H
#ifndef _SCH51_H
#define _SCH51_H

#include "Main.h"

// ------ Public data type declarations ----------------------------

// Store in DATA area, if possible, for rapid access  
// Total memory per task is 7 bytes
typedef data struct 
   {
   // Pointer to the task (must be a 'void (void)' function)
   //指向任务函数的函数指针
   void (code * pTask)(void);  

   // Delay (ticks) until the function will (next) be run
   // - see SCH_Add_Task() for further details
   // 首次运行制定的延时时间ticks为单位
   tWord Delay;       

   // Interval (ticks) between subsequent runs.
   // - see SCH_Add_Task() for further details
   //-周期性任务的周期数 -ticks为单位
   tWord Period;       

   // Incremented (by scheduler) when task is due to execute
   //在调度器中增加(调度器实际为1mS(可修改)定时器中断函数,在定时器中断函数中修改Runme标志,在刷新函数中检测标志,当大于0时执行任务函数)
   //任务在创建是此标志为0
   tByte RunMe;       
   } sTask; 

// ------ Public function prototypes -------------------------------

// Core scheduler functions
void  SCH_Dispatch_Tasks(void);
tByte SCH_Add_Task(void (code*) (void), const tWord, const tWord);  
bit   SCH_Delete_Task(const tByte);
void  SCH_Report_Status(void);

// ------ Public constants -----------------------------------------

// The maximum number of tasks required at any one time
// during the execution of the program
//
// MUST BE ADJUSTED FOR EACH NEW PROJECT
#define SCH_MAX_TASKS   (1)   
 
#endif
                              
/*------------------------------------------------------------------*-
  ---- END OF FILE -------------------------------------------------
-*------------------------------------------------------------------*/



路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)