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.