Ioctl() is a system call to invoke input output controls to a device file. It takes an integer code which signifies the control operation and an argument as pointer to provide inputs for the operation. Same input pointer can be used to get the output from the operation. It returns zero on success and non-zero if some error happened or if this ioctl code is not implemented by kernel/driver.
IOCTL low layer
It passes argument buffer from user mode and jumps to kernel mode using software interrupt. Kernel calls driver ioctl routine. Driver copies argument to kernel buffer. Driver can do register manipulation if needed and copies return buffer to user mode. Driver can return error if ioctl code is not implemented in driver or argument is not in proper format. Kernel returns call and switch context to user mode and control returns back to user code.
PARPORT IOCTL codes
- Data register
- PPRDATA - read 8 bit data register
- PPWDATA - write 8 bit data register
- PPDATADIR mode=0 - Sets data direction bits to write mode
- PPDATADIR mode=FFh/255 - Sets data direction bits to read mode
- Control register
- PPRCONTROL - Reads control register
- PPWCONTROL - Writes to control register
- PPFCONTROL - atomic modify control register(read write at once)
- Status register
- PPRSTATUS - Reads the status register
Source CodeHere is a small example to invoke ioctl to parallel port of PC. We have connected a LED to PIN 1 (strobe) of parallel port (LPT0) with a 1K resistor to ground. We are executing ioctl code PPFCONTROL to parallel port 0 with argument of strobe control bit. First we are giving strobe bit as 1 and then with some delay we are setting 0. This will create a sequence of on and off of the strobe LED.
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average