Download GE863-PRO Linux Software User Guide - Glyn High
Transcript
1vv0300781 Rev. 0 - 04/06/08
fcntl.h
Prototype:
int open(const char *pathname, int flags)
Parameters:
pathname – file name with its own path
flags – an int specifying file opening mode: that can be O_RDONLY, O_WRONLY or O_RDWR
which request opening the file read-only, write-only or read/write, respectively
Returns:
The new file descriptor fildes if operation is completed successfully, otherwise it is -1
Example:
Open the /dev/watchdog.
int fd;
// file descriptor for the /dev/watchdog entry
if((fd = open("/dev/watchdog", O_WRONLY) < 0)
{
/* Error Management Routine */
} else {
/* Watchdog Device Opened */
}
4.5.2 ioctl()
The ioctl() function manipulates the underlying device parameters. In particular, many operating
characteristics can be controlled with ioctl() requests.
Header file:
sys/ioctl.h
linux/watchdog.h
Prototype:
int ioctl(int fildes, int request, ...)
Parameters:
fildes – file descriptor
request – device-dependent request code.
The following ioctls request codes can be used for watchdog device:
WDIOC_KEEPALIVE: to notify the watchdog that userspace is still alive
WDIOC_SETTIMEOUT: to set a timeout
WDIOC_SETOPTIONS: to enable or disable the watchdog
WDIOC_GETTIMEOUT: to query the timeout
The third argument is a void * and depends on the ioctl request code used: see the examples below.
Returns:
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved
page 51 of 59