Understanding the task of ITRON entry (TASK)

Overview

In a system with a real-time operating system, the program runs as a task.
When understanding the real-time operating system and ITRON specifications, understanding the "task" is the beginning of everything.
ITRON runs the system centered on this task.

The program runs a bit like a worker at work

#include <stdio.h>

int main(void)
{
    
    
	long calc = 0;

	calc = 100 + 200;

	printf("结果:%d", calc);

	return 0;
}

While executing the steps of such a program, you may have run the program line by line. This program moves line by line, which is what the worker is doing.

In C language, the program runs from the main function. In other words, when the program starts, a worker is prepared and he says to that worker: "Let's implement the main function!" This means that the program is moving.

Challenges of programs not equipped with real-time operating systems

In a system that is not equipped with a real-time operating system, there is no concept of tasks at all. Nevertheless, the labor to implement the main function is also ready, so what you have to say can also be said to be a task of one person (single task). Let us consider under what circumstances the problem in a single-task system occurs. The software system creates and runs various tasks in the form of programs. From now on, on the basis of making 2 tasks, we will clarify the difficulty of a single task.

LED blinking task

The program is based on sequential processing and is executed from top to bottom in the order described.
For example, let us look at the current next program. The LED flashes because the task is executing this task.

The task of blinking the LED every second

  • Light up the LED orange.
  • Turn off the green of the LED.
  • Wait for 1 second (1000 milliseconds).
  • Turn off the orange of the LED.
  • Light up the LED green.
  • Wait 1 second (1000 milliseconds)
void MAIN(VP_INT exinf)
{
    
    
    while(1)
    {
    
    
        Led_setLight(D_LED_KIND_ORANGE, D_LED_LIGHT_ON);
        Led_setLight(D_LED_KIND_GREEN, D_LED_LIGHT_OFF);
        dly_tsk(1000);

        Led_setLight(D_LED_KIND_ORANGE, D_LED_LIGHT_OFF);
        Led_setLight(D_LED_KIND_GREEN, D_LED_LIGHT_ON);
        dly_tsk(1000);
    }

    return;
}

The dly_tsk function is a function of the ITRON specification and is a function that stops the task operation only within a specified time (milliseconds). It is easy to write a program that faithfully performs tasks determined in order like this.

Task of making sounds

So, let's do another task next. Suppose a task that needs to output the buzzing sound twice every 2 seconds.

Buzzer output task

  • Output "trembling" sound.
  • Wait for 100 milliseconds.
  • Stop the sound output.
  • Wait for 100 milliseconds.
    ※The output of beep means to repeat this procedure twice.
void MAIN(VP_INT exinf)
{
    
    
    while(1)
    {
    
    
        int i;

        // 发出400ms的时间蜂鸣声
        for (i=0 ; i < 2 ; i++)
        {
    
    
            Spk_start(E_SPK_SCALE_DO);
            dly_tsk(100);

            Spk_stop();
            dly_tsk(100);
        }

        // 等待2000ms - 400ms
        dly_tsk(1600);
    }

    return;
}

The relationship between tasks, threads and processes

task

A term representing the execution unit of parallel processing in a real-time operating system. There are multiple tasks in the system called multitasking.

Thread

A term representing the execution unit of parallel processing in Windows or Linux. This is the same task in ITRON. The existence of multiple threads in the system is called multithreading.

process

A term used in Windows or Linux to indicate the unit of execution of an application program. For example, when you start an application such as Excel or Word, each application will start as a different process. The mechanism by which multiple applications can be started at the same time is called multi-process. You can belong to multiple threads in a process. This concept does not exist in ITRON. Because it can only have one application in the system, there is no need for a unit called a process.

The difference between process and thread

The huge difference between a process and a thread is shared or not shared memory space. Since Windows and Linux manage memory independently in units of processes, if the processes are different, the memory of other processes cannot be accessed.

For example, you cannot call a function defined in Word from a program running in Excel. If there is such a thing, malicious programs may disrupt the operation of various applications.

This is the mechanism by which Windows and Linux use virtual memory to protect memory in units of processes. On the other hand, multiple threads existing in the same process share memory. Therefore, the threads in each process can freely access the functions and global variables defined in the process.

Guess you like

Origin blog.csdn.net/qq_18191333/article/details/107524357