Call other driver functions in the driver (fastcall)

Source: Internet
Author: User

Call other driver functions in the driver (fastcall)

Author: Lai yuping (auly) aulyp@163.com

 

In embedded systems, some communication ports are public, such as IIC ports and serial ports. Drivers of these ports are usually written by the OEM manufacturer and tested, relatively stable. We do not need to write an IIC driver when developing drivers for other devices that require these communication ports, you only need to call the corresponding ioctrol once to use related operations as you do with your own functions,

Method:

(1) declare a fastcall variable

I2c_fastcall FC; // I2C fastcall driver-to-driver entrypoints

(2) Enable the IIC driver in the drive's xxx_init.

Hi2c = createfile (L "i2c0 :",

Generic_read | generic_write,

File_pai_read | file_pai_write,

Null, open_existing, 0, 0 );

(3) essence:

If (! Deviceiocontrol (hi2c, ioctl_i2c_get_fastcall,

Null, 0,

& FC, sizeof (FC ),

& Bytes, null ))

{

Dwerr = getlasterror ();

Return NULL;

}

After the above actions, the driver can easily use the read, write, and other functions in the IIC driver.

 

(4) For example, IIC read Operations

// Use the driver-to-driver call

Retval = (short INT) FC. i2cread (FC. context,

Slaveaddr, // slaveaddress

(Pi2c_io_desc) lpbuffer)-> wordaddr, // wordaddress

PUC,

(Pi2c_io_desc) lpbuffer)-> count );

FC. i2cread: This is the hw_read function that calls the IIC driver;

Write operations are also used:

Retval = (short INT) FC. i2cwrite (FC. context,

Slaveaddr, // slaveaddress

Wordaddr, // wordaddress

Wribuffer,

1 );

 

Principle: Why can I use the function in the target driver only through deviceiocontrol? The reason is that the IIC Driver provides the ioctl_i2c_get_fastcall interface in i2c_iocontrol. In this interface, the space of the two functions is mapped to the external call:

(Pi2c_fastcall) pbufout)-> i2cread = hw_read;

(Pi2c_fastcall) pbufout)-> i2cwrite = hw_write;

This is exquisite.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.