All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pruiotools.bas
Go to the documentation of this file.
/'* \file pruiotools.bas
\brief Common source code for the helper tools dts_custom.bas and dts_universal.bas.
This file contains common source code used by the device tree overlay
helper tools dts_custom.bas and dts_universal.bas. Do not edit (experts
only).
Licence: GPLv3
Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net
\since 0.2
'/
'* The name of the pinmux folders in /sys/devices/ocp.* (must match the definition in pruio.bas).
#DEFINE PMUX_NAME "pruio-"
TYPE AS UBYTE uint8 '*< Type alias.
' Convenience declarations.
#INCLUDE ONCE "../pruio/pruio_pins.bi"
'* The start of the source file
#DEFINE ALL_START _
"// dts file auto generated by pruio_config (don't edit)" _
!"\n/dts-v1/;" _
!"\n/plugin/;" _
!"\n" _
!"\n/ {" _
!"\n compatible = ""ti,beaglebone"", ""ti,beaglebone-black"";" _
!"\n" _
!"\n // identification" _
!"\n board-name = """ & FILE_NAME & """;" _
!"\n manufacturer = ""TJF"";" _
!"\n part-number = ""PruIoBBB"";" _
!"\n version = """ & VERS_NAME & """;" _
!"\n" _
!"\n // state the resources this cape uses" _
!"\n exclusive-use ="
'* An entry line for the `exclusive-use =` section.
#DEFINE ENTRY_EXCL(_T_) !"\n """ & _T_ & ""","
'* The end of the source file (pinmux setting).
#DEFINE ALL_END _
!"\n fragment@2 {" _
!"\n target = <&pruss>;" _
!"\n __overlay__ {" _
!"\n status = ""okay"";"_
!"\n };" _
!"\n };" _
!"\n };"
'* The start of fragment0 in the source file (pinmux settings).
#DEFINE FRAG0_START _
!"\n ""pruss"";" _
!"\n" _
!"\n fragment@0 {" _
!"\n target = <&am33xx_pinmux>;" _
!"\n __overlay__ {"
'* The end of fragment0 in the source file (pinmux settings).
#DEFINE FRAG0_END _
!"\n };" _
!"\n };"
'* The start of fragment1 in the source file (pinmux_helper).
#DEFINE FRAG1_START _
!"\n fragment@1 {" _
!"\n target = <&ocp>;" _
!"\n __overlay__ {"
'* The end of fragment1 in the source file (pinmux_helper).
#DEFINE FRAG1_END _
!"\n };" _
!"\n };"
'* Enumerators for pin modes.
ENUM
NP = &b001000 '*< no resistor connected
PU = &b010000 '*< pullup resistor connected
PD = &b000000 '*< pulldown resistor connected
RX = &b100000 '*< input receiver enabled
_O_ = NP '*< setting for an output pin.
_I_ = RX + PD '*< setting for an input pin.
I_O = RX + NP '*< setting for an in-/out-put pin.
IOD = RX + NP '*< setting for an in-/out-put pin.
TMRi = _I_ '*< setting for a TIMER input pin.
TMRo = _O_ '*< setting for a TIMER output pin.
CAPi = _I_ '*< setting for a CAP input pin.
CAPo = _O_ '*< setting for a CAP output pin.
QEPi = _I_ '*< setting for a QEP input pin.
QEPo = _O_ '*< setting for a QEP output pin (sync).
PWMi = _I_ '*< setting for a PWM input pin (sync).
PWMo = _O_ '*< setting for a PWM output pin.
END ENUM
'* The default settings for the GPIO modes.
#DEFINE GPIO_DEF CHR( _
7 + RX + NP _ ' input, open (no resistor)
, 7 + RX + PU _ ' input, pullup resistor
, 7 + RX + PD _ ' input, pulldown resistor
, 7 + NP _ ' output (no resistor)
)
'* Macro to delete the pin configuration for a pin set array.
#DEFINE PIN_DEL(_A_) FOR i AS LONG = 0 TO UBOUND(_A_) : M(_A_(i)) = "" : NEXT
'* The array to be filled with modus settings for all pins.
DIM SHARED AS STRING M(109)
/'* \brief Create lines for fragment0 for all settings of a pin.
\param I The index (ball number) of the pin in global array M.
\returns A string containing several lines with pin settings for fragment0.
FIXME
'/
FUNCTION f0custom(BYVAL I AS UBYTE) AS STRING
VAR x = HEX(ASC(M(I)), 2) _
, b4 = HEX(I * 4, 3)
SELECT CASE AS CONST I
CASE 89 : b4 = "1A0 0x2F 0x" & b4
CASE 104 : b4 = "164 0x2F 0x" & b4
CASE 106 : b4 = "1B4 0x2F 0x" & b4
CASE 108 : b4 = "1A8 0x2F 0x" & b4
END SELECT
RETURN !"\n 0x" & b4 & " 0x" & x
END FUNCTION
/'* \brief Create lines for fragment0 for all settings of a pin.
\param I The index (ball number) of the pin in global array M.
\returns A string containing several lines with pin settings for fragment0.
FIXME
'/
FUNCTION f0entry(BYVAL I AS UBYTE) AS STRING
VAR r = "" _
, b0 = HEX(I, 2) _
, b4 = HEX(I * 4, 3)
SELECT CASE AS CONST I
CASE 89 : b4 = "1A0 0x2F 0x" & b4
CASE 104 : b4 = "164 0x2F 0x" & b4
CASE 106 : b4 = "1B4 0x2F 0x" & b4
CASE 108 : b4 = "1A8 0x2F 0x" & b4
END SELECT
FOR j AS LONG = 0 TO LEN(M(I)) - 1
VAR x = HEX(M(I)[j], 2) _
, n = b0 & "_" & x
r &= _
!"\n B" & n & ": " & n _
& " {pinctrl-single,pins = <0x" & b4 & " 0x" & x & ">;};"
NEXT : RETURN r
END FUNCTION
/'* \brief Create lines for fragment1 for all settings of a pin.
\param I The index (ball number) of the pin in global array M.
\returns A string containing an entry with pin settings for fragment1.
FIXME
\note The maximum number of configurations for a pin is 36.
'/
FUNCTION f1entry(BYVAL I AS UBYTE) AS STRING
VAR _
j = 0 _
, tn = HEX(I, 2) _
, t0 = _
!"\n " & PMUX_NAME & tn & " {" _
!"\n compatible = ""bone-pinmux-helper"";" _
!"\n status = ""okay"";" _
!"\n pinctrl-names = " _
, t1 = _
!"\n };" _
, l = "" _
, n = ""
FOR j = 0 TO LEN(M(I)) - 2
VAR t = HEX(M(I)[j], 2)
n &= """x" & t & """, "
l &= !"\n pinctrl-" & j & " = <&B" & tn & "_" & t & ">;"
NEXT
VAR t = HEX(M(I)[j], 2)
n &= """x" & t & """;"
l &= !"\n pinctrl-" & j & " = <&B" & tn & "_" & t & ">;"
RETURN t0 & n & l & t1
END FUNCTION
/'* \brief Get header pin connected to CPU ball.
\param Ball The CPU ball number.
\returns A string pointer (don't free it) on success (otherwise zero).
\since 0.2
This function creates a text description of the header pin connected to
a CPU ball. The returned string is owned by this function and must not
be freed.
When the CPU ball is not connected to a header pin, this function
returns 0 (zero).
'/
FUNCTION nameBall CDECL(BYVAL Ball AS UBYTE) AS ZSTRING PTR
SELECT CASE AS CONST Ball ' find name
CASE 6 : RETURN @"P8.03"
CASE 7 : RETURN @"P8.04"
CASE 2 : RETURN @"P8.05"
CASE 3 : RETURN @"P8.06"
CASE 36 : RETURN @"P8.07"
CASE 37 : RETURN @"P8.08"
CASE 39 : RETURN @"P8.09"
CASE 38 : RETURN @"P8.10"
CASE 13 : RETURN @"P8.11"
CASE 12 : RETURN @"P8.12"
CASE 9 : RETURN @"P8.13"
CASE 10 : RETURN @"P8.14"
CASE 15 : RETURN @"P8.15"
CASE 14 : RETURN @"P8.16"
CASE 11 : RETURN @"P8.17"
CASE 35 : RETURN @"P8.18"
CASE 8 : RETURN @"P8.19"
CASE 33 : RETURN @"P8.20"
CASE 32 : RETURN @"P8.21"
CASE 5 : RETURN @"P8.22"
CASE 4 : RETURN @"P8.23"
CASE 1 : RETURN @"P8.24"
CASE 0 : RETURN @"P8.25"
CASE 31 : RETURN @"P8.26"
CASE 56 : RETURN @"P8.27"
CASE 58 : RETURN @"P8.28"
CASE 57 : RETURN @"P8.29"
CASE 59 : RETURN @"P8.30"
CASE 54 : RETURN @"P8.31"
CASE 55 : RETURN @"P8.32"
CASE 53 : RETURN @"P8.33"
CASE 51 : RETURN @"P8.34"
CASE 52 : RETURN @"P8.35"
CASE 50 : RETURN @"P8.36"
CASE 48 : RETURN @"P8.37"
CASE 49 : RETURN @"P8.38"
CASE 46 : RETURN @"P8.39"
CASE 47 : RETURN @"P8.40"
CASE 44 : RETURN @"P8.41"
CASE 45 : RETURN @"P8.42"
CASE 42 : RETURN @"P8.43"
CASE 43 : RETURN @"P8.44"
CASE 40 : RETURN @"P8.45"
CASE 41 : RETURN @"P8.46"
CASE 28 : RETURN @"P9.11"
CASE 30 : RETURN @"P9.12"
CASE 29 : RETURN @"P9.13"
CASE 18 : RETURN @"P9.14"
CASE 16 : RETURN @"P9.15"
CASE 19 : RETURN @"P9.16"
CASE 87 : RETURN @"P9.17"
CASE 86 : RETURN @"P9.18"
CASE 95 : RETURN @"P9.19"
CASE 94 : RETURN @"P9.20"
CASE 85 : RETURN @"P9.21"
CASE 84 : RETURN @"P9.22"
CASE 17 : RETURN @"P9.23"
CASE 97 : RETURN @"P9.24"
CASE 107 : RETURN @"P9.25"
CASE 96 : RETURN @"P9.26"
CASE 105 : RETURN @"P9.27"
CASE 103 : RETURN @"P9.28"
CASE 101 : RETURN @"P9.29"
CASE 102 : RETURN @"P9.30"
CASE 100 : RETURN @"P9.31"
CASE 109 : RETURN @"P9.41"
CASE 89 : RETURN @"P9.42"
END SELECT : RETURN 0
END FUNCTION