📄 hsch51.lst
字号:
C51 COMPILER V6.10 HSCH51 04/19/2001 11:26:09 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE HSCH51
OBJECT MODULE PLACED IN .\HSCH51.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\HSCH51.C OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 hSCH51.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 /// HYBRID SCHEDULER CORE ///
8
9 *** THESE ARE THE CORE SCHEDULER FUNCTIONS ***
10 --- These functions may be used with all 8051 devices ---
11
12 *** hSCH_MAX_TASKS *must* be set by the user ***
13 --- see "Sch51.h" ---
14
15 *** Includes power-saving mode ***
16 --- You *MUST* confirm that the power-down mode is adapted ---
17 --- to match your chosen device (usually only necessary with
18 --- Extended 8051s, such as c515c, c509, etc ---
19
20 COPYRIGHT
21 ---------
22
23 This code is from the book:
24
25 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont
26 [Pearson Education, 2001; ISBN: 0-201-33138-1].
27
28 This code is copyright (c) 2001 by Michael J. Pont.
29
30 See book for copyright details and other information.
31
32 -*------------------------------------------------------------------*/
33
34 #include "Main.h"
35 #include "Port.h"
36
37 #include "hSch51.h"
38
39 // ------ Public variable definitions ------------------------------
40
41 // The array of tasks
42 sTaskH hSCH_tasks_G[hSCH_MAX_TASKS];
43
44 // Used to display the error code
45 // See Main.H for details of error codes
46 // See Port.H for details of the error port
47 tByte Error_code_G = 0;
48
49 // ------ Private function prototypes ------------------------------
50
51 static void hSCH_Go_To_Sleep(void);
52
53 // ------ Private variables ----------------------------------------
54
55 // Keeps track of time since last error was recorded (see below)
C51 COMPILER V6.10 HSCH51 04/19/2001 11:26:09 PAGE 2
56 static tWord Error_tick_count_G;
57
58 // The code of the last error (reset after ~1 minute)
59 static tByte Last_error_code_G;
60
61
62 /*------------------------------------------------------------------*-
63
64 hSCH_Dispatch_Tasks()
65
66 This is the 'dispatcher' function. When a task (function)
67 is due to run, hSCH_Dispatch_Tasks() will run it.
68 This function must be called (repeatedly) from the main loop.
69
70 -*------------------------------------------------------------------*/
71 void hSCH_Dispatch_Tasks(void)
72 {
73 1 tByte Index;
74 1
75 1 // Dispatches (runs) the next task (if one is ready)
76 1 for (Index = 0; Index < hSCH_MAX_TASKS; Index++)
77 1 {
78 2 // Only dispatching co-operative tasks
79 2 if ((hSCH_tasks_G[Index].Co_op) && (hSCH_tasks_G[Index].RunMe > 0))
80 2 {
81 3 (*hSCH_tasks_G[Index].pTask)(); // Run the task
82 3
83 3 hSCH_tasks_G[Index].RunMe -= 1; // Reset / reduce RunMe flag
84 3
85 3 // Periodic tasks will automatically run again
86 3 // - if this is a 'one shot' task, remove it from the array
87 3 if (hSCH_tasks_G[Index].Period == 0)
88 3 {
89 4 // Faster than call to delete task
90 4 hSCH_tasks_G[Index].pTask = 0;
91 4 }
92 3 }
93 2 }
94 1
95 1 // Report system status
96 1 hSCH_Report_Status();
97 1
98 1 // The scheduler enters idle mode at this point
99 1 hSCH_Go_To_Sleep();
100 1 }
101
102 /*------------------------------------------------------------------*-
103
104 hSCH_Add_Task()
105
106 Causes a task (function) to be executed at regular intervals
107 or after a user-defined delay
108
109 Fn_P - The name of the function which is to be scheduled.
110 NOTE: All scheduled functions must be 'void, void' -
111 that is, they must take no parameters, and have
112 a void return type.
113
114 Del - The interval (TICKS) before the task is first executed
115
116 Rep - If 'Rep' is 0, the function is only called once,
117 at the time determined by 'Del'. If Rep is non-zero,
C51 COMPILER V6.10 HSCH51 04/19/2001 11:26:09 PAGE 3
118 then the function is called repeatedly at an interval
119 determined by the vakue of Rep (see below for examples
120 that should help clarify this).
121
122 Co-op - Set to 1 if it a co-op task; 0 if pre-emptive
123
124 RETN: The position in the task array at which the task has been added.
125 If the return value is hSCH_MAX_TASKS then the task could not be
126 added to the array (there was insufficient space). If the
127 return value is < hSCH_MAX_TASKS, then the task was added
128 successfully.
129
130 Note: this return value may be required, if a task is
131 to be subsequently deleted - see hSCH_Delete_Task().
132
133
134 EXAMPLES:
135
136 Task_ID = hSCH_Add_Task(Do_X,1000,0,0);
137 Causes the function Do_X() to be executed once after 1000 ticks.
138 (Pre-emptive task)
139
140 Task_ID = hSCH_Add_Task(Do_X,0,1000,1);
141 Causes the function Do_X() to be executed regularly, every 1000 ticks.
142 (co-operative task)
143
144 Task_ID = hSCH_Add_Task(Do_X,300,1000,0);
145 Causes the function Do_X() to be executed regularly, every 1000 ticks.
146 Task will be first executed at T = 300 ticks, then 1300, 2300, etc.
147 (Pre-emptive task)
148
149 -*------------------------------------------------------------------*/
150 tByte hSCH_Add_Task(void (code* Fn_p)(), // Task function pointer
151 tWord Del, // Num ticks 'til task first runs
152 tWord Per, // Num ticks between repeat runs
153 bit Co_op) // Co_op / pre_emp
154 {
155 1 tByte Index = 0;
156 1
157 1 // First find a gap in the array (if there is one)
158 1 while ((hSCH_tasks_G[Index].pTask != 0) && (Index < hSCH_MAX_TASKS))
159 1 {
160 2 Index++;
161 2 }
162 1
163 1 // Have we reached the end of the list?
164 1 if (Index == hSCH_MAX_TASKS)
165 1 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -