libpruio  0.2
Input/Output driver for digital/analog lines on Beagleboard hardware
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pruiotools.bas
Go to the documentation of this file.
1 /'* \file pruiotools.bas
2 \brief Common source code for the helper tools dts_custom.bas and dts_universal.bas.
3 
4 This file contains common source code used by the device tree overlay
5 helper tools dts_custom.bas and dts_universal.bas. Do not edit (experts
6 only).
7 
8 Licence: GPLv3
9 
10 Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net
11 
12 \since 0.2
13 
14 '/
15 
16 '* The name of the pinmux folders in /sys/devices/ocp.* (must match the definition in pruio.bas).
17 #DEFINE PMUX_NAME "pruio-"
18 TYPE AS UBYTE uint8 '*< Type alias.
19 ' Convenience declarations.
20 #INCLUDE ONCE "../pruio/pruio_pins.bi"
21 
22 '* The start of the source file
23 #DEFINE ALL_START _
24  "// dts file auto generated by pruio_config (don't edit)" _
25  !"\n/dts-v1/;" _
26  !"\n/plugin/;" _
27  !"\n" _
28  !"\n/ {" _
29  !"\n compatible = ""ti,beaglebone"", ""ti,beaglebone-black"";" _
30  !"\n" _
31  !"\n // identification" _
32  !"\n board-name = """ & FILE_NAME & """;" _
33  !"\n manufacturer = ""TJF"";" _
34  !"\n part-number = ""PruIoBBB"";" _
35  !"\n version = """ & VERS_NAME & """;" _
36  !"\n" _
37  !"\n // state the resources this cape uses" _
38  !"\n exclusive-use ="
39 
40 '* An entry line for the `exclusive-use =` section.
41 #DEFINE ENTRY_EXCL(_T_) !"\n """ & _T_ & ""","
42 
43 '* The end of the source file (pinmux setting).
44 #DEFINE ALL_END _
45  !"\n fragment@2 {" _
46  !"\n target = <&pruss>;" _
47  !"\n __overlay__ {" _
48  !"\n status = ""okay"";"_
49  !"\n };" _
50  !"\n };" _
51  !"\n };"
52 
53 
54 '* The start of fragment0 in the source file (pinmux settings).
55 #DEFINE FRAG0_START _
56  !"\n ""pruss"";" _
57  !"\n" _
58  !"\n fragment@0 {" _
59  !"\n target = <&am33xx_pinmux>;" _
60  !"\n __overlay__ {"
61 
62 '* The end of fragment0 in the source file (pinmux settings).
63 #DEFINE FRAG0_END _
64  !"\n };" _
65  !"\n };"
66 
67 
68 '* The start of fragment1 in the source file (pinmux_helper).
69 #DEFINE FRAG1_START _
70  !"\n fragment@1 {" _
71  !"\n target = <&ocp>;" _
72  !"\n __overlay__ {"
73 
74 '* The end of fragment1 in the source file (pinmux_helper).
75 #DEFINE FRAG1_END _
76  !"\n };" _
77  !"\n };"
78 
79 
80 '* Enumerators for pin modes.
81 ENUM
82  NP = &b001000 '*< no resistor connected
83  PU = &b010000 '*< pullup resistor connected
84  PD = &b000000 '*< pulldown resistor connected
85  RX = &b100000 '*< input receiver enabled
86 
87  _O_ = NP '*< setting for an output pin.
88  _I_ = RX + PD '*< setting for an input pin.
89  I_O = RX + NP '*< setting for an in-/out-put pin.
90  IOD = RX + NP '*< setting for an in-/out-put pin.
91 
92  TMRi = _I_ '*< setting for a TIMER input pin.
93  TMRo = _O_ '*< setting for a TIMER output pin.
94  CAPi = _I_ '*< setting for a CAP input pin.
95  CAPo = _O_ '*< setting for a CAP output pin.
96  QEPi = _I_ '*< setting for a QEP input pin.
97  QEPo = _O_ '*< setting for a QEP output pin (sync).
98  PWMi = _I_ '*< setting for a PWM input pin (sync).
99  PWMo = _O_ '*< setting for a PWM output pin.
100 END ENUM
101 
102 '* The default settings for the GPIO modes.
103 #DEFINE GPIO_DEF CHR( _
104  7 + RX + NP _ ' input, open (no resistor)
105  , 7 + RX + PU _ ' input, pullup resistor
106  , 7 + RX + PD _ ' input, pulldown resistor
107  , 7 + NP _ ' output (no resistor)
108  )
109 
110 '* Macro to delete the pin configuration for a pin set array.
111 #DEFINE PIN_DEL(_A_) FOR i AS LONG = 0 TO UBOUND(_A_) : M(_A_(i)) = "" : NEXT
112 
113 '* The array to be filled with modus settings for all pins.
114 DIM SHARED AS STRING M(109)
115 
116 
117 
118 /'* \brief Create lines for fragment0 for all settings of a pin.
119 \param I The index (ball number) of the pin in global array M.
120 \returns A string containing several lines with pin settings for fragment0.
121 
122 FIXME
123 
124 '/
125 FUNCTION f0custom(BYVAL I AS UBYTE) AS STRING
126  VAR x = HEX(ASC(M(I)), 2) _
127  , b4 = HEX(I * 4, 3)
128 
129  SELECT CASE AS CONST I
130  CASE 89 : b4 = "1A0 0x2F 0x" & b4
131  CASE 104 : b4 = "164 0x2F 0x" & b4
132  CASE 106 : b4 = "1B4 0x2F 0x" & b4
133  CASE 108 : b4 = "1A8 0x2F 0x" & b4
134  END SELECT
135  RETURN !"\n 0x" & b4 & " 0x" & x
136 END FUNCTION
137 
138 
139 /'* \brief Create lines for fragment0 for all settings of a pin.
140 \param I The index (ball number) of the pin in global array M.
141 \returns A string containing several lines with pin settings for fragment0.
142 
143 FIXME
144 
145 '/
146 FUNCTION f0entry(BYVAL I AS UBYTE) AS STRING
147  VAR r = "" _
148  , b0 = HEX(I, 2) _
149  , b4 = HEX(I * 4, 3)
150 
151  SELECT CASE AS CONST I
152  CASE 89 : b4 = "1A0 0x2F 0x" & b4
153  CASE 104 : b4 = "164 0x2F 0x" & b4
154  CASE 106 : b4 = "1B4 0x2F 0x" & b4
155  CASE 108 : b4 = "1A8 0x2F 0x" & b4
156  END SELECT
157 
158  FOR j AS LONG = 0 TO LEN(M(I)) - 1
159  VAR x = HEX(M(I)[j], 2) _
160  , n = b0 & "_" & x
161  r &= _
162  !"\n B" & n & ": " & n _
163  & " {pinctrl-single,pins = <0x" & b4 & " 0x" & x & ">;};"
164  NEXT : RETURN r
165 END FUNCTION
166 
167 
168 /'* \brief Create lines for fragment1 for all settings of a pin.
169 \param I The index (ball number) of the pin in global array M.
170 \returns A string containing an entry with pin settings for fragment1.
171 
172 FIXME
173 
174 \note The maximum number of configurations for a pin is 36.
175 
176 '/
177 FUNCTION f1entry(BYVAL I AS UBYTE) AS STRING
178  VAR _
179  j = 0 _
180  , tn = HEX(I, 2) _
181  , t0 = _
182  !"\n " & PMUX_NAME & tn & " {" _
183  !"\n compatible = ""bone-pinmux-helper"";" _
184  !"\n status = ""okay"";" _
185  !"\n pinctrl-names = " _
186  , t1 = _
187  !"\n };" _
188  , l = "" _
189  , n = ""
190 
191  FOR j = 0 TO LEN(M(I)) - 2
192  VAR t = HEX(M(I)[j], 2)
193  n &= """x" & t & """, "
194  l &= !"\n pinctrl-" & j & " = <&B" & tn & "_" & t & ">;"
195  NEXT
196  VAR t = HEX(M(I)[j], 2)
197  n &= """x" & t & """;"
198  l &= !"\n pinctrl-" & j & " = <&B" & tn & "_" & t & ">;"
199  RETURN t0 & n & l & t1
200 END FUNCTION
201 
202 
203 /'* \brief Get header pin connected to CPU ball.
204 \param Ball The CPU ball number.
205 \returns A string pointer (don't free it) on success (otherwise zero).
206 \since 0.2
207 
208 This function creates a text description of the header pin connected to
209 a CPU ball. The returned string is owned by this function and must not
210 be freed.
211 
212 When the CPU ball is not connected to a header pin, this function
213 returns 0 (zero).
214 
215 '/
216 FUNCTION nameBall CDECL(BYVAL Ball AS UBYTE) AS ZSTRING PTR
217  SELECT CASE AS CONST Ball ' find name
218  CASE 6 : RETURN @"P8.03"
219  CASE 7 : RETURN @"P8.04"
220  CASE 2 : RETURN @"P8.05"
221  CASE 3 : RETURN @"P8.06"
222  CASE 36 : RETURN @"P8.07"
223  CASE 37 : RETURN @"P8.08"
224  CASE 39 : RETURN @"P8.09"
225  CASE 38 : RETURN @"P8.10"
226  CASE 13 : RETURN @"P8.11"
227  CASE 12 : RETURN @"P8.12"
228  CASE 9 : RETURN @"P8.13"
229  CASE 10 : RETURN @"P8.14"
230  CASE 15 : RETURN @"P8.15"
231  CASE 14 : RETURN @"P8.16"
232  CASE 11 : RETURN @"P8.17"
233  CASE 35 : RETURN @"P8.18"
234  CASE 8 : RETURN @"P8.19"
235  CASE 33 : RETURN @"P8.20"
236  CASE 32 : RETURN @"P8.21"
237  CASE 5 : RETURN @"P8.22"
238  CASE 4 : RETURN @"P8.23"
239  CASE 1 : RETURN @"P8.24"
240  CASE 0 : RETURN @"P8.25"
241  CASE 31 : RETURN @"P8.26"
242  CASE 56 : RETURN @"P8.27"
243  CASE 58 : RETURN @"P8.28"
244  CASE 57 : RETURN @"P8.29"
245  CASE 59 : RETURN @"P8.30"
246  CASE 54 : RETURN @"P8.31"
247  CASE 55 : RETURN @"P8.32"
248  CASE 53 : RETURN @"P8.33"
249  CASE 51 : RETURN @"P8.34"
250  CASE 52 : RETURN @"P8.35"
251  CASE 50 : RETURN @"P8.36"
252  CASE 48 : RETURN @"P8.37"
253  CASE 49 : RETURN @"P8.38"
254  CASE 46 : RETURN @"P8.39"
255  CASE 47 : RETURN @"P8.40"
256  CASE 44 : RETURN @"P8.41"
257  CASE 45 : RETURN @"P8.42"
258  CASE 42 : RETURN @"P8.43"
259  CASE 43 : RETURN @"P8.44"
260  CASE 40 : RETURN @"P8.45"
261  CASE 41 : RETURN @"P8.46"
262  CASE 28 : RETURN @"P9.11"
263  CASE 30 : RETURN @"P9.12"
264  CASE 29 : RETURN @"P9.13"
265  CASE 18 : RETURN @"P9.14"
266  CASE 16 : RETURN @"P9.15"
267  CASE 19 : RETURN @"P9.16"
268  CASE 87 : RETURN @"P9.17"
269  CASE 86 : RETURN @"P9.18"
270  CASE 95 : RETURN @"P9.19"
271  CASE 94 : RETURN @"P9.20"
272  CASE 85 : RETURN @"P9.21"
273  CASE 84 : RETURN @"P9.22"
274  CASE 17 : RETURN @"P9.23"
275  CASE 97 : RETURN @"P9.24"
276  CASE 107 : RETURN @"P9.25"
277  CASE 96 : RETURN @"P9.26"
278  CASE 105 : RETURN @"P9.27"
279  CASE 103 : RETURN @"P9.28"
280  CASE 101 : RETURN @"P9.29"
281  CASE 102 : RETURN @"P9.30"
282  CASE 100 : RETURN @"P9.31"
283  CASE 109 : RETURN @"P9.41"
284  CASE 89 : RETURN @"P9.42"
285  END SELECT : RETURN 0
286 END FUNCTION
287