libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
performance.bas
Go to the documentation of this file.
1 
30 
31 ' include libpruio
32 #INCLUDE ONCE "BBB/pruio.bi"
33 ' include the convenience macros for header pins
34 #INCLUDE ONCE "BBB/pruio_pins.bi"
35 
36 
37 #DEFINE C_IN P9_42
38 
39 #DEFINE GOUT P8_16
40 
41 #DEFINE G_IN P8_14
42 
43 
44 #MACRO FREQ(_N_)
45  IF .Cap->Value(C_IN, @f0, NULL) THEN _ ' get CAP input
46  ?"Cap->Value failed (" & *.Errr & ")" : EXIT DO
47  sf(_N_) += f0
48  IF f0 < nf(_N_) THEN nf(_N_) = f0
49  IF f0 > xf(_N_) THEN xf(_N_) = f0
50  ?f0,
51  SLEEP 1
52 #ENDMACRO
53 
54 
55 #MACRO DIRECT(_O_)
56  IF _O_ THEN
57  cd AND= NOT m0
58  sd OR= m0
59  ELSE
60  cd OR= m0
61  sd AND= NOT m0
62  END IF
63 
64  WHILE .DRam[1] : WEND ' wait, if PRU is busy (should never happen)
65  .DRam[5] = oe
66  .DRam[4] = sd
67  .DRam[3] = cd
68  .DRam[2] = ad
69  .DRam[1] = PRUIO_COM_GPIO_CONF SHL 24
70 #ENDMACRO
71 
72 
73 #DEFINE FUNC(_O_) IF .Gpio->setValue(GOUT, _O_) THEN _ ' set GPIO output
74  ?"GPIO setValue failed (" & *.Errr & ")" : EXIT DO
75 
76 
77 ' ***** main *****
78 
79 VAR io = NEW PruIo(PRUIO_DEF_ACTIVE, 0, 0, 0)
80 
81 WITH *io
82  DO
83  IF .Errr THEN ?"initialisation failed (" & *.Errr & ")" : EXIT DO
84 
85  IF .Gpio->setValue(GOUT, 0) THEN _ ' configure GPIO output GOUT
86  ?"GOUT configuration failed (" & *.Errr & ")" : EXIT DO
87 
88  IF .Gpio->config(G_IN, PRUIO_GPIO_IN) THEN _ ' conf. GPIO input G_IN
89  ?"G_IN configuration failed (" & *.Errr & ")" : EXIT DO
90 
91  IF .Cap->config(C_IN, 1000) THEN _ ' configure CAP input C_IN
92  ?"C_IN configuration failed (" & *.Errr & ")" : EXIT DO
93 
94  IF .Adc->setStep(1, 0, 0, 0, 0) THEN _ ' configure fast Adc step
95  ?"ADC setStep failed (" & *.Errr & ")" : EXIT DO
96 
97  IF .config(1, 1 SHL 1) THEN _ ' start IO mode
98  ?"config failed (" & *.Errr & ")" : EXIT DO
99 
100  DIM AS CONST ZSTRING PTR desc(...) = _
101  { @"Open loop, direct GPIO" _
102  , @"Open loop, function Gpio->Value" _
103  , @"Closed loop, direct GPIO to direct GPIO" _
104  , @"Closed loop, function Gpio->Value to direct GPIO" _
105  , @"Closed loop, function Gpio->Value to function Gpio->setValue" _
106  , @"Closed loop, Adc->Value to direct GPIO" _
107  , @"Closed loop, Adc->Value to function Gpio->Value"}
108  DIM AS Float_t _
109  f0 _
110  , nf(UBOUND(desc)) _
111  , xf(UBOUND(desc)) _
112  , sf(UBOUND(desc))
113  DIM AS UInt32 _
114  n = 0 _
115  , c = 3 _
116  , r1 = .BallGpio(G_IN) _
117  , g1 = r1 SHR 5 _
118  , m1 = 1 SHL (r1 AND 31) _
119  , r0 = .BallGpio(GOUT) _
120  , g0 = r0 SHR 5 _
121  , m0 = 1 SHL (r0 AND 31) _
122  , cd = 0 _
123  , sd = 0 _
124  , ad = .Gpio->Conf(g0)->DeAd + &h100 _
125  , oe = .Gpio->Conf(g0)->OE
126 
127  FOR i AS INTEGER = 0 TO UBOUND(desc) ' initialize minimum values
128  nf(i) = 100e6
129  NEXT
130 
131  FOR n = 0 TO 49 ' perform the tests
132 '' Open loop controllers
133  FOR i AS INTEGER = 0 TO c
134  DIRECT(1)
135  DIRECT(0)
136  NEXT
137  FREQ(0) ' Open loop, direct GPIO
138 
139  FOR i AS INTEGER = 0 TO c
140  FUNC(1) ' set GPIO output high
141  FUNC(0) ' set GPIO output low
142  NEXT
143  FREQ(1) ' Open loop, function Gpio->Value
144 
145 '' Closed loop controllers
146  FOR i AS INTEGER = 0 TO c
147  DIRECT(1) ' set GPIO output high
148  WHILE 0 = (.Gpio->Raw(g1)->Mix AND m1) : WEND
149 
150  DIRECT(0) ' set GPIO output low
151  WHILE m1 = (.Gpio->Raw(g1)->Mix AND m1) : WEND
152  NEXT
153  FREQ(2) ' Closed loop, direct GPIO to direct GPIO
154 
155  FOR i AS INTEGER = 0 TO c
156  DIRECT(1) ' set GPIO output high
157  WHILE .Gpio->Value(G_IN) < 1 : WEND
158 
159  DIRECT(0) ' set GPIO output low
160  WHILE .Gpio->Value(G_IN) > 0 : WEND
161  NEXT
162  FREQ(3) ' Closed loop, function Gpio->Value to direct GPIO
163 
164  FOR i AS INTEGER = 0 TO c
165  FUNC(1) ' set GPIO output high
166  WHILE .Gpio->Value(G_IN) < 1 : WEND
167 
168  FUNC(0) ' set GPIO output low
169  WHILE .Gpio->Value(G_IN) > 0 : WEND
170  NEXT
171  FREQ(4) ' Closed loop, function Gpio->Value to function Gpio->setValue
172 
173  FOR i AS INTEGER = 0 TO c
174  DIRECT(1)
175  WHILE .Adc->Value[1] <= &h7FFF : WEND
176 
177  DIRECT(0)
178  WHILE .Adc->Value[1] > &h7FFF : WEND
179  NEXT
180  FREQ(5) ' Closed loop, Adc->Value to direct GPIO
181 
182  FOR i AS INTEGER = 0 TO c
183  FUNC(1) ' set GPIO output high
184  WHILE .Adc->Value[1] <= &h7FFF : WEND
185 
186  FUNC(0) ' set GPIO output low
187  WHILE .Adc->Value[1] > &h7FFF : WEND
188  NEXT
189  FREQ(6) ' Closed loop, Adc->Value to function Gpio->Value
190  ?
191  NEXT
192  ?" Results:"
193  FOR i AS INTEGER = 0 TO UBOUND(desc)
194  ?*desc(i) & ":"
195  ?" Minimum: "; nf(i)
196  ?" Avarage: "; sf(i) / n
197  ?" Maximum: "; xf(i)
198  NEXT : ?
199  LOOP UNTIL 1
200  IF .Errr THEN ?"press any key to quit" : SLEEP
201 END WITH
202 
203 DELETE io ' reset ADC, PinMux and GPIOs, clear memory
204 
205 '' help Doxygen to document the main code
206 '&/** The main function. */
207 '&int main() {PruIo::PruIo(); GpioUdt::config(); PruIo::config(); CapMod::Value(); GpioUdt::Value(); GpioUdt::setValue(); PruIo::~PruIo();}
208 
209