CN103713908A - Method for designing digital quantity input functional unit driving program of CPCI (compact peripheral component interface) bus under VxWorks operating system - Google Patents

Method for designing digital quantity input functional unit driving program of CPCI (compact peripheral component interface) bus under VxWorks operating system Download PDF

Info

Publication number
CN103713908A
CN103713908A CN201410024766.3A CN201410024766A CN103713908A CN 103713908 A CN103713908 A CN 103713908A CN 201410024766 A CN201410024766 A CN 201410024766A CN 103713908 A CN103713908 A CN 103713908A
Authority
CN
China
Prior art keywords
function
input
plate
digital
digital input
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201410024766.3A
Other languages
Chinese (zh)
Inventor
刘大同
马云彤
奚成义
见其拓
彭宇
彭喜元
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Harbin Institute of Technology Shenzhen
Original Assignee
Harbin Institute of Technology Shenzhen
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Harbin Institute of Technology Shenzhen filed Critical Harbin Institute of Technology Shenzhen
Priority to CN201410024766.3A priority Critical patent/CN103713908A/en
Publication of CN103713908A publication Critical patent/CN103713908A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Power Sources (AREA)

Abstract

VxWorks操作系统下CPCI总线数字量输入功能单元驱动程序设计方法,属于数字量输入功能模块驱动程序开发领域。为了解决传统的VxWorks操作系统下基于CPCI总线的数字量输入模块驱动程序开发存在驱动开发人员需要抽象出设备的数据结构,完成设备的创建及设备驱动程序的安装的复杂过程,给驱动开发人员带来了很多不便的问题。数字量输入功能模块运行CPCI机箱中,应用程序运行在控制计算机上,通过CPCI总线实现对数字量输入功能模块的控制,数字量输入功能模块的驱动程序设计主要包括初始化设备,功能函数接口的实现及封装。实现对数字量输入功能模块的控制,面向应用程序直接定义驱动接口的形式,直接封装功能接口函数。

Figure 201410024766

The invention discloses a design method for a driver program of a CPCI bus digital quantity input function unit under the VxWorks operating system, and belongs to the field of development of a driver program of a digital quantity input function module. In order to solve the problem of developing the digital input module driver based on the CPCI bus under the traditional VxWorks operating system, the driver developer needs to abstract the data structure of the device, complete the complex process of creating the device and installing the device driver, and bring more benefits to the driver developer. A lot of inconveniences came. The digital input function module runs in the CPCI chassis, the application program runs on the control computer, and the control of the digital input function module is realized through the CPCI bus. The driver design of the digital input function module mainly includes the initialization device and the realization of the function interface and packaging. Realize the control of the digital input function module, directly define the form of the drive interface for the application program, and directly encapsulate the function interface function.

Figure 201410024766

Description

VxWorks操作系统下CPCI总线数字量输入功能单元驱动程序设计方法Design method of CPCI bus digital input function unit driver under VxWorks operating system

技术领域technical field

本发明涉及VxWorks操作系统下CPCI总线数字量输入功能单元驱动程序设计方法,属于数字量输入功能模块驱动程序开发领域。The invention relates to a design method for a driver program of a CPCI bus digital quantity input function unit under a VxWorks operating system, and belongs to the field of development of a driver program of a digital quantity input function module.

背景技术Background technique

VxWorks操作系统下CPCI总线数字量输入功能模块作为自动测试系统中重要的测试模块,已广泛的应用于各个领域。传统的VxWorks操作系统下基于CPCI总线的数字量输入模块驱动程序开发,是根据需要,实现相应的功能函数接口,并封装成标准的I/O接口(七个标准的I/O接口,例如open(),close(),read()等),注册到系统驱动列表中,挂接在I/O子系统下。在整个过程中,驱动开发人员需要抽象出设备的数据结构,完成设备的创建及设备驱动程序的安装,这个过程比较复杂,给驱动开发人员带来了很多不便。As an important test module in the automatic test system, the CPCI bus digital input function module under the VxWorks operating system has been widely used in various fields. Under the traditional VxWorks operating system, the development of the digital input module driver based on the CPCI bus is based on the need to realize the corresponding function interface and package it into a standard I/O interface (seven standard I/O interfaces, such as open (), close(), read(), etc.), registered in the system driver list, and mounted under the I/O subsystem. In the whole process, the driver developer needs to abstract the data structure of the device, complete the creation of the device and the installation of the device driver. This process is relatively complicated and brings a lot of inconvenience to the driver developer.

针对上述问题,本发明提出了VxWorks操作系统下CPCI总线数字量输入模块的驱动程序设计及封装,根据对数字量输入功能模块的常见操作,提出一种新的数字量输入驱动接口封装形式,以实现对数字量输入功能模块有效控制的同时,可以大大降低驱动开发人员的开发难度。For the problems referred to above, the present invention proposes the driver program design and packaging of the CPCI bus digital input module under the VxWorks operating system, and according to the common operations to the digital input functional modules, proposes a new digital input driver interface packaging form, with While realizing the effective control of the digital input function module, it can greatly reduce the development difficulty of the driver developer.

发明内容Contents of the invention

本发明的目的是发明一种VxWorks操作系统下CPCI总线数字量输入功能模块的驱动程序设计方法,以解决传统的VxWorks操作系统下基于CPCI总线的数字量输入模块驱动程序开发存在驱动开发人员需要抽象出设备的数据结构,完成设备的创建及设备驱动程序的安装的复杂过程,给驱动开发人员带来了很多不便的问题。The purpose of the invention is to invent a driver program design method of the CPCI bus digital input function module under the VxWorks operating system, so as to solve the traditional VxWorks operating system based on the digital input module driver development of the CPCI bus. The complex process of extracting the data structure of the device, completing the creation of the device and the installation of the device driver has brought a lot of inconvenience to the driver developer.

本发明为解决上述技术问题采取的技术方案是:The technical scheme that the present invention takes for solving the problems of the technologies described above is:

一种VxWorks操作系统下CPCI总线数字量输入功能单元驱动程序设计方法,所述方法的具体实现过程为:A kind of CPCI bus digital input functional unit driver design method under VxWorks operating system, the concrete realization process of described method is:

步骤一、初始化设备:Step 1. Initialize the device:

初始化设备过程为硬件分配系统资源,获取基于CPCI总线的数字量输入功能模块的设备信息、设备内存映射及中断链接;The process of initializing the device allocates system resources for the hardware, and obtains the device information, device memory map and interrupt link of the digital input function module based on the CPCI bus;

步骤二、功能函数的实现及封装:Step 2. Realization and encapsulation of functional functions:

功能函数接口用来实现对数字量输入功能模块的具体操作,对于数字量输入功能模块的操作主要有打开、关闭和读取功能;The function function interface is used to realize the specific operation of the digital input function module, and the operation of the digital input function module mainly includes opening, closing and reading functions;

数字量输入功能模块的主要控制过程为:应用程序首先执行打开指定数字量输入模块板卡的操作,加载数字量输入模块的驱动程序,然后调用数字量输入采集接口,应用程序传入数字量输入模块的板号和通道号,启用相应的数字量输入通道,采集数字量输入;32路数字量输入由2个16位寄存器控制;The main control process of the digital input function module is: the application program first executes the operation of opening the specified digital input module board, loads the driver program of the digital input module, and then calls the digital input acquisition interface, and the application program passes in the digital input module. The board number and channel number of the module enable the corresponding digital input channel to collect digital input; 32 digital inputs are controlled by two 16-bit registers;

数字量输入模块在系统上电后,完成板卡的内存映射,根据硬件的寄存器接口手册及各个驱动接口函数需完成的操作,来具体实现各个驱动接口函数,具体过程为:After the system is powered on, the digital input module completes the memory mapping of the board, and implements each driver interface function according to the hardware register interface manual and the operations to be completed by each driver interface function. The specific process is as follows:

步骤二(1)、打开数字量输入功能单元(数字量输入板卡):(见表1)Step 2 (1), open the digital input function unit (digital input board): (see Table 1)

加载数字量输入驱动程序,打开指定板号的数字量输入板,以对数字量输入板进行后续操作;对数字量输入板的输出通道进行清零;Load the digital input driver, open the digital input board with the specified board number to perform subsequent operations on the digital input board; clear the output channel of the digital input board;

函数原型为STATUS IOOpen(int num),The function prototype is STATUS IOOpen(int num),

入口参数num是板号,范围是1~N,N为控制计算机的数字量输入板数量;The entry parameter num is the board number, the range is 1 to N, and N is the number of digital input boards of the control computer;

返回值打开成功返回OK,失败返回非零负值故障码;Return value Open successfully and return OK, fail to return a non-zero negative fault code;

所述函数能识别错误的板号输入,并返回对应的故障码;The function can identify wrong board number input and return the corresponding fault code;

IOOpen函数的实现过程如下:The implementation process of the IOOpen function is as follows:

首先应用程序传递要打开的数字量输入板卡号,在函数体中判断板号是否正确,如果正确则将初始化函数执行后获得的数字量输入板卡内存映射基址值赋给一个全局变量,再对指定数字量输入板卡各通道清零,最后函数返回OK,如果板号参数不是用户允许的,则返回板号错误故障码。First, the application passes the number of the digital input board to be opened, and judges whether the board number is correct in the function body. If it is correct, assign the base address value of the digital input board memory map obtained after the initialization function is executed to a global variable. Then clear each channel of the specified digital input board, and finally the function returns OK. If the board number parameter is not allowed by the user, it returns the board number error fault code.

步骤二(2)、关闭数字量输入功能单元(数字量输入板):Step 2 (2), close the digital input functional unit (digital input board):

关闭指定板号的数字量输入板,卸载I/O驱动程序,完成后释放I/O板的硬件资源,不能再对I/O板进行除打开以外的其他操作;Close the digital input board with the specified board number, uninstall the I/O driver, and release the hardware resources of the I/O board after completion, and no other operations can be performed on the I/O board except opening;

函数原型为STATUS IOClose(int num);The function prototype is STATUS IOClose(int num);

入口参数num是板号,范围是1~N,N为控制计算机的数字量输入板数量;The entry parameter num is the board number, the range is 1 to N, and N is the number of digital input boards of the control computer;

返回值关闭成功返回OK,失败返回非零负值故障码;Return value Close successfully returns OK, fails to return a non-zero negative fault code;

所述函数能识别错误的板号输入,并返回相应的故障码;The function can identify wrong board number input and return the corresponding fault code;

IOClose函数的实现过程如下(如图4):The implementation process of the IOClose function is as follows (as shown in Figure 4):

首先应用程序传递要关闭的指定数字量输入板卡号,在函数体中,判断传递的板号参数是否正确,如果正确,则将保存有内存基址的全局变量清零,函数返回OK,如果板卡号错误,则返回板号错误故障码。First, the application passes the specified digital input board number to be closed. In the function body, it is judged whether the passed board number parameter is correct. If it is correct, the global variable that holds the memory base address is cleared, and the function returns OK. If If the board number is wrong, it will return a board number error fault code.

步骤二(3)、数字量输入功能单元(数字量输入板)读位操作:(见表3)Step 2 (3), digital input functional unit (digital input board) bit reading operation: (see Table 3)

指定数字量输入板的板号,读取指定一路输入通道的状态,并将结果传给char类型参数指针*pdata;Specify the board number of the digital input board, read the state of the specified input channel, and pass the result to the char type parameter pointer *pdata;

函数原型为STATUS IOReadBit(int num,int chan,char*pdata)The function prototype is STATUS IOReadBit(int num,int chan,char*pdata)

入口参数num是板号,范围是1~N,N为控制计算机的数字量输入板数量;The entry parameter num is the board number, the range is 1 to N, and N is the number of digital input boards of the control computer;

int chan为通道号,赋值0~M-1,M为数字量输入板的输入通道数量;int chan is the channel number, assigned 0~M-1, M is the number of input channels of the digital input board;

char*pdata存放读数结果,取值为0或1;char*pdata stores the reading result, the value is 0 or 1;

返回值读取成功返回OK,失败返回非零负值故障码Return value If the reading is successful, it returns OK, and if it fails, it returns a non-zero negative fault code

所述函数能识别错误的板号输入,并返回相应的故障码;The function can identify wrong board number input and return the corresponding fault code;

IOReadBit函数的实现过程如下:(图5所示):The implementation process of the IOReadBit function is as follows: (shown in Figure 5):

DARevertData函数的实现过程如下:The implementation process of the DARevertData function is as follows:

首先应用程序传递要进行数据输入的数字量输入板卡号和通道号参数,在函数体中,先判断传递的板号是否是用户允许输入的板号,如果是,再进一步判断传递的通道号是否是用户允许输入的通道号,如果是,回读指定输入通道的状态值,并保存,函数返回OK,表示用户可以从相应的通道读取指定输入通道的状态值。如果上述判断的过程出现否定,则退出函数返回相应错误故障码。Firstly, the application program transmits the digital input board number and channel number parameters for data input. In the function body, first judge whether the passed board number is the board number that the user allows to input, and if so, further judge the passed channel number Is it the channel number that the user is allowed to input? If so, read back the state value of the specified input channel and save it. The function returns OK, indicating that the user can read the state value of the specified input channel from the corresponding channel. If the above judgment process is negative, the exit function returns the corresponding error code.

步骤二(4)、数字量输入功能单元(数字量输入板)读字节操作:(见表4)Step 2 (4), digital input functional unit (digital input board) read byte operation: (see Table 4)

指定数字量输入板的板号,以offset为偏移量地址读一个字节的数据,即8位输入通道的状态,并将结果传给char类型参数指针*pdata;Specify the board number of the digital input board, read one byte of data with offset as the offset address, that is, the state of the 8-bit input channel, and pass the result to the char type parameter pointer *pdata;

函数原型为STATUS IOReadByte(int num,int offset,char*pdata);The function prototype is STATUS IOReadByte(int num,int offset,char*pdata);

入口参数num是板号,范围是1~N,N为控制计算机的数字量输入板数量;The entry parameter num is the board number, the range is 1 to N, and N is the number of digital input boards of the control computer;

Offset为偏移量,赋值0~P-1,P为数字量输入板的输入通道数量除以8;Offset is the offset, assigned 0 to P-1, P is the number of input channels of the digital input board divided by 8;

Pdata用于存储读取的结果,取值00~FFH;Pdata is used to store the read results, the value is 00~FFH;

返回值读取成功返回OK,失败返回非零负值故障码;If the return value is successfully read, it returns OK, and if it fails, it returns a non-zero negative fault code;

所述函数能识别错误的板号输入,并返回对应的故障码;还能识别错误的偏移量,并返回对应的故障码;The function can identify the wrong board number input and return the corresponding fault code; it can also identify the wrong offset and return the corresponding fault code;

函数IOReadByte的实现过程如下:The implementation process of the function IOReadByte is as follows:

首先应用程序传递要进行数据输入的数字量输入板卡号和偏移量参数,在函数体中,先判断传递的板号是否是用户允许输入的板号,如果是,再进一步判断传递的通道号是否是用户允许输入的偏移量,如果是,回读指定8路输入通道的状态值,并保存,函数返回OK,表示用户可以从相应的通道读取指定输入通道的状态值。如果上述判断的过程出现否定,则退出函数返回相应错误故障码。Firstly, the application program transmits the digital input board number and offset parameter for data input. In the function body, first judge whether the passed board number is the board number that the user allows to input, and if so, further judge the passed channel Is the number the offset allowed by the user? If so, read back the state values of the specified 8 input channels and save them. The function returns OK, indicating that the user can read the state values of the specified input channels from the corresponding channels. If the above judgment process is negative, the exit function returns the corresponding error code.

步骤二(5)数字量输入功能单元(数字量输入板)读全通道操作:(见表5)Step 2 (5) Digital input functional unit (digital input board) reads all channels: (See Table 5)

指定数字量输入板的板号,读取一块板所有输入通道的状态,并将结果放在指定首地址的数据buffer中;Specify the board number of the digital input board, read the status of all input channels of a board, and put the result in the data buffer of the specified first address;

STATUS IOReadAll(int num,char*pbuf)STATUS IOReadAll(int num,char*pbuf)

入口参数num是板号,范围是1~N,N为控制计算机的数字量输入板数量;The entry parameter num is the board number, the range is 1 to N, and N is the number of digital input boards of the control computer;

Buffer为首地址,buffer大小根据硬件根据硬件实际通道数定;Buffer is the first address, and the buffer size is determined according to the hardware and the actual channel number of the hardware;

返回值读取成功返回OK,失败返回非零负值故障码;If the return value is successfully read, it returns OK, and if it fails, it returns a non-zero negative fault code;

所述函数能识别错误的板号输入,并返回对应的故障码;The function can identify wrong board number input and return the corresponding fault code;

函数IOReadAll的实现过程如下:The implementation process of the function IOReadAll is as follows:

首先应用程序传递要进行数据输入的数字量输入板卡号和偏移量参数,在函数体中,先判断传递的板号是否是用户允许输入的板号,如果是,回读所有输入通道的状态值,并保存,函数返回OK。如果上述判断的过程出现否定,则退出函数返回相应错误故障码。Firstly, the application program transmits the digital input board number and the offset parameter for data input. In the function body, it first judges whether the passed board number is the board number that the user allows to input. If so, read back all the input channels. State value, and save, the function returns OK. If the above judgment process is negative, the exit function returns the corresponding error code.

步骤二(6)、数字量输入功能单元(数字量输入板)实时监测:(见表6)Step 2 (6), real-time monitoring of the digital input functional unit (digital input board): (see Table 6)

对指定的板号的数字量输入板进行在位实时监测;On-site real-time monitoring of digital input boards with specified board numbers;

函数原型为STATUS IORTWatch(int num);The function prototype is STATUS IORTWatch(int num);

入口参数num为板号,范围是1~N,N为控制计算机的数字量输入板的数量;The entry parameter num is the board number, the range is 1 to N, and N is the number of digital input boards of the control computer;

返回值监测正常返回OK,失败返回非零负值故障码;The return value monitoring returns OK if it is normal, and returns a non-zero negative fault code if it fails;

所述函数能识别错误的板号输入,并返回对应的故障码;The function can identify wrong board number input and return the corresponding fault code;

IORTWatch函数的实现过程如下:The implementation process of the IORTWatch function is as follows:

首先应用程序传递指定数字量输入功能单元板号,在函数体中,判断传递的板号是否是用户允许的板号,如果是,下一步调用PciFindDevice()函数,判断PciFindDevice()函数的返回值是否为OK,如果是,则函数接口返回OK。如果上述判断出现否定,如果上述判断的过程出现否定,则退出函数返回相应错误故障码。First, the application transmits the board number of the specified digital input function unit. In the function body, judge whether the passed board number is the board number allowed by the user. If yes, the next step is to call the PciFindDevice() function to judge the return value of the PciFindDevice() function. Whether it is OK, if yes, the function interface returns OK. If the above judgment is negative, if the above judgment process is negative, the exit function returns the corresponding error code.

所述步骤一的具体实施过程为:The concrete implementation process of described step 1 is:

步骤一(1)获取基于CPCI总线的数字量输入功能模块的设备信息Step 1 (1) Obtain the device information of the digital input function module based on the CPCI bus

PCI设备上电后,BIOS配置PCI设备,目标机的BIOS在启动时列出找到的PCI设备及Vendor ID、Device ID、设备类型、分配的中断号信息;After the PCI device is powered on, the BIOS configures the PCI device, and the BIOS of the target machine lists the found PCI device, Vendor ID, Device ID, device type, and assigned interrupt number information when it starts;

初始化函数先根据设备Vendor ID和Device ID利用函数pciFindDevice()找到对应的设备,根据Vendor ID、Device ID和相同设备顺序号(一个系统中可能有相同的PCI设备)来扫描总线,找出设备所在的BUS No、Device No和Func No;然后根据总线号、设备号和功能号调用pciConfigInLong()及pciConfigInByte()函数确定设备的寄存器基地址以及中断号;再把基地址与I/O屏蔽位相与得到真正的板上内部寄存器基地址;The initialization function first uses the function pciFindDevice() to find the corresponding device according to the device Vendor ID and Device ID, and scans the bus according to the Vendor ID, Device ID and the same device sequence number (there may be the same PCI device in a system) to find out where the device is located. BUS No, Device No, and Func No; then call the pciConfigInLong() and pciConfigInByte() functions to determine the register base address and interrupt number of the device according to the bus number, device number, and function number; then compare the base address with the I/O mask bit Get the real base address of the internal register on the board;

步骤一(2)设备内存映射Step 1 (2) Device memory mapping

用户使用VxWorks提供的标准的MMU(内存管理单元)来分配PCI设备的内存空间;在明确基地址和内存空间大小后,调用函数sysMmuMapAdd()函数将内存空间配置到MMU;完成数字量输入功能模块的设备内存映射后,通过对设备内存的访问,实现对设备的控制;The user uses the standard MMU (memory management unit) provided by VxWorks to allocate the memory space of the PCI device; after specifying the base address and the size of the memory space, call the function sysMmuMapAdd() to configure the memory space to the MMU; complete the digital input function module After the device memory is mapped, the control of the device is realized by accessing the device memory;

步骤一(3)中断链接Step one (3) break the link

VxWorks操作系统中使用intConnect()链接中断服务程序(ISR),采用pciIntConncet()挂接中断,pciIntConncet()定义在pciIntLib.c中,使用时包含头文件pciIntLib.h,中断矢量ventor通过INUM_TO_IVEC换算获得;In the VxWorks operating system, intConnect() is used to link the interrupt service routine (ISR), and pciIntConncet() is used to hook the interrupt. pciIntConncet() is defined in pciIntLib.c, and the header file pciIntLib.h is included when used. The interrupt vector ventor is obtained through INUM_TO_IVEC conversion ;

在VxWorks系统下使用pciIntConnect()函数将中断和特定的C程序连接起来后,所述函数将指定的C函数与指定的中断向量相联系,函数的地址将存储在所述中断向量中,当中断发生时,系统将调用所述特定的C程序函数,即中断服务程序。After the pciIntConnect() function is used to connect the interrupt with a specific C program under the VxWorks system, the function will associate the specified C function with the specified interrupt vector, and the address of the function will be stored in the interrupt vector. When the interrupt When that happens, the system will call said specific C program function, the Interrupt Service Routine.

本发明的有益效果是:The beneficial effects of the present invention are:

本发明根据数字量输入功能模块的特点,开发驱动实现对数字量输入功能模块的控制,同时提供一种新的数字量输入功能模块的驱动接口封装形式,面向应用程序直接定义驱动接口的形式,直接封装功能接口函数。这样在驱动开发的过程中,不涉及到传统数字量输入功能模块的设备数据结构的设计、设备创建及驱动安装,很大程度上降低了驱动开发人员的开发难度。具本优点表现在以下几个方面;According to the characteristics of the digital quantity input functional module, the present invention develops the drive to realize the control of the digital quantity input functional module, and provides a new encapsulation form of the driving interface of the digital quantity input functional module, and directly defines the form of the driving interface for the application program. Direct encapsulation of functional interface functions. In this way, in the process of driver development, the design of device data structure, device creation and driver installation of traditional digital input function modules are not involved, which greatly reduces the development difficulty of driver developers. This advantage is manifested in the following aspects;

1)、本方法提供的数字量输入功能模块驱动程序能够实现对功能模块的有效控制;1), the digital input function module driver program provided by this method can realize the effective control of the function module;

2)、本方法提供的数字量输入功能模块驱动程序直接面向用户应用程序提供通用的驱动函数接口;2), the digital input function module driver program provided by this method directly provides a general driver function interface for the user application program;

3)、本方法提供的数字量输入功能模块驱动程序设计及封装大大降低驱动开发的难度;3), the digital input function module driver design and packaging provided by this method greatly reduce the difficulty of driver development;

4)、本方法提供的数字量输入功能模块驱动程序设计及封装具有独立性与通用性,可应用于其它设计。4) The design and packaging of the digital input function module driver program provided by this method are independent and versatile, and can be applied to other designs.

附图说明Description of drawings

图1是数字输入量功能模块的整体架构图,图2是初始化函数流程图,图3是打开数字量输入板流程图,图4是关闭数字量输入板流程,图5是数字量输入板读位操作程序流程图,图6是数字量输入板读字节程序流程图,图7是数字量输入读全通道程序流程图,图8是数字量输入板实时监测图。Figure 1 is the overall architecture diagram of the digital input function module, Figure 2 is the initialization function flow chart, Figure 3 is the flow chart of opening the digital input board, Figure 4 is the process of closing the digital input board, Figure 5 is the digital input board read Bit operation program flow chart, Figure 6 is a digital input board read byte program flow chart, Figure 7 is a digital input board read full channel program flow chart, Figure 8 is a digital input board real-time monitoring diagram.

具体实施方式Detailed ways

参见图1至图8,本实施方式是对本发明所述的VxWorks操作系统下CPCI总线数字量输入功能单元驱动程序设计方法进行详细描述:Referring to Fig. 1 to Fig. 8, present embodiment is described in detail CPCI bus digital input functional unit driver design method under the VxWorks operating system of the present invention:

本实施方式所述的数字量输入功能模块的整体架构如图1所示:The overall architecture of the digital input functional module described in this embodiment is shown in Figure 1:

数字量输入功能模块运行在CPCI机箱中,控制计算机通过CPCI总线实现对数字量输入功能模块的读写控制。CPCI总线和数字量输入功能电路之间需要实现CPCI总线接口控制器,CPCI总线控制器采用PLX公司的PCI9054接口芯片实现,将CPCI总线转换到本地总线。PCI9054接口芯片完全兼容PCI2.2规范,且突发传输速率高,价格低,通用性好,可以有效降低开发难度。PCI9054本地总线端使用FPGA实现总线接口译码,同时,FPGA内部设计控制寄存器,实现对数字量输入功能电路的控制。数字量输入功能模块由32路光耦组成。外部32路数字量输入经过光耦隔离后输入FPGA,FPGA可以检测输入通道的状态。The digital input function module runs in the CPCI chassis, and the control computer realizes the reading and writing control of the digital input function module through the CPCI bus. The CPCI bus interface controller needs to be implemented between the CPCI bus and the digital input function circuit. The CPCI bus controller is realized by the PCI9054 interface chip of PLX Company, and converts the CPCI bus to the local bus. The PCI9054 interface chip is fully compatible with the PCI2.2 specification, and has high burst transmission rate, low price, and good versatility, which can effectively reduce the difficulty of development. The PCI9054 local bus terminal uses FPGA to realize bus interface decoding, and at the same time, FPGA internally designs control registers to realize the control of digital input functional circuits. The digital input function module is composed of 32 optocouplers. The external 32-channel digital input is input to FPGA after optocoupler isolation, and FPGA can detect the state of the input channel.

数字量输入功能模块驱动程序设计过程为:The design process of the digital input function module driver is as follows:

数字量输入功能模块运行CPCI机箱中,应用程序运行在控制计算机上,通过CPCI总线实现对数字量输入功能模块的控制,因此需要开发基于CPCI总线数字量输入功能模块的驱动程序。数字量输入功能模块的驱动程序设计主要包括初始化设备,功能函数接口的实现及封装。The digital input function module runs in the CPCI chassis, the application program runs on the control computer, and the control of the digital input function module is realized through the CPCI bus, so it is necessary to develop a driver for the digital input function module based on the CPCI bus. The driver program design of the digital input function module mainly includes initializing the device, realizing and encapsulating the function interface.

步骤一、初始化设备Step 1. Initialize the device

初始化设备作为CPCI设备驱动开发的重要环节,主要是为硬件分配系统资源,这里主要是获取基于CPCI总线的数字量输入功能模块的设备信息、设备内存映射及中断链接。As an important part of CPCI device driver development, the initialization device is mainly to allocate system resources for the hardware. Here, it is mainly to obtain the device information, device memory map and interrupt link of the digital input function module based on the CPCI bus.

(1)获取基于CPCI总线的数字量输入功能模块的设备信息(1) Obtain the device information of the digital input function module based on the CPCI bus

PCI设备上电后,BIOS会配置PCI设备。目标机的BIOS在启动时会有一个界面列出找到的PCI设备及Vendor ID、Device ID、设备类型、分配的中断号等信息。After the PCI device is powered on, the BIOS configures the PCI device. When the BIOS of the target machine starts, there will be an interface listing the found PCI devices, Vendor ID, Device ID, device type, assigned interrupt number and other information.

初始化函数先根据设备Vendor ID和Device ID利用函数pciFindDevice()找到对应的设备,根据Vendor ID、Device ID和相同设备顺序号(一个系统中可能有相同的PCI设备)来扫描总线,找出设备所在的BUS No.(总线号)、Device No.(设备号)和Func No.(功能号)。然后根据总线号、设备号和功能号调用pciConfigInLong()及pciConfigInByte()函数确定设备的寄存器基地址以及中断号。再把基地址与I/O屏蔽位相与得到真正的板上内部寄存器基地址。初始化函数流程如下图2所示。The initialization function first uses the function pciFindDevice() to find the corresponding device according to the device Vendor ID and Device ID, and scans the bus according to the Vendor ID, Device ID and the same device sequence number (there may be the same PCI device in a system) to find out where the device is located. The BUS No. (bus number), Device No. (device number) and Func No. (function number) of the Then call the pciConfigInLong() and pciConfigInByte() functions according to the bus number, device number and function number to determine the register base address and interrupt number of the device. Then compare the base address with the I/O mask phase to obtain the real base address of the internal register on the board. The initialization function flow is shown in Figure 2 below.

(2)设备内存映射(2) Device memory mapping

VxWorks提供了标准的MMU(内存管理单元),用户可以使用MMU来分配PCI设备的内存空间。在明确基地址和内存空间大小后,调用函数sysMmuMapAdd()函数即可将内存空间配置到MMU。完成了数字量输入功能模块的设备内存映射后,可以通过对设备内存的访问,实现对设备的控制。VxWorks provides a standard MMU (Memory Management Unit), users can use MMU to allocate memory space of PCI devices. After specifying the base address and the size of the memory space, call the function sysMmuMapAdd() to configure the memory space to the MMU. After completing the device memory mapping of the digital input function module, the device can be controlled by accessing the device memory.

(3)中断链接(3) Broken link

VxWorks操作系统中使用intConnect()链接中断服务程序(ISR),但对于CPCI设备,一般采用pciIntConncet()挂接中断,它与intConnect()的主要不同在于intConnect()使用的中断向量是独占的,而pciIntConncet()则可使多个外部中断共享一个中断向量。pciIntConncet()定义在pciIntLib.c中,使用时应包含头文件pciIntLib.h。应注意ventor是中断矢量,需要通过INUM_TO_IVEC换算获得。In the VxWorks operating system, intConnect() is used to connect the interrupt service routine (ISR), but for CPCI devices, pciIntConncet() is generally used to connect interrupts. The main difference between it and intConnect() is that the interrupt vector used by intConnect() is exclusive. And pciIntConncet () can make multiple external interrupts share an interrupt vector. pciIntConncet() is defined in pciIntLib.c, and the header file pciIntLib.h should be included when used. It should be noted that ventor is an interrupt vector and needs to be obtained through INUM_TO_IVEC conversion.

在VxWorks系统下使用pciIntConnect()函数将中断和特定的C程序连接起来后,该函数将指定的C函数与指定的中断向量相联系,函数的地址将存储在这个中断向量中。当中断发生时,系统将调用这个特定的C程序函数,即中断服务程序。After using the pciIntConnect() function to connect the interrupt with a specific C program under the VxWorks system, this function will link the specified C function with the specified interrupt vector, and the address of the function will be stored in this interrupt vector. When an interrupt occurs, the system will call this specific C program function, the interrupt service routine.

步骤二、功能函数接口的实现及封装Step 2. Realization and encapsulation of functional interface

功能函数接口用来实现对数字量输入功能模块的具体操作,对于数字量输入功能模块的操作,常见的主要有打开、关闭和读取等功能。The function function interface is used to realize the specific operation of the digital input function module. For the operation of the digital input function module, the common functions mainly include opening, closing and reading.

数字量输入功能模块的主要控制过程为:应用程序首先执行打开指定数字量输入模块板卡的操作,加载数字量输入模块的驱动程序,下一步调用数字量输入采集接口,应用程序传入数字量输入模块的板号和通道号,启用相应的数字量输入通道,采集数字量输入。32路数字量输入由2个16位寄存器控制。The main control process of the digital input function module is: the application program first executes the operation of opening the specified digital input module board, loads the driver program of the digital input module, and then calls the digital input acquisition interface, and the application program passes in the digital input module. Input the board number and channel number of the module, enable the corresponding digital input channel, and collect digital input. The 32 digital inputs are controlled by two 16-bit registers.

数字量输入模块在系统上电后,完成板卡的内存映射,根据硬件设计人员提供的驱动硬件寄存器接口手册及各个驱动接口函数需完成的操作,来具体实现各个驱动接口函数。After the system is powered on, the digital input module completes the memory mapping of the board, and implements each driver interface function according to the driver hardware register interface manual provided by the hardware designer and the operations to be completed by each driver interface function.

(1)、打开数字量输入板卡,见表1(1) Turn on the digital input board, see Table 1

表1打开数字量输入板卡Table 1 Open the digital input board

Figure BDA0000453819220000071
Figure BDA0000453819220000071

Figure BDA0000453819220000081
Figure BDA0000453819220000081

程序流程图如下图3所示;The program flow chart is shown in Figure 3 below;

(2)、关闭数字量输入板,见表2;(2), close the digital input board, see Table 2;

表2关闭数字量输入板Table 2 Close the digital input board

Figure BDA0000453819220000082
Figure BDA0000453819220000082

程序实现流程如下图4所示;The program implementation process is shown in Figure 4 below;

(3)、数字量输入板读位操作,见表3;(3) Bit reading operation of the digital input board, see Table 3;

表3数字量输入板读位操作Table 3 Digital input board read bit operation

Figure BDA0000453819220000083
Figure BDA0000453819220000083

程序实现流程如下图5所示;The program implementation flow is shown in Figure 5 below;

(4)、数字量输入板读字节操作,见表4;(4) Read byte operation of digital input board, see Table 4;

表4数字量输入板读字节操作Table 4 Digital input board read byte operation

Figure BDA0000453819220000091
Figure BDA0000453819220000091

程序实现流程如下图6所示;The program implementation flow is shown in Figure 6 below;

(5)、数字量输入板读全通道操作,见表5;(5), digital input board read full channel operation, see Table 5;

表5数字量输入板读全通道操作Table 5 Digital input board read full channel operation

Figure BDA0000453819220000092
Figure BDA0000453819220000092

程序实现流程如下图7所示;The program implementation process is shown in Figure 7 below;

(6)、数字量输入板实时监测,见表6;(6) Real-time monitoring of the digital input board, see Table 6;

表6I/O板实时监测Table 6 I/O board real-time monitoring

Figure BDA0000453819220000101
Figure BDA0000453819220000101

程序流程如下图8所示。The program flow is shown in Figure 8 below.

Claims (2)

1. a cpci bus digital quantity input function unit drives Programming Methodology under vxworks operating system, is characterized in that, the specific implementation process of described method is:
Step 1, initialization apparatus:
Initialization apparatus process is hardware distributing system resource, obtains facility information, device memory mapping and the Break Link of the digital quantity input functional module based on cpci bus;
The realization of step 2, power function and encapsulation:
Power function interface is used for realizing the concrete operations to digital quantity input functional module, for the operation of digital quantity input functional module, mainly contains and opens, closes and read functions;
The major control process of digital quantity input functional module is: first application program carries out the operation of opening designation number amount load module board, load the driver of digital quantity input module, then call number amount is inputted acquisition interface, application program is imported plate number and the channel number of digital quantity input module into, enable corresponding digital quantity input channel, gather digital quantity input; 32 railway digital amount inputs are controlled by 2 16 bit registers;
Digital quantity input module, after system powers on, completes the memory-mapped of board, and according to the register interface handbook of hardware and each operation that drives interface function to complete, each drives interface function to carry out specific implementation, and detailed process is:
Step 2 (1), open digital quantity input function unit:
Load digital quantity input driver, open the digital input of given plate number, so that digital input is carried out to subsequent operation; The output channel of digital input is carried out to zero clearing;
Function prototype is STATUS IOOpen (int num),
Suction parameter num is plate number, and scope is 1~N, and N is for controlling the digital input quantity of computing machine;
Rreturn value is opened and is successfully returned to OK, unsuccessfully returns to non-zero negative value diagnostic trouble code;
Number input of the plate of described function energy identification error, and return to corresponding diagnostic trouble code;
The implementation procedure of IOOpen function is as follows:
First the digital input card number that application passes will be opened, in function body, judge whether plate is number correct, if correct, the digital input card memory-mapped base value obtaining after initialization function is carried out is assigned to a global variable, again to each passage zero clearing of designation number amount input card, last function returns to OK, if not being user, plate parameter do not allow, Returning plate fault code;
Step 2 (2), close digital quantity input function unit:
Close the digital input of given plate number, unloading I/O driver, discharges the hardware resource of I/O plate after completing, can not other operations except opening to I/O plate again;
Function prototype is STATUS IOClose (int num);
Suction parameter num is plate number, and scope is 1~N, and N is for controlling the digital input quantity of computing machine;
Rreturn value is closed and is successfully returned to OK, unsuccessfully returns to non-zero negative value diagnostic trouble code;
Number input of the plate of described function energy identification error, and return to corresponding diagnostic trouble code;
The implementation procedure of IOClose function is as follows:
First the designation number amount tablet card number that application passes will be closed, in function body, whether the plate parameter that judgement is transmitted is correct, if correct, will preserve the global variable zero clearing of memory base address, function returns to OK, if plate card number mistake, Returning plate fault code;
Step 2 (3), the operation of digital quantity input function unit read bit:
The plate number of designation number amount tablet, reads the state of specifying a road input channel, and result is passed to char type parameter pointer * pdata;
Function prototype is STATUS IOReadBit (int num, int chan, char*pdata)
Suction parameter num is plate number, and scope is 1~N, and N is for controlling the digital input quantity of computing machine;
Int chan is channel number, assignment 0~M-1, the input channel quantity that M is digital input;
Char*pdata deposits reading result, and value is 0 or 1;
Rreturn value reads successfully returns to OK, unsuccessfully returns to non-zero negative value diagnostic trouble code
Number input of the plate of described function energy identification error, and return to corresponding diagnostic trouble code;
The implementation procedure of IOReadBit function is as follows:
The implementation procedure of DARevertData function is as follows:
First application passes will be carried out digital input card number and the channel number parameter of data input, in function body, whether the plate that first judgement is transmitted number is the plate number that user allows input, if so, more further judge whether the channel number transmitting is the channel number that user allows input, if, the state value of input channel is specified in retaking of a year or grade, and preserve, function returns to OK, represents that user can read the state value of specifying input channel from corresponding passage; If the process of above-mentioned judgement occurs negating to exit function and return to corresponding fault code;
Byte manipulation is read in step 2 (4), digital quantity input function unit:
The plate number of designation number amount tablet, the data that the offset of take is a byte of side-play amount address read, i.e. the state of 8 input channels, and result is passed to char type parameter pointer * pdata;
Function prototype is STATUS IOReadByte (int num, int offset, char*pdata);
Suction parameter num is plate number, and scope is 1~N, and N is for controlling the digital input quantity of computing machine;
Offset is side-play amount, assignment 0~P-1, and the input channel quantity that P is digital input is divided by 8;
Pdata is for storing the result reading, value 00~FFH;
Rreturn value reads successfully returns to OK, unsuccessfully returns to non-zero negative value diagnostic trouble code;
Number input of the plate of described function energy identification error, and return to corresponding diagnostic trouble code; Side-play amount that can also identification error, and return to corresponding diagnostic trouble code;
The implementation procedure of function IOReadByte is as follows:
First application passes will be carried out digital input card number and the offset parameter of data input, in function body, whether the plate that first judgement is transmitted number is the plate number that user allows input, if so, more further judge whether the channel number transmitting is the side-play amount that user allows input, if, the state value of 8 tunnel input channels is specified in retaking of a year or grade, and preserve, function returns to OK, represents that user can read the state value of specifying input channel from corresponding passage; If the process of above-mentioned judgement occurs negating to exit function and return to corresponding fault code;
Full tunnel operation is read in step 2 (5) digital quantity input function unit:
The plate number of designation number amount tablet, reads the state of all input channels of plate, and result is placed in the data b uffer that specifies first address;
STATUS?IOReadAll(int?num,char*pbuf)
Suction parameter num is plate number, and scope is 1~N, and N is for controlling the digital input quantity of computing machine;
Buffer is first address, and buffer size is fixed according to hardware physical channel number according to hardware;
Rreturn value reads successfully returns to OK, unsuccessfully returns to non-zero negative value diagnostic trouble code;
Number input of the plate of described function energy identification error, and return to corresponding diagnostic trouble code;
The implementation procedure of function IOReadAll is as follows:
First application passes will be carried out digital input card number and the offset parameter of data input, and in function body, whether the plate that first judgement is transmitted number is the plate number that user allows input, if, the state value of all input channels of retaking of a year or grade, and preserve, function returns to OK; If the process of above-mentioned judgement occurs negating to exit function and return to corresponding fault code;
Step 2 (6), digital quantity input function unit Real-Time Monitoring:
Digital input to the plate of appointment number carries out Real-Time Monitoring in place;
Function prototype is STATUS IORTWatch (int num);
Suction parameter num is plate number, and scope is 1~N, and N is for controlling the quantity of the digital input of computing machine;
OK is normally returned in rreturn value monitoring, unsuccessfully returns to non-zero negative value diagnostic trouble code;
Number input of the plate of described function energy identification error, and return to corresponding diagnostic trouble code;
The implementation procedure of IORTWatch function is as follows:
First application passes designation number amount input function cell board number, in function body, whether the plate number that judgement is transmitted is the plate number that user allows, if, next step calls PciFindDevice () function, whether the rreturn value that judges PciFindDevice () function is OK, and if so, function interface returns to OK; If above-mentioned judgement occurs, if the process of above-mentioned judgement occurs negating to exit function and return to corresponding fault code.
2. cpci bus digital quantity input function unit drives Programming Methodology under a kind of vxworks operating system according to claim 1, is characterized in that, the specific implementation process of described step 1 is:
Step 1 (1) is obtained the facility information of the digital quantity input functional module based on cpci bus:
After PCI device power, BIOS PCI allocation equipment, the BIOS of target machine lists the interrupt number information of the PCI equipment that finds and Vendor ID, Device ID, device type, distribution when starting;
Initialization function first utilizes function pciFindDevice () to find corresponding equipment according to equipment Vendor ID and Device ID, according to Vendor ID, Device ID and identical device serial number, scan bus, find out BUS No, Device No and the Func No at equipment place; Then according to Bus number, device number and function number, call register base address and the interrupt number that pciConfigInLong () and pciConfigInByte () function are determined equipment; Again base address and I/O mask bit phase with obtain internal register base address on real plate;
The mapping of step 1 (2) device memory
The MMU of the standard that user provides with VxWorks distributes the memory headroom of PCI equipment; After clear and definite base address and memory headroom size, call function sysMmuMapAdd () function is configured to MMU by memory headroom; Complete after the device memory mapping of digital quantity input functional module, by the access to device memory, realize the control to equipment;
Step 1 (3) Break Link
In vxworks operating system, use intConnect () link interruption service routine, adopt pciIntConncet () to articulate interruption, pciIntConncet () is defined in pciIntLib.c, during use, comprise header file pciIntLib.h, interrupt vector ventor is by the INUM_TO_IVEC acquisition that converts;
After using pciIntConnect () function that interruption and specific c program are coupled together under VxWorks system, described function is associated the C function of appointment with the interrupt vector of appointment, the address of function will be stored in described interrupt vector, when an interrupt occurs, system will be called described specific c program function, i.e. interrupt service routine.
CN201410024766.3A 2014-01-07 2014-01-07 Method for designing digital quantity input functional unit driving program of CPCI (compact peripheral component interface) bus under VxWorks operating system Pending CN103713908A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410024766.3A CN103713908A (en) 2014-01-07 2014-01-07 Method for designing digital quantity input functional unit driving program of CPCI (compact peripheral component interface) bus under VxWorks operating system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410024766.3A CN103713908A (en) 2014-01-07 2014-01-07 Method for designing digital quantity input functional unit driving program of CPCI (compact peripheral component interface) bus under VxWorks operating system

Publications (1)

Publication Number Publication Date
CN103713908A true CN103713908A (en) 2014-04-09

Family

ID=50406915

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410024766.3A Pending CN103713908A (en) 2014-01-07 2014-01-07 Method for designing digital quantity input functional unit driving program of CPCI (compact peripheral component interface) bus under VxWorks operating system

Country Status (1)

Country Link
CN (1) CN103713908A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109117374A (en) * 2018-08-20 2019-01-01 浪潮电子信息产业股份有限公司 A kind of method and system of automatic acquisition failure
CN111124842A (en) * 2019-12-10 2020-05-08 山东超越数控电子股份有限公司 Method for displaying equipment information on domestic firmware interface
CN112231003A (en) * 2020-10-15 2021-01-15 天津津航计算技术研究所 CAN equipment management method under VxWorks system

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109117374A (en) * 2018-08-20 2019-01-01 浪潮电子信息产业股份有限公司 A kind of method and system of automatic acquisition failure
CN109117374B (en) * 2018-08-20 2021-10-22 浪潮电子信息产业股份有限公司 A method and system for automatically acquiring faults
CN111124842A (en) * 2019-12-10 2020-05-08 山东超越数控电子股份有限公司 Method for displaying equipment information on domestic firmware interface
CN112231003A (en) * 2020-10-15 2021-01-15 天津津航计算技术研究所 CAN equipment management method under VxWorks system

Similar Documents

Publication Publication Date Title
CN108415717B (en) ZYNQ SOC firmware upgrading method and upgrading device
CN113076227B (en) MCU verification method, system and terminal device
US6658633B2 (en) Automated system-on-chip integrated circuit design verification system
CN103412841B (en) The driver of cpci bus RS422 communication module and driving method under vxworks operating system
CN104268078A (en) Automatic chip validation method based on parameterized IP test case set
CN105353989B (en) Storing data access method and relevant controller, equipment, host and system
CN103049363B (en) Verification method of NAND (neither agree not disagree) Flash controller
CN109656593A (en) The method for realizing FPGA program remote upgrading based on ZYNQ chip
CN106484581B (en) It may be programmed SOC device single-particle inversion detection system and method under space radiation environment
WO2016197711A1 (en) Method and apparatus for configuring register
CN105224345A (en) A kind of programmable logic device (PLD) remote update system and method thereof
CN105930186B (en) The method for loading software of multi -CPU and software loading apparatus based on multi -CPU
CN116681013B (en) Simulation verification method, platform, device, equipment and medium of network chip
CN108664264A (en) A kind of device and method remotely updating FPGA by JTAG modes based on CPU
CN103677855A (en) Design method for driver of CPCI (Compact Peripheral Component Interconnect) bus DAC (digital-to-analog conversion) function unit under VxWorks operating system
CN105956302A (en) Method for automatically generating front-end netlist of configurable anti-radiation chip
CN117278890A (en) Optical module access method, device and system, electronic equipment and readable storage medium
CN116089281A (en) Chip testing method, testing platform and device
CN105511581A (en) Method for controlling battery status based on domestic Fei Teng processor
CN103713908A (en) Method for designing digital quantity input functional unit driving program of CPCI (compact peripheral component interface) bus under VxWorks operating system
US20240319984A1 (en) Ecu upgrade method and device, and readable storage medium
CN118052196A (en) Chip verification test method and device based on UVM and electronic equipment
US11593547B1 (en) Prediction and optimization of multi-kernel circuit design performance using a programmable overlay
CN107908578A (en) The general DMA transfer method driven based on PXIe buses and VISA
CN110109849B (en) CAN equipment driving device and method based on PCI bus

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20140409