libpruio  0.2
Input/Output driver for digital/analog lines on Beagleboard hardware
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pruio.bi
Go to the documentation of this file.
1 /'* \file pruio.bi
2 \brief FreeBASIC header file for libpruio.
3 
4 Header file for including libpruio to FreeBASIC programs. It binds the
5 different components together and provides all declarations.
6 
7 '/
8 
9 #IFNDEF __PRUIO_COMPILING__
10 #INCLIB "pruio"
11 #ENDIF
12 
13 '* version string
14 #DEFINE PRUIO_VERSION "0.2"
15 
16 TYPE AS BYTE Int8 '*< 8 bit signed integer data type
17 TYPE AS SHORT Int16 '*< 16 bit signed integer data type
18 TYPE AS LONG Int32 '*< 32 bit signed integer data type
19 TYPE AS UBYTE UInt8 '*< 8 bit unsigned integer data type
20 TYPE AS USHORT UInt16 '*< 16 bit unsigned integer data type
21 TYPE AS ULONG UInt32 '*< 32 bit unsigned integer data type
22 TYPE AS SINGLE Float_t '*< float data type
23 
24 '* forward declaration
25 TYPE AS PruIo Pruio_
26 
27 '* tell pruss_intc_mapping.bi that we use ARM33xx
28 #DEFINE AM33XX
29 
30 ' the PRUSS driver library
31 #INCLUDE ONCE "BBB/prussdrv.bi"
32 ' PRUSS driver interrupt settings
33 #INCLUDE ONCE "BBB/pruss_intc_mapping.bi"
34 
35 '* constants for pinmuxing: pullup/-down resistors and GPIO states
36 ENUM PinMuxing
37  PRUIO_NO_PULL = &b001000 '*< no resistor connected
38  PRUIO_PULL_UP = &b010000 '*< pullup resistor connected
39  PRUIO_PULL_DOWN = &b000000 '*< pulldown resistor connected
40  PRUIO_RX_ACTIV = &b100000 '*< input receiver enabled
41  PRUIO_GPIO_OUT0 = 7 + PRUIO_NO_PULL '*< GPIO output low (no resistor)
42  PRUIO_GPIO_OUT1 = 7 + PRUIO_NO_PULL + 128 '*< GPIO output high (no resistor)
43  PRUIO_GPIO_IN = 7 + PRUIO_NO_PULL + PRUIO_RX_ACTIV '*< GPIO input (no resistor)
44  PRUIO_GPIO_IN_0 = 7 + PRUIO_PULL_DOWN + PRUIO_RX_ACTIV '*< GPIO input (pulldown resistor)
45  PRUIO_GPIO_IN_1 = 7 + PRUIO_PULL_UP + PRUIO_RX_ACTIV '*< GPIO input (pullup resistor)
46  PRUIO_PIN_RESET = &hFF
47 END ENUM
48 
49 ' common macros, shared with PRU pasm compiler
50 #INCLUDE ONCE "pruio.hp"
51 ' header for ADC part
52 #INCLUDE ONCE "pruio_adc.bi"
53 ' header for GPIO part
54 #INCLUDE ONCE "pruio_gpio.bi"
55 ' header for PWMSS part, containing modules QEP, CAP and PWM
56 #INCLUDE ONCE "pruio_pwmss.bi"
57 
58 '* the channel for PRU messages (must match PRUIO_IRPT)
59 #DEFINE PRUIO_CHAN CHANNEL5
60 '* the mask to enable PRU interrupts (must match PRUIO_IRPT)
61 #DEFINE PRUIO_MASK PRU_EVTOUT5_HOSTEN_MASK
62 '* the event for PRU messages (mapping, must match PRUIO_IRPT)
63 #DEFINE PRUIO_EMAP PRU_EVTOUT5
64 '* the event for PRU messages (must match PRUIO_IRPT)
65 #DEFINE PRUIO_EVNT PRU_EVTOUT_5
66 
67 '* Macro to calculate the total size of an array in bytes.
68 #DEFINE ArrayBytes(_A_) (UBOUND(_A_) + 1) * SIZEOF(_A_)
69 '* macro to check a CPU ball number (0 to 109 is valid range)
70 #DEFINE BallCheck(_T_,_R_) IF Ball > PRUIO_AZ_BALL THEN .Errr = @"unknown" _T_ " pin number" : RETURN _R_
71 
72 
73 /'* \brief Mask to be used in the constructor to choose PRUSS number and enable divices controls.
74 
75 This enumerators are used in the constructor PruIo::PruIo() to enable
76 single subsystems. By default all subsystems are enabled. If a device
77 is not enabled, libpruio wont wake it up nor allocate memory to control
78 it. It just reads the version information to see if the subsystem is in
79 operation.
80 
81 An enabled subsystem will get activated in the constructor
82 PruIo::PruIo() and libpruio will set its configuration.
83 
84 '/
85 ENUM ActivateDevice
86  PRUIO_ACT_PRU1 = &b000000000001 '*< activate PRU-1 (= default, instead of PRU-0)
87  PRUIO_ACT_ADC = &b000000000010 '*< activate ADC
88  PRUIO_ACT_GPIO0 = &b000000000100 '*< activate GPIO-0
89  PRUIO_ACT_GPIO1 = &b000000001000 '*< activate GPIO-1
90  PRUIO_ACT_GPIO2 = &b000000010000 '*< activate GPIO-2
91  PRUIO_ACT_GPIO3 = &b000000100000 '*< activate GPIO-3
92  PRUIO_ACT_PWM0 = &b000001000000 '*< activate PWMSS-0 (including eCAP, eQEP, ePWM)
93  PRUIO_ACT_PWM1 = &b000010000000 '*< activate PWMSS-1 (including eCAP, eQEP, ePWM)
94  PRUIO_ACT_PWM2 = &b000100000000 '*< activate PWMSS-2 (including eCAP, eQEP, ePWM)
95  PRUIO_DEF_ACTIVE = &b111111111111 '*< activate all subsystems
96 END ENUM
97 
98 
99 /'* \brief Structure for Control Module, containing pad configurations.
100 
101 This UDT contains a set of all pad control registers. This is the
102 muxing between CPU balls and the internal subsystem targets, the pullup
103 or pulldown configuration and the receiver activation.
104 
105 '/
106 TYPE BallSet
107  AS UInt32 DeAd '*< Base address of Control Module subsystem.
108  AS UInt8 Value(PRUIO_AZ_BALL) '*< The values of the pad control registers.
109 END TYPE
110 
111 /'* \brief Main structure, binding all components together.
112 
113 This UDT glues all together. It downloads and start software on the
114 PRUSS, controls the initialisation and configuration processes and
115 reads or writes the pinmux configurations.
116 
117 '/
118 TYPE PruIo
119  AS AdcUdt PTR Adc '*< Pointer to ADC subsystem structure.
120  AS GpioUdt PTR Gpio '*< Pointer to GPIO subsystems structure.
121  AS PwmssUdt PTR PwmSS '*< Pointer to PWMSS subsystems structure.
122  AS PwmMod PTR Pwm '*< Pointer to the ePWM module structure (in PWMSS subsystems).
123  AS CapMod PTR Cap '*< Pointer to the eCAP module structure (in PWMSS subsystems).
124  'AS QepMod PTR Qep '*< Pointer to the eQEP module structure (in PWMSS subsystems).
125 
126  AS ZSTRING PTR _
127  Errr = 0 '*< Pointer for error messages.
128  AS UInt32 PTR DRam '*< Pointer to access PRU DRam.
129  AS BallSet PTR _
130  Init _ '*< The subsystems register data at start-up (to restore when finished).
131  , Conf '*< The subsystems register data used by libpruio (current local data to be uploaded by PruIo::Config() ).
132  AS ANY PTR _
133  ERam _ '*< Pointer to read PRU external ram.
134  , DInit _ '*< Pointer to block of subsystems initial data.
135  , DConf _ '*< Pointer to block of subsystems configuration data.
136  , MOffs '*< Configuration offset for modules.
137  AS UInt8 PTR _
138  BallInit _ '*< Pointer for original Ball configuration.
139  , BallConf '*< Pointer to ball configuration (CPU pin muxing).
140  AS UInt32 _
141  EAddr _ '*< The address of the external memory (PRUSS-DDR).
142  , ESize _ '*< The size of the external memory (PRUSS-DDR).
143  , DSize _ '*< The size of a data block (DInit or DConf).
144  , PruNo _ '*< The PRU number to use (defaults to 1).
145  , PruEvtOut _ '*< The interrupt channel to send commands to PRU.
146  , PruIRam _ '*< The PRU instruction ram to load.
147  , PruDRam '*< The PRU data ram.
148  AS INT16 _
149  ArmPruInt _ '*< The interrupt to send.
150  , ParOffs _ '*< The offset for the parameters of a module.
151  , DevAct '*< Active subsystems.
152  AS STRING _
153  MuxAcc '*< Path for pinmuxing.
154 
155  '* interrupt settings (we also set default interrupts, so that the other PRUSS can be used in parallel)
156  AS tpruss_intc_initdata IntcInit = _
157  TYPE<tpruss_intc_initdata>( _
158  { PRU0_PRU1_INTERRUPT _
159  , PRU1_PRU0_INTERRUPT _
160  , PRU0_ARM_INTERRUPT _
161  , PRU1_ARM_INTERRUPT _
162  , ARM_PRU0_INTERRUPT _
163  , ARM_PRU1_INTERRUPT _
164  , PRUIO_IRPT _
165  , CAST(BYTE, -1) }, _
166  { TYPE<tsysevt_to_channel_map>(PRU0_PRU1_INTERRUPT, CHANNEL1) _
167  , TYPE<tsysevt_to_channel_map>(PRU1_PRU0_INTERRUPT, CHANNEL0) _
168  , TYPE<tsysevt_to_channel_map>(PRU0_ARM_INTERRUPT, CHANNEL2) _
169  , TYPE<tsysevt_to_channel_map>(PRU1_ARM_INTERRUPT, CHANNEL3) _
170  , TYPE<tsysevt_to_channel_map>(ARM_PRU0_INTERRUPT, CHANNEL0) _
171  , TYPE<tsysevt_to_channel_map>(ARM_PRU1_INTERRUPT, CHANNEL1) _
172  , TYPE<tsysevt_to_channel_map>(PRUIO_IRPT, PRUIO_CHAN) _
173  , TYPE<tsysevt_to_channel_map>(-1, -1)}, _
174  { TYPE<tchannel_to_host_map>(CHANNEL0, PRU0) _
175  , TYPE<tchannel_to_host_map>(CHANNEL1, PRU1) _
176  , TYPE<tchannel_to_host_map>(CHANNEL2, PRU_EVTOUT0) _
177  , TYPE<tchannel_to_host_map>(CHANNEL3, PRU_EVTOUT1) _
178  , TYPE<tchannel_to_host_map>(PRUIO_CHAN, PRUIO_EMAP) _
179  , TYPE<tchannel_to_host_map>(-1, -1) }, _
180  (PRU0_HOSTEN_MASK OR PRU1_HOSTEN_MASK OR _
181  PRU_EVTOUT0_HOSTEN_MASK OR PRU_EVTOUT1_HOSTEN_MASK OR PRUIO_MASK) _
182  )
183 
184  '* list of GPIO numbers, corresponding to ball index
185  AS UInt8 BallGpio(PRUIO_AZ_BALL) = { _
186  32, 33, 34, 35, 36, 37, 38, 39, 22, 23 _
187  , 26, 27, 44, 45, 46, 47, 48, 49, 50, 51 _ ' 10
188  , 52, 53, 54, 55, 56, 57, 58, 59, 30, 31 _
189  , 60, 61, 62, 63, 64, 65, 66, 67, 68, 69 _ ' 30
190  , 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 _
191  , 80, 81, 8, 9, 10, 11, 86, 87, 88, 89 _ ' 50
192  , 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 _
193  , 100, 16, 17, 21, 28, 105, 106, 82, 83, 84 _ ' 70
194  , 85, 29, 0, 1, 2, 3, 4, 5, 6, 7 _
195  , 40, 41, 42, 43, 12, 13, 14, 15, 101, 102 _ ' 90
196  , 110, 111, 112, 113, 114, 115, 116, 117, 19, 20}
197 
198  DECLARE CONSTRUCTOR( _
199  BYVAL AS UInt16 = PRUIO_DEF_ACTIVE _
200  , BYVAL AS UInt8 = PRUIO_DEF_AVRAGE _
201  , BYVAL AS UInt32 = PRUIO_DEF_ODELAY _
202  , BYVAL AS UInt8 = PRUIO_DEF_SDELAY)
203  DECLARE DESTRUCTOR()
204  DECLARE FUNCTION config CDECL( _
205  BYVAL AS UInt32 = PRUIO_DEF_SAMPLS _
206  , BYVAL AS UInt32 = PRUIO_DEF_STPMSK _
207  , BYVAL AS UInt32 = PRUIO_DEF_TIMERV _
208  , BYVAL AS UInt16 = PRUIO_DEF_LSLMOD) AS ZSTRING PTR
209  DECLARE FUNCTION Pin CDECL( _
210  BYVAL AS UInt8 _
211  , BYVAL AS UInt32 = 0) AS ZSTRING PTR
212  DECLARE FUNCTION setPin CDECL( _
213  BYVAL AS UInt8 _
214  , BYVAL AS UInt8) AS ZSTRING PTR
215  DECLARE FUNCTION nameBall CDECL( _
216  BYVAL AS UInt8) AS ZSTRING PTR
217  DECLARE FUNCTION rb_start CDECL() AS ZSTRING PTR
218  DECLARE FUNCTION mm_start CDECL( _
219  BYVAL AS UInt32 = 0 _
220  , BYVAL AS UInt32 = 0 _
221  , BYVAL AS UInt32 = 0 _
222  , BYVAL AS UInt32 = 0) AS ZSTRING PTR
223 END TYPE
224 
225