1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 /*******************************************************************************************************************//**
8 * @defgroup BSP_IO BSP I/O access
9 * @ingroup RENESAS_COMMON
10 * @brief This module provides basic read/write access to port pins.
11 *
12 * @{
13 **********************************************************************************************************************/
14
15 #ifndef BSP_IO_H
16 #define BSP_IO_H
17
18 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
19 FSP_HEADER
20
21 /***********************************************************************************************************************
22 * Macro definitions
23 **********************************************************************************************************************/
24
25 /* Private definition to set enumeration values. */
26 #define BSP_IO_PRV_PFS_PSEL_OFFSET (24)
27 #define BSP_IO_PRV_8BIT_MASK (0xFF)
28 #define BSP_IO_PWPR_B0WI_OFFSET (7U)
29 #define BSP_IO_PWPR_PFSWE_OFFSET (6U)
30 #define BSP_IO_PFS_PDR_OUTPUT (4U)
31 #define BSP_IO_PRV_PIN_WRITE_MASK (0xFFFE3FFE)
32
33 /***********************************************************************************************************************
34 * Typedef definitions
35 **********************************************************************************************************************/
36
37 /** Levels that can be set and read for individual pins */
38 typedef enum e_bsp_io_level
39 {
40 BSP_IO_LEVEL_LOW = 0, ///< Low
41 BSP_IO_LEVEL_HIGH ///< High
42 } bsp_io_level_t;
43
44 /** Direction of individual pins */
45 typedef enum e_bsp_io_dir
46 {
47 BSP_IO_DIRECTION_INPUT = 0, ///< Input
48 BSP_IO_DIRECTION_OUTPUT ///< Output
49 } bsp_io_direction_t;
50
51 /** Superset list of all possible IO ports. */
52 typedef enum e_bsp_io_port
53 {
54 BSP_IO_PORT_00 = 0x0000, ///< IO port 0
55 BSP_IO_PORT_01 = 0x0100, ///< IO port 1
56 BSP_IO_PORT_02 = 0x0200, ///< IO port 2
57 BSP_IO_PORT_03 = 0x0300, ///< IO port 3
58 BSP_IO_PORT_04 = 0x0400, ///< IO port 4
59 BSP_IO_PORT_05 = 0x0500, ///< IO port 5
60 BSP_IO_PORT_06 = 0x0600, ///< IO port 6
61 BSP_IO_PORT_07 = 0x0700, ///< IO port 7
62 BSP_IO_PORT_08 = 0x0800, ///< IO port 8
63 BSP_IO_PORT_09 = 0x0900, ///< IO port 9
64 BSP_IO_PORT_10 = 0x0A00, ///< IO port 10
65 BSP_IO_PORT_11 = 0x0B00, ///< IO port 11
66 BSP_IO_PORT_12 = 0x0C00, ///< IO port 12
67 BSP_IO_PORT_13 = 0x0D00, ///< IO port 13
68 BSP_IO_PORT_14 = 0x0E00, ///< IO port 14
69 } bsp_io_port_t;
70
71 /** Superset list of all possible IO port pins. */
72 typedef enum e_bsp_io_port_pin_t
73 {
74 BSP_IO_PORT_00_PIN_00 = 0x0000, ///< IO port 0 pin 0
75 BSP_IO_PORT_00_PIN_01 = 0x0001, ///< IO port 0 pin 1
76 BSP_IO_PORT_00_PIN_02 = 0x0002, ///< IO port 0 pin 2
77 BSP_IO_PORT_00_PIN_03 = 0x0003, ///< IO port 0 pin 3
78 BSP_IO_PORT_00_PIN_04 = 0x0004, ///< IO port 0 pin 4
79 BSP_IO_PORT_00_PIN_05 = 0x0005, ///< IO port 0 pin 5
80 BSP_IO_PORT_00_PIN_06 = 0x0006, ///< IO port 0 pin 6
81 BSP_IO_PORT_00_PIN_07 = 0x0007, ///< IO port 0 pin 7
82 BSP_IO_PORT_00_PIN_08 = 0x0008, ///< IO port 0 pin 8
83 BSP_IO_PORT_00_PIN_09 = 0x0009, ///< IO port 0 pin 9
84 BSP_IO_PORT_00_PIN_10 = 0x000A, ///< IO port 0 pin 10
85 BSP_IO_PORT_00_PIN_11 = 0x000B, ///< IO port 0 pin 11
86 BSP_IO_PORT_00_PIN_12 = 0x000C, ///< IO port 0 pin 12
87 BSP_IO_PORT_00_PIN_13 = 0x000D, ///< IO port 0 pin 13
88 BSP_IO_PORT_00_PIN_14 = 0x000E, ///< IO port 0 pin 14
89 BSP_IO_PORT_00_PIN_15 = 0x000F, ///< IO port 0 pin 15
90
91 BSP_IO_PORT_01_PIN_00 = 0x0100, ///< IO port 1 pin 0
92 BSP_IO_PORT_01_PIN_01 = 0x0101, ///< IO port 1 pin 1
93 BSP_IO_PORT_01_PIN_02 = 0x0102, ///< IO port 1 pin 2
94 BSP_IO_PORT_01_PIN_03 = 0x0103, ///< IO port 1 pin 3
95 BSP_IO_PORT_01_PIN_04 = 0x0104, ///< IO port 1 pin 4
96 BSP_IO_PORT_01_PIN_05 = 0x0105, ///< IO port 1 pin 5
97 BSP_IO_PORT_01_PIN_06 = 0x0106, ///< IO port 1 pin 6
98 BSP_IO_PORT_01_PIN_07 = 0x0107, ///< IO port 1 pin 7
99 BSP_IO_PORT_01_PIN_08 = 0x0108, ///< IO port 1 pin 8
100 BSP_IO_PORT_01_PIN_09 = 0x0109, ///< IO port 1 pin 9
101 BSP_IO_PORT_01_PIN_10 = 0x010A, ///< IO port 1 pin 10
102 BSP_IO_PORT_01_PIN_11 = 0x010B, ///< IO port 1 pin 11
103 BSP_IO_PORT_01_PIN_12 = 0x010C, ///< IO port 1 pin 12
104 BSP_IO_PORT_01_PIN_13 = 0x010D, ///< IO port 1 pin 13
105 BSP_IO_PORT_01_PIN_14 = 0x010E, ///< IO port 1 pin 14
106 BSP_IO_PORT_01_PIN_15 = 0x010F, ///< IO port 1 pin 15
107
108 BSP_IO_PORT_02_PIN_00 = 0x0200, ///< IO port 2 pin 0
109 BSP_IO_PORT_02_PIN_01 = 0x0201, ///< IO port 2 pin 1
110 BSP_IO_PORT_02_PIN_02 = 0x0202, ///< IO port 2 pin 2
111 BSP_IO_PORT_02_PIN_03 = 0x0203, ///< IO port 2 pin 3
112 BSP_IO_PORT_02_PIN_04 = 0x0204, ///< IO port 2 pin 4
113 BSP_IO_PORT_02_PIN_05 = 0x0205, ///< IO port 2 pin 5
114 BSP_IO_PORT_02_PIN_06 = 0x0206, ///< IO port 2 pin 6
115 BSP_IO_PORT_02_PIN_07 = 0x0207, ///< IO port 2 pin 7
116 BSP_IO_PORT_02_PIN_08 = 0x0208, ///< IO port 2 pin 8
117 BSP_IO_PORT_02_PIN_09 = 0x0209, ///< IO port 2 pin 9
118 BSP_IO_PORT_02_PIN_10 = 0x020A, ///< IO port 2 pin 10
119 BSP_IO_PORT_02_PIN_11 = 0x020B, ///< IO port 2 pin 11
120 BSP_IO_PORT_02_PIN_12 = 0x020C, ///< IO port 2 pin 12
121 BSP_IO_PORT_02_PIN_13 = 0x020D, ///< IO port 2 pin 13
122 BSP_IO_PORT_02_PIN_14 = 0x020E, ///< IO port 2 pin 14
123 BSP_IO_PORT_02_PIN_15 = 0x020F, ///< IO port 2 pin 15
124
125 BSP_IO_PORT_03_PIN_00 = 0x0300, ///< IO port 3 pin 0
126 BSP_IO_PORT_03_PIN_01 = 0x0301, ///< IO port 3 pin 1
127 BSP_IO_PORT_03_PIN_02 = 0x0302, ///< IO port 3 pin 2
128 BSP_IO_PORT_03_PIN_03 = 0x0303, ///< IO port 3 pin 3
129 BSP_IO_PORT_03_PIN_04 = 0x0304, ///< IO port 3 pin 4
130 BSP_IO_PORT_03_PIN_05 = 0x0305, ///< IO port 3 pin 5
131 BSP_IO_PORT_03_PIN_06 = 0x0306, ///< IO port 3 pin 6
132 BSP_IO_PORT_03_PIN_07 = 0x0307, ///< IO port 3 pin 7
133 BSP_IO_PORT_03_PIN_08 = 0x0308, ///< IO port 3 pin 8
134 BSP_IO_PORT_03_PIN_09 = 0x0309, ///< IO port 3 pin 9
135 BSP_IO_PORT_03_PIN_10 = 0x030A, ///< IO port 3 pin 10
136 BSP_IO_PORT_03_PIN_11 = 0x030B, ///< IO port 3 pin 11
137 BSP_IO_PORT_03_PIN_12 = 0x030C, ///< IO port 3 pin 12
138 BSP_IO_PORT_03_PIN_13 = 0x030D, ///< IO port 3 pin 13
139 BSP_IO_PORT_03_PIN_14 = 0x030E, ///< IO port 3 pin 14
140 BSP_IO_PORT_03_PIN_15 = 0x030F, ///< IO port 3 pin 15
141
142 BSP_IO_PORT_04_PIN_00 = 0x0400, ///< IO port 4 pin 0
143 BSP_IO_PORT_04_PIN_01 = 0x0401, ///< IO port 4 pin 1
144 BSP_IO_PORT_04_PIN_02 = 0x0402, ///< IO port 4 pin 2
145 BSP_IO_PORT_04_PIN_03 = 0x0403, ///< IO port 4 pin 3
146 BSP_IO_PORT_04_PIN_04 = 0x0404, ///< IO port 4 pin 4
147 BSP_IO_PORT_04_PIN_05 = 0x0405, ///< IO port 4 pin 5
148 BSP_IO_PORT_04_PIN_06 = 0x0406, ///< IO port 4 pin 6
149 BSP_IO_PORT_04_PIN_07 = 0x0407, ///< IO port 4 pin 7
150 BSP_IO_PORT_04_PIN_08 = 0x0408, ///< IO port 4 pin 8
151 BSP_IO_PORT_04_PIN_09 = 0x0409, ///< IO port 4 pin 9
152 BSP_IO_PORT_04_PIN_10 = 0x040A, ///< IO port 4 pin 10
153 BSP_IO_PORT_04_PIN_11 = 0x040B, ///< IO port 4 pin 11
154 BSP_IO_PORT_04_PIN_12 = 0x040C, ///< IO port 4 pin 12
155 BSP_IO_PORT_04_PIN_13 = 0x040D, ///< IO port 4 pin 13
156 BSP_IO_PORT_04_PIN_14 = 0x040E, ///< IO port 4 pin 14
157 BSP_IO_PORT_04_PIN_15 = 0x040F, ///< IO port 4 pin 15
158
159 BSP_IO_PORT_05_PIN_00 = 0x0500, ///< IO port 5 pin 0
160 BSP_IO_PORT_05_PIN_01 = 0x0501, ///< IO port 5 pin 1
161 BSP_IO_PORT_05_PIN_02 = 0x0502, ///< IO port 5 pin 2
162 BSP_IO_PORT_05_PIN_03 = 0x0503, ///< IO port 5 pin 3
163 BSP_IO_PORT_05_PIN_04 = 0x0504, ///< IO port 5 pin 4
164 BSP_IO_PORT_05_PIN_05 = 0x0505, ///< IO port 5 pin 5
165 BSP_IO_PORT_05_PIN_06 = 0x0506, ///< IO port 5 pin 6
166 BSP_IO_PORT_05_PIN_07 = 0x0507, ///< IO port 5 pin 7
167 BSP_IO_PORT_05_PIN_08 = 0x0508, ///< IO port 5 pin 8
168 BSP_IO_PORT_05_PIN_09 = 0x0509, ///< IO port 5 pin 9
169 BSP_IO_PORT_05_PIN_10 = 0x050A, ///< IO port 5 pin 10
170 BSP_IO_PORT_05_PIN_11 = 0x050B, ///< IO port 5 pin 11
171 BSP_IO_PORT_05_PIN_12 = 0x050C, ///< IO port 5 pin 12
172 BSP_IO_PORT_05_PIN_13 = 0x050D, ///< IO port 5 pin 13
173 BSP_IO_PORT_05_PIN_14 = 0x050E, ///< IO port 5 pin 14
174 BSP_IO_PORT_05_PIN_15 = 0x050F, ///< IO port 5 pin 15
175
176 BSP_IO_PORT_06_PIN_00 = 0x0600, ///< IO port 6 pin 0
177 BSP_IO_PORT_06_PIN_01 = 0x0601, ///< IO port 6 pin 1
178 BSP_IO_PORT_06_PIN_02 = 0x0602, ///< IO port 6 pin 2
179 BSP_IO_PORT_06_PIN_03 = 0x0603, ///< IO port 6 pin 3
180 BSP_IO_PORT_06_PIN_04 = 0x0604, ///< IO port 6 pin 4
181 BSP_IO_PORT_06_PIN_05 = 0x0605, ///< IO port 6 pin 5
182 BSP_IO_PORT_06_PIN_06 = 0x0606, ///< IO port 6 pin 6
183 BSP_IO_PORT_06_PIN_07 = 0x0607, ///< IO port 6 pin 7
184 BSP_IO_PORT_06_PIN_08 = 0x0608, ///< IO port 6 pin 8
185 BSP_IO_PORT_06_PIN_09 = 0x0609, ///< IO port 6 pin 9
186 BSP_IO_PORT_06_PIN_10 = 0x060A, ///< IO port 6 pin 10
187 BSP_IO_PORT_06_PIN_11 = 0x060B, ///< IO port 6 pin 11
188 BSP_IO_PORT_06_PIN_12 = 0x060C, ///< IO port 6 pin 12
189 BSP_IO_PORT_06_PIN_13 = 0x060D, ///< IO port 6 pin 13
190 BSP_IO_PORT_06_PIN_14 = 0x060E, ///< IO port 6 pin 14
191 BSP_IO_PORT_06_PIN_15 = 0x060F, ///< IO port 6 pin 15
192
193 BSP_IO_PORT_07_PIN_00 = 0x0700, ///< IO port 7 pin 0
194 BSP_IO_PORT_07_PIN_01 = 0x0701, ///< IO port 7 pin 1
195 BSP_IO_PORT_07_PIN_02 = 0x0702, ///< IO port 7 pin 2
196 BSP_IO_PORT_07_PIN_03 = 0x0703, ///< IO port 7 pin 3
197 BSP_IO_PORT_07_PIN_04 = 0x0704, ///< IO port 7 pin 4
198 BSP_IO_PORT_07_PIN_05 = 0x0705, ///< IO port 7 pin 5
199 BSP_IO_PORT_07_PIN_06 = 0x0706, ///< IO port 7 pin 6
200 BSP_IO_PORT_07_PIN_07 = 0x0707, ///< IO port 7 pin 7
201 BSP_IO_PORT_07_PIN_08 = 0x0708, ///< IO port 7 pin 8
202 BSP_IO_PORT_07_PIN_09 = 0x0709, ///< IO port 7 pin 9
203 BSP_IO_PORT_07_PIN_10 = 0x070A, ///< IO port 7 pin 10
204 BSP_IO_PORT_07_PIN_11 = 0x070B, ///< IO port 7 pin 11
205 BSP_IO_PORT_07_PIN_12 = 0x070C, ///< IO port 7 pin 12
206 BSP_IO_PORT_07_PIN_13 = 0x070D, ///< IO port 7 pin 13
207 BSP_IO_PORT_07_PIN_14 = 0x070E, ///< IO port 7 pin 14
208 BSP_IO_PORT_07_PIN_15 = 0x070F, ///< IO port 7 pin 15
209
210 BSP_IO_PORT_08_PIN_00 = 0x0800, ///< IO port 8 pin 0
211 BSP_IO_PORT_08_PIN_01 = 0x0801, ///< IO port 8 pin 1
212 BSP_IO_PORT_08_PIN_02 = 0x0802, ///< IO port 8 pin 2
213 BSP_IO_PORT_08_PIN_03 = 0x0803, ///< IO port 8 pin 3
214 BSP_IO_PORT_08_PIN_04 = 0x0804, ///< IO port 8 pin 4
215 BSP_IO_PORT_08_PIN_05 = 0x0805, ///< IO port 8 pin 5
216 BSP_IO_PORT_08_PIN_06 = 0x0806, ///< IO port 8 pin 6
217 BSP_IO_PORT_08_PIN_07 = 0x0807, ///< IO port 8 pin 7
218 BSP_IO_PORT_08_PIN_08 = 0x0808, ///< IO port 8 pin 8
219 BSP_IO_PORT_08_PIN_09 = 0x0809, ///< IO port 8 pin 9
220 BSP_IO_PORT_08_PIN_10 = 0x080A, ///< IO port 8 pin 10
221 BSP_IO_PORT_08_PIN_11 = 0x080B, ///< IO port 8 pin 11
222 BSP_IO_PORT_08_PIN_12 = 0x080C, ///< IO port 8 pin 12
223 BSP_IO_PORT_08_PIN_13 = 0x080D, ///< IO port 8 pin 13
224 BSP_IO_PORT_08_PIN_14 = 0x080E, ///< IO port 8 pin 14
225 BSP_IO_PORT_08_PIN_15 = 0x080F, ///< IO port 8 pin 15
226
227 BSP_IO_PORT_09_PIN_00 = 0x0900, ///< IO port 9 pin 0
228 BSP_IO_PORT_09_PIN_01 = 0x0901, ///< IO port 9 pin 1
229 BSP_IO_PORT_09_PIN_02 = 0x0902, ///< IO port 9 pin 2
230 BSP_IO_PORT_09_PIN_03 = 0x0903, ///< IO port 9 pin 3
231 BSP_IO_PORT_09_PIN_04 = 0x0904, ///< IO port 9 pin 4
232 BSP_IO_PORT_09_PIN_05 = 0x0905, ///< IO port 9 pin 5
233 BSP_IO_PORT_09_PIN_06 = 0x0906, ///< IO port 9 pin 6
234 BSP_IO_PORT_09_PIN_07 = 0x0907, ///< IO port 9 pin 7
235 BSP_IO_PORT_09_PIN_08 = 0x0908, ///< IO port 9 pin 8
236 BSP_IO_PORT_09_PIN_09 = 0x0909, ///< IO port 9 pin 9
237 BSP_IO_PORT_09_PIN_10 = 0x090A, ///< IO port 9 pin 10
238 BSP_IO_PORT_09_PIN_11 = 0x090B, ///< IO port 9 pin 11
239 BSP_IO_PORT_09_PIN_12 = 0x090C, ///< IO port 9 pin 12
240 BSP_IO_PORT_09_PIN_13 = 0x090D, ///< IO port 9 pin 13
241 BSP_IO_PORT_09_PIN_14 = 0x090E, ///< IO port 9 pin 14
242 BSP_IO_PORT_09_PIN_15 = 0x090F, ///< IO port 9 pin 15
243
244 BSP_IO_PORT_10_PIN_00 = 0x0A00, ///< IO port 10 pin 0
245 BSP_IO_PORT_10_PIN_01 = 0x0A01, ///< IO port 10 pin 1
246 BSP_IO_PORT_10_PIN_02 = 0x0A02, ///< IO port 10 pin 2
247 BSP_IO_PORT_10_PIN_03 = 0x0A03, ///< IO port 10 pin 3
248 BSP_IO_PORT_10_PIN_04 = 0x0A04, ///< IO port 10 pin 4
249 BSP_IO_PORT_10_PIN_05 = 0x0A05, ///< IO port 10 pin 5
250 BSP_IO_PORT_10_PIN_06 = 0x0A06, ///< IO port 10 pin 6
251 BSP_IO_PORT_10_PIN_07 = 0x0A07, ///< IO port 10 pin 7
252 BSP_IO_PORT_10_PIN_08 = 0x0A08, ///< IO port 10 pin 8
253 BSP_IO_PORT_10_PIN_09 = 0x0A09, ///< IO port 10 pin 9
254 BSP_IO_PORT_10_PIN_10 = 0x0A0A, ///< IO port 10 pin 10
255 BSP_IO_PORT_10_PIN_11 = 0x0A0B, ///< IO port 10 pin 11
256 BSP_IO_PORT_10_PIN_12 = 0x0A0C, ///< IO port 10 pin 12
257 BSP_IO_PORT_10_PIN_13 = 0x0A0D, ///< IO port 10 pin 13
258 BSP_IO_PORT_10_PIN_14 = 0x0A0E, ///< IO port 10 pin 14
259 BSP_IO_PORT_10_PIN_15 = 0x0A0F, ///< IO port 10 pin 15
260
261 BSP_IO_PORT_11_PIN_00 = 0x0B00, ///< IO port 11 pin 0
262 BSP_IO_PORT_11_PIN_01 = 0x0B01, ///< IO port 11 pin 1
263 BSP_IO_PORT_11_PIN_02 = 0x0B02, ///< IO port 11 pin 2
264 BSP_IO_PORT_11_PIN_03 = 0x0B03, ///< IO port 11 pin 3
265 BSP_IO_PORT_11_PIN_04 = 0x0B04, ///< IO port 11 pin 4
266 BSP_IO_PORT_11_PIN_05 = 0x0B05, ///< IO port 11 pin 5
267 BSP_IO_PORT_11_PIN_06 = 0x0B06, ///< IO port 11 pin 6
268 BSP_IO_PORT_11_PIN_07 = 0x0B07, ///< IO port 11 pin 7
269 BSP_IO_PORT_11_PIN_08 = 0x0B08, ///< IO port 11 pin 8
270 BSP_IO_PORT_11_PIN_09 = 0x0B09, ///< IO port 11 pin 9
271 BSP_IO_PORT_11_PIN_10 = 0x0B0A, ///< IO port 11 pin 10
272 BSP_IO_PORT_11_PIN_11 = 0x0B0B, ///< IO port 11 pin 11
273 BSP_IO_PORT_11_PIN_12 = 0x0B0C, ///< IO port 11 pin 12
274 BSP_IO_PORT_11_PIN_13 = 0x0B0D, ///< IO port 11 pin 13
275 BSP_IO_PORT_11_PIN_14 = 0x0B0E, ///< IO port 11 pin 14
276 BSP_IO_PORT_11_PIN_15 = 0x0B0F, ///< IO port 11 pin 15
277
278 BSP_IO_PORT_12_PIN_00 = 0x0C00, ///< IO port 12 pin 0
279 BSP_IO_PORT_12_PIN_01 = 0x0C01, ///< IO port 12 pin 1
280 BSP_IO_PORT_12_PIN_02 = 0x0C02, ///< IO port 12 pin 2
281 BSP_IO_PORT_12_PIN_03 = 0x0C03, ///< IO port 12 pin 3
282 BSP_IO_PORT_12_PIN_04 = 0x0C04, ///< IO port 12 pin 4
283 BSP_IO_PORT_12_PIN_05 = 0x0C05, ///< IO port 12 pin 5
284 BSP_IO_PORT_12_PIN_06 = 0x0C06, ///< IO port 12 pin 6
285 BSP_IO_PORT_12_PIN_07 = 0x0C07, ///< IO port 12 pin 7
286 BSP_IO_PORT_12_PIN_08 = 0x0C08, ///< IO port 12 pin 8
287 BSP_IO_PORT_12_PIN_09 = 0x0C09, ///< IO port 12 pin 9
288 BSP_IO_PORT_12_PIN_10 = 0x0C0A, ///< IO port 12 pin 10
289 BSP_IO_PORT_12_PIN_11 = 0x0C0B, ///< IO port 12 pin 11
290 BSP_IO_PORT_12_PIN_12 = 0x0C0C, ///< IO port 12 pin 12
291 BSP_IO_PORT_12_PIN_13 = 0x0C0D, ///< IO port 12 pin 13
292 BSP_IO_PORT_12_PIN_14 = 0x0C0E, ///< IO port 12 pin 14
293 BSP_IO_PORT_12_PIN_15 = 0x0C0F, ///< IO port 12 pin 15
294
295 BSP_IO_PORT_13_PIN_00 = 0x0D00, ///< IO port 13 pin 0
296 BSP_IO_PORT_13_PIN_01 = 0x0D01, ///< IO port 13 pin 1
297 BSP_IO_PORT_13_PIN_02 = 0x0D02, ///< IO port 13 pin 2
298 BSP_IO_PORT_13_PIN_03 = 0x0D03, ///< IO port 13 pin 3
299 BSP_IO_PORT_13_PIN_04 = 0x0D04, ///< IO port 13 pin 4
300 BSP_IO_PORT_13_PIN_05 = 0x0D05, ///< IO port 13 pin 5
301 BSP_IO_PORT_13_PIN_06 = 0x0D06, ///< IO port 13 pin 6
302 BSP_IO_PORT_13_PIN_07 = 0x0D07, ///< IO port 13 pin 7
303 BSP_IO_PORT_13_PIN_08 = 0x0D08, ///< IO port 13 pin 8
304 BSP_IO_PORT_13_PIN_09 = 0x0D09, ///< IO port 13 pin 9
305 BSP_IO_PORT_13_PIN_10 = 0x0D0A, ///< IO port 13 pin 10
306 BSP_IO_PORT_13_PIN_11 = 0x0D0B, ///< IO port 13 pin 11
307 BSP_IO_PORT_13_PIN_12 = 0x0D0C, ///< IO port 13 pin 12
308 BSP_IO_PORT_13_PIN_13 = 0x0D0D, ///< IO port 13 pin 13
309 BSP_IO_PORT_13_PIN_14 = 0x0D0E, ///< IO port 13 pin 14
310 BSP_IO_PORT_13_PIN_15 = 0x0D0F, ///< IO port 13 pin 15
311
312 BSP_IO_PORT_14_PIN_00 = 0x0E00, ///< IO port 14 pin 0
313 BSP_IO_PORT_14_PIN_01 = 0x0E01, ///< IO port 14 pin 1
314 BSP_IO_PORT_14_PIN_02 = 0x0E02, ///< IO port 14 pin 2
315 BSP_IO_PORT_14_PIN_03 = 0x0E03, ///< IO port 14 pin 3
316 BSP_IO_PORT_14_PIN_04 = 0x0E04, ///< IO port 14 pin 4
317 BSP_IO_PORT_14_PIN_05 = 0x0E05, ///< IO port 14 pin 5
318 BSP_IO_PORT_14_PIN_06 = 0x0E06, ///< IO port 14 pin 6
319 BSP_IO_PORT_14_PIN_07 = 0x0E07, ///< IO port 14 pin 7
320 BSP_IO_PORT_14_PIN_08 = 0x0E08, ///< IO port 14 pin 8
321 BSP_IO_PORT_14_PIN_09 = 0x0E09, ///< IO port 14 pin 9
322 BSP_IO_PORT_14_PIN_10 = 0x0E0A, ///< IO port 14 pin 10
323 BSP_IO_PORT_14_PIN_11 = 0x0E0B, ///< IO port 14 pin 11
324 BSP_IO_PORT_14_PIN_12 = 0x0E0C, ///< IO port 14 pin 12
325 BSP_IO_PORT_14_PIN_13 = 0x0E0D, ///< IO port 14 pin 13
326 BSP_IO_PORT_14_PIN_14 = 0x0E0E, ///< IO port 14 pin 14
327 BSP_IO_PORT_14_PIN_15 = 0x0E0F, ///< IO port 14 pin 15
328 } bsp_io_port_pin_t;
329
330 /***********************************************************************************************************************
331 * Exported global variables
332 **********************************************************************************************************************/
333 extern volatile uint32_t g_protect_pfswe_counter;
334
335 /***********************************************************************************************************************
336 * Exported global functions (to be accessed by other files)
337 **********************************************************************************************************************/
338
339 /*******************************************************************************************************************//**
340 * Read the current input level of the pin.
341 *
342 * @param[in] pin The pin
343 *
344 * @retval Current input level
345 **********************************************************************************************************************/
R_BSP_PinRead(bsp_io_port_pin_t pin)346 __STATIC_INLINE uint32_t R_BSP_PinRead (bsp_io_port_pin_t pin)
347 {
348 /* Read pin level. */
349 return R_PFS->PORT[pin >> 8].PIN[pin & BSP_IO_PRV_8BIT_MASK].PmnPFS_b.PIDR;
350 }
351
352 /*******************************************************************************************************************//**
353 * Set a pin to output and set the output level to the level provided. If PFS protection is enabled, disable PFS
354 * protection using R_BSP_PinAccessEnable() before calling this function.
355 *
356 * @param[in] pin The pin
357 * @param[in] level The level
358 **********************************************************************************************************************/
R_BSP_PinWrite(bsp_io_port_pin_t pin,bsp_io_level_t level)359 __STATIC_INLINE void R_BSP_PinWrite (bsp_io_port_pin_t pin, bsp_io_level_t level)
360 {
361 /* Clear PMR, ASEL, ISEL and PODR bits. */
362 uint32_t pfs_bits = R_PFS->PORT[pin >> 8].PIN[pin & BSP_IO_PRV_8BIT_MASK].PmnPFS;
363 pfs_bits &= BSP_IO_PRV_PIN_WRITE_MASK;
364
365 /* Set output level and pin direction to output. */
366 uint32_t lvl = ((uint32_t) level | pfs_bits);
367 #if (3U == BSP_FEATURE_IOPORT_VERSION)
368 R_PFS->PORT[pin >> 8].PIN[pin & BSP_IO_PRV_8BIT_MASK].PmnPFS = (uint16_t) (BSP_IO_PFS_PDR_OUTPUT | lvl);
369 #else
370 R_PFS->PORT[pin >> 8].PIN[pin & BSP_IO_PRV_8BIT_MASK].PmnPFS = (BSP_IO_PFS_PDR_OUTPUT | lvl);
371 #endif
372 }
373
374 /*******************************************************************************************************************//**
375 * Configure a pin. If PFS protection is enabled, disable PFS protection using R_BSP_PinAccessEnable() before calling
376 * this function.
377 *
378 * @param[in] pin The pin
379 * @param[in] cfg Configuration for the pin (PmnPFS register setting)
380 **********************************************************************************************************************/
R_BSP_PinCfg(bsp_io_port_pin_t pin,uint32_t cfg)381 __STATIC_INLINE void R_BSP_PinCfg (bsp_io_port_pin_t pin, uint32_t cfg)
382 {
383 /* Configure a pin. */
384 #if (3U == BSP_FEATURE_IOPORT_VERSION)
385 R_PFS->PORT[pin >> 8].PIN[pin & BSP_IO_PRV_8BIT_MASK].PmnPFS = (uint16_t) cfg;
386 #else
387 R_PFS->PORT[pin >> 8].PIN[pin & BSP_IO_PRV_8BIT_MASK].PmnPFS = cfg;
388 #endif
389 }
390
391 /*******************************************************************************************************************//**
392 * Enable access to the PFS registers. Uses a reference counter to protect against interrupts that could occur
393 * via multiple threads or an ISR re-entering this code.
394 **********************************************************************************************************************/
R_BSP_PinAccessEnable(void)395 __STATIC_INLINE void R_BSP_PinAccessEnable (void)
396 {
397 #if BSP_CFG_PFS_PROTECT
398
399 /** Get the current state of interrupts */
400 FSP_CRITICAL_SECTION_DEFINE;
401 FSP_CRITICAL_SECTION_ENTER;
402
403 /** If this is first entry then allow writing of PFS. */
404 if (0 == g_protect_pfswe_counter)
405 {
406 #if BSP_TZ_SECURE_BUILD || (BSP_FEATURE_TZ_VERSION == 2 && FSP_PRIV_TZ_USE_SECURE_REGS)
407 R_PMISC->PWPRS = 0; ///< Clear BOWI bit - writing to PFSWE bit enabled
408 R_PMISC->PWPRS = 1U << BSP_IO_PWPR_PFSWE_OFFSET; ///< Set PFSWE bit - writing to PFS register enabled
409 #else
410 R_PMISC->PWPR = 0; ///< Clear BOWI bit - writing to PFSWE bit enabled
411 R_PMISC->PWPR = 1U << BSP_IO_PWPR_PFSWE_OFFSET; ///< Set PFSWE bit - writing to PFS register enabled
412 #endif
413 }
414
415 /** Increment the protect counter */
416 g_protect_pfswe_counter++;
417
418 /** Restore the interrupt state */
419 FSP_CRITICAL_SECTION_EXIT;
420 #endif
421 }
422
423 /*******************************************************************************************************************//**
424 * Disable access to the PFS registers. Uses a reference counter to protect against interrupts that could occur via
425 * multiple threads or an ISR re-entering this code.
426 **********************************************************************************************************************/
R_BSP_PinAccessDisable(void)427 __STATIC_INLINE void R_BSP_PinAccessDisable (void)
428 {
429 #if BSP_CFG_PFS_PROTECT
430
431 /** Get the current state of interrupts */
432 FSP_CRITICAL_SECTION_DEFINE;
433 FSP_CRITICAL_SECTION_ENTER;
434
435 /** Is it safe to disable PFS register? */
436 if (0 != g_protect_pfswe_counter)
437 {
438 /* Decrement the protect counter */
439 g_protect_pfswe_counter--;
440 }
441
442 /** Is it safe to disable writing of PFS? */
443 if (0 == g_protect_pfswe_counter)
444 {
445 #if BSP_TZ_SECURE_BUILD || (BSP_FEATURE_TZ_VERSION == 2 && FSP_PRIV_TZ_USE_SECURE_REGS)
446 R_PMISC->PWPRS = 0; ///< Clear PFSWE bit - writing to PFSWE bit enabled
447 R_PMISC->PWPRS = 1U << BSP_IO_PWPR_B0WI_OFFSET; ///< Set BOWI bit - writing to PFS register enabled
448 #else
449 R_PMISC->PWPR = 0; ///< Clear PFSWE bit - writing to PFS register disabled
450 R_PMISC->PWPR = 1U << BSP_IO_PWPR_B0WI_OFFSET; ///< Set BOWI bit - writing to PFSWE bit disabled
451 #endif
452 }
453
454 /** Restore the interrupt state */
455 FSP_CRITICAL_SECTION_EXIT;
456 #endif
457 }
458
459 /** @} (end addtogroup BSP_IO) */
460
461 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
462 FSP_FOOTER
463
464 #endif
465