User manual
6 OnRISC Hardware API
• GPIO_CMD_GET_CTRL/GPIO_CMD_SET_CTRL - set/get data direction register value
• GPIO_CMD_GET_IRQMASK/GPIO_CMD_SET_IRQMASK - set/get interrupt mask register value
• GPIO_CMD_GET_CHANGE - get status register value
• GPIO_CMD_GET_CHANGES - get interrupt count (reflected in /proc/vscom/gpio_changes)
The digital I/O driver also supports select() and poll() calls. To use this functionality the
interrupt must be enabled for the desired pins.
To change the register values special structure and macros will be used (see the Listing below).
#de fine GPIO_BIT_0 0 x01 // DIO0 or o p t i c a l l y i s o l a t e d i npu t
#de fine GPIO_BIT_1 0 x02 // DIO1 or o p t i c a l l y i s o l a t e d i npu t
#de fine GPIO_BIT_2 0 x04 // DIO2
#de fine GPIO_BIT_3 0 x08 // DIO3
#de fine GPIO_BIT_4 0 x10 // DIO4
#de fine GPIO_BIT_5 0 x20 // DIO5
#de fine GPIO_BIT_6 0 x40 // DIO6 or r e l a y
#de fine GPIO_BIT_7 0 x80 // DIO7 or r e l a y
struct g pi o _s t ru c t
{
unsigned long mask ; // b i t s to modify
unsigned long va lue ; // v a l u e t o s e t
} ;
Listing 4: GPIO struct
The following Listing shows how to change pins DIO0 and DIO2 to output and then read the
control register back. To change the register direction struct gpio_struct is used because you
need to specify what bits are going to changed and to what values (Lines 5-6). To read the register
you only need to give unsigned long variable to the IOCTL command (Line 9).
1 . . .
2 struct g pi o _s t ruc t gp io _val ;
3 unsigned long v a l ;
4
5 gp io_va l . mask = (GPIO_BIT_0 | GPIO_BIT_2) ;
6 gp io_va l . v al ue = (GPIO_BIT_0 | GPIO_BIT_2 ) ;
7
8 i o c t l ( fd , GPIO_CMD_SET_CTRL, &g pio_ val ) ;
9 i o c t l ( fd , GPIO_CMD_GET_CTRL, &val ) ;
10 . . .
Listing 5: GPIO usage Example
6.1.2. Alekto2
Digital I/O in Alekto2 is made via TCA6416A I2C I/O expander. 8 I/O pins are divided in 3 groups
(refer to Table 4). The direction (input/output) can be configured only for the whole group, i.e. if
you set pin 0 from Group 0 to output, then pins 1-3 are also set to output.
You can set/get I/O status via onrisctool.py (refer to Section B.4)
May 2014 OnRISC User Manual 40