This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
rtos运作机理我能不能认为是以main函数为基础,各个任务就像拥有自己优先级的中断函数?有没有这方面的资料呢?
CCS Debug调试模式下,在 "Tools->RTOS Object Viewer (ROV)" 下面可以看到各个任务的优先级,IAR也是ROV下面
动手试试TI的Academy.
http://dev.ti.com/tirex/content/simplelink_academy_cc13x0sdk_1_13_03_11/modules/rtos_concepts/rtos_concepts.html
“A real-time operating system (RTOS) is an operating system (OS) intended to serve real-time application process data as it comes in, typically without buffering delays. (wikipedia.org)”
Key factors in an RTOS are minimal interrupt latency and minimal thread switching latency. An RTOS is valued more for how quickly or how predictably it can respond than for the amount of work it can perform in a given period of time.
For embedded devices, the general rule is that an RTOS is used when the application needs to do more than a few simple actions. An RTOS allows an application to be structured in a manner that scales as more application/system features are added (e.g. communication stacks, power management, etc.).
A RTOS has the following goals
In this workshop we'll cover general RTOS topics. The SimpleLink™ software development kit (SDK) supports both TI-RTOS and FreeRTOS. It also supports POSIX APIs on top of either RTOS. We'll use POSIX APIs below as a concrete example of an RTOS but the concepts are applicable for both RTOS offerings.
Here's what we'll learn:
Let's first standardize on some key definitions. It's assumed that you have a basic understanding of embedded processing in regards to knowing what an interrupt is, what a stack is, etc.
For this workshop we are going to use the term thread as a generic term for any execution block. Here are the typical threads in every RTOS based application.
Every RTOS has at its core a scheduler. The scheduler is responsible to manage the execution of threads in the system. There are two main ways a scheduler manages this:
Preemptive Scheduling: This is the most common type of RTOS scheduler. With a preemptive scheduler, a running thread continues until it either
sleep()
).Both TI-RTOS and FreeRTOS have preemptive schedulers. This workshop will focus on preemptive schedulers.
Task_sleep()
or Semaphore_pend()
(with a non-zero timeout and the semaphore is not available), the task is blocked and another thread is allowed to run. Note: spinning on a register in a tight loop is not blocking…that’s polling.Let's look a little more closely at a typical bare-metal application. These applications can typically be broken down into three key pieces
main()
.Here's a pictoral view of these key pieces.
Bare-metal applications have their place. They are generally small, fast and relatively easy to understand with a simple application. Once more complicated logic is required, an RTOS starts to shine.
Let's look at a comparison of a bare-metal application to a minimal RTOS application (and then to a more traditional RTOS application). As you can see, the three key pieces we talked about before (init, super-loop and ISRs) are basically the same between a bare-metal application and a minimal RTOS application. However, with the minimal RTOS application, you now have the stepping off point to a much more complex application that allows multiple developers to add their content without dealing with potentially a fragile super-loop.
Here are some of the main components of an RTOS. The SimpleLink SDK offers all of these features for both TI-RTOS and FreeRTOS.
POSIX is an IEEE industry API standard for OS compatibility. The SimpleLink SDK has both TI-RTOS and FreeRTOS support, however it also offers POSIX support on top of either of these RTOS's. This allows applications to be independent of the underlying RTOS.
The POSIX APIs in the SimpleLink SDK are a small shim on top of the underlying RTOS. When a POSIX Pthread is created, an underlying TI-RTOS (or FreeRTOS) Task is created. Similarly, when a POSIX Pthread semaphore is created, an underlying TI-RTOS (or FreeRTOS) semaphore is created.
A nice feature of POSIX support is the ability to grab POSIX based code from the web and quickly get it to work.
For a more details description of the POSIX support in SimpleLink SDKs, please refer to the POSIX Overview Workshop.
It is a OS compatibility layer to allow an application to port easily between operating systems.
All RTOS's offers standard communication mechanisms like semaphores, mutexes, message queues, linked list, etc. Let's look a little closer at a couple of these...
A semaphore allows resource management. A task can block on a sem_wait()
until a resource is available and a sem_post()
is done. A common use case is for a Hwi to receive data and post a semaphore so a task can process it. This is desirable because it minimizes the duration of the interrupt.
Most RTOS's supports both binary and counting semaphores.
Message Queues are useful for sending data between threads. Message Queues can be configured to send/receive user defined messages of any size. Here a task is sending a message to another task.
Message Queues are useful when you want to centralize a specific functionality into a single task. All other threads can send messages to the centralized task for processing. The message queue handles the messages in a thread-safe manner.
Please note message queues in the POSIX support layer are built on top of Mailboxes in TI-RTOS and Queues in FreeRTOS in the SimpleLink SDK.
Let's see a preemptive scheduler in action. Let's assume the following threads were created in main().
Let's look at the following execution graph and talk about what is happening.
Once the kernel's scheduler starts (in this case BIOS_start()
in main()
), all the tasks are ready to run, however it's the highest task (High) that runs first since it has the highest priority and is ready to run. Here's a description of some of the key transition points noted in the above graph.
Task_sleep()
(or some blocking API). Now MidA can run.Semaphore_pend()
). Now MidB can run.Task_sleep()
expired). MidB is now preempted.All of the above context switching is managed by the scheduler in the RTOS.
Additional training and reference material for RTOS is available in the following places: