Blog2 | Qimeng Liu
Introduction
In this blog, I will introduce the RTOS(Real Time Operating System), and show the basic rtos functions and demos. I will explain the basic function of rtos in C language and do some revise of the demos.
Basic Function
RTOS
RTOS is short for Real Time Operating System. It is common method used in one chip embedded system to do many different tasks at the "same time"(it's not a real same time). RTOS can split the whole functions into different tasks. The each tasks is a loop. The diagram is shown below:
The main function jump to different tasks(loops) to finish different functions.
Demos
Demo1
In this demo, there are four different tasks with different rate time.The task code like this:
The rate means the period time of the task is called. The result is shown below:
Demo2
In this demo, rtos_terminate() is used to break the system loop and step the system.
The result is shown below:
Demo3
In this demo, there are 3 task with different rate time. Thus the frequenct of different task are differernt. The result is like this:
The different number display in different frequency. Which task1 is called every 1000ms, task2 is called every 500ms, task3 is called every 100ms.
There are some enable and disable function as well. The code diagram is shown below:
The second task show that, if the condition is completed, the third task is disabled in first task and the third task is enabled in the second task.
I did some revise in this demo as well. I added one more task in this demo, the diagram is shown below:
Demo4
In this demo, the message is used.
#task(rate=1000ms,max=100ms,queue=2)
There is a 2 byte quene which is FIFO in each task to store data.
In this demo, task 2 keep sending count to queue in task 1 every 0.5s.
Task 1 checks if it receive anything, if yes, read and print it and relied by sending count to task 2 queue.
The result is shown below:
I find that when the count is bigger enough, the count become negitive number. The count is shown below:
Because the type of count is int8, which is signed integrated number with 8 bit. The range of this is -128 - 127.
Demo5
In this demo,
rtos_yield ( );
this line is used. which means the cpu can do another task and then return this task.
The result is shown below:
Demo6
In this demo, semaphores is very important key word in RTOS.
For example,
It like a bathroom. Sem = 1 means there is one key to open the toilet.
It like a bathroom. Sem = 1 means there is one key to open the toilet.
rtos_wait(sem) -> take the key (enter bathroom)
rtos_signal(sem) -> return the key(leave the bathroom)
We can use this key word to make sure one or more tasks finished, other task can begin.
The result is shown below:
You can find that when the task2 finshed, the task1 begin. Which means only when one task finished, the another task begin.
But, when I revise the value of sem is 2, the result is shown below:
Demo7
In this demo, rtos_await() is used. Which is mean the condition is this function is ture, it will do the next step, in the time CPU can do other task.
The result is shwon below:We can find that, the when the count is equal 10, the task 1 begin.
In this demo, I did some revise as well. I change the condition parameter to >=5. The result is shown below:
Demo8
In this demo, Task 2 is a “load generator” whose work gradually increases until it becomes too slow (overruns). Task 1 periodically reads and prints RTOS statistics about Task 2: total CPU time used, min, max. When Task 2 overruns, the RTOS can detect it with rtos_overrun() and Task 2 prints an overrun warning and resets its load.
The result is shown below:
I did some revise as well. I change the max time of task 2 to 50ms and delay 20ms. The revised result is shown below:
Demo9
This demo builds a simple command-line “kernel” task over the serial port that can enable/disable RTOS tasks while the RTOS keeps running. You type commands like enable1 or disable2 in a serial terminal, and the RTOS reacts without stopping the other tasks.
We can use some command to control the system like this:
When enter disable1 -> stop taks1
When enter disable2 -> stop task2
When enter enable1 -> begin task1
When enter enable2 -> begin task2
The result like this :

.png)














Comments
Post a Comment