summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c')
-rw-r--r--c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c b/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c
new file mode 100644
index 0000000000..79d6b1e504
--- /dev/null
+++ b/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c
@@ -0,0 +1,88 @@
+/**
+ * @file pinmux.c
+ *
+ * @ingroup tms570
+ *
+ * @brief I/O Multiplexing Module (IOMM) basic support
+ */
+
+/*
+ * Copyright (c) 2015 Premysl Houdek <kom541000@gmail.com>
+ *
+ * Google Summer of Code 2014 at
+ * Czech Technical University in Prague
+ * Zikova 1903/4
+ * 166 36 Praha 6
+ * Czech Republic
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <bsp/tms570.h>
+#include <bsp/tms570-pinmux.h>
+
+/**
+ * @brief select desired function of pin/ball
+ *
+ * The function setups multiplexer to interconnect pin with
+ * specified function/peripheral. Pin number is index into pinmux
+ * entries array. Predefined values for pins are in a format
+ * TMS570_BALL_<column><row> (for example TMS570_BALL_N19).
+ * The multiplexer allows to interconnect one pin to multiple
+ * signal sources/sings in the theory but it is usually bad choice.
+ * The function sets only specified function and clears all other
+ * connections.
+ *
+ * @param[in] pin_num pin/ball identifier (index into pinmux array)
+ * @param[in] pin_fnc function number 0 .. 7, if value TMS570_PIN_FNC_AUTO
+ * is specified then pin function is extracted from
+ * pin_num argument
+ * @retval Void
+ */
+void
+tms570_bsp_pin_set_function(int pin_num, int pin_fnc)
+{
+ unsigned int pin_shift;
+ typeof(TMS570_IOMM.PINMUX.PINMMR0) *pinmmrx;
+
+ if ( pin_fnc == TMS570_PIN_FNC_AUTO ) {
+ pin_fnc = (pin_num & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT;
+ }
+ pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT;
+
+ pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0;
+ pinmmrx += (pin_num >> 2);
+ pin_shift = (pin_num & 0x3)*8;
+ *pinmmrx = (*pinmmrx & ~(0xff << pin_shift)) | (1 << (pin_fnc + pin_shift));
+}
+
+/**
+ * @brief clear connection between pin and specified peripherals/function
+ *
+ * This function switches off given connection and leaves rest
+ * of multiplexer setup intact.
+ *
+ * @param[in] pin_num pin/ball identifier (index into pinmux array)
+ * @param[in] pin_fnc function number 0 .. 7, if value TMS570_PIN_FNC_AUTO
+ * is specified then pin function is extracted from
+ * pin_num argument
+ * @retval Void
+ */
+void
+tms570_bsp_pin_clear_function(int pin_num, int pin_fnc)
+{
+ unsigned int pin_shift;
+ typeof(TMS570_IOMM.PINMUX.PINMMR0) *pinmmrx;
+
+ if ( pin_fnc == TMS570_PIN_FNC_AUTO ) {
+ pin_fnc = (pin_num & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT;
+ }
+ pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT;
+
+ pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0;
+ pinmmrx += (pin_num >> 2);
+ pin_shift = (pin_num & 0x3)*8;
+ *pinmmrx = *pinmmrx & ~(1 << (pin_fnc+pin_shift));
+}