PCI device RTX driver development method

1. When operating peripherals under RTX , you need to move the device from Windows to RTX. For the 

specific migration method, please refer to the section Converting a Windows Device to an RTX Device in the RTX Help document or refer to the attachment <<Serial Port Device Migration Wizard.doc> > 


2. The characteristics of the PCI driver 

Before designing the driver, you must first analyze the hardware device you want to control in detail, and you need to understand the characteristics of the hardware device in detail. The characteristics of the hardware device will have a significant impact on the design of the driver. The main hardware features that need to be understood include: 

(1) The bus structure of the

device What bus structure the  device uses is very important, because different bus types (such as ISA and PCI) are different in many hardware working mechanisms, so the driver design Also different. 

(2) Registers 

should understand the set control registers, data registers and status registers, as well as the characteristics of these registers. 

(3) Device error and status It is 

necessary to understand how to judge the status and error signal of the device, and these signals should be returned to the user through the driver. 

(4) Interrupt behavior 

requires understanding of the conditions under which the device generates interrupts and the number of interrupts used. 

(5) Data transmission mechanism The 

most common data transmission mechanism is through the I/O port (port), which is to read and write data through the CPU. Another important transmission mechanism of the PC is DMA, but the PCI specification does not include the description of subordinate DMA. 

(6) Device memory 

Many devices have their own memory, and most PCI devices are mapped to the physical memory of the PC system by means of mapping. Some devices also need to set the device's interface register through the driver 


3. The overall architecture of the RTX driver 

uses the RTX Device Driver development wizard to select support 

(1) Interrupt Service Routine (ISR) 

(2) Support for Sharing an Interrupt 

(3) Basic Port I/O Support 

(4) Basic Mapped Memory Support, 

namely Can generate RTX PCI device driver framework. 

The program framework is divided into two functions, Driver file and DriverFunc file: 

Driver file mainly includes main function, interrupt service routine and interrupt service thread; 

DriverFunc file is mainly the basic operation function of PCI device, including PCI device search, PCI device initialization, Enable or disable interrupts, handle PCI device sharing interrupts, and PCI driver resource cleaning functions. 

4. The complete RTX PCI driver is 

based on the RTX PCI device driver framework, and the user needs to add the corresponding code. The following analysis is based on the RTX driver of the reflective memory card. 

The basic characteristics of reflective memory card: 

(1) PCI, PCIe, PMC, VME shape, the nodes form a ring connection or through the optical fiber Hub to form a star connection 

(2) The deterministic transmission delay of data between nodes, the delay is less than 750us 

The RTX driver of the PCI reflective memory card is also divided into two files: Driver file and DriverFunc file. Driver file mainly includes main function, interrupt service routine and interrupt service thread. The following is a detailed analysis: 

(1) Main function: 

Main function is not a part of RTX PCI driver, exactly how it uses RTX PCI driver Process. What users need to do: 

a. The main function generated in the RTX PCI device driver framework needs to add the device open (open()) function after the device initialization (DeviceInit()) is completed and before the PCI interrupt is enabled. The function of this function It is mainly to create a semaphore and initialize the board. 

b. After enabling the PCI interrupt, the user can call the read and write functions in the PCI driver to write a simple read and write test program. 

(2) Interrupt service routine: 

After receiving the interrupt, this function is handed over to the interrupt service thread for processing, and the user generally does not need to change it. 

(3) Interrupt service thread: The 

interrupt service thread mainly finishes reading and recording the interrupt information of the PCI board, releasing related semaphores, etc. Generally, it does not complete the specific interrupt processing work. The PCI driver generally provides a function to capture these released semaphores and complete the analysis of the specific meaning of the interrupt. 

The DriverFunc file is mainly for the basic operation functions of PCI devices, including PCI device search, PCI device initialization, enabling or disabling interrupts, handling PCI device sharing interrupts, and PCI driver resource cleaning, data reading and writing, sending and receiving message interrupts And other functions. The following is a detailed analysis: 

(1) DeviceSearch function 

This function searches for PCI devices based on the Vendor ID and Device ID of the PCI device, and returns PCI configuration information and slot Number. The user can modify the Vendor ID and Device ID. 

(2) DeviceInit function 

PCI device initialization function. This function calls two RTX system functions RtTranslateBusAddress() and RtMapMemory(), RtTranslateBusAddress() is used to convert the PCI device address into a physical address that can be directly accessed by the CPU, RtMapMemory() The function maps physical addresses to virtual addresses. After mapping to the virtual address space, ring3 users can read and write PCI memory space or I/O space. What users need to pay attention to is the address range from physical address to virtual address mapping, which is generally set to 4K Bytes. By default, the maximum address range that can be mapped by the RtMapMemory() function is 64M Bytes. If you need a larger range, you can refer to the section on memory management. 

(3) The Enable/Disable Interrupts On Chip function 

enables or disables interrupts on PCI devices. The user makes modifications according to the PCI device. 

(4) IsMyInterrupt function 

RTX PCI device interrupt number can be shared. If there is PCI device sharing under RTX, you need to distinguish whether it is the interrupt of the device in the middle of this function. 

(5) DeviceCleanup function 

This function releases the interrupt handle and releases the mapping between the physical address and the virtual address. The user basically does not need to modify this function. 

(6) RFM2gOpen function 

Reflective memory function. The function of this function is mainly to create semaphore and initialize the board for hardware function modules such as DMA channel, sending and receiving Event (a kind of message interrupt of reflective memory). In order to prevent access conflicts on hardware resources, semaphores must be obtained before using these hardware resources, and these semaphores must be released after use. 

(7) The RFM2gEnableEvent function 

reflects the memory function function. Enable the board to receive message interrupts. 

(8) The RFM2gSendEvent function 

reflects the memory function function. Send message interrupts to other nodes. 

(9) RFM2gWaitForEvent function 

reflects memory

Guess you like

Origin blog.51cto.com/15135055/2662573