Summary of the invention
The present invention is in order to address the above problem, and proposes a kind of method of the many serial equipments of driving for vxworks operating system.
The method of a kind of many serial equipments of driving for vxworks operating system proposed by the invention comprises the steps:
Obtain the location, PCI/PCIE MEM space base of many serial equipments;
Many serial equipments of initialization serial ports passage;
Programme and register the installation interrupt service routine driving service routine;
Create serial ports passage character device.
In the present embodiment, get access to the quantity of serial ports passage by the related register information of many serial equipments, perhaps according to circuit design, the actual serial ports passage number that uses arranges.Initialization serial ports channel unit description scheme body array comprises register plot, baud rate, clock frequency, interrupt mode.When interrupt request takes place, according to the processing that interrupt type carries out, comprise receiving data, transmission data, removing mistake etc.The data member of the program structure body of assignment comprises: equipment control function, device start transmission data function, call back function are installed function, device polling detects and receives data function, device polling detection transmission data.
The present invention realizes the driving of many serial equipments in vxworks operating system, with the real-time communication (employing interrupt mode) that realizes many serial equipments.The present invention is according to the characteristics of Vxworks Embedded Real-Time platform, according to different chip custom driver, simplify volume by the customization to driver, not only the software volume is less, reduced the spending of system resource, and the expansion by chip functions can realize multiple serial communication technology flexibly, and for example 9bit communication mode, higher-level flow pattern etc. make the vxworks operating system system that better Communications service is provided.
Embodiment
Fig. 1 is the method synoptic diagram of the many serial equipments of driving that are used for vxworks operating system that propose of the present invention.Present embodiment is the driving that realizes many serial equipments in VxWorks 5.5 operating systems, the platform that adopts is RMI MIPS framework embedded platform, by the PCIE x1 bus expansion chip of serial port chip OXPCIe958 more than two (master slave mode), with reference to figure 2, wherein main OXPCIe958 chip is connected with processor by the PCIe port, be connected with main OXPCIe958 chip from the OXPCIe958 chip, because the OXPCIe958 chip has 8 serial ports passages, so the principal and subordinate OXPCIe958 chip of this embodiment can be realized maximum 16 serial ports passages.
Among this embodiment, the method that the present invention proposes mainly comprises four steps:
Steps A. the OXPCIe958 chip that adopts because of the present invention adopts PCIE interface, the location, PCIE MEM space base that need obtain principal and subordinate OXPCIe958 chip earlier;
The serial ports passage of step B. initialization principal and subordinate OXPCIe958 chip, the serial ports passage initialization function of OXPCIe958 chip is called in configuration driver data structure and initialization;
Step C: programme and register the installation interrupt service routine driving service routine;
Step D: creating serial ports passage character device, because the serial ports passage is an equipment, therefore also is the character device of creating the respective channel number.
Fig. 3 is the concrete steps that steps A is obtained location, PCIE MEM space base:
Steps A 1. is according to many serial equipments of use chip, it is the OXPCIe958 chip, define two grand PCI_VENDOR_ID_OXPCIE958 0x1415 and PCI_DEVICE_ID_OXPCIE958 0xc308, and use these two macro definitions to come producer sign (Vendor ID) and the device identification (Device ID) of initialization apparatus;
Steps A 2. is called the device identification that the pciFindDevice function is sought main OXPCIe958 chip, if do not find then ending step A, if found the device identification of main OXPCIe958 chip, then continues steps A 3;
Steps A 3. gets access to OXPCIe958 device bus number, device number and function number by the pciFindDevice function;
In the present embodiment, the Bus number that obtains is 0, and device number is 0, and function number is 0.This device number is different with device identification, and device identification Device ID is that the equipment that manufacturer arranges when hardware dispatches from the factory indicates, and device number then is the device number of the OXPCIe958 equipment of carry on bus, i.e. which equipment under bus.
Steps A 4. is returned the PCIE device type of OXPCIe958 equipment by the pciConfigInByte function;
Steps A 5. use PciConfigInLong obtain the equipment base address PCI_CFG_BASE_ADDRESS data in the OXPCIe958 equipment PCIE configuration space, it is location, PCIE MEM space base, thereby the register base address that obtains equipment of serial passage 0 is 0xc0001000h, then ending step A.
Fig. 4 is the concrete steps of step B initialization principal and subordinate OXPCIe958 chip:
Step B1. creates the serial ports passage description scheme body OXPCIE958SIO_CHAN of OXPCIe958 equipment;
Step B2. arranges the quantity of serial ports passage, and the value that the serial ports number of channels is set in the present embodiment is 16.Can adopt dual mode can get access to the quantity of serial ports passage, the firstth, the related register 0xc0000004h bit[4:0 in the MEM space by OXPCIe958 equipment] information gets access to the quantity of serial ports passage, the secondth, according to circuit design, the actual serial ports number of channels that uses arranges, the quantity that actual usage quantity may indicate less than the register read value;
It is the OXPCIE958SIO_CHAN array that step B3. creates type according to the quantity of serial ports passage, and the array number of members is corresponding with the serial ports number of channels.In the present embodiment, create the pChan_obj[16 of OXPCIE958SIO_CHAN type] array, and to each parameter initialize, wherein parameter comprises register plot, baud rate, clock frequency, passage mode of operation (interrupting or poll);
Step B4. creates the variable OxPcie958SioDrvFuncs of driver data structure body SIO_DRV_FUNCS type, and its structure member carried out initialization, its structure member comprise facility control program, device start send data, call back function installation procedure, device polling detect receive data program, device polling detects and sends data program.Write corresponding function subfunction at last, comprise that function subfunction OxPcie958SioIoctl is used for the control of serial ports passage; Function subfunction function OxPcie958SioTxStartup is used for enabling to send interrupting, thereby log-on data sends; Function subfunction OxPcie958SioCallbackInstall is used for will receiving, sending character function and is associated with a virtual driving layer call back function, in order to can call to take away the data in the hardware reception formation or data are sent to the hardware transmit queue.Function subfunction OxPcie958SioPollInput, OxPcie958SioPollOutput receives and sends the function that will call for using polling mode to carry out data;
With reference to figure 7, wherein the effect of function subfunction OxPcie958SioIoctl is control serial ports passage, this function call OxPcie958SioBaudSet arranges the baud rate of serial ports passage, call OxPcie958SioModeSet and carry out the setting (comprise and interrupting and poll) of serial ports passage mode of operation, call OxPcie958SioOptsSet and carry out data bit, position of rest, the setting of parity check bit and Flow Control, call OxPcie958SioHup and realize closing the serial ports passage, call OxPcie958SioOpen and realize unlatching to the serial ports passage, call the setting that OxPcie958Sio9BitModeSet realizes special 9bit pattern.All functions all are to realize by serial ports channel hardware register being configured operation.The relevant setting of different hardware is closely not identical.Specifically can provide the programming handbook to write with reference to producer.
Step B5. calls serial ports passage initialization function OxPcie958DevInit (), further improve device description structure member is carried out assignment, comprise the data bit that acquiescence is set, position of rest, parity checking, and the OxPcie958SioDrvFuncs driver structure of finishing among the B4 etc., then that partial sum register is relevant value is written in the hardware register, with reference to figure 6, the device initialize function call two functions help initialization, one is that the OxPcie958SioBaudSet function arranges serial ports passage default baud rate, another is by the OxPcie958SioOptSet function serial ports passage mode of operation to be set, comprise data bit, position of rest, parity check bit and Flow Control arrange etc.Last ending step B.
Fig. 5 is the realization flow figure of step C1 interrupt service routine, and interrupt service routine OxPcie958SioInt is the interrupt bit of each serial ports passage in the poll register successively.
Step C11. reads the interrupt bit of all serial ports passages, and for reading the value of Globe UART IRQ Status register, register address is 0xc0000008h bit[16:0 in OXPCIE958 equipment MEM space].Be saved in then among the temporary variable temp;
Step C12. adopt step-by-step and mode judge whether current serial ports passage interrupts, if interrupt request does not take place, then jump to step C14, if interrupt request takes place, then enter next step;
Step C13. judges this interrupt type, terminal server is made corresponding processing, these are handled all is to the operation of hardware register and call the virtual call back function that drives layer and realize according to the programming handbook of OXPCIE958 chip, comprise the interruption of accepting data, transmission data, handling wrong generation, remove interruption etc.;
Step C14. judges whether that the serial ports passage needs to detect in addition, and namely whether Temp is more than or equal to 1, if then representative also has the serial ports passage to need detection, then repeating step C12 to C14; Then handle the interruption of all serial ports passages if not, then continued next step;
Step C15. notice CPU also withdraws from interrupt service routine.
Step C2 registers interrupt service routine, and the registration interrupt service routine can carry out related with interrupt service routine the unusual entry address of interrupt vector.CPU jumped to unusual entry address according to interrupt vector after central broken hair was given birth to, and interrupted accordingly handling according to the interrupt service routine of registering in the entry address.
At last, step D, the user is convenient to conduct interviews and operates the serial ports passage in order to make, and the serial ports passage is created as corresponding serial ports passage name (also being the character device name), on the upper strata serial ports passage is operated exactly character device is operated.The method for packing of character device is at first setting up the character device name successively according to serial ports port number, serial ports channel number, call the sysSerialChanGet function according to the serial ports channel number and obtain this serial ports channel unit description scheme body, use ttyDevCreate to carry out related with relevant device description scheme body serial ports passage name then, and create virtual driving layer buffer circle, finish the establishment of character device.
IO system and multi-serial-port card driver method of calling are: when sending data, system uses Write () function to send to the output buffer circle, the virtual driving layer ttyDrv/tylib that the meeting calling system provides in this process down sends, and finally calls the transmission of bottom layer driving power function log-on data.When hardware queue is sent completely, can produce the interrupt call interrupt service routine and handle, if the buffer data sky, then close to send and interrupt, and finish to send, if buffer data exists, then call call back function and send a given data and send to the hardware transmit queue.When data receive, system produces interrupts, received data by which passage of interrupt service routine poll, and by call back function hardware received queuing data and be pushed to the ttyDrv/tyLib layer and put into buffer circle, the user finally by read () function with data read.
The present invention is simple and easy to realize for the driving that realizes many serial ports in the Vxworks system provides a kind of method, and can make the driver can flexible customization.
Only in order to illustrate structure of the present invention, those of ordinary skill in the art can make various deformation and variation to above specific embodiment under design of the present invention, and these distortion and variation include within protection scope of the present invention.