source: rtems/c/src/lib/libbsp/arm/tms570/pinmux/pinmux.c @ e5d5767e

5
Last change on this file since e5d5767e was e5d5767e, checked in by Premysl Houdek <kom541000@…>, on 11/12/15 at 22:11:28

bsp/tms570: Pinmux support and EMAC pin definition added

Signed-off-by: Premysl Houdek <kom541000@…>

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file pinmux.c
3 *
4 * @ingroup tms570
5 *
6 * @brief I/O Multiplexing Module (IOMM) basic support
7 */
8
9/*
10 * Copyright (c) 2015 Premysl Houdek <kom541000@gmail.com>
11 *
12 * Google Summer of Code 2014 at
13 * Czech Technical University in Prague
14 * Zikova 1903/4
15 * 166 36 Praha 6
16 * Czech Republic
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 */
22
23#include <bsp/tms570.h>
24#include <bsp/tms570-pinmux.h>
25
26/**
27 * @brief select desired function of pin/ball
28 *
29 * The function setups multiplexer to interconnect pin with
30 * specified function/peripheral. Pin number is index into pinmux
31 * entries array. Predefined values for pins are in a format
32 * TMS570_BALL_<column><row> (for example TMS570_BALL_N19).
33 * The multiplexer allows to interconnect one pin to multiple
34 * signal sources/sings in the theory but it is usually bad choice.
35 * The function sets only specified function and clears all other
36 * connections.
37 *
38 * @param[in] pin_num  pin/ball identifier (index into pinmux array)
39 * @param[in] pin_fnc  function number 0 .. 7, if value TMS570_PIN_FNC_AUTO
40 *                     is specified then pin function is extracted from
41 *                     pin_num argument
42 * @retval Void
43 */
44void
45tms570_bsp_pin_set_function(int pin_num, int pin_fnc)
46{
47  unsigned int pin_shift;
48  typeof(TMS570_IOMM.PINMUX.PINMMR0) *pinmmrx;
49
50  if ( pin_fnc == TMS570_PIN_FNC_AUTO ) {
51    pin_fnc = (pin_num & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT;
52  }
53  pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT;
54
55  pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0;
56  pinmmrx += (pin_num >> 2);
57  pin_shift = (pin_num & 0x3)*8;
58  *pinmmrx = (*pinmmrx & ~(0xff << pin_shift)) | (1 << (pin_fnc + pin_shift));
59}
60
61/**
62 * @brief clear connection between pin and specified peripherals/function
63 *
64 * This function switches off given connection and leaves rest
65 * of multiplexer setup intact.
66 *
67 * @param[in] pin_num  pin/ball identifier (index into pinmux array)
68 * @param[in] pin_fnc  function number 0 .. 7, if value TMS570_PIN_FNC_AUTO
69 *                     is specified then pin function is extracted from
70 *                     pin_num argument
71 * @retval Void
72 */
73void
74tms570_bsp_pin_clear_function(int pin_num, int pin_fnc)
75{
76  unsigned int pin_shift;
77  typeof(TMS570_IOMM.PINMUX.PINMMR0) *pinmmrx;
78
79  if ( pin_fnc == TMS570_PIN_FNC_AUTO ) {
80    pin_fnc = (pin_num & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT;
81  }
82  pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT;
83
84  pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0;
85  pinmmrx += (pin_num >> 2);
86  pin_shift = (pin_num & 0x3)*8;
87  *pinmmrx = *pinmmrx & ~(1 << (pin_fnc+pin_shift));
88}
Note: See TracBrowser for help on using the repository browser.