CN112286858A - Linux system I2C driver method based on signal - Google Patents

Linux system I2C driver method based on signal Download PDF

Info

Publication number
CN112286858A
CN112286858A CN202011195845.2A CN202011195845A CN112286858A CN 112286858 A CN112286858 A CN 112286858A CN 202011195845 A CN202011195845 A CN 202011195845A CN 112286858 A CN112286858 A CN 112286858A
Authority
CN
China
Prior art keywords
signal
file
function
driver
unit
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
CN202011195845.2A
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.)
Shandong Zhonghai Intelligent Technology Co ltd
Original Assignee
Shandong Zhonghai Intelligent Technology Co ltd
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 Shandong Zhonghai Intelligent Technology Co ltd filed Critical Shandong Zhonghai Intelligent Technology Co ltd
Priority to CN202011195845.2A priority Critical patent/CN112286858A/en
Publication of CN112286858A publication Critical patent/CN112286858A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/42Bus transfer protocol, e.g. handshake; Synchronisation
    • G06F13/4282Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention belongs to the technical field of embedded drivers, and relates to a signal-based linux system I2C driver method, which comprises an asynchronous notification mechanism for preparing a start-up file, an asynchronous notification interface unit for designing a driver, a signal installation unit and a function test unit for designing the driver; the invention applies a signal mechanism to the driving program and informs the user program to read data.

Description

Linux system I2C driver method based on signal
Technical Field
The invention belongs to the technical field of embedded driving, and particularly relates to a signal-based Linux system I2C driver method.
Background
With the rapid development of electronic technology, embedded systems based on microprocessors have rapidly become widespread. The embedded system has two working modes, the first one is based on a single chip microcomputer, the hardware resource of the system is limited, the software is simple, and the system does not contain an operating system; the second one can run an operating system, and greatly utilizes rich resources of a PC, and in an embedded operating system, Linux is an open source code, is developed most rapidly and is applied most widely. The I2C bus transfers information between devices connected to the bus through a serial data line (SDA) and a Serial Clock Line (SCL), each device is identified according to an address, the I2C has two working modes, namely a master-sending master-receiving mode and a slave-sending slave-receiving mode, the slave-receiving slave-sending mode is master-sending of slave equipment, and the return time of the equipment is uncertain, so that an interrupt mode is adopted. The Linux driver only realizes the functions of main transmission, main transmission and main reception and only realizes half of I2C.
In the I2C bus driving process, Linux needs a user to actively operate a device file, and a user program cannot predict the arrival time of device data, so that the software running efficiency is reduced, the real-time performance is poor, meanwhile, a hardware interrupt mechanism cannot be well utilized to process an emergency, and only a function is utilized to periodically query whether a device is readable, so that the efficiency is not high. This is a drawback in the prior art.
In view of the above, it is desirable to provide a signal-based Linux system I2C driver method to solve the problems in the prior art.
Disclosure of Invention
The invention aims to provide a method for designing a signal-based Linux system I2C driver, aiming at the defects of low efficiency and poor real-time performance of timing query of device data based on a query mode in a Linux system I2C driver in the prior art, and solving the technical problem by applying a signal mechanism to the driver and informing a user program of reading data.
In order to achieve the purpose, the invention provides the following technical scheme: a signal-based linux system I2C driver method, comprising the steps of:
s1: preparing an asynchronous notification mechanism for an enabled file;
s2: designing a driven asynchronous notification interface unit;
s3: designing a signal installation unit;
s4: and designing a functional test unit of the driver.
Preferably, in step S1: the asynchronous notification mechanism for preparing the enabled file modifies a standard I2C driver under a Linux system, and comprises the steps of adding macro definition USE _ ASYNC in an I2c _ adapter data structure in an I2c.h file, and realizing the definition of variables I2c _ event and queue; adding macro definition USE _ ASYNC in an i2c _ dev _ fos data structure in an i2c _ dev.c file to realize fasync, i2cdev _ fasync and newly adding a static function i2cdev _ fasync;
the i2c _ xxx module sending the SIGIO signal includes that the i2c _ xxx _ add _ bus function under the i2c _ algo _ xxx module increases by i2c _ xxx _ ap ═ adap; in the interrupt function iic _ xxx _ handle of the i2c _ xxx module, the following statement is added before the data processing is finished and ready to return,
#ifdef USE_ASYNC
if(i2c_xxx_ap->i2c_event)
kill_fasync(&(i2c_xxx_ap->i2c_event),SIGIO,POLL_IN)。
preferably, in step S2: the design uses a driven asynchronous notification interface unit, an interface method corresponding to the fcntl system call of the user program is set, and when the process uses the fcntl system call to execute the F _ SETOWN command, the process ID number of the owner process is stored in file- > F _ winner; setting a FASYNC mark in the equipment after the fcntl command F _ SETFL is completed, wherein the equipment can request to send a SIGIO signal when new data arrives, and the SIGIO signal is stored in a process in file- > F _ inner;
setting a semaphore host, taking a file descriptor and adding an asynchronous reading mark in a user program; the user program is conditioned for using an asynchronous notification interface.
Preferably, in step S3: the signal installation unit initializes semaphore, installs signal function by using sign (), supports signal transmission information and can transmit file handle.
Preferably, the sigaction () function sets three parameters, the first parameter is the value of the signal, the second parameter is a pointer pointing to the sigainfo _ t structure, and the parameters include the processing of the specified signal, the information of signal transmission, and which functions should be masked during the execution of the signal processing function; the object pointed by the third parameter oldact is used for saving the original processing of the corresponding signal; setting a SA _ SIGINFO flag bit in the structure action to indicate that parameters attached to a signal can be transmitted to a signal processing function, wherein the flag bit SA _ SIGINFO is regarded as a switch for judging whether the signal transmits the parameters or not; the processing function is specified by sa _ gesture in the gesture structure, which specifies which signals should be blocked during execution of the signal processing routine.
Preferably, in step S4, the functional test unit of the driver is configured with two I2C devices fd, fd1 to test the application of signals in the driver; the function test unit comprises a main i2c file initialization unit; i2c-bit file initialization unit; an initialization unit of the signal; setting a signal function unit; the main function compiling unit is used for ensuring that the driving program of the Linux system I2C based on the signal runs normally;
the main I2c file initialization unit comprises setting I2C bus controller clock frequency; setting a master sending and receiving and a slave sending and receiving, and setting a seven-bit address; the i2c-bit file initialization unit sets a seven-bit address;
the initialization unit of the signal comprises a signal function setting unit, a semaphore host, a file descriptor fetching unit, an asynchronous reading mark adding unit, an asynchronous reading semaphore setting unit and a keyboard reset unit;
the signal setting function unit comprises the steps of acquiring an SIGIO signal, transmitting a main i2c file handle and transmitting an i2c-bit file handle;
and the main function writing unit judges the states of fd and fd1 and executes corresponding operation.
Preferably, i2c _ init () defines a structure sign variable, and sets the signal processing function name myread:
action.sa_sigaction=myread;
and (3) transmitting additional information:
action.sa_flags=SA_SIGINFO;
sigaction () function install signal:
sigaction(SIGIO,&action,NULL);
the myread code is as follows:
Figure BDA0002753983110000041
Figure BDA0002753983110000051
firstly, judging whether the signal type is SIGIO through a sign, then transmitting a file descriptor through a si _ fd member of a siginfo _ t structure, automatically distributing by a system when a device is opened by an open method, and finally entering a processing module, wherein i2c _ readevent (), i2c _ readkb () are respectively processed, and codes are as follows:
Figure BDA0002753983110000052
Figure BDA0002753983110000061
thus, the I2C bus driver is signal processed to meet the requirement of real-time interrupt basically.
The invention has the advantages that the I2C driver based on asynchronous notification well utilizes a hardware interrupt mechanism to process emergency events, the main transmission and the main reception of the I2c bus are set without interruption, and the auxiliary transmission and the auxiliary reception of the I2c bus are completely carried out in the interruption as long as the simple return is carried out, so that the real-time processing of the interruption is realized, meanwhile, a plurality of drivers work in an asynchronous notification mode without mutual interference, the data processing efficiency is improved, and the invention has more advantages when the data volume is large; the Linux system I2C driving program based on the signal has novel thought, so that the user program calling method in the Linux system is simpler and more practical than the traditional method, and the programming efficiency is improved; the method can be popularized to the compiling of other driving programs, the Linux code is optimized, and the efficiency is improved. In addition, the invention has reliable design principle, simple structure and very wide application prospect.
Therefore, compared with the prior art, the invention has substantial characteristics and remarkable progress, and the beneficial effects of the implementation are also obvious.
Drawings
FIG. 1 is a flowchart of a signal-based Linux system I2C driver method.
FIG. 2 is a schematic diagram of a hierarchy of I2C drivers of the Linux system.
Detailed Description
The present invention will be described in detail below with reference to the accompanying drawings by way of specific examples, which are illustrative of the present invention and are not limited to the following embodiments.
As shown in FIG. 1, the present invention provides a signal-based Linux system I2C driver method, comprising the steps of:
a signal-based linux system I2C driver method, comprising the steps of:
s1: preparing an asynchronous notification mechanism for an enabled file;
s2: designing a driven asynchronous notification interface unit;
s3: designing a signal installation unit;
s4: and designing a functional test unit of the driver.
In this embodiment, the samsung ARM9 processor 2410 is taken as an example:
in the step S1: the asynchronous notification mechanism for preparing the enabled file modifies a standard I2C driver under a Linux system, and comprises the steps of adding macro definition USE _ ASYNC in an I2c _ adapter data structure in an I2c.h file, and realizing the definition of variables I2c _ event and queue; adding macro definition USE _ ASYNC in an i2c _ dev _ fos data structure in an i2c _ dev.c file to realize fasync, i2cdev _ fasync and newly adding a static function i2cdev _ fasync;
the i2c _ s3c2410 module sending the SIGIO signal includes the i2c _ s3c2410_ add _ bus function under the i2c _ algo _ s3c2410 module increasing i2c _ s3c2410_ ap to adap; in the interrupt function iic _ s3c2410_ handler of the i2c _ s3c2410 module, the following statement is added before the data processing is finished and ready to return,
#ifdef USE_ASYNC
if(i2c_s3c2410_ap->i2c_event)
kill_fasync(&(i2c_s3c2410_ap->i2c_event),SIGIO,POLL_IN)。
in the step S2: the design uses a driven asynchronous notification interface unit, an interface method corresponding to the fcntl system call of the user program is set, and when the process uses the fcntl system call to execute the F _ SETOWN command, the process ID number of the owner process is stored in file- > F _ winner; setting a FASYNC mark in the equipment after the fcntl command F _ SETFL is completed, wherein the equipment can request to send a SIGIO signal when new data arrives, and the SIGIO signal is stored in a process in file- > F _ inner; setting a semaphore host, taking a file descriptor and adding an asynchronous reading mark in a user program; the user program is conditioned for using an asynchronous notification interface.
In the step S3: the signal installation unit initializes semaphore, installs signal function by using sign (), supports signal transmission information and can transmit file handle. The sigaction () function sets three parameters, the first parameter is the value of the signal, the second parameter is a pointer pointing to the sigainfo _ t structure, and the functions which should be shielded in the execution process of the information signal processing function of the designated signal processing and signal transmission are included; the object pointed by the third parameter oldact is used for saving the original processing of the corresponding signal; setting a SA _ SIGINFO flag bit in the structure action to indicate that parameters attached to a signal can be transmitted to a signal processing function, wherein the flag bit SA _ SIGINFO is regarded as a switch for judging whether the signal transmits the parameters or not; the processing function is specified by sa _ gesture in the gesture structure, which specifies which signals should be blocked during execution of the signal processing routine.
In step S4, the functional test unit of the driver is configured with two I2C devices fd, fd1 to test the application of signals in the driver; the function test unit comprises a main i2c file initialization unit; i2c-bit file initialization unit; an initialization unit of the signal; setting a signal function unit; the main function compiling unit is used for ensuring that the driving program of the Linux system I2C based on the signal runs normally;
the main I2c file initialization unit comprises setting I2C bus controller clock frequency; setting a master sending and receiving and a slave sending and receiving, and setting a seven-bit address; the i2c-bit file initialization unit sets a seven-bit address; the initialization unit of the signal comprises a signal function setting unit, a semaphore host, a file descriptor fetching unit, an asynchronous reading mark adding unit, an asynchronous reading semaphore setting unit and a keyboard reset unit; the signal setting function unit comprises the steps of acquiring an SIGIO signal, transmitting a main i2c file handle and transmitting an i2c-bit file handle; and the main function writing unit judges the states of fd and fd1 and executes corresponding operation.
A structure sign variable is defined at i2c _ init (), the signal processing function name myread is set:
action.sa_sigaction=myread;
and (3) transmitting additional information:
action.sa_flags=SA_SIGINFO;
sigaction () function install signal:
sigaction(SIGIO,&action,NULL);
the myread code is as follows:
Figure BDA0002753983110000101
firstly, judging whether the signal type is SIGIO through a sign, then transmitting a file descriptor through a si _ fd member of a siginfo _ t structure, automatically distributing by a system when a device is opened by an open method, and finally entering a processing module, wherein i2c _ readevent (), i2c _ readkb () are respectively processed, and codes are as follows:
Figure BDA0002753983110000102
Figure BDA0002753983110000111
thus, the I2C bus driver is signal processed to meet the requirement of real-time interrupt basically.
The above disclosure is only for the preferred embodiments of the invention, but the invention is not limited thereto, and any non-inventive changes that can be made by those skilled in the art and several modifications and amendments made without departing from the principle of the invention shall fall within the protection scope of the invention.

Claims (9)

1. A signal-based linux system I2C driver method, comprising the steps of:
s1: preparing an asynchronous notification mechanism for an enabled file;
s2: designing a driven asynchronous notification interface unit;
s3: designing a signal installation unit;
s4: and designing a functional test unit of the driver.
2. The signal-based linux system I2C driver method of claim 1, wherein: the asynchronous notification mechanism for preparing the enabled file modifies a standard I2C driver under a Linux system, and comprises the steps of adding macro definition USE _ ASYNC in an I2c _ adapter data structure in an I2c.h file, and realizing the definition of variables I2c _ event and queue; adding macro definition USE _ ASYNC in an i2c _ dev _ fos data structure in an i2c _ dev.c file to realize fasync, i2cdev _ fasync and newly adding a static function i2cdev _ fasync;
the i2c _ xxx module sending the SIGIO signal includes that the i2c _ xxx _ add _ bus function under the i2c _ algo _ xxx module increases by i2c _ xxx _ ap ═ adap; in the interrupt function iic _ xxx _ handle of the i2c _ xxx module, the following statement is added before the data processing is finished and ready to return,
#ifdef USE_ASYNC
if(i2c_xxx_ap->i2c_event)
kill_fasync(&(i2c_xxx_ap->i2c_event),SIGIO,POLL_IN)。
3. the signal-based linux system I2C driver method of claim 2, wherein: the design uses a driven asynchronous notification interface unit, an interface method corresponding to the fcntl system call of the user program is set, and when the process uses the fcntl system call to execute the F _ SETOWN command, the process ID number of the owner process is stored in file- > F _ winner; the FASYNC flag is set in the device by the fcntl command F _ SETFL; setting a semaphore host, taking a file descriptor and adding an asynchronous reading mark in a user program; the user program is conditioned for using an asynchronous notification interface.
4. One of the claims 3, characterized in that: the signal installation unit comprises the initialization of semaphore and the installation of a signal function by using sigaction ().
5. The signal-based linux system I2C driver method of claim 4, wherein: the command () function sets three parameters, sets SA _ SIGINFO flag bit in the structure command, specifies the processing function by SA _ command in the command structure, and specifies which signals should be blocked during the execution of the signal processing program by SA _ mask of the structure command.
6. The signal-based linux system I2C driver method of claim 5, wherein: the function test unit of the driver is provided with two I2C devices fd and fd1 to test the application of signals in the driver; the function test unit comprises a main i2c file initialization unit, an i2c-bit file initialization unit, a signal setting function unit and a main function writing unit.
7. The signal-based linux system I2C driver method of claim 6, wherein: the main I2c file initialization unit comprises setting I2C bus controller clock frequency; setting a master sending and receiving and a slave sending and receiving, and setting a seven-bit address; the i2c-bit file initialization unit sets seven-bit address.
8. The signal-based linux system I2C driver method of claim 6, wherein: the initialization unit of the signal comprises the steps of setting a signal function, setting transmission additional information, setting a semaphore and a semaphore host, taking a file descriptor, adding an asynchronous reading mark, setting an asynchronous reading semaphore and resetting a keyboard.
9. The signal-based linux system I2C driver method of claim 6, wherein: the signal setting function unit comprises the steps of acquiring an SIGIO signal, transmitting a main i2c file handle and transmitting an i2c-bit file handle; the main function writing unit judges the states of fd and fd1 for fd and fd1 devices and executes corresponding operations.
CN202011195845.2A 2020-10-30 2020-10-30 Linux system I2C driver method based on signal Pending CN112286858A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011195845.2A CN112286858A (en) 2020-10-30 2020-10-30 Linux system I2C driver method based on signal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011195845.2A CN112286858A (en) 2020-10-30 2020-10-30 Linux system I2C driver method based on signal

Publications (1)

Publication Number Publication Date
CN112286858A true CN112286858A (en) 2021-01-29

Family

ID=74352995

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011195845.2A Pending CN112286858A (en) 2020-10-30 2020-10-30 Linux system I2C driver method based on signal

Country Status (1)

Country Link
CN (1) CN112286858A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030145127A1 (en) * 2002-01-03 2003-07-31 Unice W. Kyle Method and computer program product for providing a device driver
CN101071387A (en) * 2006-09-08 2007-11-14 华南理工大学 Driving program reinforcing method based on virtual server
CN102117223A (en) * 2011-02-22 2011-07-06 哈尔滨工业大学 Method for realizing interrupt response of application program of LXI loading board to M module by utilizing asynchronous notification
US20170223712A1 (en) * 2014-06-05 2017-08-03 Ocado Innovation Limited Systems and methods for communication
CN107992407A (en) * 2017-11-15 2018-05-04 烽火通信科技股份有限公司 System and method using USB flash disk to android terminal equipment debugging
CN108847997A (en) * 2018-04-03 2018-11-20 郑州云海信息技术有限公司 A kind of method and device thereof communicated by api interface
CN110561911A (en) * 2019-09-05 2019-12-13 福州三龙喷码科技有限公司 High-resolution ink jet printer system based on embedded Linux

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030145127A1 (en) * 2002-01-03 2003-07-31 Unice W. Kyle Method and computer program product for providing a device driver
CN101071387A (en) * 2006-09-08 2007-11-14 华南理工大学 Driving program reinforcing method based on virtual server
CN102117223A (en) * 2011-02-22 2011-07-06 哈尔滨工业大学 Method for realizing interrupt response of application program of LXI loading board to M module by utilizing asynchronous notification
US20170223712A1 (en) * 2014-06-05 2017-08-03 Ocado Innovation Limited Systems and methods for communication
CN107992407A (en) * 2017-11-15 2018-05-04 烽火通信科技股份有限公司 System and method using USB flash disk to android terminal equipment debugging
CN108847997A (en) * 2018-04-03 2018-11-20 郑州云海信息技术有限公司 A kind of method and device thereof communicated by api interface
CN110561911A (en) * 2019-09-05 2019-12-13 福州三龙喷码科技有限公司 High-resolution ink jet printer system based on embedded Linux

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
刘新: ""信号量在LINUX系统I2C驱动程序的应用"", 《中国新通信》 *
森林图书工作室, 北京航空航天大学出版社 *
谢川 等: "《嵌入式Linux开发基础》", 31 August 2011, 中国铁道出版社 *

Similar Documents

Publication Publication Date Title
CN106371847B (en) CPCI bus RS422 communication driving method and system under Windows xp system
CN103942178A (en) Communication method between real-time operating system and non-real-time operating system on multi-core processor
US5937200A (en) Using firmware to enhance the functionality of a controller
CN103559045A (en) Hardware real-time operation system
CN103593189A (en) Method for implementing user mode drive program in embedded Linux
US11341087B2 (en) Single-chip multi-processor communication
US20220283928A1 (en) Kernel debugging system and method
CN101593164A (en) Based on built-in Linux from USB HID device and firmware implementation method
CN103309830A (en) Driver of CPCI bus CAN communicating module under VxWorks operating system and driving method
CN103795814A (en) Short message equipment universal communication interface based on fully domestic CPU and OS
CN111737180A (en) Serial port driving system based on PCI bus
CN110968352A (en) PCIE equipment resetting system and server system
CN114296808B (en) Pin configuration method and device, electronic equipment and storage medium
CN101763324B (en) Method for realizing equipment simulating and device thereof
WO1998043173A1 (en) Emulation system and information processor
US10176133B2 (en) Smart device with no AP
CN112286858A (en) Linux system I2C driver method based on signal
JP2007516536A (en) Method and apparatus for handling hot key input using interrupt handling visible to the operating system
CN109189705B (en) USB extension method, device, equipment, storage medium and system
CN110262349A (en) A kind of the remote online programmed method and system of C8051F series monolithic
CN106844025B (en) Asynchronous interrupt processing method and interrupt controller
CN110109849B (en) CAN equipment driving device and method based on PCI bus
CN111427813A (en) Inter-core communication method based on serial port, terminal and storage medium
CN112860622B (en) Processing system and system on chip
CN110572387A (en) link layer processing method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20210129