aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/hal/ports/MSP430X/hal_pal_lld.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/MSP430X/hal_pal_lld.c')
-rw-r--r--lib/chibios-contrib/os/hal/ports/MSP430X/hal_pal_lld.c229
1 files changed, 229 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/MSP430X/hal_pal_lld.c b/lib/chibios-contrib/os/hal/ports/MSP430X/hal_pal_lld.c
new file mode 100644
index 000000000..30e6b8bf4
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/ports/MSP430X/hal_pal_lld.c
@@ -0,0 +1,229 @@
1/*
2 ChibiOS - Copyright (C) 2016 Andrew Wygle aka awygle
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file MSP430X/hal_pal_lld.c
19 * @brief MSP430X PAL subsystem low level driver source.
20 *
21 * @addtogroup PAL
22 * @{
23 */
24
25#include "hal.h"
26
27#if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__)
28
29/*===========================================================================*/
30/* Driver local definitions. */
31/*===========================================================================*/
32
33/*===========================================================================*/
34/* Driver exported variables. */
35/*===========================================================================*/
36
37/*===========================================================================*/
38/* Driver local variables and types. */
39/*===========================================================================*/
40
41/*===========================================================================*/
42/* Driver local functions. */
43/*===========================================================================*/
44
45/*===========================================================================*/
46/* Driver interrupt handlers. */
47/*===========================================================================*/
48
49/*===========================================================================*/
50/* Driver exported functions. */
51/*===========================================================================*/
52
53/**
54 * @brief MSP430X I/O ports configuration.
55 * @details GPIO registers initialization
56 *
57 * @param[in] config the MSP430X ports configuration
58 *
59 * @notapi
60 */
61void _pal_lld_init(const PALConfig *config) {
62
63#if defined(PA_BASE) || defined(__DOXYGEN__)
64 PAOUT = config->porta.out;
65 PADIR = config->porta.dir;
66 PAREN = config->porta.ren;
67 PASEL0 = config->porta.sel0;
68 PASEL1 = config->porta.sel1;
69 PAIES = config->porta.ies;
70 PAIE = config->porta.ie;
71 PAIFG = 0;
72#endif
73#if defined(PB_BASE) || defined(__DOXYGEN__)
74 PBOUT = config->portb.out;
75 PBDIR = config->portb.dir;
76 PBREN = config->portb.ren;
77 PBSEL0 = config->portb.sel0;
78 PBSEL1 = config->portb.sel1;
79 PBIES = config->portb.ies;
80 PBIE = config->portb.ie;
81 PBIFG = 0;
82#endif
83#if defined(PC_BASE) || defined(__DOXYGEN__)
84 PCOUT = config->portc.out;
85 PCDIR = config->portc.dir;
86 PCREN = config->portc.ren;
87 PCSEL0 = config->portc.sel0;
88 PCSEL1 = config->portc.sel1;
89#if defined(PCIE) || defined(__DOXYGEN__)
90 PCIES = config->portc.ies;
91 PCIE = config->portc.ie;
92 PCIFG = 0;
93#endif
94#endif
95#if defined(PD_BASE) || defined(__DOXYGEN__)
96 PDOUT = config->portd.out;
97 PDDIR = config->portd.dir;
98 PDREN = config->portd.ren;
99 PDSEL0 = config->portd.sel0;
100 PDSEL1 = config->portd.sel1;
101#if defined(PDIE) || defined(__DOXYGEN__)
102 PDIES = config->portd.ies;
103 PDIE = config->portd.ie;
104 PDIFG = 0;
105#endif
106#endif
107#if defined(PE_BASE) || defined(__DOXYGEN__)
108 PEOUT = config->porte.out;
109 PEDIR = config->porte.dir;
110 PEREN = config->porte.ren;
111 PESEL0 = config->porte.sel0;
112 PESEL1 = config->porte.sel1;
113#if defined(PEIE) || defined(__DOXYGEN__)
114 PEIES = config->porte.ies;
115 PEIE = config->porte.ie;
116 PEIFG = 0;
117#endif
118#endif
119#if defined(PF_BASE) || defined(__DOXYGEN__)
120 PFOUT = config->portf.out;
121 PFDIR = config->portf.dir;
122 PFREN = config->portf.ren;
123 PFSEL0 = config->portf.sel0;
124 PFSEL1 = config->portf.sel1;
125#if defined(PFIE) || defined(__DOXYGEN__)
126 PFIES = config->portf.ies;
127 PFIE = config->portf.ie;
128 PFIFG = 0;
129#endif
130#endif
131 PJOUT = config->portj.out;
132 PJDIR = config->portj.dir;
133 PJREN = config->portj.ren;
134 PJSEL0 = config->portj.sel0;
135 PJSEL1 = config->portj.sel1;
136
137 PM5CTL0 &= ~LOCKLPM5;
138}
139
140/**
141 * @brief Pads mode setup.
142 * @details This function programs a pads group belonging to the same port
143 * with the specified mode.
144 * @note @p PAL_MODE_UNCONNECTED is implemented as input with pullup.
145 *
146 * @param[in] port the port identifier
147 * @param[in] mask the group mask
148 * @param[in] mode the mode
149 *
150 * @notapi
151 */
152void _pal_lld_setgroupmode(ioportid_t port,
153 ioportmask_t mask,
154 iomode_t mode) {
155
156 switch (mode) {
157 case PAL_MODE_RESET:
158 case PAL_MODE_INPUT:
159 port->dir &= ~mask;
160 port->ren &= ~mask;
161 if ((port->sel0 & mask) && (port->sel1 & mask))
162 port->selc = mask;
163 else {
164 port->sel0 &= ~mask;
165 port->sel1 &= ~mask;
166 }
167 break;
168 case PAL_MODE_UNCONNECTED:
169 case PAL_MODE_INPUT_PULLUP:
170 port->dir &= ~mask;
171 port->ren |= mask;
172 port->out |= mask;
173 if ((port->sel0 & mask) && (port->sel1 & mask))
174 port->selc = mask;
175 else {
176 port->sel0 &= ~mask;
177 port->sel1 &= ~mask;
178 }
179 break;
180 case PAL_MODE_INPUT_PULLDOWN:
181 port->dir &= ~mask;
182 port->ren |= mask;
183 port->out &= ~mask;
184 if ((port->sel0 & mask) && (port->sel1 & mask))
185 port->selc = mask;
186 else {
187 port->sel0 &= ~mask;
188 port->sel1 &= ~mask;
189 }
190 break;
191 case PAL_MODE_OUTPUT_PUSHPULL:
192 port->dir |= mask;
193 if ((port->sel0 & mask) && (port->sel1 & mask))
194 port->selc = mask;
195 else {
196 port->sel0 &= ~mask;
197 port->sel1 &= ~mask;
198 }
199 break;
200 case PAL_MSP430X_ALTERNATE_1:
201 if (!(port->sel0 & mask) && (port->sel1 & mask))
202 port->selc = mask;
203 else {
204 port->sel0 |= mask;
205 port->sel1 &= ~mask;
206 }
207 break;
208 case PAL_MSP430X_ALTERNATE_2:
209 if ((port->sel0 & mask) && !(port->sel1 & mask))
210 port->selc = mask;
211 else {
212 port->sel0 &= ~mask;
213 port->sel1 |= mask;
214 }
215 break;
216 case PAL_MSP430X_ALTERNATE_3:
217 if (!(port->sel0 & mask) && !(port->sel1 & mask))
218 port->selc = mask;
219 else {
220 port->sel0 |= mask;
221 port->sel1 |= mask;
222 }
223 break;
224 }
225}
226
227#endif /* HAL_USE_PAL == TRUE */
228
229/** @} */