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/sinks 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 | */ |
---|
44 | void |
---|
45 | tms570_bsp_pin_set_function(int pin_num, int pin_fnc) |
---|
46 | { |
---|
47 | unsigned int pin_shift; |
---|
48 | volatile uint32_t *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 | tms570_bsp_pin_to_pinmmrx(&pinmmrx, &pin_shift, pin_num); |
---|
54 | *pinmmrx = (*pinmmrx & ~(0xff << pin_shift)) | (1 << (pin_fnc + pin_shift)); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * @brief clear connection between pin and specified peripherals/function |
---|
59 | * |
---|
60 | * This function switches off given connection and leaves rest |
---|
61 | * of multiplexer setup intact. |
---|
62 | * |
---|
63 | * @param[in] pin_num pin/ball identifier (index into pinmux array) |
---|
64 | * @param[in] pin_fnc function number 0 .. 7, if value TMS570_PIN_FNC_AUTO |
---|
65 | * is specified then pin function is extracted from |
---|
66 | * pin_num argument |
---|
67 | * @retval Void |
---|
68 | */ |
---|
69 | void |
---|
70 | tms570_bsp_pin_clear_function(int pin_num, int pin_fnc) |
---|
71 | { |
---|
72 | unsigned int pin_shift; |
---|
73 | volatile uint32_t *pinmmrx; |
---|
74 | |
---|
75 | if ( pin_fnc == TMS570_PIN_FNC_AUTO ) { |
---|
76 | pin_fnc = (pin_num & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT; |
---|
77 | } |
---|
78 | tms570_bsp_pin_to_pinmmrx(&pinmmrx, &pin_shift, pin_num); |
---|
79 | *pinmmrx = *pinmmrx & ~(1 << (pin_fnc+pin_shift)); |
---|
80 | } |
---|