Replacement for ioctl () function

I am developing a driver driver input / output model for small microcontroller applications using POSIX as a guideline for interface design. I implemented ioctl() as a means of controlling driver / hardware parameters, such as UART baud rate, I2C slave address, etc.

I notice that POSIX: 2008 lists ioctl() and <stropts.h> as deprecated. What is the recommended alternative mechanism for communicating with a device driver?

+6
source share
1 answer

POSIX defines only a very limited subset of the ioctl() functionality associated with STREAMS. Because the STREAMS tool is deprecated, the interface to it is also deprecated on POSIX.

However, ioctl() been part of Unix since then "forever" (it was, of course, in the 7th release of UNIX, and I am confident that it was not new even then). This is the “way” to manage device drivers after they open. The only problem is that such interfaces and controls are not standardized.

You can see the <termios.h> files for a set of functions written for control terminals. I expect a typical implementation to use ioctl() or other similar specialized mechanisms, but the interface was made common when it was standardized (the <termios.h> interface is not identical to any earlier interface, either the 7th edition, or System III or any other interface). If you wanted to, you could write standard functions on top of your ioctl() interface, which your users will use; you must implement these functions to call your ioctl() interface.

So ioctl() does not go away; This is the right way to manage device drivers. POSIX has a slightly different agenda, that's all.

+8
source

Source: https://habr.com/ru/post/896560/


All Articles