?? os_core.lst
字號:
219 *
220 * Returns : none
221 *********************************************************************************************************
222 */
223
224 void OSInit (void)
225 {
226 1 INT16U i;
227 1
228 1
229 1 OSTime = 0L; /* Clear the 32-bit system clock */
230 1 OSIntNesting = 0; /* Clear the interrupt nesting counter */
231 1 OSLockNesting = 0; /* Clear the scheduling lock counter */
232 1 #if OS_TASK_CREATE_EN || OS_TASK_CREATE_EXT_EN || OS_TASK_DEL_EN
233 1 OSTaskCtr = 0; /* Clear the number of tasks */
234 1 #endif
235 1 OSRunning = FALSE; /* Indicate that multitasking not started */
236 1 OSIdleCtr = 0L; /* Clear the 32-bit idle counter */
C51 COMPILER V8.08 OS_CORE 04/13/2009 13:31:21 PAGE 5
237 1 #if OS_TASK_STAT_EN && OS_TASK_CREATE_EXT_EN
OSIdleCtrRun = 0L;
OSIdleCtrMax = 0L;
OSStatRdy = FALSE; /* Statistic task is not ready */
#endif
242 1 OSCtxSwCtr = 0; /* Clear the context switch counter */
243 1 OSRdyGrp = 0; /* Clear the ready list */
244 1 for (i = 0; i < OS_RDY_TBL_SIZE; i++) {
245 2 OSRdyTbl[i] = 0;
246 2 }
247 1
248 1 OSPrioCur = 0;
249 1 OSPrioHighRdy = 0;
250 1 OSTCBHighRdy = (OS_TCB *)0; /* TCB Initialization */
251 1 OSTCBCur = (OS_TCB *)0;
252 1 OSTCBList = (OS_TCB *)0;
253 1 for (i = 0; i < (OS_LOWEST_PRIO + 1); i++) { /* Clear the priority table */
254 2 OSTCBPrioTbl[i] = (OS_TCB *)0;
255 2 }
256 1 for (i = 0; i < (OS_MAX_TASKS + OS_N_SYS_TASKS - 1); i++) { /* Init. list of free TCBs */
257 2 OSTCBTbl[i].OSTCBNext = &OSTCBTbl[i + 1];
258 2 }
259 1 OSTCBTbl[OS_MAX_TASKS + OS_N_SYS_TASKS - 1].OSTCBNext = (OS_TCB *)0; /* Last OS_TCB */
260 1 OSTCBFreeList = &OSTCBTbl[0];
261 1
262 1 #if OS_MAX_EVENTS >= 2
263 1 for (i = 0; i < (OS_MAX_EVENTS - 1); i++) { /* Init. list of free EVENT control blocks */
264 2 OSEventTbl[i].OSEventPtr = (OS_EVENT *)&OSEventTbl[i + 1];
265 2 }
266 1 OSEventTbl[OS_MAX_EVENTS - 1].OSEventPtr = (OS_EVENT *)0;
267 1 OSEventFreeList = &OSEventTbl[0];
268 1 #endif
269 1
270 1 #if OS_Q_EN && (OS_MAX_QS >= 2)
OSQInit(); /* Initialize the message queue structures */
#endif
273 1
274 1 #if OS_MEM_EN && OS_MAX_MEM_PART >= 2
OSMemInit(); /* Initialize the memory manager */
#endif
277 1
278 1 #if OS_STK_GROWTH == 1
279 1 #if OS_TASK_CREATE_EXT_EN
280 1 OSTaskCreateExt(OSTaskIdle,
281 1 (void *)0, /* No arguments passed to OSTaskIdle() */
282 1 &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Top-Of-Stack */
283 1 OS_IDLE_PRIO, /* Lowest priority level */
284 1 OS_TASK_IDLE_ID,
285 1 &OSTaskIdleStk[0], /* Set Bottom-Of-Stack */
286 1 OS_TASK_IDLE_STK_SIZE,
287 1 (void *)0, /* No TCB extension */
288 1 OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack */
289 1 #else
OSTaskCreate(OSTaskIdle, (void *)0, &OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], OS_IDLE_PRIO);
#endif
292 1 #else
#if OS_TASK_CREATE_EXT_EN
OSTaskCreateExt(OSTaskIdle,
(void *)0, /* No arguments passed to OSTaskIdle() */
&OSTaskIdleStk[0], /* Set Top-Of-Stack */
OS_IDLE_PRIO, /* Lowest priority level */
OS_TASK_IDLE_ID,
C51 COMPILER V8.08 OS_CORE 04/13/2009 13:31:21 PAGE 6
&OSTaskIdleStk[OS_TASK_IDLE_STK_SIZE - 1], /* Set Bottom-Of-Stack */
OS_TASK_IDLE_STK_SIZE,
(void *)0, /* No TCB extension */
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);/* Enable stack checking + clear stack */
#else
OSTaskCreate(OSTaskIdle, (void *)0, &OSTaskIdleStk[0], OS_IDLE_PRIO);
#endif
#endif
307 1
308 1 #if OS_TASK_STAT_EN
#if OS_TASK_CREATE_EXT_EN
#if OS_STK_GROWTH == 1
OSTaskCreateExt(OSTaskStat,
(void *)0, /* No args passed to OSTaskStat() */
&OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],/* Set Top-Of-Stack */
OS_STAT_PRIO, /* One higher than the idle task */
OS_TASK_STAT_ID,
&OSTaskStatStk[0], /* Set Bottom-Of-Stack */
OS_TASK_STAT_STK_SIZE,
(void *)0, /* No TCB extension */
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); /* Enable stack checking + clear */
#else
OSTaskCreateExt(OSTaskStat,
(void *)0, /* No args passed to OSTaskStat() */
&OSTaskStatStk[0], /* Set Top-Of-Stack */
OS_STAT_PRIO, /* One higher than the idle task */
OS_TASK_STAT_ID,
&OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1],/* Set Bottom-Of-Stack */
OS_TASK_STAT_STK_SIZE,
(void *)0, /* No TCB extension */
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); /* Enable stack checking + clear */
#endif
#else
#if OS_STK_GROWTH == 1
OSTaskCreate(OSTaskStat,
(void *)0, /* No args passed to OSTaskStat() */
&OSTaskStatStk[OS_TASK_STAT_STK_SIZE - 1], /* Set Top-Of-Stack */
OS_STAT_PRIO); /* One higher than the idle task */
#else
OSTaskCreate(OSTaskStat,
(void *)0, /* No args passed to OSTaskStat() */
&OSTaskStatStk[0], /* Set Top-Of-Stack */
OS_STAT_PRIO); /* One higher than the idle task */
#endif
#endif
#endif
345 1 }
346 /*$PAGE*/
347 /*
348 *********************************************************************************************************
349 * ENTER ISR
350 *
351 * Description: This function is used to notify uC/OS-II that you are about to service an interrupt
352 * service routine (ISR). This allows uC/OS-II to keep track of interrupt nesting and thus
353 * only perform rescheduling at the last nested ISR.
354 *
355 * Arguments : none
356 *
357 * Returns : none
358 *
359 * Notes : 1) Your ISR can directly increment OSIntNesting without calling this function because
360 * OSIntNesting has been declared 'global'. You MUST, however, be sure that the increment
C51 COMPILER V8.08 OS_CORE 04/13/2009 13:31:21 PAGE 7
361 * is performed 'indivisibly' by your processor to ensure proper access to this critical
362 * resource.
363 * 2) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
364 * 3) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
365 * to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
366 * end of the ISR.
367 *********************************************************************************************************
368 */
369
370 void OSIntEnter(void)
371 {
372 1
373 1 #if OS_CRITICAL_METHOD == 2
374 1 data int_ss;
375 1 #endif
376 1
377 1 OS_ENTER_CRITICAL();
378 1 OSIntNesting++; /* Increment ISR nesting level */
379 1 OS_EXIT_CRITICAL();
380 1 }
381 /*$PAGE*/
382 /*
383 *********************************************************************************************************
384 * EXIT ISR
385 *
386 * Description: This function is used to notify uC/OS-II that you have completed serviving an ISR. When
387 * the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
388 * a new, high-priority task, is ready to run.
389 *
390 * Arguments : none
391 *
392 * Returns : none
393 *
394 * Notes : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair. In other words, for every call
395 * to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
396 * end of the ISR.
397 * 2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
398 *********************************************************************************************************
399 */
400
401 void OSIntExit(void)
402 {
403 1 #if OS_CRITICAL_METHOD == 2
404 1 unsigned DTYPE int_ss;
405 1 #endif
406 1
407 1 OS_ENTER_CRITICAL();
408 1 if ((--OSIntNesting | OSLockNesting) == 0) { /* Reschedule only if all ISRs completed & not locked */
409 2 OSIntExitY = OSUnMapTbl[OSRdyGrp];
410 2 OSPrioHighRdy = (INT8U)((OSIntExitY << 3) + OSUnMapTbl[OSRdyTbl[OSIntExitY]]);
411 2 if (OSPrioHighRdy != OSPrioCur) { /* No context switch if current task is highest ready */
412 3 OSTCBHighRdy = OSTCBPrioTbl[OSPrioHighRdy];
413 3 OSCtxSwCtr++; /* Keep track of the number of context switches */
414 3 OSIntCtxSw(); /* Perform interrupt level context switch */
415 3 }
416 2 }
417 1 OS_EXIT_CRITICAL();
418 1 }
419 /*$PAGE*/
420 /*
421 *********************************************************************************************************
422 * SCHEDULER
C51 COMPILER V8.08 OS_CORE 04/13/2009 13:31:21 PAGE 8
423 *
424 * Description: This function is called by other uC/OS-II services to determine whether a new, high
425 * priority task has been made ready to run. This function is invoked by TASK level code
426 * and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
427 *
428 * Arguments : none
429 *
430 * Returns : none
431 *
432 * Notes : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
433 * 2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
434 *********************************************************************************************************
435 */
436
437 void OSSched(void)reentrant
438 {
439 1 #if OS_CRITICAL_METHOD == 2
440 1 unsigned DTYPE int_ss;
441 1 #endif
442 1
443 1 INT8U y;
444 1
445 1
446 1 OS_ENTER_CRITICAL();
447 1 if ((OSLockNesting | OSIntNesting) == 0) { /* Task scheduling must be enabled and not ISR level */
448 2 y = OSUnMapTbl[OSRdyGrp]; /* Get pointer to highest priority task ready to run
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -