What is a task?
This month’s article begins with an explanation of the functions provided by a real-time OS.
The functions provided by real-time OSs will be explained in detail, showing sample programs in each issue. In addition, the sample program described in this article can actually run on T-Kernel 2.0, for which T-Engine Forum distributes the source code free of charge.
T-Kernel 2.0 supports the T-Engine reference board with Arm11, but a CPU emulator that runs on Windows PC (emulates Arm11) and integrated development environment (Eclipse) are also available. You can run the -Kernel 2.0 program, so please run the program every time to check the actual real-time OS operation.
What is a Task?
In general, embedded devices require a variety of functions. For example, they can read sensor values and analyze the results, draw graphics on the screen, or communicate with the outside world via a network. These are functions that can operate independently of each other.
T-Kernel 2.0 (hereinafter simply referred to as T-Kernel) has a function to execute multiple such processes in parallel. but they are executed in parallel between different tasks.
However, “executed in parallel” is a conceptual behavior from the application’s point of view, and in reality, T-Kernel automatically switches between multiple tasks and executes them in parallel.
So how exactly do you describe a task?
T-Kernel tasks can be described as functions in C. If you create a function in C and register it in T-Kernel, T-Kernel will execute it as a task.
For example, in the following example, lines 5 to 12 and lines 14 to 21 are a program that executes functions as tasks. If you can get these basics down, you can develop a multitasking program using T-Kernel.
【Listing 1: Task A’s doWorkA is executed after Task B’s doWorkB is completed.】
#include <basic.h> /* Basic definitions such as type */ #include <tk/tkernel.h> /* Definitions related to T-Kernel */ #include <tm/tmonitor.h> /* Definition of when to use the monitor function */ void taskA( INT stacd, VP exinf ) /* Task A (function name is optional) */ { while(1){ tm_putstring( (UB*)"I'm Task A.¥n" ); tk_dly_tsk( 1000 ); /* Hold the process for one second. */ } tk_ext_tsk(); /* End of task */ } void taskB( INT stacd, VP exinf ) /* Task B (function name is optional) */ { while(1){ tm_putstring( (UB*)"I'm Task B.¥n" ); tk_dly_tsk( 2000 ); /* Hold processing for 2 seconds. */ } tk_ext_tsk(); /* End of task */ } EXPORT INT usermain( void ) /* Functions called by the initial task */ { T_CTSK ctskA = { NULL, TA_HLNG|TA_RNG0, taskA, 1, 4*1024 }; T_CTSK ctskB = { NULL, TA_HLNG|TA_RNG0, taskB, 1, 4*1024 }; ID tskIdA; /* Task A Identifier */ ID tskIdB; /* Task B Identifier */ tskIdA = tk_cre_tsk( &ctskA ); /* Task A is registered in T-Kernel. */ tk_sta_tsk( tskIdA, 0 ); /* Start executing Task A. */ tskIdB = tk_cre_tsk( &ctskB ); /* Task B is registered in T-Kernel. */ tk_sta_tsk( tskIdB, 0 ); /* Start execution of Task B. */ tk_slp_tsk(TMO_FEVR); /* Transitioning to a wake-up call. */ return 0; }
Inter-Task Communication
In the case of embedded systems, each task often works together to form a single processing unit. Inter-task communication is used in such cases. The better you master inter-task communication, the easier it will be to design an embedded system, and the more emotional it will be when it actually works. Let’s make sure that you are able to use it well.
Synchronization with Interrupts by Event Flags
In inter-task communication, event flags make it easy to incorporate “systematic” processes such as “when 00 is set, do ∆∆”. These processes have long been utilized in “wait by flag” or “wait by polling”; RTOS provides mechanisms such as event flags, semaphores, mailboxes, data queues, message buffers, and rendezvous, depending on the size of the data.
Embedded systems have implemented a number of external interrupt features for peripheral functions and external factors. In order to make effective use of these, interrupts are necessary. It is also called an exception. Depending on how you build your system with these interrupts, you may also improve the performance and effectiveness of your system.
Of course, the difference between using RTOS and not using RTOS is not zero, but the ease of handling is quite different.
“もっと見る” カテゴリーなし
Mbed TLS overview and features
In this article, I'd like to discuss Mbed TLS, which I've touched on a few times in the past, Transport …
What is an “IoT device development platform”?
I started using Mbed because I wanted a microcontroller board that could connect natively to the Internet. At that time, …
Mbed OS overview and features
In this article, I would like to write about one of the components of Arm Mbed, and probably the most …