A design scheme of Linux-based embedded system applied to measurement and control system

1 Introduction

With the rapid development of network control technology, industrial Ethernet has been gradually improved, and it has become more and more widely used in the field of industrial control. Industrial Ethernet uses the TCP/IP protocol, which is convenient for networking and has the advantages of high-speed control network. With the decline in the price of 32-bit embedded CPUs and the improvement of performance indicators, a broad space has been provided for the wide application of embedded systems and the development of Linux in embedded systems. Due to the high flexibility of Linux, it can be easily customized and developed according to the characteristics of the application field to meet actual application needs.

2. The design of Linux-based embedded system in the measurement and control system

The computer measurement and control system is essentially a computer control system. In order to control the controlled object, it is indispensable to detect its parameters and status.

2.1 The overall design of the measurement and control system

The measurement and control system is based on a Linux-based embedded system as the core. The application program can be updated through the network, the man-machine dialogue is carried out through the keyboard, and the data can be displayed on the spot through the LCD. Important data can be stored in the Flash memory in the form of files. Data and alarm information can also be transmitted to the host computer through the serial port, and information can also be released to the Internet through the Ethernet port. The user can view the equipment status through the display interface, set equipment parameters, and realize remote monitoring and remote maintenance.

A design scheme of Linux-based embedded system applied to measurement and control system

2.2 Overall block diagram

2.3 Embedded system hardware design

2.3.1 Hardware block diagram

Considering that the general measurement and control system requires more functions for embedded systems: keyboard interface, display interface, A/D (or D/A) conversion unit, expandable UO interface, printer interface, serial interface for communication with PC , Ethernet port, etc. The hardware block diagram of the implemented embedded system is shown in Figure 2-2:

A design scheme of Linux-based embedded system applied to measurement and control system

2.3.2 Development of device driver under Linux

In the Linux system, the kernel provides a protection mechanism, and processes in the user space generally cannot directly access the hardware. Linux devices are abstracted out, and all devices are treated as files. The user process accesses the device driver through the interface of the file system. The device driver mainly performs the following functions:

â‘ Detect the device and initialize the device; â‘¡Receive data from the device and submit it to the kernel; â‘¢Receive data from the kernel and send it to the device; â‘£Detect and handle device errors.

3. Software implementation of embedded system based on RTAI-Linux

3.1 Implementation mechanism of RTAI real-time hardware abstraction layer

The new data structure rt_hal is introduced to form the Real Time Hardware Abatract Layer (RTHAL). The definition of the rt_hal structure is as follows:

struct rt_hal

{

struct desc_struct*idt table;

void (*disint) (void);

void (*enint) (void);

unsigned int(*getflags)(void);

void (*setflags) (unsigned int flags);

void (*mask_and_ack_8259A) (unsigned int irq);

void (*unmask_8259A_irq) (unsigned int irq);

void (*ack_APIC_irq) (void);

void (*mask_IO_APIC_irq) (unsigned int irq);

void (*unmask_I0_APIC_irq) (unsigned int irq);

unsigned long *Io_apic_irgs;

void*irq_controller_lock;

void*irq_desc;

int *irq_vector;

void *irq_2_pin;

void* ret_from_intr;

struct desc_struct *gdt_table;

volaTIle int*idle_weight;

void (*lxrt_cli) (void);

};

It is initialized to rthal in usr/src/Linux/arch/i386/kernel/irq.c:

struct rt_hal rthal

{

idt_table, /*interrupt vector table*/

Linux_cli, /*Close interrupt function*/

Linux_sTI, /*Open interrupt function*/

Linux_save_flags, /*Save the flags before interruption*/

Linux_restore_flags, /*Restore the flags before the interruption*/

Task_and_ack_8259A, /*Interrupt masking*/

Enable_8259A_irq, /*interrupt enable*/

Linux_ack_APIC_irq,

(), /*Set in the io_apic.c file*/

&io_apic_irgs,

&irq_controller_lock,

irq_desc,

irq_vector,

(), /*Set in the io_apic.c file*/

&ret_from_imr,

gdt_table, /*Global Descriptor Table*/

&idle_weight,

()

};

When rthal is initialized, the pointer variable to the function points to the function that realizes the functions of opening and closing interrupts in the original standard Linux as follows:

staTIc void linux_cli(void)

{

hard_cli();

}

staTIc void linux_sti(void)

{

hard_sti();

}

static unsigned int linux_save_flags(void)

{

int flags;

hard_save_flags (flags)

turn flags

}

static void linux_restore_flags (unsigned int flags)

{

hard_restore_flags(flags);

}

When loading the RTAI module, execute the rt_mount_rtai function as follows:

void rt_mountes_rtai(void)

{

rthal.disint=linux_cli;

rthal.enint=linux_sti;

rthal.getflags=linux_save_flags;

rthal.setflags=linux_restore_flags;

rthal.mask_and_ack_8259A=trpd_mask_and_ack_irq;

rthal.unmask_8259A_irq=trpd_unmask_irq;

}

The pointer variable pointing to the function in rthal points to the function of the same name implemented in RTAI. The interrupt function implemented in RTAI is as follows:

static void linux_cli(void)

{

processorï¼»hard_cpu_id()ï¼½.intr_flag=0;

}

Introduce a new data structure processor in RTAI to describe the state of the processor related to the interrupt:

static struct cpu_own_status

{

volatile unsigned int intr_flag;

volatile unsigned int linux_intr_flag;

volatile unsigned int pending_irqs;

volatile unsigned int activ_irqs;

}

processorï¼»NR_RT_CPUSï¼½;

When the interrupt is executed, the interrupt flag bit intr_flag in the data structure processor is set to 0, rather than the IF flag of the eflags register is actually cleared to turn off the interrupt, which solves the problem of long-term off interrupt in Linux.

3.2 Use RTAI to enhance the realization of Linux real-time

By modifying the source files related to the Linux kernel, a real-time hardware abstraction layer is formed. Execute the insmod command, mount the rtai, rtai_sched, and rtai_fifos modules that provide real-time services, and get the following information:

Linux tick at 100Hz

Calibrated cpu frequency 551268530Hz

Calibrated 8254-timer-interrupt-to-scheduler latency 8000ns

Calibrated one shot setup time 3000ns

Module Size Used by

rtai_sched 16608 0 unused

rtai_fifos 33468 0 unused

rtai 20728 1 (rati_sched rtai-fifos)

After loading the RTAI module required by the application, you can develop the application in the RTAI-Linux environment.

3.3 Development of applications based on RTAI-Linux

For specific applications such as data acquisition, data processing, control, and communication of industrial measurement and control systems, the application programs are divided into real-time tasks and non-real-time tasks. Real-time tasks are developed using the API provided by RTAI, compiled into a kernel module, and work in the core state of Linux. User processes can make use of a large number of resources provided by the Linux operating system for TCP/IP network communication, development of graphical user interface programs, etc. Communication between real-time tasks, real-time tasks and non-real-time tasks can be achieved through Fifo queues and shared memory. The RTAI-Linux application structure is shown in Figure 3-1.

A design scheme of Linux-based embedded system applied to measurement and control system

The main functions of the data acquisition task in rt_process.c are as follows:

static void data_collect()

{

rtf_put(FIFO, &data_value, sizeof(data_value);/*Put the collected data into the real-time FIFO*/

rt_task_wait_period();

}

int int_module(void)

rtime tick_period;

rt_set_periodic_mode(); /*Set the timer to periodic mode*/

rt_task_init(&rt_task, data_collect, l, Stack_size, task_priority, 1, 0);/*Initialize the data collection task*/

return ()

}

void cleanup_module(void)

{

stop_rt_timer();

rtf_destroy(FIFO);

rt_task_delete(&rt_task);

return;

}

The main functions of the data display program in disaplay.c:

int main(void)

{

if((fifo=open("/dev/rtf()", ()_rdonly)) "0)

{

fprintf(stderr, "Error opening/dev/rtf()");

exit(1);

}

read(fifo, &data_value, sizeof(data_value));/*User process reads data from real-time FIFO*/

printf("data%f", data_value)

}

4 Conclusion

This paper presents a Linux-based embedded system design scheme applied to the measurement and control system, which can ensure the real-time and reliability of the completion of the measurement and control task, and can be connected to the industrial Ethernet to realize remote monitoring. It is very useful in the field of industrial control. Good application prospects.

Innovation: In the design and implementation of embedded system software, it provides an interface for developing real-time application programs; uses real-time application interface (RTAI) to enhance the real-time performance of Linux, and introduces real-time hardware abstraction layer structure (rthal) and real-time scheduling Real-time services such as monitors, real-time FIFOs, etc.; methods for developing real-time application programs in industrial measurement and control systems under the RTAI-Linux environment are given

multi-in and multi-out connector

5 Pins Lamps Connector ,Circuit Screwless Connector For Led Lighting Connector,Multi-In And Multi-Out Lamps Connector

Guangdong Ojun Technology Co., Ltd. , https://www.ojunconnector.com