tree: f72fb307c3a51f2685c586fbbfc1328dcd0d0079 [path history] [tgz]

GPIO testport for use with Titan test executor on Raspberry Pi

General introduction

Titan is a TTCN-3 compiler and test executor, which is able to run on the Raspberry Pi (model 2B and 3B were tested). GPIO (general purpose input/output) pins on the Raspberry Pi are able to control and/or receive signals from physical computing devices (leds, buttons, valves, etc...). Testports are programmable connections between Titan and any physical interface on a device, in this case GPIO pins on the Raspberry Pi.

The current implementation is using the sysfs interface to access GPIO pins.



  • In Your TTCN-3 module the GPIOPinPort module must be included:

    import from GPIOPinPort all;

  • Create a component in the module: ** Important: the name of the port instance MUST be either gpio# or in case of port arrays gpio[#], where # is an integer between (and including) 2 and 27, which will be the actual pin number of the GPIO!

    type component GPIO { port GPIO_Pin_Port gpio27; port GPIO_Pin_Port gpio[2..26]; timer t_short; }

  • Map any or all the ports You want to use:

    map(self:gpio[11], system:gpio[11]); map(self:gpio27, system:gpio27); map(self:gpio[26], system:gpio[26]);

Setting a pin to output, and setting the value of the pin

  • To set direction on the gpio pin to OUT a “send” operation is to be performed:

    var GPIO_PIN_DIRECTION gpio27_direction := OUT; gpio27.send(gpio27_direction);

  • Similarly, to set the value (HIGH/LOW) a “send” operation is to be performed:

    var GPIO_PIN_VALUE gpio27_value := HIGH; gpio27.send(gpio27_value);

Listening for input changes on pin(s)

var integer v_index;

var GPIO_PIN_DIRECTION gpio_direction_in := IN;

alt {
    [] gpio27.receive {
       setverdict(pass,"message received on port index 27");
    [] any from gpio.receive -> @index value v_index {
       setverdict(fail,"unexpected message received on port index: ",v_index);
    [] t_short.timeout {
       log("Timeout while waiting for input to change");

Unmap all the used ports

unmap(self:gpio27, system:gpio27);
unmap(self:gpio[11], system:gpio[11]);
unmap(self:gpio[26], system:gpio[26]);