Embedded printing Terminal System Based on arm9-and Linux

Source: Internet
Author: User

Zhang Zhen

Master's Degree

Mailbox 601, Nanjing Information Engineering University, Nanjing 210044, China

0 Introduction

With
With the rapid development of open source code, more and more attention is paid to Linux operating systems. Its excellent scalability and portability, excellent efficiency and stability, and supporting multi-processor architecture
Features make Linux more and more widely used in the embedded field. At the same time, the high-frequency processing speed, large-capacity FLASH memory chip and MMU Control Unit of the arm9-processor support the embedded
Linux becomes stable and efficient. The printing terminal system designed and implemented in this article is built based on these two software and hardware platforms.

1. Design Principle of embedded printing Terminal System


Figure 1 print the terminal schematic

Embed
Figure 1 shows how the inbound printing terminal works. It consists of four parts: Development Board, host, printer and scanner. A host is a PC. The Development Board is developed by Samsung S3C2410.
The kernel of the board and the kernel of the ARM9. the kernel runs the 2.4 kernel version of the embedded Linux operating system. Scanners are hand-held scanners used in supermarkets. Add a micro printer to the gpio port of the Development Board.

Workflow: The Development Board reads the scanner data from the serial port and sends the data to the host for retrieval. The Development Board waits until it receives the processed data from the host and forwards it to the printer to print the information.

2 hardware design of embedded printing Terminal System

2.1 structure of hardware development platform S3C2410

3.
Star's S3C2410 Development Board uses a 32-bit RISC architecture based on the ARM920T core. Its enhanced MMU unit and AMBA bus support real-time functions such as WinCE and Linux.
Operating System. On-chip resource rich interface, including LCD controller, USB host, cs9800a network chip, SD card, three UART universal asynchronous serial port and other device interfaces. [1]

2.2 printer and Development Board interface circuit design

Me
They use parallel interfaces for micro-printers. Because the parallel port is not provided on the Development Board, you must design a board interface circuit to connect the parallel port of the printer to our embedded development board. View
The circuit schematic diagram of S3c2410. Because the LCD screen is not required for this system, the gpio port used on the board for LCD connection can be transformed according to the LCD circuit pins of arm9core and
The LCD slot on the board is defined. 2. 14 idle gpio ports are found:

Gpio_c8 ~ Gpio_d15, gpi0_d0 ~ Gpio_d4. Use these 14 universal input and output ports to connect the parallel port of the micro-printer.

Figure 2 LCD pins of the core and the LCD pins on the board

At the same time, check the printer circuit manual and pin definition, choose its STB choose line, Ack answer pulse line, busy line, DATA0-DATA7 data line to be connected with the gpio port of the Development Board, and initialize the level value. To avoid interference between connections, create an interface board to define each pin connection 3.

Now, the circuit design and connection of the hardware are complete.

Shape/* mergeformat

Figure 3 design diagram of the printer parallel port and the gpio port interface board of the Development Board

3 software design of embedded printing Terminal System

The software platform uses a 2.4-Core Embedded Linux system. The cross-compiler toolkit is cross2.95.3.tgz (including arm-Linux-GCC ).

3.1 Printer Driver Compilation

Linux devices are divided into Block devices, character devices, and network devices. The micro-printer used by the system is a character device. The following describes how to design a printer driver.

3.1.1 define the device name

# Define device_name weida_printer

3.1.2 module function design

In this system, a modular method is used to load the driver. Therefore, initialization and uninstallation functions of the module must be implemented. Use devfs to register a printer.

The initialization function weida_init registers a device with the system through the devfs_register function.

Function prototype devfs_register (null, device_name, devfs_fl_default, 0, 0, s_ifchr | s_irusr | s_iwusr, & weida_printer_fops, null );

Among them, device_name is the main device name, weida_printer_fops is a defined data structure, used for file operations, including open, close, write and so on.

3.1.3 initialize the print Port

The first thing to do to initialize the printer is to initialize the gpio port. The initialization function is as follows:

Static void weida_init (void ){

Devfs_register ();/* register the device driver */

Set_gpio_ctrl (weida_stb | gpio_pullup_dis | gpio_mode_out);/* set the STB port */

Write_gpio_bit (weida_stb, 1 );

Weida_printer_io_port_init ();

/* Set other IO ports and assign initial values */}

Among them, weida_stb is initialized to a high level for the connection port of the printer, gpio_pull_dis is set to whether the pull-resistance is required, and gpio_mode_out is set to the output port of the gpio port. Finally, use module_init (weida_printer_init); and load the driver in the module mode. [2]

3.1.4 interface function design

The IOCTL () function is used to set parameters such as the Printer Font and line spacing. during the design process, how to transmit user data and kernel data must be solved. You can use the copy_from_user function to read data from the user State and run the data in the kernel state.

Weida_printer_write () first checks whether the printer is online, whether it is busy, whether it is ready for further judgment, and then prints. When printing, pay attention to the delay of 150 milliseconds for each character, because if the print data is too fast to be processed by the printer, you need to set the delay.

Open/close functions open/close files, because in Linux, devices are operated as files, so open and close interfaces are required.

3.2 scanner serial port settings

The scanner used in the embedded mobile printing terminal is a serial scanner. Compared with the USB interface scanner, the scanner has simple control. After scanning, the scanner can directly read data from the serial port.

3.2.1 serial port settings [3]

Set the serial speed function: set_speed (int fd, int speed). FD indicates the opened device file, and speed indicates the speed.

Set
Set serial port parameters: set_parity (int fd, int databits, int stopbits, int
Parity), databits indicates the number of data bits, stopbit indicates the number of Stop bits, and parity indicates the parity bits. Set the serial port baud rate to 9600.
8 bits, One Stop bits, no check bits.

3.2.2 compile the Scanner Data Reading Function

First open the device file. The serial port used in the system is Serial Port 2. Therefore, the function to open is:

Open ("/dev/ttys1", o_rdwr | o_nonblock | o_ndelay); o_rdwr indicates readable and writable, o_nonblock indicates non-blocking mode, and o_ndelay indicates no delay and immediate release.

3.2.3 client and server socket programming

The embedded printing terminal adopts the C/S mode. The PC is used as the server, and the Development Board is used as the client and connected over Ethernet. The client establishes a socket connection to find the service program on the PC. The PC also runs a socket for listen request and binding. The TCP connection is used.

3.4 Primary Application Design

The main function of the application on the Development Board registers two threads P1 and P2, and two global arrays C1 and C2.

Thread P1 puts the data read from the serial port into C1, and then the sent socket directly removes the data from C1 and sends it to the server. Thread P2 is responsible for placing the stored ed socket data into the C2 array, and then directly taking the data from C2 to the printer for printing.

Here two semaphores are used for the thread, and the initialization is: sem_init (& sem1,); sem_init (& sem2,); [4]

The core code of the two threads is as follows:

Void thread1 (void ){

Open the serial port; set the serial port; establish a connection;

While (1 ){

Sem_wait (& sem1 );

Reading data from the serial port;

Use clinetsocket to send data;

Sem_post (& sem2 );}

}

Void thread2 (void ){

Enable the printer device;

While (1 ){

Sem_wait (& sem2 );

Receive data and throw it to the printer;

Sem_post (& sem1 );}

}

This allows two threads to run synchronously and execute multiple scanning and printing tasks.

Ben
Innovation and economic benefits of the author: The system features high mobility and low power consumption, and it has a low cost advantage compared with traditional printing terminals implemented by PCS. Widely used in supermarket cash registers
Systems, automated deposit machines for banks, and other industrial fields. I tried to port the 802.11g wireless network card to the Development Board, and successfully achieved wireless communication with the host, making the system more convenient.
Attach. According to the research on supermarkets in Nanjing university campuses, this system is estimated to produce an economic benefit of 0.5 million yuan.

References:

[1]
Samsung. S3C2410A 200 MHz & 266 MHz 32-bit Proteus microprocessor user's
Manual [Eb/Ol]. http://www.samsung.com/, 2004-03. 35,367-408

[2] Corbet J, Rubini A. Linux Device Driver (Third edition) [M]. China Power Press, 2006. 46-74 tp316.81

[3] sun Qiong. Detailed description of Embedded Linux application development [M]. People's post and telecommunications Press, 2006. 184-191 tp424.89

[4] Tian Jialin, Chen Lixue, Ke Xianghui. Transplantation of Linux Embedded Operating System on arm [J]. Microcomputer Information, 2007,4-2: P60-62.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.