libpruio  0.0
AM33xx-PRU driver for digital input / output and analog input
 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 contains
5 the declarations.
6 
7 '/
8 
9 #IFNDEF __PRUIO_COMPILING__
10 #INCLIB "pruio"
11 #ENDIF
12 
13 '* tell pruss_intc_mapping.bi that we use ARM33xx
14 #DEFINE AM33XX
15 
16 '* common macros, shared with PRU pasm compiler
17 #INCLUDE ONCE "pruio.hp"
18 '* the PRUSS driver library
19 #INCLUDE ONCE "BBB/prussdrv.bi"
20 '* PRUSS driver interrupt settings
21 #INCLUDE ONCE "BBB/pruss_intc_mapping.bi"
22 
23 '* the channel for PRU messages (must match PRUIO_IRPT)
24 #DEFINE PRUIO_CHAN CHANNEL5
25 '* the mask to enable PRU interrupts (must match PRUIO_IRPT)
26 #DEFINE PRUIO_MASK PRU_EVTOUT5_HOSTEN_MASK
27 '* the event for PRU messages (mapping, must match PRUIO_IRPT)
28 #DEFINE PRUIO_EMAP PRU_EVTOUT5
29 '* the event for PRU messages (must match PRUIO_IRPT)
30 #DEFINE PRUIO_EVNT PRU_EVTOUT_5
31 
32 '* the default setting for avaraging
33 #DEFINE PRUIO_DEF_AVRAGE 4
34 '* the default value for open delay in channel settings
35 #DEFINE PRUIO_DEF_ODELAY 183
36 '* the default value for sample delay in channel settings
37 #DEFINE PRUIO_DEF_SDELAY 0
38 '* the default PRU subsystem to use
39 #DEFINE PRUIO_DEF_PRUSS 1
40 '* the default number of samples to use (configures single mode)
41 #DEFINE PRUIO_DEF_SAMPLS 0
42 '* the default step mask (steps 1 to 8 for AIN0 to AIN7, no charge step)
43 #DEFINE PRUIO_DEF_STPMSK &b111111110
44 '* the default timer value (sampling rate)
45 #DEFINE PRUIO_DEF_TIMERV 0
46 '* the default bit mode (4 = 16 bit encoding)
47 #DEFINE PRUIO_DEF_LSLMOD 4
48 '* the default clock divisor (0 = full speed AFE = 2.4 MHz)
49 #DEFINE PRUIO_DEF_CLKDIV 0
50 
51 '* convenience macro to configure an input pin without pullup or pulldown
52 #define PRUIO_IN &b00101111
53 '* convenience macro to configure an low input pin (with pulldown resistor)
54 #define PRUIO_IN_0 &b00100111
55 '* convenience macro to configure an high input pin (with pullup resistor)
56 #define PRUIO_IN_1 &b00110111
57 '* convenience macro to configure an output pin initial low
58 #define PRUIO_OUT0 &b00001111
59 '* convenience macro to configure an output pin initial high
60 #define PRUIO_OUT1 &b10001111
61 '* convenience macro to re-configure a pin to its original (initial) state
62 #define PRUIO_PIN_RESET &b11111111
63 
65  PRUIO_UNLOCK_CURR '*< unlock a pin, don't change the configuration
66  PRUIO_UNLOCK_ORIG '*< unlock a pin, change to original (initial) configuration
67  PRUIO_UNLOCK_NEW '*< unlock a pin, change to parameter configuration
68  PRUIO_LOCK_CURR '*< lock a pin, don't change the configuration
69  PRUIO_LOCK_ORIG '*< lock a pin, change to original (initial) configuration
70  PRUIO_LOCK_NEW '*< lock a pin, change to parameter configuration
71  PRUIO_LOCK_CHECK '*< don't change pin locking, skip operation if pin is locked
72 END ENUM
73 
74 TYPE AS UINTEGER uint32 '*< 32 bit unsigned integer data type
75 TYPE AS USHORT uint16 '*< 16 bit unsigned integer data type
76 TYPE AS UBYTE uint8 '*< 8 bit unsigned integer data type
77 TYPE AS INTEGER int32 '*< 32 bit signed integer data type
78 TYPE AS SHORT int16 '*< 16 bit signed integer data type
79 TYPE AS BYTE int8 '*< 8 bit signed integer data type
80 
81 '* user defined type for a step setting
82 TYPE AdcSteps
83  AS uint32 _
84  Confg _ '*< context for configuration register
85  , Delay '*< context for delay register
86 END TYPE
87 
88 '* user defined type for a GPIO setting
89 TYPE GpioSet
90  AS uint32 _
91  Addr _ '*< base address of GPIO device
92  , ClrM _ '*< mask to clear pins to low
93  , SetM _ '*< mask to set pins to high
94  , OutE _ '*< mask to enable pins for output
95  , Stat _ '*< current state of pins (mixed)
96  , StaO _ '*< current state of output pins
97  , fe1 _ '*< future expansion
98  , fe2
99 END TYPE
100 
101 '* user defined type (class) for the driver structure
102 TYPE PruIo
103 '' don't change the order from here
104  AS uint32 _
105  Samples _ '*< number of samples
106  , TimerVal _ '*< timer value in [ns]
107  , StepMask '*< mask to specify active channels
108  AS uint16 _
109  LslMode _ '*< bit shift modus (0 to 4)
110  , ClockDiv '*< divisor for ADC input clock (register 0x4C)
111 
112  AS uint32 _
113  AdcReg24 = 0 _ '*< ADC register IRQ_STATUS_RAW
114  , AdcReg28 = 0 _ '*< ADC register IRQ_STATUS
115  , AdcReg2C = 0 _ '*< ADC register IRQENABLE_SET
116  , AdcReg30 = 0 _ '*< ADC register IRQENABLE_CLR
117  , AdcReg34 = 0 _ '*< ADC register IRQWAKEUP
118  , AdcReg38 = 0 _ '*< ADC register DMAENABLE_SET
119  , AdcReg3C = 0 _ '*< ADC register DMAENABLE_CLR
120  , AdcReg40 = 0 '*< ADC register CRTL (bits 0, 1 and 2 gets set by driver)
121 
122  '* step configuration (charge step + 16 steps + idle step, by default steps 1 to 8 are used for AIN0 to AIN7)
123  AS AdcSteps St_p(17)
124 
125  AS uint32 PTR DRam '*< pointer to access PRU DRam
126 '' don't change the order to here
127 
128  AS ANY PTR ERam _ '*< pointer to read PRU external ram
129  , BallOrg '*< buffer pointer for original Ball configuration
130  AS uint32 PTR AdcOrg _ '*< buffer pointer for original ADC configuration (= 0 in case of ADC down at startup)
131  , GpioOrg '*< buffer pointer for original GPIO configuration
132  AS uint16 PTR Value '*< pointer to read sampled ADC input data
133  AS uint8 PTR BallRef _ '*< pointer to ball reference (GPIO# for CPU pins or lock)
134  , BallConf '*< pointer to ball configuration (CPU pin muxing)
135  AS ZSTRING PTR Errr = 0 '*< pointer for error messages
136  AS uint32 _
137  EOffs _ '*< the offset of the external memory (PRUSS-DDR)
138  , ESize _ '*< the size of the external memory (PRUSS-DDR)
139  , CSize _ '*< the size of the original configuration block
140  , PruNo _ '*< the PRU number to use (defaults to 1)
141  , PruEvtout _ '*< the interrupt channel to send commands to PRU
142  , PruIRam _ '*< the PRU instruction ram to load
143  , PruDRam '*< the PRU data ram
144  AS int16 _
145  ArmPruInt _ '*< the interrupt to send
146  , ChAz '*< number of active channels
147 
148  '* interrupt settings (we also set default interrupts, so that the other PRUSS can be used in parallel)
149  AS tpruss_intc_initdata IntcInit = _
150  TYPE<tpruss_intc_initdata>( _
151  { PRU0_PRU1_INTERRUPT _
152  , PRU1_PRU0_INTERRUPT _
153  , PRU0_ARM_INTERRUPT _
154  , PRU1_ARM_INTERRUPT _
155  , ARM_PRU0_INTERRUPT _
156  , ARM_PRU1_INTERRUPT _
157  , PRUIO_IRPT _
158  , CAST(BYTE, -1) }, _
159  { TYPE<tsysevt_to_channel_map>(PRU0_PRU1_INTERRUPT, CHANNEL1) _
160  , TYPE<tsysevt_to_channel_map>(PRU1_PRU0_INTERRUPT, CHANNEL0) _
161  , TYPE<tsysevt_to_channel_map>(PRU0_ARM_INTERRUPT, CHANNEL2) _
162  , TYPE<tsysevt_to_channel_map>(PRU1_ARM_INTERRUPT, CHANNEL3) _
163  , TYPE<tsysevt_to_channel_map>(ARM_PRU0_INTERRUPT, CHANNEL0) _
164  , TYPE<tsysevt_to_channel_map>(ARM_PRU1_INTERRUPT, CHANNEL1) _
165  , TYPE<tsysevt_to_channel_map>(PRUIO_IRPT, PRUIO_CHAN) _
166  , TYPE<tsysevt_to_channel_map>(-1, -1)}, _
167  { TYPE<tchannel_to_host_map>(CHANNEL0, PRU0) _
168  , TYPE<tchannel_to_host_map>(CHANNEL1, PRU1) _
169  , TYPE<tchannel_to_host_map>(CHANNEL2, PRU_EVTOUT0) _
170  , TYPE<tchannel_to_host_map>(CHANNEL3, PRU_EVTOUT1) _
171  , TYPE<tchannel_to_host_map>(PRUIO_CHAN, PRUIO_EMAP) _
172  , TYPE<tchannel_to_host_map>(-1, -1) }, _
173  (PRU0_HOSTEN_MASK OR PRU1_HOSTEN_MASK OR _
174  PRU_EVTOUT0_HOSTEN_MASK OR PRU_EVTOUT1_HOSTEN_MASK OR PRUIO_MASK) _
175  )
176 
177  AS GpioSet PTR Gpio '*< pointer to GPIO structure (current values)
178  '* initial GPIO definitions
180  TYPE<GpioSet>(&h44E07100uL, &h44E00408uL, 0, 0, 0, 0, 0, 0) _
181  , TYPE<GpioSet>(&h4804C100uL, &h44E000ACuL, 0, 0, 0, 0, 0, 0) _
182  , TYPE<GpioSet>(&h481AC100uL, &h44E000B0uL, 0, 0, 0, 0, 0, 0) _
183  , TYPE<GpioSet>(&h481AE100uL, &h44E000B4uL, 0, 0, 0, 0, 0, 0) _
184  }
185 
186  '* list of GPIO numbers, corresponding to ball index
187  AS uint8 BallGpio(PRUIO_BALL_AZ) = { _
188  32, 33, 34, 35, 36, 37, 38, 39, 22, 23 _
189  , 26, 27, 44, 45, 46, 47, 48, 49, 50, 51 _ ' 10
190  , 52, 53, 54, 55, 56, 57, 58, 59, 30, 31 _
191  , 60, 61, 62, 63, 64, 65, 66, 67, 68, 69 _ ' 30
192  , 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 _
193  , 80, 81, 8, 9, 10, 11, 86, 87, 88, 89 _ ' 50
194  , 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 _
195  , 100, 16, 17, 21, 28, 105, 106, 82, 83, 84 _ ' 70
196  , 85, 29, 0, 1, 2, 3, 4, 5, 6, 7 _
197  , 40, 41, 42, 43, 12, 13, 14, 15, 101, 102 _ ' 90
198  , 110, 111, 112, 113, 114, 115, 116, 117, 19, 20}
199 
200  DECLARE CONSTRUCTOR( _
201  BYVAL AS uint8 = PRUIO_DEF_AVRAGE _
202  , BYVAL AS uint32 = PRUIO_DEF_ODELAY _
203  , BYVAL AS uint8 = PRUIO_DEF_SDELAY _
204  , BYVAL AS uint8 = PRUIO_DEF_PRUSS)
205  DECLARE DESTRUCTOR()
206  DECLARE FUNCTION config CDECL( _
207  BYVAL AS uint32 = PRUIO_DEF_SAMPLS _
208  , BYVAL AS uint32 = PRUIO_DEF_STPMSK _
209  , BYVAL AS uint32 = PRUIO_DEF_TIMERV _
210  , BYVAL AS uint16 = PRUIO_DEF_LSLMOD _
211  , BYVAL AS uint16 = PRUIO_DEF_CLKDIV) AS ZSTRING PTR
212  DECLARE FUNCTION adc_step CDECL( _
213  BYVAL AS uint8 _
214  , BYVAL AS uint8 _
215  , BYVAL AS uint8 = PRUIO_DEF_AVRAGE _
216  , BYVAL AS uint8 = PRUIO_DEF_SDELAY _
217  , BYVAL AS uint32 = PRUIO_DEF_ODELAY) AS ZSTRING PTR
218 
219  DECLARE FUNCTION gpio_get CDECL( _
220  BYVAL AS uint8) AS uint32
221  DECLARE FUNCTION gpio_set CDECL( _
222  BYVAL AS uint8 _
223  , BYVAL AS uint8 = PRUIO_IN_0 _
224  , BYVAL AS uint8 = PRUIO_LOCK_CHECK) AS ZSTRING PTR
225  DECLARE FUNCTION gpio_out CDECL( _
226  BYVAL AS uint8 _
227  , BYVAL AS uint8 = 0) AS ZSTRING PTR
228  DECLARE FUNCTION gpio_get_config CDECL( _
229  BYVAL AS uint8) AS ZSTRING PTR
230 
231  DECLARE FUNCTION mm_trg_pin CDECL( _
232  BYVAL AS uint8 _
233  , BYVAL AS uint8 = 0 _
234  , BYVAL AS uint16 = 0) AS uint32
235  DECLARE FUNCTION mm_trg_ain CDECL( _
236  BYVAL AS uint8 _
237  , BYVAL AS int32 _
238  , BYVAL AS uint8 = 0 _
239  , BYVAL AS uint16 = 0) AS uint32
240  DECLARE FUNCTION mm_trg_pre CDECL( _
241  BYVAL AS uint8 _
242  , BYVAL AS int32 _
243  , BYVAL AS uint16 = 0 _
244  , BYVAL AS uint8 = 0) AS uint32
245  DECLARE FUNCTION mm_start CDECL( _
246  BYVAL AS uint32 = 0 _
247  , BYVAL AS uint32 = 0 _
248  , BYVAL AS uint32 = 0 _
249  , BYVAL AS uint32 = 0) AS ZSTRING PTR
250 END TYPE
251 
252