1 | /** |
---|
2 | * @file tms570-pinmux.h |
---|
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 | #ifndef LIBBSP_ARM_TMS570_PINMUX_H |
---|
24 | #define LIBBSP_ARM_TMS570_PINMUX_H |
---|
25 | |
---|
26 | #ifndef ASM |
---|
27 | #include <bsp/tms570.h> |
---|
28 | |
---|
29 | #ifdef __cplusplus |
---|
30 | extern "C" { |
---|
31 | #endif /* __cplusplus */ |
---|
32 | |
---|
33 | |
---|
34 | #define TMS570_PIN_NUM_SHIFT 0 |
---|
35 | #define TMS570_PIN_NUM_MASK 0x000007ff |
---|
36 | |
---|
37 | /* |
---|
38 | * Request clear of interconnection in setup |
---|
39 | * to ensure that previous peripheral to pin |
---|
40 | * connection is not enabled in parallel to other one. |
---|
41 | * Mask is ored with pin number in such list. |
---|
42 | */ |
---|
43 | #define TMS570_PIN_CLEAR_RQ_MASK 0x00000800 |
---|
44 | |
---|
45 | #define TMS570_PIN_FNC_SHIFT 12 |
---|
46 | #define TMS570_PIN_FNC_MASK 0x0000f000 |
---|
47 | |
---|
48 | #define TMS570_PIN_NUM_FNC_MASK 0x0000ffff |
---|
49 | |
---|
50 | #define TMS570_PIN_IN_ALT_SHIFT 16 |
---|
51 | #define TMS570_PIN_IN_ALT_MASK 0xffff0000 |
---|
52 | |
---|
53 | #define TMS570_PIN_FNC_AUTO (-1) |
---|
54 | |
---|
55 | #define TMS570_PIN_AND_FNC(pin, fnc) \ |
---|
56 | ((pin) | ((fnc) << TMS570_PIN_FNC_SHIFT)) |
---|
57 | |
---|
58 | #define TMS570_PIN_WITH_IN_ALT(pin_num_and_fnc, pin_in_alt_num_and_fnc) \ |
---|
59 | ((pin_num_and_fnc) | ((pin_in_alt_num_and_fnc) << TMS570_PIN_IN_ALT_SHIFT)) |
---|
60 | |
---|
61 | #define TMS570_BALL_WITH_MMR(mmrx, pos) \ |
---|
62 | ((pos) | ((mmrx) << 2)) |
---|
63 | |
---|
64 | /* Generic functions select pin to peripheral connection */ |
---|
65 | |
---|
66 | void tms570_bsp_pin_set_function(int pin_num, int pin_fnc); |
---|
67 | |
---|
68 | void tms570_bsp_pin_clear_function(int pin_num, int pin_fnc); |
---|
69 | |
---|
70 | void tms570_bsp_pin_config_one(uint32_t pin_num_and_fnc); |
---|
71 | |
---|
72 | void tms570_bsp_pinmmr_config(const uint32_t *pinmmr_values, int reg_start, int reg_count); |
---|
73 | |
---|
74 | static inline void |
---|
75 | tms570_bsp_pin_to_pinmmrx(volatile uint32_t **pinmmrx, unsigned int *pin_shift, |
---|
76 | int pin_num) |
---|
77 | { |
---|
78 | pin_num = (pin_num & TMS570_PIN_NUM_MASK) >> TMS570_PIN_NUM_SHIFT; |
---|
79 | *pinmmrx = &TMS570_IOMM.PINMUX.PINMMR0 + (pin_num >> 2); |
---|
80 | *pin_shift = (pin_num & 0x3)*8; |
---|
81 | } |
---|
82 | |
---|
83 | #define TMS570_PINMMR_REG_SINGLE_VAL_ACTION(reg, pin) \ |
---|
84 | (((((pin) & TMS570_PIN_NUM_MASK) >> 2 != (reg)) || ((pin) & TMS570_PIN_CLEAR_RQ_MASK))? 0: \ |
---|
85 | 1 << ((((pin) & TMS570_PIN_FNC_MASK) >> TMS570_PIN_FNC_SHIFT) + \ |
---|
86 | ((pin) & 3) * 8) \ |
---|
87 | ) |
---|
88 | |
---|
89 | #define TMS570_PINMMR_REG_VAL_ACTION(reg, pin) \ |
---|
90 | TMS570_PINMMR_REG_SINGLE_VAL_ACTION(reg, pin) | \ |
---|
91 | ((pin) & TMS570_PIN_IN_ALT_MASK? \ |
---|
92 | TMS570_PINMMR_REG_SINGLE_VAL_ACTION(reg, (pin) >> TMS570_PIN_IN_ALT_SHIFT ): \ |
---|
93 | 0) | |
---|
94 | |
---|
95 | /** |
---|
96 | * Macro which computes value for PINMMRx register from pin list |
---|
97 | * which is defined as macro calling action macro for each pin |
---|
98 | * |
---|
99 | * @param reg PINMMR register number (0 .. 30 for TMS570LS3137) |
---|
100 | * @param pin_list declared as macro with parameters |
---|
101 | * \c per_pin_action and \c common_arg which expands |
---|
102 | * to list of \c per_pin_action(\c common_arg, \c TMS570_BALL_xx_function) |
---|
103 | * |
---|
104 | * @retval number which represents connections which should be enabled |
---|
105 | * in given PINMMR register. Pin setup for other registers than specified |
---|
106 | * are ignored |
---|
107 | */ |
---|
108 | #define TMS570_PINMMR_REG_VAL(reg, pin_list) \ |
---|
109 | pin_list(TMS570_PINMMR_REG_VAL_ACTION, reg) 0 |
---|
110 | |
---|
111 | #define TMS570_PINMMR_COMA_LIST_ACTION(reg, pin) \ |
---|
112 | (pin), |
---|
113 | |
---|
114 | /** |
---|
115 | * Macro which generates list of pin and function specification from |
---|
116 | * from pin list which is defined as macro calling action macro for each pin |
---|
117 | * |
---|
118 | * @param pin_list declared as macro with parameters |
---|
119 | * \c per_pin_action and \c common_arg which expands |
---|
120 | * to list of \c per_pin_action(\c common_arg, \c TMS570_BALL_xx_function) |
---|
121 | * |
---|
122 | * @retval list of coma separated pin+function combined values which is terminated by coma |
---|
123 | * at the end |
---|
124 | */ |
---|
125 | #define TMS570_PINMMR_COMA_LIST(pin_list) \ |
---|
126 | pin_list(TMS570_PINMMR_COMA_LIST_ACTION, 0) |
---|
127 | |
---|
128 | |
---|
129 | #endif |
---|
130 | |
---|
131 | /** @} */ |
---|
132 | |
---|
133 | #ifdef __cplusplus |
---|
134 | } |
---|
135 | #endif /* __cplusplus */ |
---|
136 | |
---|
137 | #endif /* LIBBSP_ARM_TMS570_IRQ_H */ |
---|