Research and Implementation of VxWorks serial port driver

Source: Internet
Author: User

Summary: Taking the serial port driver of the b0x Chip Based on the ARM7TDMI kernel as an example, this paper analyzes the hierarchy and mechanism of the VxWorks serial port driver, and studies the working principle of the TTY driver and the underlying SCC driver. Combined with the serial port driver of the b0x chip, the design method and precautions of the VxWorks serial port driver are given.

Keywords: VxWorks; serial driver; tty device

Introduction

Program developers in VxWorks often need to solve the problem of serial port driver, which is an essential basic step for BSP and upper-layer application development, especially for board-level support packages (BSP) with the development of upper-layer applications, it is particularly important to master the principles of serial-port drivers and develop serial-port drivers. VxWorks serial communication is controlled by the serial communication controller SCC (Serial Communication Controller). It communicates with the standard I/O library with a tty driver, and then the TTY driver communicates with the underlying SCC driver. This article studies the characteristics of the VxWorks serial port driver, and uses the b0x as an example to provide steps and implementation methods for developing the VxWorks serial port driver.

Serial device level and tty driver

Serial Port Level

The layer of the VxWorks serial device adopts a three-layer Abstract Software Structure: Standard I/O Library (iolib)-> tty Library (ttydrv/tylib)-> underlying SCC Driver (xxdrv ), 1. It can be seen that the serial device driver xxdrv does not directly interact with the I/O system, and there is a ttydrv (including tylib) in the middle ). In fact, during kernel startup, not the xxdrv function is installed in the driver table, but the function provided by ttydrv/tylib. The serial port tty Driver (ttydrv/tylib) makes the I/O system independent of the specific SCC driver, ensuring code reusability and unified interface. The SCC Driver (xxdrv/yydrv) processes the components related to the underlying hardware. Therefore, when writing a serial port driver, you need to understand the principle of the serial port tty driver and the serial port input and output process. On this basis, the underlying SCC driver code is modified based on the Program Execution Process of VxWorks and the characteristics of the specific MCU chip.

Figure 1 VxWorks serial port Software Structure

Serial Port tty driver

Creating a tty device includes two steps: driver initialization and device creation. Both steps are completed in usrroot. After the tty device is created, you can call the write () and read () functions in iolib to read and write the serial port.

* Driver initialization
The initialize ttydrv () function is a virtual driver that manages both the interaction with I/O and the interaction with the underlying hardware driver. It calls iosdrvinstall () to install the functions in ttydrv and tylib to the driver table of the system. Ttydrv is responsible for the access of ttyopen and ttyioctl, while tylib is responsible for the access of tyread and tywrite.

* Create a device
The device creation function ttydevcreate () is mainly used to allocate and initialize the device description structure, call tydevinit () to initialize the tylib library, initialize selectlib (), create Input and Output Ring buffering, and create semaphores, call iosdevadd () and add the device to the device list to start the serial channel in an interrupted manner. Another important operation is to install the input/output callback functions tyitx () and tyird () provided by the tylib device, so that the underlying SCC driver can be called.

* Tty Input and Output
After a tty device is created, open the corresponding serial port with open (). The file handle returned by the open function is the identifier FD of the device. Based on the reading and writing mark when the serial port is opened, you can perform read and write operations on the serial port. The basic I/O read/write requests of a user program are implemented by tywrite () and tyread () of tylib. These two functions are installed in the driver table when ttydrv () is initialized to TTY, as shown in 2.

 

Figure 2 VxWorks Input and Output

Implementation of underlying SCC driver-serial port driver

The compilation of the VxWorks serial driver is mainly concentrated in syslib under the target/config/bsname/directory. c. sysserial. c. c. config. h, target/config/All and other files. Writing a serial driver mainly requires the following work.

Device Initialization

Determine the number of serial channels to be supported by the system, initialize the data structure xx_chan, and write the SCC initialization code (initialize the processor serial I/O port, reset Serial Port Controller ).

(1) Define parameters related to the serial port driver in the system: Specific parameters are defined in config. h.
# Define de_tty_dev/* define the tty device */
# Define de_serial/* define serial port */
# Define num_tty n_sio_channels/* define the number of serial ports */
# Define console_tty 0/* as the console channel is com0 */
# Define lele_baud_rate 115200/* set the serial port baud rate of the console */
If the system also defines the serial port as the wdb connection download channel, perform the following Configuration:
# Define wdb_comm_type wdb_comm_serial/* wdb is in serial port mode */
# Define wdb_tty_channel 1/* wdb download channel COM1 */
# Define wdb_tty_baud 115200/* serial port baud rate of the wdb connection channel */
# Define wdb_tty_dev_name "/Tyco/1"/* define the device name of the wbd channel in tty */

(2) initialize the data structure: Write a serial device to define its own device descriptor XX _ Dev structure according to the specific serial device. The specific member of a serial device is a base structure of b0_chan, indicating the channel of the device.

(3) SCC initialization code: the SCC driver describes the serial port initialization sequence in VxWorks in two steps 3, where ttydrv () and ttydevcreate () the general code provided by the involved I/O system does not need to be modified. You need to modify the data structure devparas [] of the serial port involving the b0x chip, and set the interrupt number, vector number, and register base address for usart sending and receiving.

Figure 3 VxWorks serial port initialization process

Before the system starts the kernel, after the first initialization in usrinit (), the serial port SCC is reset to prevent interruption. The serial port can be accessed through the query method. The system-level debugging is implemented as follows.

Syshwinit (): Initialize the processor I/O port. Call the portinit () function in the syshwinit () function to set the corresponding serial I/O port; note that both partb and partf have a uart2 setting option for the b0x chip. You can only select one of them to select uart2. Otherwise, wdb cannot be used to download the VxWorks image.

44b0devinit (): Initialize the serial port function pointer pchan-> SiO2. pdrvfuncs = & jx44b0siodrvfuncs; then, 8-bit data is used for the ulcon, ufcon, and umcon of the serial chip, and FIFO and AFC are prohibited; the serial communication mode is the round robin mode when the serial communication mode is called, and initialize the baud rate. After the system activates the kernel, perform Step 2 initialization in the root task usrroot () to enable the serial port to interrupt the underlying support for the TTY library.

Syshwinit2 (): Call intlibinit to initialize the intvectable. Call intconnect () to write the entry addresses of sysclkint () and sysauxclkint () to intvectable and sysserialhwinit2 () function connection is interrupted.

Sysserialhwinit2 (): Use intconnect () to connect the serial interrupt handlers, such as b0xinttx and b0xintrcv, to the corresponding interrupt vector. enable two interrupts by intenable () and call b0xdevinit2 () assign values to the _ ucon register to complete the final configuration of the serial port from polling mode to interrupt mode.

Write the device interrupt service program (ISR)

When data is sent or received, the hardware is interrupted and the corresponding interrupt service program is executed for processing, in this way, the CPU does not have to spend as much time querying the operating status of external devices as the polling method, effectively improving the CPU usage efficiency and enabling the system to have high real-time performance. Here we mainly write the Interrupt Processing driver for the data input and output related to the interrupt processing. The driver of the data sending part is a function for starting the sending, and an isrs3c44b0xtxint () for sending and output interruptions ().

① B0xtxstrartup () when a user wants to write data to a device, tywrite is called. After tywrite writes the data to the data output ring, it calls b0xtxstrartup () to start sending the device data. Here, you only need to write one byte to the serial port buffer, and enable sending interrupt; then, the byte sends the interrupt handler for processing.

② B0xtxint () in interrupt mode, when the output is complete, the device will generate an interrupt that can receive the next character, then call the interrupt processing program b0xtxint () to complete the rest of the data transmission work.

The driver of the received data is similar to the output driver, which is composed of a 44b0xrxint. When the interrupt handler receives the data, it writes the data in the register into the ring buffer of the driver through the callback function. Through the above work, you can write the VxWorks serial port driver.

Conclusion

For VxWorks serial port driver development, you should pay attention to the following issues: Understanding the START process and I/O system layers and organizational structure of VxWorks; it is necessary to clearly understand the physical address, register address and Its Meaning of the hardware environment, and understand the working principles of the hardware and software of the serial device. The main problems in the serial port debugging process are generally focused on whether the I/O port is correctly initialized at the start, whether the value of the serial port device register meets the software requirements, and whether the hardware can work properly, set the connection ISR program and interrupt priority and write the intermediate processing function.

References:

1. Wind River Inc. Tornado BSP developer's kit for VxWorks User's Guide [p]. Tornado 2.0.edition 1.1999
2. Wind River Inc. VxWorks BSP reference [p]. Tornado 2.2.edition 1.2000
3. Zhou qiping. Guide to device drivers and BSP development under VxWorks [M]. China Power Press. 2004.9
4. Chen Zhiyu. VxWorks program development practices [M]. Beijing: People's post and telecommunications press, 2004.5

Referenced in "casual BBS" "2 beanet": www.2beanet.com/bbs http://www.2beanet.com/

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.