Development of data acquisition card driver in VxWorks

Source: Internet
Author: User
Development of data acquisition card driver in VxWorks
[Date:] Source: China Power Grid Author: Yang, Yang smart, Li Xu, Li zhengxi [Font: large, medium, and small]

 

1 Introduction

With the development of embedded technology, data collection is widely used in field equipment. Based on the actual project requirements, this article develops the driver of the data acquisition card in the VxWorks operating system to facilitate application development.

The data acquisition card used in this article is the ADT700 Acquisition Card Based on PC/104 bus of shengbo co-operative Company. It forms a high-performance data acquisition and control system through the bus and PC/104 embedded system. The ADT700 has the following features:

Analog Input 16 single-ended/8 differential input; 12-bit resolution; 100 kHz Max A/D sampling rate; 0 ~ + 10 V,-5 ~ + 5 V,-10 ~ + 10 V bipolar or single polarity input range; 1, 2, 4, 8 times programmable gain; DMA achieves high-speed data transmission.

Analog output 4-channel output;-5 ~ + 5 V,-10 ~ + 10 V, 0 ~ 5 V, 0 ~ The 10 V range is optional; the number of channels is set separately or the number of 4 channels is set simultaneously.

Digital I/O programmable peripheral interface, 24-channel TTL/CMOS compatibility; I/O interface pull-up or drop-down throttling resistance.

Timing/Counter 6 16-bit, 10 MHz (max) Timing/count

2. VxWorks and its character device drivers

VxWorks is a preemptible real-time operating system. It is widely used in many industries with its high reliability, excellent real-time performance, and flexible cutting ability. In VxWorks, the I/O system provides device-independent user interfaces. Applications can use standard interface functions such as create (), remove (), open (), close (), read (), write (), ioctl (), etc. The ADT700 is a memory-type device. Its driver must support the above interface functions.

The following uses the open () operation in a character device as an example to describe the driver structure of the character device.

1. When the application calls fd = open ("/xx0", ORDONLY, 0, the I/O system searches for devices in the device list based on the file name "/xx0" (devices exist in the form of files, and the file name is the device name) (as shown in ① ); find the corresponding device and locate the driver table (as shown in ②) based on the driver number. The I/O system reserves a table item fd = 3 (as shown in ③) in the file description table ); then the I/O system calls the xxoOpen () function in the driver and returns the value to be retained, that is, the device description pointer (as shown in ④ ); the I/O system fills in the driver number and driver return value in the file descriptor table (as shown in ⑤). Finally, the I/O system returns the index of the new opeh () file in the file descriptor table, the application obtains the file descriptor fd = 3 (as shown in Figure 6 ). You can access an I/O device through an operation file.

3. Driver implementation

3.1 feature categories

The ADT700 features A/D, D/A conversion, digital I/O, timing/counting, and other functions. It can be analyzed in three categories:

(1) A/D is converted to read-only, while D/A is converted to write-only;
(2) numbers I/O are both readable and writable;
(3) The Timer/Counter does not need to be read or written. You only need to set it.

Based on the above functions, three drivers are required:

(1) The adtDrv driver is used to read the data converted by A/D and write the data converted by D/A. The device descriptor is "/adt ";
(2) The ppiDrv driver is used to read or write digital I/O numbers. The device descriptor is "/ppi ";
(3) The pitDrv driver is used to set the timer/counter and the device descriptor is "/pit ".

3.2 Basic Process

(1) install the driver

The function of the I/O system is to convert users' I/O requests into calls to the specific operation functions of the corresponding driver, it is implemented by maintaining an address table that includes all driver operation functions. You can dynamically install the driver by calling iOS-drvinstall (). The parameters of this function are seven basic I/O operation function pointers. The iosdrvinstall () function writes these addresses to an idle storage area in the driver table, and returns the number of the storage area, that is, the driver number, it can be used by devices associated with the driver. The prototype of iosdrvinstall () is:

Int iosdrvtnstall (funcptr pcreate, funcptrpdelete, funcptr popen, funcptr pclose, funcptr pread, funcptr pwrite, funcptr pi-octl );

After iosdrvinstall () is called to register the I/O function, run the iosdrvshow command in shell to view the driver entry of the adt700 in the driver table.

(2) create a device

To create a device, call iosdevadd () to add the device to the device list of the I/O system. The prototype of iosdevadd () is:

Status iosdevadd (dev_hdr * pdevhdr, char * Name, int drvnum );

Dev_hdr is a descriptor pointer to the device, and the first item in the dev_hdr structure points to the descriptor pointer of the next device.

After the device is created, run the Devs command in shell to view the device descriptor of the adt700 in the device list.

Take the adtdrv driver in the adt700 as an example. The above two steps are completed in step 2.

(3) Implement I/O functions

After installing the driver and creating the device, you need to implement the I/O function, that is, the function in the driver table. The same function is usually used for device activation and device creation for devices with the same underlying drivers. Once the device driver is installed, you do not need to delete it. remove () invalid. Therefore, xxRemove () is null in the underlying driver. The following provides the implementation template of ppiRead () in the ppiDrv driver.

After completing the preceding three steps, the driver is basically implemented. In this case, you can use standard interface functions in the application. Take the timing/Counter in the ADT700 as an example. The drive is pitDrv.

In this case, you can use the iosFdShow command in shell to observe the newly created file descriptor "/pit/timer ".

4 knots

This article takes the data acquisition card driver as an example to introduce in detail the development process of the character device driver in the Vx-Works operating system. The driver encapsulates almost all functions of the ADT700 and supports standard I/O system interface functions. You can use the ADT700 as a file. You only need to define the file name and create a file descriptor. You do not need to care about the underlying implementation to complete operations on the file. This shortens the application development time and improves the efficiency.

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.