📄 hsch51.lst
字号:
166 2 // Task list is full
167 2 //
168 2 // Set the global error variable
169 2 Error_code_G = ERROR_SCH_TOO_MANY_TASKS;
170 2
171 2 // Also return an error code
172 2 return hSCH_MAX_TASKS;
173 2 }
174 1
175 1 // If we're here, there is a space in the task array
176 1 hSCH_tasks_G[Index].pTask = Fn_p;
177 1
178 1 hSCH_tasks_G[Index].Delay = Del;
179 1 hSCH_tasks_G[Index].Period = Per;
C51 COMPILER V6.10 HSCH51 04/18/2001 14:03:44 PAGE 4
180 1
181 1 hSCH_tasks_G[Index].Co_op = Co_op;
182 1
183 1 hSCH_tasks_G[Index].RunMe = 0;
184 1
185 1 return Index; // return position of task (to allow later deletion)
186 1 }
187
188 /*------------------------------------------------------------------*-
189
190 hSCH_Delete_Task()
191
192 Removes a task from the scheduler. Note that this does
193 *not* delete the associated function from memory:
194 it simply means that it is no longer called by the scheduler.
195
196 PARAMS: Task_index - The task index. Provided by hSCH_Add_Task().
197
198 RETURNS: RETURN_ERROR or RETURN_NORMAL
199
200 -*------------------------------------------------------------------*/
201 bit hSCH_Delete_Task(tByte Task_index)
202 {
203 1 bit Return_code;
204 1
205 1 if (hSCH_tasks_G[Task_index].pTask == 0)
206 1 {
207 2 // No task at this location...
208 2 //
209 2 // Set the global error variable
210 2 Error_code_G = ERROR_SCH_CANNOT_DELETE_TASK;
211 2
212 2 // ...also return an error code
213 2 Return_code = RETURN_ERROR;
214 2 }
215 1 else
216 1 {
217 2 Return_code = RETURN_NORMAL;
218 2 }
219 1
220 1 hSCH_tasks_G[Task_index].pTask = 0;
221 1 hSCH_tasks_G[Task_index].Delay = 0;
222 1 hSCH_tasks_G[Task_index].Period = 0;
223 1
224 1 hSCH_tasks_G[Task_index].RunMe = 0;
225 1
226 1 return Return_code; // return status
227 1 }
228
229
230 /*------------------------------------------------------------------*-
231
232 hSCH_Report_Status()
233
234 Simple function to display error codes.
235
236 This version displays code on a port with attached LEDs:
237 adapt, if required, to report errors over serial link, etc.
238
239 Errors are only displayed for a limited period
240 (60000 ticks = 1 minute at 1ms tick interval).
241 After this the the error code is reset to 0.
C51 COMPILER V6.10 HSCH51 04/18/2001 14:03:44 PAGE 5
242
243 This code may be easily adapted to display the last
244 error 'for ever': this may be appropriate in your
245 application.
246
247 See Chapter 14 for further information.
248
249 -*------------------------------------------------------------------*/
250 void hSCH_Report_Status(void)
251 {
252 1 #ifdef SCH_REPORT_ERRORS
253 1 // ONLY APPLIES IF WE ARE REPORTING ERRORS
254 1 // Check for a new error code
255 1 if (Error_code_G != Last_error_code_G)
256 1 {
257 2 // Negative logic on LEDs assumed
258 2 Error_port = 255 - Error_code_G;
259 2
260 2 Last_error_code_G = Error_code_G;
261 2
262 2 if (Error_code_G != 0)
263 2 {
264 3 Error_tick_count_G = 60000;
265 3 }
266 2 else
267 2 {
268 3 Error_tick_count_G = 0;
269 3 }
270 2 }
271 1 else
272 1 {
273 2 if (Error_tick_count_G != 0)
274 2 {
275 3 if (--Error_tick_count_G == 0)
276 3 {
277 4 Error_code_G = 0; // Reset error code
278 4 }
279 3 }
280 2 }
281 1 #endif
282 1 }
283
284
285 /*------------------------------------------------------------------*-
286
287 hSCH_Go_To_Sleep()
288
289 This scheduler enters 'idle mode' between clock ticks
290 to save power. The next clock tick will return the processor
291 to the normal operating state.
292
293 Note: a slight performance improvement is possible if this
294 function is implemented as a macro, or if the code here is simply
295 pasted into the 'dispatch' function.
296
297 However, by making this a function call, it becomes easier
298 - during development - to assess the performance of the
299 scheduler, using the 'performance analyser' in the Keil
300 hardware simulator. See Chapter 14 for examples for this.
301
302 *** May wish to disable this if using a watchdog ***
303
C51 COMPILER V6.10 HSCH51 04/18/2001 14:03:44 PAGE 6
304 *** ADAPT AS REQUIRED FOR YOUR HARDWARE ***
305
306 -*------------------------------------------------------------------*/
307 void hSCH_Go_To_Sleep()
308 {
309 1 PCON |= 0x01; // Enter idle mode (generic 8051 version)
310 1
311 1 // Entering idle mode requires TWO consecutive instructions
312 1 // on 80c515 / 80c505 - to avoid accidental triggering
313 1 //PCON |= 0x01; // Enter idle mode (#1)
314 1 //PCON |= 0x20; // Enter idle mode (#2)
315 1 }
316
317
318 /*------------------------------------------------------------------*-
319 ---- END OF FILE -------------------------------------------------
320 -*------------------------------------------------------------------*/
321
322
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 346 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 20 5
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -