[Zhongke Bluexun AB32VG1 RISC-V Evaluation Board] Try to use RTThread multitasking
[Copy link]
Due to the needs of study and work, I have used FreeRTOS and ucOS before. I have also heard from friends around me that RTThread is a good domestic RTOS. Taking advantage of the EE's kindness, I was given the opportunity to evaluate it, so I tried to learn and understand RTThread.
The most basic and most important function of an RTOS is task scheduling. Below we will try to start two RTThread tasks and print their respective information.
As shown in the figure above, we initialize and start two threads, thread_1 and thread_2. The function rt_thread_create is used to initialize the task information, and _rt_thread_startup is used to start the task.
We can see that the functions of the two tasks are very simple, just printing information every 1000 milliseconds.
rt_thread_t rt_thread_create(const char *name,
void (*entry)(void *parameter),
void *parameter,
rt_uint32_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick)
The above figure is the prototype of rt_thread_create. The first parameter is the thread name, the second is the thread function entry, the third is the thread parameter, the fourth is the stack size, the fifth is the priority, and the sixth is the time slice.
The most interesting one is the sixth parameter, which is a setting I have not seen in other RTOS. It allows users to set thread time slices, which gives RTOS users more flexibility in controlling threads.
The above is a screenshot of the running results.
|