piControl is the central system driver of the Revolution Pi system. The driver forms the technical basis for the real-time communication between the Linux operating system on the RevPi base module and the RevPi expansion modules.

Tasks of piControl:

  • Provides the cyclically updated process image

  • Reads the RevPi I/O module values cyclically

  • Transmits the data for the outputs to the RevPi I/O modules

  • Configures the RevPi I/O modules according to the PiCtory configuration file

Process Image #

piControl generates a continuously updated memory image of all I/O data. This image can be read or written by programs such as Node-RED or Python scripts.

piControl provides a device file /dev/piControl0, which applications can use to read and write to the process image.

Configuration File #

piControl reads the configuration of the Revolution Pi system from the configuration file /etc/revpi/config.rsc, which is typically created with PiCtory, and sets up the RevPi devices accordingly.

Resetting the Driver #

The driver can be reset via PiCtory. This re-reads the PiCtory configuration file and all values will be reset to their default values.

▷ Start PiCtory.

▷ Select Tools › Reset Driver.

Alternatively, the driver can be reset using the command line tool piTest:

piTest -x

Cycle Time #

The cycle time defines how often all values are exchanged between the RevPi base module and the I/O modules. By default, a cycle is executed as quickly as possible. The time for a cycle can be adjusted via a kernel module parameter.

  • A longer cycle time reduces the CPU load.

  • A shorter cycle time allows a faster response to input and output values.

The cycle time metrics can be read from files in the directory /sys/class/piControl/piControl0/.

Metric Description

cycle_duration

Cycle time in microseconds (µs). The default 0 runs the cycle as fast as possible, so cycles_missed is not increased. Writing a non-zero value sets a fixed cycle time, clamped to the range 50 to 45 000.

min_cycle

Shortest measured cycle time since the start of piControl. Can be reset by writing a 0.

max_cycle

Longest measured cycle time since the start of piControl. Can be reset by writing a 0.

max_cycle_deviation

Maximum tolerated deviation from the reference cycle time in microseconds. The reference is the fixed cycle_duration if one is set, otherwise the shortest measured cycle. A value of 0 disables the cycles_exceeded count.

cycles_exceeded

Number of cycles that ran longer than the reference cycle time plus max_cycle_deviation. Only counted while max_cycle_deviation is non-zero. Can be reset by writing a 0.

cycles_missed

Number of cycles that were missed due to the cycle time being set too low and the current cycle being too long. Only counted when a fixed cycle_duration is set. Can be reset by writing a 0.

last_cycle

Duration of the last cycle in microseconds (µs).

Reading the Cycle Time #

▷ Log in to the RevPi via a terminal.

▷ Read the cycle time:

cat /sys/class/piControl/piControl0/cycle_duration

❯❯ The default value 0 runs the cycle as fast as possible.

Adjusting Cycle Time (persistent) #

▷ Define a new kernel module parameter to adjust cycle time by creating a file with the file extension .conf under /etc/modprobe.d.

▷ Define a cycle time cycle_duration in microseconds.

▷ Reload the kernel module:

sudo rmmod piControl && sudo modprobe piControl

Removing and reloading the kernel module is only possible if no application is accessing /dev/piControl0, otherwise, the operation fails. In this case, restart the RevPi.

Example: For a cycle time of 20 milliseconds, create a file /etc/modprobe.d/picontrol-cycle-duration.conf with:

options piControl picontrol_cycle_duration=20000

The new kernel module parameter is only read when the module is loaded, so it takes effect after reloading the module or restarting the RevPi. Resetting the driver with piTest -x does not re-read module parameters.

Adjusting Cycle Time (non-persistent) #

Alternatively, the cycle time can be changed during the runtime of the piControl driver via the file cycle_duration.

▷ Set a non-persistent cycle time of e.g. 20 milliseconds with:

echo "20000" | sudo tee /sys/class/piControl/piControl0/cycle_duration

Communication Errors #

The RevPi I/O modules exchange data with the RevPi base module via a serial line. The data is transmitted electrically according to the RS485 standard. The status byte RS485ErrorCnt counts the communication errors on this internal RS485 bus.

Each module in the cyclic RS485 exchange keeps its own error counter. Every cycle the counter is checked against two limits:

  • On reaching RS485ErrorLimit1, a warning is written to kern.log.

  • On reaching RS485ErrorLimit2, the module is taken offline, flagged as absent in the RevPiStatus byte, and an error is written to kern.log. It is brought back online automatically once it responds again.

These limit values are set as defaults and offer a good balance between fault tolerance and system stability for most applications:

  • RS485ErrorLimit1: 10

  • RS485ErrorLimit2: 1000

If one of the limit values is set to 0, the respective check is deactivated.

Disabling piControl #

In special applications, it may be necessary to deactivate piControl.

▷ Log in to the RevPi via a terminal.

▷ Deactivate piControl with:

sudo rmmod piControl

If the command fails because piControl is in use, stop the applications accessing /dev/piControl0 first. Use sudo lsof /dev/piControl0 to find them.

▷ Reactivate piControl with:

sudo modprobe piControl

After rebooting a RevPi, piControl is restarted automatically.

To deactivate piControl permanently, the configuration must be adapted:

▷ Log in to the RevPi via a terminal.

▷ Open the file /etc/modules-load.d/picontrol.conf in an editor.

▷ Comment out the line for piControl with #.

▷ Save and close the file.

Further Resources #