Linux-based PC104 bus and CAN bus communication design

1 Introduction

PC104 embedded industrial computer because of its small size structures, stack-type connection, easy bus-driven features have been widely used. Fieldbus field, CAN bus has been widely supported by the computer chip business, they have introduced CAN interface directly with microprocessor (MCU) chip.

Chip MCU with CAN's total has reached 100 million 3000 million pieces, so in the interface chip technology, CAN has been far ahead of FF, PRO-FIBUS, LONWORKS all other fieldbus. But the PC104 bus can not communicate directly with the CAN bus, CAN bus control system so difficult to use.

To solve the above problems, to AVR microcontroller co-processor designed for the PC104 bus and CAN bus converter card, and taking into account the PC104 embedded industrial computer running Linux operating system is usually characterized by the preparation of the conversion card under Linux dual-port RAM PC104 bus access drivers. The adapter used in industrial control systems, can actually show that the stable and reliable in operation.

2 hardware

PC104 CAN bus converter card to the hardware system block diagram shown in Figure 1. In the PC104 bus and CAN bus communication, the main issue to consider is the PC104 bus and CAN bus data synchronization. PC104 bus and CAN bus bus speed are very different, commonly used for such problems is to use dual-port RAM or FIFO as a buffer, where a dual-port RAM as a data buffer, while the dual-port RAM, set aside a few bytes as the ATmega64 processor and PC104 embedded computer soft handshake signals the completion of the above methods PC104 bus and CAN bus data synchronization. Altera EPM7128 to the CPLD, here using the CPLD is mainly used for CAN-bus converter card PC104 to the address decoding. CAN bus communication use SJA1000 CAN bus controller, in order to meet the harsh electromagnetic environment of industrial site, in the SJA1000 and PC82C250 in the light compartment after treatment.

Linux-based PC104 bus and CAN bus communication design

2.1 PC104 bus interface circuit with IDT7134
IDT7134 PC104 bus and interface circuit diagram shown in Figure 2.

PC104 embedded computer to read the dual-port RAM IDT7134 data. First IDT7134 mapped to the PC104 embedded computer memory space, use SMEMR *, SMEMW * as IDT7134 the OER, R / W control signal. Another advantage of the PC104 bus CPLD EPM7128 high three addresses SA19, SA18, SA17 decoding the chip select signal as IDT7134.

Linux-based PC104 bus and CAN bus communication design

2.2 ATmega64 and IDT7134 interface circuit

ATmega64 processor used is the address line, data line time-multiplexing, thus the need for address latch. EPM7128 VHDL hardware description language used in the design of the address latch. ATmega64 and IDT7134 interface circuit shown in Figure 3.

Linux-based PC104 bus and CAN bus communication design

2.3 CPLD EPM7128 internal logic

CPLD EPM7128 in the whole design was completed for decoding, and address latch function. In the Quartus Ⅱ 6.0 environment, through the VHDL hardware description language, completion of the function. The source code is as follows:

Linux-based PC104 bus and CAN bus communication design

In the above VHDL code CSSJA1000 for the SJA1000 chip select signal, CS7134L left port for the IDT7134 chip select, CS7134R for the IDT7134 chip select the right port.

Software part 3

To achieve the PC104 bus and CAN bus data communication hardware design in the above mentioned dual-port RAM is used as a data buffer method, which involves the dual-port RAM in the data area opened up as PC104 Embedded PC, and ATmega64 soft handshake flag. Handshake to ATmega64 PC104 embedded PC, the software program and implement, the process is as follows: First, open up the dual-port RAM, two buffer, were used to send and receive data buffer CAN bus. When there is data to the PC104 bus, CAN bus, the first dual-port RAM, data is written to send the CAN data buffer, and then to the dual-port RAM reserved for the flag field to write a specific value, the circular ATmega64 with data through CAN bus send, ATmega64 using the query method to measure the flag field, when a specific flag field detected value, to read dual-port RAM of the CAN data transmission buffer, while read data to the CAN bus. After the above process, ATmega64 program will reset the field flags. Thus completed the PC104 bus data transmission on the CAN bus. CAN bus data on the PC104 bus to send the opposite of this process.
3.1 ATmaga64 processor program

ATmaga64 processor on the CAN bus read and write the bottom of the work, while data written in the dual-port RAM IDT7134 and IDT7134 stored in the first flag byte set to notify the PC104 embedded PC, with data being updated to require PC104 Embedded PC, be read on the IDT7134. Based on the above process ATmaga64 processor initialization procedure includes SJA1000, SJA1000 interrupt handler, and access IDT7134 procedures.

3.2 PC104 bus access dual-port RAM in the Linux driver

Linux driver from the structure is divided into three parts:

(1) equipment configuration and initialization, including the existence of inspection equipment, status, equipment, registration and related device driver initialization. This part of the general initialization procedure is called only once, he was included in the init_module () routine.

(2) I / O request service programs primarily through system calls, the completion of the user's request features such as Read, Write, etc., and equipment operating by the majority of I / O request completion of services, including Read, Write, Ioct1 and other routine .

(3) interrupt service routine, the system receives all the hardware interrupt, then calls the appropriate interrupt service routine.

In the Linux system, device drivers the way the document appears, the device driver interface is a file system interface, which consists of a data structure struct file_operations () to define the data structure is the virtual file system standard interfaces. So first define a dual-port RAM PC104 bus driver to access the file system data structures.

Linux-based PC104 bus and CAN bus communication design

PC104 memory segment for the Linux kernel at boot time to access these addresses on the establishment of a page table, access to their virtual address and the actual physical address are different, need to use ioremap to map physical address to virtual address so we can visit on the PC104 bus, to read the dual port RAM data. ioremap function is defined as:


Void * ioremap (unsigned long phy_addr, unsigned longsize)

Parameter phys_addr the physical address, size for the physical address length. ioremap return value is a unique virtual address can be used to access the specified the physical memory area, the virtual address to call iounmap to release last fall. The following will detail the various Linux drivers for the concrete realization of the function.

3.2.1 Initialization function and unloading functions to achieve

Equipment configuration and initialization function init_module () called, respectively:

register_chrdev (): for device registration;

request_irq (): interrupt request channel;

request_mem_region (): allocation of I / O memory area;

ioremap (): physical address mapped to the virtual address.

Source code is as follows:

Linux-based PC104 bus and CAN bus communication design

This completes the device driver initialization. Unloading part of the device driver and initialization Instead, uninstall is assigned to the device driver recovered a variety of resources. cleanup_module () call, respectively:

iounmap (): release of virtual address;

release_mem_region (): release memory regions;

free_irq (): release interrupt channel.

Source code is as follows:

Linux-based PC104 bus and CAN bus communication design

3.2.2 Reading of the function implementation

Read function definition of dual-port RAM read process, the source code is as follows:

Linux-based PC104 bus and CAN bus communication design

Kernel function which copy_to_user virtual address pPxp-VirtStartAddr the count of data copied to buf pointer to user space. Before the device configuration and initialization function ink_module () in ioremap () function has dual-port RAM physical address mapped to virtual address pPxpVirtStartAddr, so you can pxp_read () function to read dual-port RAM.

3.2.3 Write a function to achieve

Write dual-port RAM, called pxp201_write () function, the principle of dual-port RAM with similar reading, but pxp201_write () function call copy_from_user () kernel function.

Linux-based PC104 bus and CAN bus communication design

3.2.4 open function and the release function to achieve

pxp_open () function to achieve the following, which increases equipment use MOD_INC_USE_COUNT reference count.

Linux-based PC104 bus and CAN bus communication design

pxp201_release () function and pxp_open () process the contrary, the use of MOD_DEC_USE_COUNT decreasing device reference count.

Since then, Linux, dual-port RAM of the drive module is complete, you can use Insmod tool to load the kernel driver module. This can be embedded in the PC104 industrial computer's Linux operating system to access the dual-port RAM.

4 Concluding Remarks

This paper introduces the PC104 bus and CAN bus communication hardware, and PC104 embedded Linux computer operating system developed under the PC104 bus on the dual-port RAM IDT7134 access driver. Signs within the open area in the IDT7134, using soft handshake method to achieve the PC104 bus and CAN bus data communication. The adapter used in industrial control systems through practical and reliable test that can be run.

Declined comment