libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
performance.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
30 
31 from __future__ import print_function
32 from libpruio import *
33 import time
34 
35 
36 C_IN = P9_42
37 
38 GOUT = P8_16
39 
40 G_IN = P8_14
41 
42 desc = [
43  "Open loop, direct GPIO"
44 , "Open loop, function Gpio->Value"
45 , "Closed loop, direct GPIO to direct GPIO"
46 , "Closed loop, function Gpio->Value to direct GPIO"
47 , "Closed loop, function Gpio->Value to function Gpio->setValue"
48 , "Closed loop, Adc->Value to direct GPIO"
49 , "Closed loop, Adc->Value to function Gpio->Value"
50 ]
51 
52 
53 f0 = c_float(0.)
54 
55 nf = [100e6,100e6,100e6,100e6,100e6,100e6,100e6]
56 
57 sf = [0.,0.,0.,0.,0.,0.,0.]
58 
59 xf = [0.,0.,0.,0.,0.,0.,0.]
60 
61 
62 r0 = c_ubyte(0)
63 
64 r1 = c_ubyte(0)
65 
66 m0 = c_ulong(0)
67 
68 m1 = c_ulong(0)
69 
70 ad = c_ulong(0)
71 
72 oe = c_ulong(0)
73 
74 cd = c_ulong(0)
75 
76 sd = c_ulong(0)
77 
78 
79 io = pruio_new(PRUIO_DEF_ACTIVE, 4, 0x98, 0)
80 
81 IO = io.contents
82 
83 
84 def FREQ(_N_):
85  if pruio_cap_Value(io, C_IN, byref(f0), None): # get CAP input
86  raise AssertionError("Cap->Value failed (%s)" % IO.Errr)
87  sf[_N_] += f0.value
88  if f0.value < nf[_N_]: nf[_N_] = f0.value
89  if f0.value > xf[_N_]: xf[_N_] = f0.value
90  print("%f" % f0.value, end="\t")
91 
92 
93 def DIRECT(_O_):
94  if _O_: cd.value &= ~m0.value; sd.value |= m0.value
95  else: sd.value &= ~m0.value; cd.value |= m0.value
96  while IO.DRam[1]: pass
97  IO.DRam[5] = oe.value
98  IO.DRam[4] = sd.value
99  IO.DRam[3] = cd.value
100  IO.DRam[2] = ad.value
101  IO.DRam[1] = PRUIO_COM_GPIO_CONF << 24
102 
103 try:
104  if IO.Errr: raise AssertionError("pruio_new failed (%s)" % IO.Errr)
105 
106  if pruio_gpio_setValue(io, GOUT, 0): # configure GPIO output GOUT
107  raise AssertionError("GOUT configuration failed (%s)" % IO.Errr)
108 
109  if pruio_gpio_config(io, G_IN, PRUIO_GPIO_IN): # conf. GPIO input G_IN
110  raise AssertionError("G_IN configuration failed (%s)" % IO.Errr)
111 
112  if pruio_cap_config(io, C_IN, 100): # configure CAP input C_IN
113  raise AssertionError("C_IN configuration failed (%s)" % IO.Errr)
114 
115  if pruio_adc_setStep(io, 1, 0, 0, 0, 0): # configure fast Adc step
116  raise AssertionError("ADC setStep failed (%s)" % IO.Errr)
117 
118  if pruio_config(io, 1, 0b10, 0, 4): # upload settings, start IO mode
119  raise AssertionError("config failed (%s)" % IO.Errr)
120 
121  r1.value = IO.BallGpio[G_IN] # Resulting input GPIO (index and bit number).
122  m1.value = 1 << (r1.value & 31)
123  r0.value = IO.BallGpio[GOUT] # Resulting output GPIO (index and bit number).
124  m0.value = 1 << (r0.value & 31)
125  g1 = r1.value >> 5 # Index of input GPIO.
126  g0 = r0.value >> 5 # Index of output GPIO.
127  ad.value = IO.Gpio.contents.Conf[g0].contents.DeAd + 0x100
128  oe.value = IO.Gpio.contents.Conf[g0].contents.OE
129  c = 4 # Number of cycles for each test
130  n = 50 # Number of tests
131  mi = IO.Gpio.contents.Raw[g1].contents # Mixes register DATAIN/DATAOUT
132  Adc = IO.Adc.contents.Value # Adc values
133  for x in range(0, n):
134  time.sleep(.001)
135  for i in range(0, c):
136  DIRECT(1)
137  DIRECT(0)
138  FREQ(0)
139 
140  time.sleep(.001)
141  for i in range(0, c):
142  if pruio_gpio_setValue(io, GOUT, 1): # set GPIO output
143  raise AssertionError("GPIO setValue failed (%s)" % Io.Errr)
144  if pruio_gpio_setValue(io, GOUT, 0): # set GPIO output
145  raise AssertionError("GPIO setValue failed (%s)" % Io.Errr)
146  FREQ(1)
147 
148  time.sleep(.001)
149  for i in range(0, c):
150  DIRECT(1)
151  while 0 == (m1.value & mi.Mix): pass
152 
153  DIRECT(0)
154  while m1 == (m1.value & mi.Mix): pass
155  FREQ(2)
156 
157  time.sleep(.001)
158  for i in range(0, c):
159  DIRECT(1)
160  while pruio_gpio_Value(io, G_IN) < 1: pass
161 
162  DIRECT(0)
163  while pruio_gpio_Value(io, G_IN) > 0: pass
164  FREQ(3)
165 
166  time.sleep(.001)
167  for i in range(0, c):
168  if pruio_gpio_setValue(io, GOUT, 1): # set GPIO output
169  raise AssertionError("GPIO setValue failed (%s)" % Io.Errr)
170  while pruio_gpio_Value(io, G_IN) < 1: pass
171 
172  if pruio_gpio_setValue(io, GOUT, 0): # set GPIO output
173  raise AssertionError("GPIO setValue failed (%s)" % Io.Errr)
174  while pruio_gpio_Value(io, G_IN) > 0: pass
175  FREQ(4)
176 
177  time.sleep(.001)
178  for i in range(0, c):
179  DIRECT(1)
180  while Adc[1] <= 0x7FFF: pass
181 
182  DIRECT(0)
183  while Adc[1] > 0x7FFF: pass
184  FREQ(5)
185 
186  time.sleep(.001)
187  for i in range(0, c):
188  if pruio_gpio_setValue(io, GOUT, 1): # set GPIO output
189  raise AssertionError("GPIO setValue failed (%s)" % Io.Errr)
190  while Adc[1] <= 0x7FFF: pass
191 
192  if pruio_gpio_setValue(io, GOUT, 0): # set GPIO output
193  raise AssertionError("GPIO setValue failed (%s)" % Io.Errr)
194  while Adc[1] > 0x7FFF: pass
195  FREQ(6)
196  print("")
197 
198  for i in range(0, 7):
199  print("%s:" % desc[i])
200  print(" Minimum: %s" % nf[i])
201  print(" Avarage: %s" % (sf[i] / n))
202  print(" Maximum: %s" % xf[i])
203 
204 finally:
205  pruio_destroy(io)
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().
char * pruio_cap_Value(pruIo *Io, uint8 Ball, float_t *Hz, float_t *Du)
Wrapper function for CapMod::Value().
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().
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().
char * pruio_gpio_setValue(pruIo *Io, uint8 Ball, uint8 Modus)
Wrapper function for GpioUdt::setValue().