Rtos 3 & 4

1,200 views

Published on

this slide ll be helpful for those who are in search of real time systems.

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,200
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
39
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Rtos 3 & 4

  1. 1. Kernel Structure <ul><li>This chapter describes some of the structural aspects of μC/OS-II. </li></ul><ul><li>How μC/OS-II handles access to critical sections of code, </li></ul><ul><li>What a task is, and how μC/OS-II knows about your tasks, </li></ul><ul><li>How tasks are scheduled, </li></ul><ul><li>How μC/OS-II can determine how much of CPU your application is using, </li></ul><ul><li>How do to write Interrupt Service Routines (ISRs), </li></ul><ul><li>What a clock tick is and how μC/OS-II handles it, </li></ul><ul><li>How to initialize μC/OS-II and, </li></ul><ul><li>How to start multitasking. </li></ul>
  2. 2. OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL(), <ul><li>μC/OS-II like all real-time kernels need to disable interrupts in order to access critical sections of code, and re-enable interrupts when done. </li></ul><ul><li>This allows μC/OS-II to protect critical code from being entered simultaneously from either multiple tasks or ISRs. </li></ul><ul><li>To hide the implementation method chosen by the compiler manufacturer, μC/OS-II defines two macros to disable and enable interrupts: </li></ul><ul><li>OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL </li></ul><ul><li>Because these macros are processor specific, they are found in a file called OS_CPU.H. </li></ul><ul><li>Each processor port will thus have its own OS_CPU.H file. </li></ul>
  3. 3. Tasks <ul><li>A task is active entity which could do some computations. </li></ul><ul><li>A task is typically an infinite loop function </li></ul>
  4. 4. <ul><li>Alternatively, the task can delete itself upon completion </li></ul><ul><li>Also, if the task calls OSTaskDel(), the task code doesn’t return back to anything. </li></ul>
  5. 5. Task States
  6. 6. Task Control Blocks (OS_TCBs) <ul><li>When a task is created, it is assigned a Task Control Block, OS_TCB . </li></ul><ul><li>A task control block is a data structure that is used by μC/OS-II to maintain the state of a task when it is preempted. </li></ul><ul><li>When the task regains control of the CPU the task control block allows the task to resume execution exactly where it left off. </li></ul><ul><li>All OS_TCBs reside in RAM. </li></ul><ul><li>An OS_TCB is initialized when a task is created </li></ul>
  7. 8. Ready List <ul><li>Each task is assigned a unique priority level between 0 and OS_LOWEST_PRIO </li></ul><ul><li>Task priority OS_LOWEST_PRIO is always assigned to the idle task when μC/OS-II is initialized. </li></ul><ul><li>Each task that is ready to run is placed in a ready list consisting of two variables, OSRdyGrp and OSRdyTbl[]. </li></ul><ul><li>Each bit in OSRdyGrp is used to indicate whenever any task in a group is ready to run. </li></ul><ul><li>When a task is ready to run it also sets its corresponding bit in the ready table, OSRdyTbl[]. </li></ul><ul><li>To determine which priority (and thus which task) will run next, the scheduler determines the lowest priority number that has its bit set in OSRdyTbl[]. </li></ul>
  8. 9. Ready List
  9. 10. Task Scheduling <ul><li>μC/OS-II always executes the highest priority task ready to run. </li></ul><ul><li>The determination of which task has the highest priority and thus, which task will be next to run is determined by the scheduler. </li></ul><ul><li>Task level scheduling is performed by OSSched(). </li></ul>
  10. 11. Locking and Unlocking the Scheduler <ul><li>The OSSchedLock() function is used to prevent task rescheduling until its counterpart, OSSchedUnlock(), is called. </li></ul><ul><li>The task that calls OSSchedLock() keeps control of the CPU even though other higher priority tasks are ready to run. </li></ul>
  11. 12. Idle Task <ul><li>μC/OS-II alwa ys creates a task the Idle Task which is executed when none of the other tasks is ready to run. </li></ul><ul><li>The idle task ( OSTaskIdle()) is always set to the lowest priority, i.e. OS_LOWEST_PRIO. </li></ul><ul><li>OSTaskIdle() does nothing but increment a 32 -bit counter called OSIdleCtr. OSIdleCtr is used by the statistics task to determine how much CPU time (in percentage) is actually being consumed by the application software. </li></ul>
  12. 13. Statistics Task <ul><li>μC/OS-II contains a task that provides run-time statistics. This task is called OSTaskStat() </li></ul><ul><li>Created if you set the configuration constant OS_TASK_STAT_EN to 1. </li></ul><ul><li>When enabled , OSTaskStat() executes every second and computes the percentage of CPU usage. </li></ul><ul><li>In other words, OSTaskStat() will tell you how much of the CPU time is used by your application, in percentage. </li></ul><ul><li>This value is placed in the variable OSCPUUsage which is a signed 8-bit integer. </li></ul>
  13. 14. μ C/OS-II Initialization
  14. 15. Data structures after calling OSInit()
  15. 16. Starting μ C/OS-II <ul><li>You start multitasking by calling OSStart() . Before you start μC/OS-II, however, you MUST create at least one of your application tasks as shown in listing </li></ul>Initializing and Starting μ C/OS-II. Starting multitasking.
  16. 17. Task Management <ul><li>Creating a Task, OSTaskCreate() </li></ul><ul><li>OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio) </li></ul>
  17. 18. Stack Checking, OSTaskStkChk() <ul><li>It is sometimes necessary to determine how much stack space a task actually uses. </li></ul>
  18. 19. Deleting a Task, OSTaskDel() <ul><li>It is sometimes necessary to delete a task. Deleting a task means that the task will be returned to the DORMANT state </li></ul><ul><li>And does not mean that the code for the task will be deleted. </li></ul><ul><li>The task code is simply no longer scheduled by μC/OS -II. </li></ul><ul><li>You delete a task by calling OSTaskDel() </li></ul><ul><li>Requesting a task to delete itself , OSTaskDelReq() </li></ul>
  19. 20. Changing a Task’s Priority, OSTaskChangePrio() <ul><li>When you create a task, you assign the task a priority. At run-time, you can change the priority of any task by calling OSTaskChangePrio(). </li></ul><ul><li>In other words, μC/OS-II allows you to change priorities dynamically. </li></ul>
  20. 21. Suspending a Task, OSTaskSuspend() <ul><li>It is sometimes useful to explicitly suspend the execution of a task. </li></ul><ul><li>This is accomplished with the OSTaskSuspend() function call. </li></ul><ul><li>A suspended task can only be resumed by calling the OSTaskResume() function call. </li></ul>
  21. 22. Getting Information about a Task, OSTaskQuery() <ul><li>Your application can obtain information about itself or other application tasks by calling OSTaskQuery(). </li></ul><ul><li>In fact, OSTaskQuery() obtains a copy of the contents of the desired task’s OS_TCB. </li></ul>
  22. 23. Time Management <ul><li>This chapter will describe five services that deal with time issues: </li></ul><ul><li>1) OSTimeDly(), </li></ul><ul><li>2) OSTimeDlyHMSM(), </li></ul><ul><li>3) OSTimeDlyResume(), </li></ul><ul><li>4) OSTimeGet() and, </li></ul><ul><li>5) OSTimeSet(). </li></ul><ul><li>The functions described in this chapter are found in the file OS_TIME.C. </li></ul>

×