?? sch51.lst
字號:
C51 COMPILER V8.01 SCH51 07/13/2008 18:02:06 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE SCH51
OBJECT MODULE PLACED IN SCH51.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE SCH51.C OPTIMIZE(6,SIZE) BROWSE DEBUG OBJECTEXTEND
line level source
1 /*------------------------------------------------------------------*-
2
3 SCH51.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 *** THESE ARE THE CORE SCHEDULER FUNCTIONS ***
8 --- These functions may be used with all 8051 devices ---
9
10 *** SCH_MAX_TASKS *must* be set by the user ***
11 --- see "Sch51.H" ---
12
13 *** Includes (optional) power-saving mode ***
14 --- You must ensure that the power-down mode is adapted ---
15 --- to match your chosen device (or disabled altogether) ---
16
17
18 COPYRIGHT
19 ---------
20
21 This code is from the book:
22
23 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont
24 [Pearson Education, 2001; ISBN: 0-201-33138-1].
25
26 This code is copyright (c) 2001 by Michael J. Pont.
27
28 See book for copyright details and other information.
29
30 -*------------------------------------------------------------------*/
31
32 #include "Main.h"
33 #include "Port.h"
34
35 #include "Sch51.h"
36
37 // ------ Public variable definitions ------------------------------
38
39 // The array of tasks
40 sTask SCH_tasks_G[SCH_MAX_TASKS];
41
42 // Used to display the error code
43 // See Main.H for details of error codes
44 // See Port.H for details of the error port
45 tByte Error_code_G = 0;
46
47 // ------ Private function prototypes ------------------------------
48
49 static void SCH_Go_To_Sleep(void);
50
51 // ------ Private variables ----------------------------------------
52
53 // Keeps track of time since last error was recorded (see below)
54 static tWord Error_tick_count_G;
55
C51 COMPILER V8.01 SCH51 07/13/2008 18:02:06 PAGE 2
56 // The code of the last error (reset after ~1 minute)
57 static tByte Last_error_code_G;
58
59
60 /*------------------------------------------------------------------*-
61
62 SCH_Dispatch_Tasks()
63
64 This is the 'dispatcher' function. When a task (function)
65 is due to run, SCH_Dispatch_Tasks() will run it.
66 This function must be called (repeatedly) from the main loop.
67
68 -*------------------------------------------------------------------*/
69 void SCH_Dispatch_Tasks(void)
70 {
71 1 tByte Index;
72 1
73 1 // Dispatches (runs) the next task (if one is ready)
74 1 for (Index = 0; Index < SCH_MAX_TASKS; Index++)
75 1 {
76 2 if (SCH_tasks_G[Index].RunMe > 0)
77 2 {
78 3 (*SCH_tasks_G[Index].pTask)(); // Run the task
79 3
80 3 SCH_tasks_G[Index].RunMe -= 1; // Reset / reduce RunMe flag
81 3
82 3 // Periodic tasks will automatically run again
83 3 // - if this is a 'one shot' task, remove it from the array
84 3 if (SCH_tasks_G[Index].Period == 0)
85 3 {
86 4 SCH_Delete_Task(Index);
87 4 }
88 3 }
89 2 }
90 1
91 1 // Report system status
92 1 SCH_Report_Status();
93 1
94 1 // The scheduler enters idle mode at this point
95 1 SCH_Go_To_Sleep();
96 1 }
97
98 /*------------------------------------------------------------------*-
99
100 SCH_Add_Task()
101
102 Causes a task (function) to be executed at regular intervals
103 or after a user-defined delay
104
105 Fn_P - The name of the function which is to be scheduled.
106 NOTE: All scheduled functions must be 'void, void' -
107 that is, they must take no parameters, and have
108 a void return type.
109
110 DELAY - The interval (TICKS) before the task is first executed
111
112 PERIOD - If 'PERIOD' is 0, the function is only called once,
113 at the time determined by 'DELAY'. If PERIOD is non-zero,
114 then the function is called repeatedly at an interval
115 determined by the value of PERIOD (see below for examples
116 which should help clarify this).
117
C51 COMPILER V8.01 SCH51 07/13/2008 18:02:06 PAGE 3
118
119 RETURN VALUE:
120
121 Returns the position in the task array at which the task has been
122 added. If the return value is SCH_MAX_TASKS then the task could
123 not be added to the array (there was insufficient space). If the
124 return value is < SCH_MAX_TASKS, then the task was added
125 successfully.
126
127 Note: this return value may be required, if a task is
128 to be subsequently deleted - see SCH_Delete_Task().
129
130 EXAMPLES:
131
132 Task_ID = SCH_Add_Task(Do_X,1000,0);
133 Causes the function Do_X() to be executed once after 1000 sch ticks.
134
135 Task_ID = SCH_Add_Task(Do_X,0,1000);
136 Causes the function Do_X() to be executed regularly, every 1000 sch ticks.
137
138 Task_ID = SCH_Add_Task(Do_X,300,1000);
139 Causes the function Do_X() to be executed regularly, every 1000 ticks.
140 Task will be first executed at T = 300 ticks, then 1300, 2300, etc.
141
142 -*------------------------------------------------------------------*/
143 tByte SCH_Add_Task(void (code * pFunction)(),
144 const tWord DELAY,
145 const tWord PERIOD)
146 {
147 1 tByte Index = 0;
148 1
149 1 // First find a gap in the array (if there is one) //注意在這里 MAIN()運行了SCH_Delete_Task(const tBy
-te TASK_INDEX)
150 1 //就把所有的任務 的函數(shù)指針SCH_tasks_G[Index].pTask清零了,所以如果沒有添加的任務,SCH_tasks_G[Index].p
-Task == 0
151 1 while ((SCH_tasks_G[Index].pTask != 0) && (Index < SCH_MAX_TASKS))
152 1 {
153 2 Index++;
154 2 }
155 1
156 1 // Have we reached the end of the list?
157 1 if (Index == SCH_MAX_TASKS)
158 1 {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -