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

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

#include "stdio.h"
#include "time.h"
#include "libpruio/pruio.h"
#include "libpruio/pruio_pins.h"
Include dependency graph for performance.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE   1
 Message for the compiler.
 
#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 (int argc, char **argv)
 The main function. More...
 

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: gcc -Wall -o performance performance.c -lpruio

Since
0.4

Definition in file performance.c.

Macro Definition Documentation

◆ DIRECT

#define DIRECT (   _O_)
Value:
if(_O_){cd &= ~m0; sd |= m0;} else {sd &= ~m0; cd |= m0;} \
while(Io->DRam[1]){} \
Io->DRam[5] = oe; \
Io->DRam[4] = sd; \
Io->DRam[3] = cd; \
Io->DRam[2] = ad; \
Io->DRam[1] = PRUIO_COM_GPIO_CONF << 24;
UInt32 cd
Register value for CLEARDATAOUT.
Definition: performance.bas:98
UInt32 oe
Output enable register.
UInt32 sd
Register value for SETDATAOUT.
Definition: performance.bas:99
UInt32 m0
Mask for output bit.
Definition: performance.bas:97
UInt32 ad
Subsystem adress.
#define PRUIO_COM_GPIO_CONF
The command number to re-configure a GPIO.
Definition: pruio.hp:118
@ _O_
setting for an output pin.
Definition: pruiotools.bas:63

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

Definition at line 55 of file performance.c.

◆ FREQ

#define FREQ (   _N_)
Value:
if(pruio_cap_Value(Io, C_IN, &f0, NULL)) { /* get CAP input */ \
printf("Cap->Value failed (%s)", Io->Errr); goto finish;} \
sf[_N_] += f0; \
if(f0 < nf[_N_]) {nf[_N_] = f0;} \
if(f0 > xf[_N_]) {xf[_N_] = f0;} \
printf("%f\t", f0);
Float_t nf
The minimum frequencies.
Definition: performance.bas:86
Float_t xf
The maximum frequencies.
Definition: performance.bas:87
Float_t f0
Variable for measured frequency.
Definition: performance.bas:85
#define C_IN
The pin to use for CAP input.
Definition: performance.c:39
char * pruio_cap_Value(pruIo *Io, uint8 Ball, float_t *Hz, float_t *Du)
Wrapper function for CapMod::Value().
const ANY_PTR NULL
The NULL pointer.

Macro to measure the frequency and compute statistics.

Definition at line 46 of file performance.c.

◆ FUNC

#define FUNC (   _O_)
Value:
if(pruio_gpio_setValue(Io, GOUT, _O_)) { /* set GPIO output */ \
printf("GPIO setValue failed (%s)", Io->Errr); goto finish;}
#define GOUT
The pin to use for GPIO output.
Definition: performance.c:41
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::setValue().

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

Definition at line 65 of file performance.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

The main function.

create new driver structure

< The counter for test loops.

< The counter for test cycles.

< The number of cycles for each test.

< Resulting input GPIO (index and bit number).

< Index of input GPIO.

< The bit number of input bit.

< Resulting output GPIO (index and bit number).

< Index of output GPIO.

< Mask for output bit. , sd

< Register value for CLEARDATAOUT.

< Register value for SETDATAOUT.

< Subsystem adress.

< Output enable register.

< The current measurement result.

< The minimum frequencies.

< The maximum frequencies.

< The summe of measured frequencies (to compute avarage).

Definition at line 70 of file performance.c.

Here is the call graph for this function: