libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
performance.bas File Reference

Example: test execution speed of several methods to toggle a GPIO pin. More...

#include "BBB/pruio.bi"
#include "BBB/pruio_pins.bi"
Include dependency graph for performance.bas:

Go to the source code of this file.

Macros

#define C_IN   /* P9_42 */
 The pin to use for CAP input.
 
#define GOUT   /* P8_16 */
 The pin to use for GPIO output.
 
#define G_IN   /* P8_14 */
 The pin to use for GPIO input.
 
#define FREQ(_N_)
 Macro to measure the frequency and compute statistics. More...
 
#define DIRECT(_O_)
 Macro to set output pin by fast direct PRU command (no error checking). More...
 
#define FUNC(_O_)
 Macro to set output by normal GPIO function (for better readability). More...
 

Functions

int main ()
 

Variables

VAR io = NEW PruIo(PRUIO_DEF_ACTIVE, 0, 0, 0)
 Create a PruIo structure, wakeup devices.
 
CONST_ZSTRING_PTR desc [...]
 A text description for the tests. More...
 
Float_t f0
 Variable for measured frequency.
 
Float_t nf
 The minimum frequencies.
 
Float_t xf
 The maximum frequencies.
 
Float_t sf
 The summe of measured frequencies (to compute avarage).
 
UInt32 n = 0
 The counter for test cycles.
 
UInt32 c = 3
 The number of cycles for each test.
 
UInt32 r1 = .BallGpio(G_IN)
 Resulting input GPIO (index and bit number).
 
UInt32 g1 = r1 SHR 5
 Index of input GPIO.
 
UInt32 m1 = 1 SHL (r1 AND 31)
 The bit number of input bit.
 
UInt32 r0 = .BallGpio(GOUT)
 Resulting output GPIO (index and bit number).
 
UInt32 g0 = r0 SHR 5
 Index of output GPIO.
 
UInt32 m0 = 1 SHL (r0 AND 31)
 Mask for output bit.
 
UInt32 cd = 0
 Register value for CLEARDATAOUT.
 
UInt32 sd = 0
 Register value for SETDATAOUT.
 
UInt32 ad = .Gpio->Conf(g0)->DeAd + &h100
 Subsystem adress.
 
UInt32 oe = .Gpio->Conf(g0)->OE
 Output enable register.
 

Detailed Description

Example: test execution speed of several methods to toggle a GPIO pin.

This file contains an example on measuring the execution speed of different controllers that toggles a GPIO output. It measures the frequency of the toggled output from open and closed loop controllers and computes their mimimum, avarage and maximum execution speed. Find a functional description in section performance.

The code performs 50 tests of each controller version and outputs the toggling frequencies in Hz at the end. The controllers are classified by

  1. Open loop
    • Direct GPIO
    • Function Gpio->Value
  2. Closed loop
    • Input direct GPIO, output direct GPIO
    • Input function Gpio->Value, output direct GPIO
    • Input function Gpio->Value, output function Gpio->setValue
    • Input Adc->Value, output direct GPIO
    • Input Adc->Value, output function Gpio->Value

Licence: GPLv3, Copyright 2014-2023 by Thomas{ doT ]Freiherr[ At ]gmx[ DoT }net

Compile by: fbc -w all performance.bas

Since
0.4.0

Definition in file performance.bas.

Macro Definition Documentation

◆ DIRECT

#define DIRECT (   _O_)
Value:
/* (multi line FreeBASIC #MACRO)
IF _O_ THEN
cd AND= NOT m0
sd OR= m0
ELSE
cd OR= m0
sd AND= NOT m0
END IF
WHILE .DRam[1] : WEND ' wait, if PRU is busy (should never happen)
.DRam[5] = oe
.DRam[4] = sd
.DRam[3] = cd
.DRam[2] = ad
.DRam[1] = PRUIO_COM_GPIO_CONF SHL 24
#ENDMACRO */

Macro to set output pin by fast direct PRU command (no error checking).

Definition at line 47 of file performance.bas.

◆ FREQ

#define FREQ (   _N_)
Value:
/* (multi line FreeBASIC #MACRO)
IF .Cap->Value(C_IN, @f0, NULL) THEN _ ' get CAP input
?"Cap->Value failed (" & *.Errr & ")" : EXIT DO
sf(_N_) += f0
IF f0 < nf(_N_) THEN nf(_N_) = f0
IF f0 > xf(_N_) THEN xf(_N_) = f0
?f0,
SLEEP 1
#ENDMACRO */

Macro to measure the frequency and compute statistics.

Definition at line 44 of file performance.bas.

◆ FUNC

#define FUNC (   _O_)
Value:
/* IF .Gpio->setValue(GOUT, _O_) THEN _ ' set GPIO output
?"GPIO setValue failed (" & *.Errr & ")" : EXIT DO */

Macro to set output by normal GPIO function (for better readability).

Definition at line 50 of file performance.bas.

Function Documentation

◆ main()

int main ( )

The main function.

Definition at line 183 of file performance.bas.

Here is the call graph for this function:

Variable Documentation

◆ desc

CONST_ZSTRING_PTR desc[...]
Initial value:
=
{ @"Open loop, direct GPIO"
, @"Open loop, function Gpio->Value"
, @"Closed loop, direct GPIO to direct GPIO"
, @"Closed loop, function Gpio->Value to direct GPIO"
, @"Closed loop, function Gpio->Value to function Gpio->setValue"
, @"Closed loop, Adc->Value to direct GPIO"
, @"Closed loop, Adc->Value to function Gpio->Value"}

A text description for the tests.

Definition at line 76 of file performance.bas.