libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
performance.c
Go to the documentation of this file.
1 
32 #define _GNU_SOURCE 1
33 #include "stdio.h"
34 #include "time.h"
35 #include "libpruio/pruio.h"
36 #include "libpruio/pruio_pins.h"
37 
39 #define C_IN P9_42
41 #define GOUT P8_16
43 #define G_IN P8_14
44 
46 #define FREQ(_N_) \
47  if(pruio_cap_Value(Io, C_IN, &f0, NULL)) { /* get CAP input */ \
48  printf("Cap->Value failed (%s)", Io->Errr); goto finish;} \
49  sf[_N_] += f0; \
50  if(f0 < nf[_N_]) {nf[_N_] = f0;} \
51  if(f0 > xf[_N_]) {xf[_N_] = f0;} \
52  printf("%f\t", f0);
53 
55 #define DIRECT(_O_) \
56  if(_O_){cd &= ~m0; sd |= m0;} else {sd &= ~m0; cd |= m0;} \
57  while(Io->DRam[1]){} \
58  Io->DRam[5] = oe; \
59  Io->DRam[4] = sd; \
60  Io->DRam[3] = cd; \
61  Io->DRam[2] = ad; \
62  Io->DRam[1] = PRUIO_COM_GPIO_CONF << 24;
63 
65 #define FUNC(_O_) \
66  if(pruio_gpio_setValue(Io, GOUT, _O_)) { /* set GPIO output */ \
67  printf("GPIO setValue failed (%s)", Io->Errr); goto finish;}
68 
70 int main(int argc, char **argv)
71 {
72  pruIo *Io = pruio_new(PRUIO_DEF_ACTIVE, 4, 0x98, 0);
73  do {
74  if (Io->Errr) {
75  printf("initialisation failed (%s)\n", Io->Errr); break;}
76 
77  if (pruio_gpio_setValue(Io, GOUT, 0)) { //configure GPIO output GOUT
78  printf("GOUT configuration failed (%s)\n", Io->Errr); break;}
79 
80  if (pruio_gpio_config(Io, G_IN, PRUIO_GPIO_IN)) { //conf. GPIO input G_IN
81  printf("G_IN configuration failed (%s)\n", Io->Errr); break;}
82 
83  if (pruio_cap_config(Io, C_IN, 1000)) { // configure CAP input C_IN
84  printf("C_IN configuration failed (%s)\n", Io->Errr); break;}
85 
86  if (pruio_adc_setStep(Io, 1, 0, 0, 0, 0)) { //configure fast Adc step
87  printf("ADC setStep failed (%s)\n", Io->Errr); break;}
88 
89  if (pruio_config(Io, 1, 1 << 1, 0, 4)) {
90  printf("config failed (%s)\n", Io->Errr); break;}
91 
92  const char *desc[] = {
93  "Open loop, direct GPIO"
94  , "Open loop, function Gpio->Value"
95  , "Closed loop, direct GPIO to direct GPIO"
96  , "Closed loop, function Gpio->Value to direct GPIO"
97  , "Closed loop, function Gpio->Value to function Gpio->setValue"
98  , "Closed loop, Adc->Value to direct GPIO"
99  , "Closed loop, Adc->Value to function Gpio->Value"
100  };
101 
102  uint32
103  i
104  , n
105  , c = 3
106  , r1 = Io->BallGpio[G_IN]
107  , g1 = r1 >> 5
108  , m1 = 1 << (r1 & 31)
109  , r0 = Io->BallGpio[GOUT]
110  , g0 = r0 >> 5
111  , m0 = 1 << (r0 & 31)
112  , cd = 0
113  , sd = 0
114  , ad = Io->Gpio->Conf[g0]->DeAd + 0x100
115  , oe = Io->Gpio->Conf[g0]->OE;
116  float_t
117  f0
118  , nf[7]
119  , xf[7]
120  , sf[7];
121 
122  for(n = 0; n < 7; n++) {
123  nf[n] = 100e6;
124  sf[n] = 0.;
125  xf[n] = 0.;
126  }
127 
128  struct timespec mSec;
129  mSec.tv_sec=0;
130  mSec.tv_nsec=1000000;
131 
132  for(n = 0; n < 50; n++) {
133  nanosleep(&mSec, NULL);
134  for(i = 0; i <= c; i++) {
135  DIRECT(1)
136  DIRECT(0)
137  }
138  FREQ(0)
139 
140  nanosleep(&mSec, NULL);
141  for(i = 0; i <= c; i++) {
142  FUNC(1)
143  FUNC(0)
144  }
145  FREQ(1)
146 
147  nanosleep(&mSec, NULL);
148  for(i = 0; i <= c; i++) {
149  DIRECT(1)
150  while( 0 == (m1 & Io->Gpio->Raw[g1]->Mix)) {}
151 
152  DIRECT(0)
153  while(m1 == (m1 & Io->Gpio->Raw[g1]->Mix)) {}
154  }
155  FREQ(2)
156 
157  nanosleep(&mSec, NULL);
158  for(i = 0; i <= c; i++) {
159  DIRECT(1)
160  while(pruio_gpio_Value(Io, G_IN) < 1) {}
161 
162  DIRECT(0)
163  while(pruio_gpio_Value(Io, G_IN) > 0) {}
164  }
165  FREQ(3)
166 
167  nanosleep(&mSec, NULL);
168  for(i = 0; i <= c; i++) {
169  FUNC(1)
170  while(pruio_gpio_Value(Io, G_IN) < 1) {}
171 
172  FUNC(0)
173  while(pruio_gpio_Value(Io, G_IN) > 0) {}
174  }
175  FREQ(4)
176 
177  nanosleep(&mSec, NULL);
178  for(i = 0; i <= c; i++) {
179  DIRECT(1)
180  while(Io->Adc->Value[1] <= 0x7FFF) {}
181 
182  DIRECT(0)
183  while(Io->Adc->Value[1] > 0x7FFF) {}
184  }
185  FREQ(5)
186 
187  nanosleep(&mSec, NULL);
188  for(i = 0; i <= c; i++) {
189  FUNC(1)
190  while(Io->Adc->Value[1] <= 0x7FFF) {}
191 
192  FUNC(0)
193  while(Io->Adc->Value[1] > 0x7FFF) {}
194  }
195  FREQ(6)
196  printf("\n");
197  }
198  printf("Results:\n");
199  for(i = 0; i < 7; i++) {
200  printf("%s:\n", desc[i]);
201  printf(" Minimum: %f\n", nf[i]);
202  printf(" Avarage: %f\n", (sf[i] / n));
203  printf(" Maximum: %f\n", xf[i]);
204  }
205 printf("%X %X %X %X %X\n", sd, cd, ad, m0, r0);
206  } while(0);
207 
208 finish:
209  pruio_destroy(Io); /* destroy driver structure */
210  return 0;
211 }
CONST_ZSTRING_PTR desc[...]
A text description for the tests.
Definition: performance.bas:76
UInt32 r0
Resulting output GPIO (index and bit number).
Definition: performance.bas:95
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 c
The number of cycles for each test.
Definition: performance.bas:91
UInt32 m0
Mask for output bit.
Definition: performance.bas:97
UInt32 r1
Resulting input GPIO (index and bit number).
Definition: performance.bas:92
Float_t nf
The minimum frequencies.
Definition: performance.bas:86
UInt32 m1
The bit number of input bit.
Definition: performance.bas:94
Float_t sf
The summe of measured frequencies (to compute avarage).
Definition: performance.bas:88
Float_t xf
The maximum frequencies.
Definition: performance.bas:87
Float_t f0
Variable for measured frequency.
Definition: performance.bas:85
UInt32 g1
Index of input GPIO.
Definition: performance.bas:93
UInt32 n
The counter for test cycles.
Definition: performance.bas:90
UInt32 ad
Subsystem adress.
UInt32 g0
Index of output GPIO.
Definition: performance.bas:96
#define GOUT
The pin to use for GPIO output.
Definition: performance.c:41
#define DIRECT(_O_)
Macro to set output pin by fast direct PRU command (no error checking).
Definition: performance.c:55
#define C_IN
The pin to use for CAP input.
Definition: performance.c:39
int main(int argc, char **argv)
The main function.
Definition: performance.c:70
#define FREQ(_N_)
Macro to measure the frequency and compute statistics.
Definition: performance.c:46
#define FUNC(_O_)
Macro to set output by normal GPIO function (for better readability).
Definition: performance.c:65
#define G_IN
The pin to use for GPIO input.
Definition: performance.c:43
unsigned int uint32
32 bit unsigned integer data type.
Definition: pruio.h:41
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().
float float_t
float data type.
Definition: pruio.h:42
uint32 pruio_gpio_Value(pruIo *Io, uint8 Ball)
Wrapper function for GpioUdt::Value().
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
@ PRUIO_GPIO_IN
GPIO input (no resistor).
Definition: pruio.h:492
char * pruio_cap_config(pruIo *Io, uint8 Ball, float_t FLow)
Wrapper function for CapMod::config().
char * pruio_adc_setStep(pruIo *Io, uint8 Stp, uint8 ChN, uint8 Av, uint8 SaD, uint32 OpD)
Wrapper function for AdcUdt::setStep().
char * pruio_gpio_config(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::config().
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo().
@ PRUIO_DEF_ACTIVE
Activate all subsystems.
Definition: pruio.h:531
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::setValue().
const ANY_PTR NULL
The NULL pointer.
VAR i
Start index.
Definition: rb_file.bas:62
uint16 * Value
Fetched ADC samples.
Definition: pruio.h:132
uint32 Mix
Current state of pins (IN&OUT mixed).
Definition: pruio.h:185
uint32 DeAd
Subsystem address.
Definition: pruio.h:142
uint32 OE
Register at offset 134h (chap. 25.4.1.16).
Definition: pruio.h:162
gpioSet * Conf[PRUIO_AZ_GPIO+1]
Current subsystem configuration, used in PruIo::config().
Definition: pruio.h:197
gpioArr * Raw[PRUIO_AZ_GPIO+1]
Pointer to current raw subsystem data (IO), all 32 bits.
Definition: pruio.h:199
Wrapper structure for PruIo.
Definition: pruio.h:550
char * Errr
Pointer for error messages.
Definition: pruio.h:551
uint8 BallGpio[PRUIO_AZ_BALL+1]
List of GPIO numbers, corresponding to ball index.
Definition: pruio.h:592
gpioUdt * Gpio
Pointer to GPIO subsystem structure.
Definition: pruio.h:554
adcUdt * Adc
Pointer to ADC subsystem structure.
Definition: pruio.h:553