sysio Driver

 

/dev/sysio is a system I/O driver for managing user and application specific I/O operations. Linux, like Windows and other operating systems, I/O operations can only be done in kernel space, not in user program space. Under uClinux, being lack of MMU, basic I/O functions can be used in user programs, however, it is still not encouraged. Using user space I/O, makes programs not portable to other Linux environments, and will increase the complexities of software maintenance.

 

/dev/sysio is a dummy character device. It has only ioctl() calls, no read / write functions. The constants are defined in app/lib/lib.h

 

// System IO driver IOCTL

#define SYSIO_GET_BTN     0x101

#define SYSIO_SET_WDT     0x102

#define SYSIO_GET_DI       0x103

#define SYSIO_SET_LED     0x104

#define SYSIO_SET_DO      0x105

#define SYSIO_CONFIG_IO    0x106

#define SYSIO_GET_SWINFO  0x107

#define SYSIO_GET_HWINFO  0x108

 

 

Before using the sysio driver, a file handle must be opened:

 

int fd = open("/dev/sysio", O_RDWR);

 

The followings are the definitions of these system calls:

 

SYSIO_GET_BTN Get user button status

 

n = ioctl(fd, SYSIO_GET_BTN,0)

 

returned value 'n'

Bit 0 = debug button

Bit 1 = restore button

 

 

SYSIO_SET_WDT Trigger Watchdog Timer

 

ioctl(fd, SYSIO_SET_WDT, 0)

 

returned value: none

 

Normally, users do not need to call this function. The system service always triggers the watchdog timer every 100 ms.

 

 

SYSIO_GET_DI Get Digital Input

       

input:

Ch - digital input channel

 

n = ioctl(fd, SYSIO_GET_DI,  Ch<<8)

 

returned value 'n'

0 or 1 - digital I/O state

 

SYSIO_SET_LED Set LED Output

       

input:

Ch - Led number

Val - 0 for off, 1 for on

 

ioctl(fd, SYSIO_SET_LED,  (Ch<<8) | Val)

 

returned value: none

 

 

SYSIO_SET_DO Set Digital Output

       

input:

Ch - digital output channel

Val - 0 or 1

 

ioctl(fd, SYSIO_SET_DO,  (Ch<<8) | Val)

 

returned value: none

 

SYSIO_CONFIG_IO Configure I/O Port

       

input:

Ch - digital I/O channel

Val - 0 for input mode, 1 for output mode

 

ioctl(fd, SYSIO_CONFIG_IO,  (Ch<<8) | Val)

 

returned value: none

 

 

SYSIO_GET_SWINFO Get Software Information      

 

input: Tag

0 - product serial number

1 - hardware ID

2 - hardware type

3 - company ID (for OEM customer)

4 - ports

 

n = ioctl(fd, SYSIO_GET_SWINFO, Tag)

 

returned value 'n'

depends on input Tag

 

These information provide basic software protection mechanism of user's applications. By validating the contents of hardware ID, type and company ID, custom software can work only on a particular hardware.

 

 

SYSIO_GET_HWINFO Get Hardware Information    

input: Tag

0 - ROM size in bytes

1 - RAM size in bytes

2 - romfs image start offset

3 - linux image start offset

 

n = ioctl(fd, SYSIO_GET_HWINFO, Tag)

 

returned value 'n'

depends on input Tag