aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios/os/hal/ports/simulator/hal_pal_lld.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios/os/hal/ports/simulator/hal_pal_lld.h')
-rw-r--r--lib/chibios/os/hal/ports/simulator/hal_pal_lld.h267
1 files changed, 267 insertions, 0 deletions
diff --git a/lib/chibios/os/hal/ports/simulator/hal_pal_lld.h b/lib/chibios/os/hal/ports/simulator/hal_pal_lld.h
new file mode 100644
index 000000000..dc8685e86
--- /dev/null
+++ b/lib/chibios/os/hal/ports/simulator/hal_pal_lld.h
@@ -0,0 +1,267 @@
1/*
2 ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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 hal_pal_lld.h
19 * @brief Simulator low level PAL driver header.
20 *
21 * @addtogroup SIMULATOR_PAL
22 * @{
23 */
24
25#ifndef HAL_PAL_LLD_H
26#define HAL_PAL_LLD_H
27
28#if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__)
29
30/*===========================================================================*/
31/* Unsupported modes and specific modes */
32/*===========================================================================*/
33
34#undef PAL_MODE_INPUT_PULLUP
35#undef PAL_MODE_INPUT_PULLDOWN
36#undef PAL_MODE_OUTPUT_OPENDRAIN
37#undef PAL_MODE_INPUT_ANALOG
38
39/*===========================================================================*/
40/* I/O Ports Types and constants. */
41/*===========================================================================*/
42
43/**
44 * @brief VIO port structure.
45 */
46typedef struct {
47 /**
48 * @brief VIO_LATCH register.
49 * @details This register represents the output latch of the VIO port.
50 */
51 uint32_t latch;
52 /**
53 * @brief VIO_PIN register.
54 * @details This register represents the logical level at the VIO port
55 * pin level.
56 */
57 uint32_t pin;
58 /**
59 * @brief VIO_DIR register.
60 * @details Direction of the VIO port bits, 0=input, 1=output.
61 */
62 uint32_t dir;
63} sim_vio_port_t;
64
65/**
66 * @brief Virtual I/O ports static initializer.
67 * @details An instance of this structure must be passed to @p palInit() at
68 * system startup time in order to initialized the digital I/O
69 * subsystem. This represents only the initial setup, specific pads
70 * or whole ports can be reprogrammed at later time.
71 */
72typedef struct {
73 /**
74 * @brief Virtual port 1 setup data.
75 */
76 sim_vio_port_t VP1Data;
77 /**
78 * @brief Virtual port 2 setup data.
79 */
80 sim_vio_port_t VP2Data;
81} PALConfig;
82
83/**
84 * @brief Width, in bits, of an I/O port.
85 */
86#define PAL_IOPORTS_WIDTH 32
87
88/**
89 * @brief Whole port mask.
90 * @details This macro specifies all the valid bits into a port.
91 */
92#define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFFFFFU)
93/** @} */
94
95/**
96 * @name Line handling macros
97 * @{
98 */
99/**
100 * @brief Forms a line identifier.
101 * @details A port/pad pair are encoded into an @p ioline_t type. The encoding
102 * of this type is platform-dependent.
103 */
104#define PAL_LINE(port, pad) \
105 ((ioline_t)((uint32_t)(port)) | ((uint32_t)(pad)))
106
107/**
108 * @brief Decodes a port identifier from a line identifier.
109 */
110#define PAL_PORT(line) \
111 ((sim_vio_port_t *)(((uint32_t)(line)) & 0xFFFFFFF0U))
112
113/**
114 * @brief Decodes a pad identifier from a line identifier.
115 */
116#define PAL_PAD(line) \
117 ((uint32_t)((uint32_t)(line) & 0x0000000FU))
118
119/**
120 * @brief Value identifying an invalid line.
121 */
122#define PAL_NOLINE 0U
123/** @} */
124
125/**
126 * @brief Digital I/O port sized unsigned type.
127 */
128typedef uint32_t ioportmask_t;
129
130/**
131 * @brief Digital I/O modes.
132 */
133typedef uint32_t iomode_t;
134
135/**
136 * @brief Type of an I/O line.
137 */
138typedef uint32_t ioline_t;
139
140/**
141 * @brief Port Identifier.
142 */
143typedef sim_vio_port_t * ioportid_t;
144
145/**
146 * @brief Type of an pad identifier.
147 */
148typedef uint32_t iopadid_t;
149
150/*===========================================================================*/
151/* I/O Ports Identifiers. */
152/*===========================================================================*/
153
154/**
155 * @brief VIO port 1 identifier.
156 */
157#define IOPORT1 (&vio_port_1)
158
159/**
160 * @brief VIO port 2 identifier.
161 */
162#define IOPORT2 (&vio_port_2)
163
164/*===========================================================================*/
165/* Implementation, some of the following macros could be implemented as */
166/* functions, if so please put them in pal_lld.c. */
167/*===========================================================================*/
168
169/**
170 * @brief Low level PAL subsystem initialization.
171 *
172 * @param[in] config architecture-dependent ports configuration
173 *
174 * @notapi
175 */
176#define pal_lld_init(config) \
177 (vio_port_1 = (config)->VP1Data, \
178 vio_port_2 = (config)->VP2Data)
179
180/**
181 * @brief Reads the physical I/O port states.
182 *
183 * @param[in] port port identifier
184 * @return The port bits.
185 *
186 * @notapi
187 */
188#define pal_lld_readport(port) ((port)->pin)
189
190/**
191 * @brief Reads the output latch.
192 * @details The purpose of this function is to read back the latched output
193 * value.
194 *
195 * @param[in] port port identifier
196 * @return The latched logical states.
197 *
198 * @notapi
199 */
200#define pal_lld_readlatch(port) ((port)->latch)
201
202/**
203 * @brief Writes a bits mask on a I/O port.
204 *
205 * @param[in] port port identifier
206 * @param[in] bits bits to be written on the specified port
207 *
208 * @notapi
209 */
210#define pal_lld_writeport(port, bits) ((port)->latch = (bits))
211
212/**
213 * @brief Pads group mode setup.
214 * @details This function programs a pads group belonging to the same port
215 * with the specified mode.
216 * @note Programming an unknown or unsupported mode is silently ignored.
217 *
218 * @param[in] port port identifier
219 * @param[in] mask group mask
220 * @param[in] offset group bit offset within the port
221 * @param[in] mode group mode
222 *
223 * @notapi
224 */
225#define pal_lld_setgroupmode(port, mask, offset, mode) \
226 _pal_lld_setgroupmode(port, mask << offset, mode)
227
228/**
229 * @brief Returns a PAL event structure associated to a pad.
230 *
231 * @param[in] port port identifier
232 * @param[in] pad pad number within the port
233 *
234 * @notapi
235 */
236#define pal_lld_get_pad_event(port, pad) NULL; (void)(port); (void)pad
237
238/**
239 * @brief Returns a PAL event structure associated to a line.
240 *
241 * @param[in] line line identifier
242 *
243 * @notapi
244 */
245#define pal_lld_get_line_event(line) NULL; (void)line
246
247#if !defined(__DOXYGEN__)
248extern sim_vio_port_t vio_port_1;
249extern sim_vio_port_t vio_port_2;
250extern const PALConfig pal_default_config;
251#endif
252
253#ifdef __cplusplus
254extern "C" {
255#endif
256 void _pal_lld_setgroupmode(ioportid_t port,
257 ioportmask_t mask,
258 iomode_t mode);
259#ifdef __cplusplus
260}
261#endif
262
263#endif /* HAL_USE_PAL == TRUE */
264
265#endif /* HAL_PAL_LLD_H */
266
267/** @} */