Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2554
  • 博文数量: 3
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-25 13:33
文章分类
文章存档

2015年(3)

我的朋友
最近访客

分类: LINUX

2015-08-31 21:08:31


μc的操作系统核心源码基本上都是os_core之类的文件,以前做项目的时候用过但是木有好好看过,现在不忙了可以每天晚上的时间看一点,一则巩固一下c语言的知识,二则可以为以后linux和vxworks打个基础
 
从main函数开始,除了硬件上的TargetInit(); 
初始化硬件上的端口(串口等)、PLL和中断
然后就是最主要的系统初始化函数
OSInit ();

点击(此处)折叠或打开

  1. /*
  2. *********************************************************************************************************
  3. * INITIALIZATION
  4. *
  5. * Description: This function is used to initialize the internals of uC/OS-II and MUST be called prior to
  6. * creating any uC/OS-II object and, prior to calling OSStart().
  7. *
  8. * Arguments : none
  9. *
  10. * Returns : none
  11. *********************************************************************************************************
  12. */

  13. void OSInit (void)
  14. {
  15. #if OS_VERSION >= 204
  16.     OSInitHookBegin(); /* Call port specific initialization code */
  17. #endif

  18.     OS_InitMisc(); /* Initialize miscellaneous variables */

  19.     OS_InitRdyList(); /* Initialize the Ready List */

  20.     OS_InitTCBList(); /* Initialize the free list of OS_TCBs */

  21.     OS_InitEventList(); /* Initialize the free list of OS_EVENTs */

  22. #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
  23.     OS_FlagInit(); /* Initialize the event flag structures */
  24. #endif

  25. #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
  26.     OS_MemInit(); /* Initialize the memory manager */
  27. #endif

  28. #if (OS_Q_EN > 0) && (OS_MAX_QS > 0)
  29.     OS_QInit(); /* Initialize the message queue structures */
  30. #endif

  31.     OS_InitTaskIdle(); /* Create the Idle Task */
  32. #if OS_TASK_STAT_EN > 0
  33.     OS_InitTaskStat(); /* Create the Statistic Task */
  34. #endif

  35. #if OS_TMR_EN > 0
  36.     OSTmr_Init(); /* Initialize the Timer Manager */
  37. #endif

  38. #if OS_VERSION >= 204
  39.     OSInitHookEnd(); /* Call port specific init. code */
  40. #endif

  41. #if OS_VERSION >= 270 && OS_DEBUG_EN > 0
  42.     OSDebugInit();
  43. #endif
  44. }

如果版本号超过204u则调用函数void OSInitHookBegin (void)
 
OS_InitMisc();杂项变量初始化

点击(此处)折叠或打开

  1. /*
  2. *********************************************************************************************************
  3. * INITIALIZATION
  4. * INITIALIZE MISCELLANEOUS VARIABLES
  5. *
  6. * Description: This function is called by OSInit() to initialize miscellaneous variables.
  7. *
  8. * Arguments : none
  9. *
  10. * Returns : none
  11. *********************************************************************************************************
  12. */

  13. static void OS_InitMisc (void)
  14. {
  15. #if OS_TIME_GET_SET_EN > 0
  16.     OSTime = 0L; /* Clear the 32-bit system clock */
  17. #endif

  18.     OSIntNesting = 0; /* Clear the interrupt nesting counter */
  19.     OSLockNesting = 0; /* Clear the scheduling lock counter */

  20.     OSTaskCtr = 0; /* Clear the number of tasks */

  21.     OSRunning = OS_FALSE; /* Indicate that multitasking not started */

  22.     OSCtxSwCtr = 0; /* Clear the context switch counter */
  23.     OSIdleCtr = 0L; /* Clear the 32-bit idle counter */

  24. #if OS_TASK_STAT_EN > 0
  25.     OSIdleCtrRun = 0L;
  26.     OSIdleCtrMax = 0L;
  27.     OSStatRdy = OS_FALSE; /* Statistic task is not ready */
  28. #endif
  29. }
OSTime系统时钟变量
OS_EXT  volatile  INT32U  OSTime;        /* Current value of system time (in ticks) */
OSIntNesting系统中断嵌套层数变量
OS_EXT  INT8U             OSIntNesting;             /* Interrupt nesting level 
OSLockNesting系统调度锁计数器
OS_EXT  INT8U             OSLockNesting;
多任务嵌套计数器
OSTaskCtr系统创建的task的个数
OS_EXT  INT8U             OSTaskCtr;                       /* Number of tasks created  
OSRunning系统内核运行标志位
OS_EXT  BOOLEAN           OSRunning;           /* Flag indicating that kernel is running   */
OSCtxSwCtr系统上下文切换计数器
OS_EXT  INT32U            OSCtxSwCtr;    /* Counter of number of context switches  */
OSIdleCtr系统空闲计数器
OS_EXT  volatile  INT32U  OSIdleCtr;                                 /* Idle counter 
OSIdleCtrRun一秒钟内空闲计数器的有效值(据我猜测)
OS_EXT  INT32U            OSIdleCtrRun;             /* Val. reached by idle ctr at run time in 1 sec.  */
OSIdleCtrMax一秒钟内空闲计数器的最大值
OS_EXT  INT32U            OSIdleCtrMax;             /* Max. value that idle ctr can take in 1 sec.     */
OSStatRdy静态任务就绪的标志位
OS_EXT  BOOLEAN           OSStatRdy;                /* Flag indicating that the statistic task is rdy  */
 
 
 void  OS_InitRdyList (void)初始化就绪任务的数组
 

点击(此处)折叠或打开

  1. /*
  2. *********************************************************************************************************
  3. * INITIALIZATION
  4. * INITIALIZE THE READY LIST
  5. *
  6. * Description: This function is called by OSInit() to initialize the Ready List.
  7. *
  8. * Arguments : none
  9. *
  10. * Returns : none
  11. *********************************************************************************************************
  12. */

  13. static void OS_InitRdyList (void)
  14. {
  15.     INT8U i;
  16. #if OS_LOWEST_PRIO <= 63
  17.     INT8U *prdytbl;
  18. #else
  19.     INT16U *prdytbl;
  20. #endif


  21.     OSRdyGrp = 0; /* Clear the ready list */
  22.     prdytbl = &OSRdyTbl[0];
  23.     for (i = 0; i < OS_RDY_TBL_SIZE; i++) {
  24.         *prdytbl++ = 0;
  25.     }

  26.     OSPrioCur = 0;
  27.     OSPrioHighRdy = 0;

  28.     OSTCBHighRdy = (OS_TCB *)0;
  29.     OSTCBCur = (OS_TCB *)0;
  30. }
系统就绪任务表OSRdyTbl[OS_RDY_TBL_SIZE]     
#if OS_LOWEST_PRIO <= 63
OS_EXT  INT8U             OSRdyGrp;                        /* Ready list group  */
OS_EXT  INT8U             OSRdyTbl[OS_RDY_TBL_SIZE]; /* Table of tasks which are ready to run */
#else
OS_EXT  INT16U            OSRdyGrp;          /* Ready list group   */
OS_EXT  INT16U            OSRdyTbl[OS_RDY_TBL_SIZE];       /* Table of tasks which are ready to run    */
#endif

 
 
阅读(319) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:UCOSII移植学习笔记(二)

给主人留下些什么吧!~~