Before making an ioctl() call to a special file (device driver description file in our case), the device must have been opened by the user, using the driver's open() function call which may look like FD=open("/dev/ICV150_0", O_RDWR, 0x666).
Then to make any ioctl() call user has to indicate the file descriptor (int FD) that has been returned by the open() function, a command parameter (unsigned char cmd) and an argument parameter (unsigned short arg[256]). The call then may look like err=ioctl(FD, cmd, arg) where err is an integer returned by the function.
This section explains the specifications of cmd and arg parameters and the returned values of the ioctl() function.
This unsigned char parameter is used to indicate to the driver which action you want to make.
read the value of one of the channels that are being scanned
read the values of all the channels that are being scanned
read the gain of one of the scanned channels
read the gains of all the scanned channels
set the number of channels that are going to be scanned
set the gain of one of the channels that are going to be scanned
set the gains of all of the channels that are going to be scanned
start continuous scanning
start external triggered scanning
stop current scanning
store all the 256 gain values in EEPROM
retrieve all the 256 gain values from EEPROM and start continuous scanning
set the debug level
RD_CHANNEL, RD_ALL_CHANNELS... are unsigned char (u8) values declared on ICV150.h:
/*ICV150.h*/
/*ioctl() cmd constants*/
#define RD_CHANNEL 0x10
#define RD_ALL_CHANNELS 0x11
#define RD_GAIN 0x12
#define RD_ALL_GAINS 0x13
#define SET_NUMBER 0x14
#define SET_GAIN 0x15
#define SET_ALL_GAINS 0x16
#define START 0x17
#define EXT_TRIG 0x18
#define STOP 0x19
#define STORE 0x1A
#define RECALL 0x1B
#define DEBUG 0x1C
This array of 256 unsigned shorts is used to pass input parameters such as channel's number or debug level and to retrieve output values such as acquisition values and gain values.
arg[0] is used to specify the channel's number and to return the acquisition value
arg[0] is used to return the acquisition value of channel 0, arg[1] for channel 1...
arg[0] is used to specify the channel's number and to return the gain value
arg[0] is used to return the gain value of channel 0, arg[1] for channel 1...
arg[0] is used to specify the number of channels to scan
arg[0] is used to specify the channel's number and arg[1] to specify the gain value
arg[0] is used to specify the gain value of channel 0, arg[1] for channel 1...
don't care
don't care
don't care
don't care
don't care
arg[0] is used to specify the debug level
MAX_CHANNELS, DEF_CHANNELS and MAX_GAIN are constants values declared on ICV150.h:
/*ICV150.h*/
#define MAX_CHANNELS 256
#define DEF_CHANNELS 32
#define MAX_GAIN 10
The ioctl() call returns 0 on success and -1 on fail. In case of fail, errno values are standardized by the include file <asm/errno.h> so that you can know what kind of problem has occurred. The following errno constants are used in the ICV150 device driver :
try again (11)
out of memory (12)
bad address (14)
device or resource busy (16)
no such device (19)
invalid argument (22)
If the driver has the required debug level, you can also use the command dmesg to see in details where and why the ioctl() call has failed.