Next Previous Contents

3. Ioctl() calls

3.1 Description

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.

3.2 Command parameter (cmd)

This unsigned char parameter is used to indicate to the driver which action you want to make.

cmd=RD_CHANNEL:

read the value of one of the channels that are being scanned

cmd=RD_ALL_CHANNELS:

read the values of all the channels that are being scanned

cmd=RD_GAIN:

read the gain of one of the scanned channels

cmd=RD_ALL_GAINS:

read the gains of all the scanned channels

cmd=SET_NUMBER:

set the number of channels that are going to be scanned

cmd=SET_GAIN:

set the gain of one of the channels that are going to be scanned

cmd=SET_ALL_GAINS:

set the gains of all of the channels that are going to be scanned

cmd=START:

start continuous scanning

cmd=EXT_TRIG:

start external triggered scanning

cmd=STOP:

stop current scanning

cmd=STORE:

store all the 256 gain values in EEPROM

cmd=RECALL:

retrieve all the 256 gain values from EEPROM and start continuous scanning

cmd=DEBUG:

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

3.3 Argument parameters (arg[256])

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.

RD_CHANNEL:

arg[0] is used to specify the channel's number and to return the acquisition value

RD_ALL_CHANNELS:

arg[0] is used to return the acquisition value of channel 0, arg[1] for channel 1...

RD_GAIN:

arg[0] is used to specify the channel's number and to return the gain value

RD_ALL_GAINS:

arg[0] is used to return the gain value of channel 0, arg[1] for channel 1...

SET_NUMBER:

arg[0] is used to specify the number of channels to scan

SET_GAIN:

arg[0] is used to specify the channel's number and arg[1] to specify the gain value

SET_ALL_GAINS:

arg[0] is used to specify the gain value of channel 0, arg[1] for channel 1...

START:

don't care

EXT_TRIG:

don't care

STOP:

don't care

STORE:

don't care

RECALL:

don't care

DEBUG:

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

3.4 Returned value

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 :

EAGAIN:

try again (11)

ENOMEM:

out of memory (12)

EFAULT:

bad address (14)

EBUSY:

device or resource busy (16)

ENODEV:

no such device (19)

EINVAL:

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.


Next Previous Contents