libpruio  0.0.2
AM33xx-PRU driver for digital input / output and analog input
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
analyse.bas
Go to the documentation of this file.
1 /'* \file analyse.bas
2 \brief Example: analyse the devices configurations.
3 
4 This file contains an example on how to use libpruio to read the
5 original configuration of the devices. It creates a PruIo structure
6 containing the initial data and then prints out in a human-readable
7 form.
8 
9 Licence: GPLv3
10 
11 Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net
12 
13 
14 Compile by:
15 
16 fbc -w all analyse.bas
17 
18 '/
19 
20 '* include libpruio
21 #INCLUDE ONCE "../pruio/pruio.bi"
22 '* include the convenience macros for header pins
23 #INCLUDE ONCE "../pruio/pruio_pins.bi"
24 
25 ' ***** main *****
26 
27 VAR io = NEW PruIo '*< create a PruIo structure, wakeup devices
28 
29 WITH *io
30  IF .Errr THEN
31  ?"initialisation failed (" & *.Errr & ")"
32  ELSE
33  FOR i AS INTEGER = 0 TO PRUIO_GPIO_AZ
34  VAR x = i * (PRUIO_GPIO_DATA SHR 2)
35  ?"GPIO" & i & " was ";
36  IF .GpioOrg[x + 4] = 2 THEN
37  ?"on"
38  ?" OE: " & BIN(.GpioOrg[x + 1], 32)
39  ?" INT0: " & BIN(.GpioOrg[x + 2], 32)
40  ?" INT1: " & BIN(.GpioOrg[x + 3], 32)
41  ELSE
42  ?"off, COUNT: " & .GpioOrg[x + 5]
43  END IF
44  NEXT
45 
46  ?"Unlocked Pins:"
47  FOR i AS INTEGER = 0 TO PRUIO_BALL_AZ
48  IF .BallRef[i] <> 255 THEN ?" " & *.gpio_get_config(i)
49  NEXT
50  ?"Locked header Pins:"
51  FOR i AS INTEGER = 0 TO UBOUND(P8_Pins)
52  VAR b = P8_Pins(i)
53  IF .BallRef[b] = 255 THEN ?" " & *.gpio_get_config(b)
54  NEXT
55  FOR i AS INTEGER = 0 TO UBOUND(P9_Pins)
56  VAR b = P9_Pins(i)
57  IF .BallRef[b] = 255 THEN ?" " & *.gpio_get_config(b)
58  NEXT
59 
60  IF .AdcOrg[0] THEN
61  ?"ADC was on"
62  ?" REVISION: &h" & HEX(.AdcOrg[ 0], 8)
63  ?" SYSCONFIG: &b" & BIN(.AdcOrg[ 4], 4)
64  ?" IRQ_STATUS_RAW: &b" & BIN(.AdcOrg[ 9], 10)
65  ?" IRQ_STATUS: &b" & BIN(.AdcOrg[10], 10)
66  ?" IRQENABLE_SET: &b" & BIN(.AdcOrg[11], 10)
67  ?" IRQENABLE_CLR: &b" & BIN(.AdcOrg[12], 10)
68  ?" IRQWAKEUP: &b" & BIN(.AdcOrg[13], 1)
69  ?" DMAENABLE_SET: &b" & BIN(.AdcOrg[14], 2)
70  ?" DMAENABLE_CLR: &b" & BIN(.AdcOrg[15], 2)
71  ?" CRTL: &b" & BIN(.AdcOrg[16], 2)
72  ?" ADCSTAT: &b" & BIN(.AdcOrg[17], 8)
73  ?" ADCRANGE: &h" & HEX(.AdcOrg[18], 8)
74  ?" ADC_CLKDIV: &h" & HEX(.AdcOrg[19], 4)
75  ?" ADC_MISC: &b" & BIN(.AdcOrg[20], 8)
76  ?" Steps: config , delay"
77  ?" idle step: &h" & HEX(.AdcOrg[22], 8)
78  ?" charge step: &h" & HEX(.AdcOrg[23], 8) & ", &h" & HEX(.AdcOrg[24], 8)
79  FOR i AS INTEGER = 1 TO 16
80  VAR x = 23 + 2 * i
81  ?" step" & RIGHT("0" & i, 2) _
82  & ": &h" & HEX(.AdcOrg[x], 8) & ", &h" & HEX(.AdcOrg[x + 1], 8)
83  NEXT
84  ELSE
85  ?"ADC was off"
86  ?" REVISION: " & HEX(.AdcOrg[1], 8)
87  ?" wakeup-count: " & HEX(.AdcOrg[2], 8)
88  END IF
89  END IF
90 END WITH
91 
92 DELETE io ' reset ADC, PinMux and GPIOs, clear memory
93