📄 os_core.lst
字号:
204 * Arguments : none
205 *
206 * Returns : none
207 *
208 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
209 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
210 *********************************************************************************************************
211 */
212
213 #if OS_SCHED_LOCK_EN > 0
void OSSchedLock (void) LG_REENTRANT
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
if (OSRunning == TRUE) { /* Make sure multitasking is running */
OS_ENTER_CRITICAL();
if (OSLockNesting < 255) { /* Prevent OSLockNesting from wrapping back to 0 */
OSLockNesting++; /* Increment lock nesting level */
}
OS_EXIT_CRITICAL();
}
}
#endif
C51 COMPILER V8.05a OS_CORE 04/18/2007 18:18:23 PAGE 5
230
231 /*$PAGE*/
232 /*
233 *********************************************************************************************************
234 * ENABLE SCHEDULING
235 *
236 * Description: This function is used to re-allow rescheduling.
237 *
238 * Arguments : none
239 *
240 * Returns : none
241 *
242 * Notes : 1) You MUST invoke OSSchedLock() and OSSchedUnlock() in pair. In other words, for every
243 * call to OSSchedLock() you MUST have a call to OSSchedUnlock().
244 *********************************************************************************************************
245 */
246
247 #if OS_SCHED_LOCK_EN > 0
void OSSchedUnlock (void) LG_REENTRANT
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
if (OSRunning == TRUE) { /* Make sure multitasking is running */
OS_ENTER_CRITICAL();
if (OSLockNesting > 0) { /* Do not decrement if already 0 */
OSLockNesting--; /* Decrement lock nesting level */
if ((OSLockNesting == 0) && (OSIntNesting == 0)) { /* See if sched. enabled and not an ISR */
OS_EXIT_CRITICAL();
OS_Sched(); /* See if a HPT is ready */
} else {
OS_EXIT_CRITICAL();
}
} else {
OS_EXIT_CRITICAL();
}
}
}
#endif
271
272 /*$PAGE*/
273 /*
274 *********************************************************************************************************
275 * START MULTITASKING
276 *
277 * Description: This function is used to start the multitasking process which lets uC/OS-II manages the
278 * task that you have created. Before you can call OSStart(), you MUST have called OSInit()
279 * and you MUST have created at least one task.
280 *
281 * Arguments : none
282 *
283 * Returns : none
284 *
285 * Note : OSStartHighRdy() MUST:
286 * a) Call OSTaskSwHook() then,
287 * b) Set OSRunning to TRUE.
288 * c) Load the context of the task pointed to by OSTCBHighRdy.
289 * d_ Execute the task.
290 *********************************************************************************************************
291 */
C51 COMPILER V8.05a OS_CORE 04/18/2007 18:18:23 PAGE 6
292
293 void OSStart (void) LG_REENTRANT
294 {
295 1 INT8U y;
296 1 INT8U x;
297 1
298 1 if (OSRunning == FALSE) {
299 2 y = OSUnMapTbl[OSRdyGrp]; /* Find highest priority's task priority number */
300 2 x = OSUnMapTbl[OSRdyTbl[y]];
301 2 OSPrioHighRdy = (INT8U)((y << 3) + x);
302 2 OSPrioCur = OSPrioHighRdy;
303 2 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy]; /* Point to highest priority task ready to run */
304 2 OSTCBCur = OSTCBHighRdy;
305 2 OSStartHighRdy(); /* Execute target specific code to start task */
306 2 }
307 1 }
308 /*$PAGE*/
309 /*
310 *********************************************************************************************************
311 * STATISTICS INITIALIZATION
312 *
313 * Description: This function is called by your application to establish CPU usage by first determining
314 * how high a 32-bit counter would count to in 1 second if no other tasks were to execute
315 * during that time. CPU usage is then determined by a low priority task which keeps track
316 * of this 32-bit counter every second but this time, with other tasks running. CPU usage is
317 * determined by:
318 *
319 * OSIdleCtr
320 * CPU Usage (%) = 100 * (1 - ------------)
321 * OSIdleCtrMax
322 *
323 * Arguments : none
324 *
325 * Returns : none
326 *********************************************************************************************************
327 */
328
329 #if OS_TASK_STAT_EN > 0
void OSStatInit (void) LG_REENTRANT
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OSTimeDly(2); /* Synchronize with clock tick */
OS_ENTER_CRITICAL();
OSIdleCtr = 0L; /* Clear idle counter */
OS_EXIT_CRITICAL();
OSTimeDly(OS_TICKS_PER_SEC); /* Determine MAX. idle counter value for 1 second */
OS_ENTER_CRITICAL();
OSIdleCtrMax = OSIdleCtr; /* Store maximum idle counter count in 1 second */
OSStatRdy = TRUE;
OS_EXIT_CRITICAL();
}
#endif
348 /*$PAGE*/
349 /*
350 *********************************************************************************************************
351 * PROCESS SYSTEM TICK
352 *
353 * Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
C51 COMPILER V8.05a OS_CORE 04/18/2007 18:18:23 PAGE 7
354 * as a 'clock tick'). This function should be called by the ticker ISR but, can also be
355 * called by a high priority task.
356 *
357 * Arguments : none
358 *
359 * Returns : none
360 *********************************************************************************************************
361 */
362
363 void OSTimeTick (void) LG_REENTRANT
364 {
365 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
368 1 OS_TCB *ptcb;
369 1
370 1
371 1 OSTimeTickHook(); /* Call user definable hook */
372 1 #if OS_TIME_GET_SET_EN > 0
OS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
OSTime++;
OS_EXIT_CRITICAL();
#endif
377 1 if (OSRunning == TRUE) {
378 2 ptcb = OSTCBList; /* Point at first TCB in TCB list */
379 2 while (ptcb->OSTCBPrio != OS_IDLE_PRIO) { /* Go through all TCBs in TCB list */
380 3 OS_ENTER_CRITICAL();
381 3 if (ptcb->OSTCBDly != 0) { /* Delayed or waiting for event with TO */
382 4 if (--ptcb->OSTCBDly == 0) { /* Decrement nbr of ticks to end of delay */
383 5 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) { /* Is task suspended? */
384 6 OSRdyGrp |= ptcb->OSTCBBitY; /* No, Make task R-to-R (timed out)*/
385 6 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
386 6 } else { /* Yes, Leave 1 tick to prevent ... */
387 6 ptcb->OSTCBDly = 1; /* ... loosing the task when the ... */
388 6 } /* ... suspension is removed. */
389 5 }
390 4 }
391 3 ptcb = ptcb->OSTCBNext; /* Point at next TCB in TCB list */
392 3 OS_EXIT_CRITICAL();
393 3 }
394 2 }
395 1 }
396 /*$PAGE*/
397 /*
398 *********************************************************************************************************
399 * GET VERSION
400 *
401 * Description: This function is used to return the version number of uC/OS-II. The returned value
402 * corresponds to uC/OS-II's version number multiplied by 100. In other words, version 2.00
403 * would be returned as 200.
404 *
405 * Arguments : none
406 *
407 * Returns : the version number of uC/OS-II multiplied by 100.
408 *********************************************************************************************************
409 */
410
411 INT16U OSVersion (void) LG_REENTRANT
412 {
413 1 return (OS_VERSION);
414 1 }
415
C51 COMPILER V8.05a OS_CORE 04/18/2007 18:18:23 PAGE 8
416 /*$PAGE*/
417 /*
418 *********************************************************************************************************
419 * DUMMY FUNCTION
420 *
421 * Description: This function doesn't do anything. It is called by OSTaskDel().
422 *
423 * Arguments : none
424 *
425 * Returns : none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -