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/toggle access to port pins and read/write access to port.
11 *
12 * @{
13 **********************************************************************************************************************/
14
15 #ifndef BSP_IO_H
16 #define BSP_IO_H
17
18 /***********************************************************************************************************************
19 * Includes <System Includes> , "Project Includes"
20 **********************************************************************************************************************/
21
22 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
23 FSP_HEADER
24
25 /***********************************************************************************************************************
26 * Macro definitions
27 **********************************************************************************************************************/
28
29 /* Private definition to set enumeration values. */
30 #define BSP_IO_PRV_8BIT_MASK (0xFF)
31 #define BSP_IO_PM_OUTPUT (3U)
32
33 /* Key code for writing PRCR register. */
34 #define BSP_IO_PRV_PRCR_KEY (0xA500U)
35 #define BSP_IO_REG_PROTECT_GPIO (0x0004U)
36
37 /* Shift to get port in bsp_io_port_t and bsp_io_port_pin_t enums. */
38 #define BSP_IO_PRV_PORT_OFFSET (8U)
39
40 /***********************************************************************************************************************
41 * Typedef definitions
42 **********************************************************************************************************************/
43
44 /** Levels that can be set and read for individual pins */
45 typedef enum e_bsp_io_level
46 {
47 BSP_IO_LEVEL_LOW = 0, ///< Low
48 BSP_IO_LEVEL_HIGH ///< High
49 } bsp_io_level_t;
50
51 /** Direction of individual pins */
52 typedef enum e_bsp_io_dir
53 {
54 BSP_IO_DIRECTION_INPUT = 0, ///< Input
55 BSP_IO_DIRECTION_OUTPUT ///< Output
56 } bsp_io_direction_t;
57
58 /** Superset list of all possible IO ports. */
59 typedef enum e_bsp_io_port
60 {
61 BSP_IO_PORT_00 = 0x0000, ///< IO port 0
62 BSP_IO_PORT_01 = 0x0100, ///< IO port 1
63 BSP_IO_PORT_02 = 0x0200, ///< IO port 2
64 BSP_IO_PORT_03 = 0x0300, ///< IO port 3
65 BSP_IO_PORT_04 = 0x0400, ///< IO port 4
66 BSP_IO_PORT_05 = 0x0500, ///< IO port 5
67 BSP_IO_PORT_06 = 0x0600, ///< IO port 6
68 BSP_IO_PORT_07 = 0x0700, ///< IO port 7
69 BSP_IO_PORT_08 = 0x0800, ///< IO port 8
70 BSP_IO_PORT_09 = 0x0900, ///< IO port 9
71 BSP_IO_PORT_10 = 0x0A00, ///< IO port 10
72 BSP_IO_PORT_11 = 0x0B00, ///< IO port 11
73 BSP_IO_PORT_12 = 0x0C00, ///< IO port 12
74 BSP_IO_PORT_13 = 0x0D00, ///< IO port 13
75 BSP_IO_PORT_14 = 0x0E00, ///< IO port 14
76 BSP_IO_PORT_15 = 0x0F00, ///< IO port 15
77 BSP_IO_PORT_16 = 0x1000, ///< IO port 16
78 BSP_IO_PORT_17 = 0x1100, ///< IO port 17
79 BSP_IO_PORT_18 = 0x1200, ///< IO port 18
80 BSP_IO_PORT_19 = 0x1300, ///< IO port 19
81 BSP_IO_PORT_20 = 0x1400, ///< IO port 20
82 BSP_IO_PORT_21 = 0x1500, ///< IO port 21
83 BSP_IO_PORT_22 = 0x1600, ///< IO port 22
84 BSP_IO_PORT_23 = 0x1700, ///< IO port 23
85 BSP_IO_PORT_24 = 0x1800, ///< IO port 24
86 BSP_IO_PORT_25 = 0x1900, ///< IO port 25
87 BSP_IO_PORT_26 = 0x1A00, ///< IO port 26
88 BSP_IO_PORT_27 = 0x1B00, ///< IO port 27
89 BSP_IO_PORT_29 = 0x1D00, ///< IO port 29
90 BSP_IO_PORT_30 = 0x1E00, ///< IO port 30
91 BSP_IO_PORT_31 = 0x1F00, ///< IO port 31
92 BSP_IO_PORT_33 = 0x2100, ///< IO port 33
93 BSP_IO_PORT_34 = 0x2200, ///< IO port 34
94 } bsp_io_port_t;
95
96 /** Superset list of all possible IO port pins. */
97 typedef enum e_bsp_io_port_pin
98 {
99 BSP_IO_PORT_00_PIN_0 = 0x0000, ///< IO port 0 pin 0
100 BSP_IO_PORT_00_PIN_1 = 0x0001, ///< IO port 0 pin 1
101 BSP_IO_PORT_00_PIN_2 = 0x0002, ///< IO port 0 pin 2
102 BSP_IO_PORT_00_PIN_3 = 0x0003, ///< IO port 0 pin 3
103 BSP_IO_PORT_00_PIN_4 = 0x0004, ///< IO port 0 pin 4
104 BSP_IO_PORT_00_PIN_5 = 0x0005, ///< IO port 0 pin 5
105 BSP_IO_PORT_00_PIN_6 = 0x0006, ///< IO port 0 pin 6
106 BSP_IO_PORT_00_PIN_7 = 0x0007, ///< IO port 0 pin 7
107
108 BSP_IO_PORT_01_PIN_0 = 0x0100, ///< IO port 1 pin 0
109 BSP_IO_PORT_01_PIN_1 = 0x0101, ///< IO port 1 pin 1
110 BSP_IO_PORT_01_PIN_2 = 0x0102, ///< IO port 1 pin 2
111 BSP_IO_PORT_01_PIN_3 = 0x0103, ///< IO port 1 pin 3
112 BSP_IO_PORT_01_PIN_4 = 0x0104, ///< IO port 1 pin 4
113 BSP_IO_PORT_01_PIN_5 = 0x0105, ///< IO port 1 pin 5
114 BSP_IO_PORT_01_PIN_6 = 0x0106, ///< IO port 1 pin 6
115 BSP_IO_PORT_01_PIN_7 = 0x0107, ///< IO port 1 pin 7
116
117 BSP_IO_PORT_02_PIN_0 = 0x0200, ///< IO port 2 pin 0
118 BSP_IO_PORT_02_PIN_1 = 0x0201, ///< IO port 2 pin 1
119 BSP_IO_PORT_02_PIN_2 = 0x0202, ///< IO port 2 pin 2
120 BSP_IO_PORT_02_PIN_3 = 0x0203, ///< IO port 2 pin 3
121 BSP_IO_PORT_02_PIN_4 = 0x0204, ///< IO port 2 pin 4
122 BSP_IO_PORT_02_PIN_5 = 0x0205, ///< IO port 2 pin 5
123 BSP_IO_PORT_02_PIN_6 = 0x0206, ///< IO port 2 pin 6
124 BSP_IO_PORT_02_PIN_7 = 0x0207, ///< IO port 2 pin 7
125
126 BSP_IO_PORT_03_PIN_0 = 0x0300, ///< IO port 3 pin 0
127 BSP_IO_PORT_03_PIN_1 = 0x0301, ///< IO port 3 pin 1
128 BSP_IO_PORT_03_PIN_2 = 0x0302, ///< IO port 3 pin 2
129 BSP_IO_PORT_03_PIN_3 = 0x0303, ///< IO port 3 pin 3
130 BSP_IO_PORT_03_PIN_4 = 0x0304, ///< IO port 3 pin 4
131 BSP_IO_PORT_03_PIN_5 = 0x0305, ///< IO port 3 pin 5
132 BSP_IO_PORT_03_PIN_6 = 0x0306, ///< IO port 3 pin 6
133 BSP_IO_PORT_03_PIN_7 = 0x0307, ///< IO port 3 pin 7
134
135 BSP_IO_PORT_04_PIN_0 = 0x0400, ///< IO port 4 pin 0
136 BSP_IO_PORT_04_PIN_1 = 0x0401, ///< IO port 4 pin 1
137 BSP_IO_PORT_04_PIN_2 = 0x0402, ///< IO port 4 pin 2
138 BSP_IO_PORT_04_PIN_3 = 0x0403, ///< IO port 4 pin 3
139 BSP_IO_PORT_04_PIN_4 = 0x0404, ///< IO port 4 pin 4
140 BSP_IO_PORT_04_PIN_5 = 0x0405, ///< IO port 4 pin 5
141 BSP_IO_PORT_04_PIN_6 = 0x0406, ///< IO port 4 pin 6
142 BSP_IO_PORT_04_PIN_7 = 0x0407, ///< IO port 4 pin 7
143
144 BSP_IO_PORT_05_PIN_0 = 0x0500, ///< IO port 5 pin 0
145 BSP_IO_PORT_05_PIN_1 = 0x0501, ///< IO port 5 pin 1
146 BSP_IO_PORT_05_PIN_2 = 0x0502, ///< IO port 5 pin 2
147 BSP_IO_PORT_05_PIN_3 = 0x0503, ///< IO port 5 pin 3
148 BSP_IO_PORT_05_PIN_4 = 0x0504, ///< IO port 5 pin 4
149 BSP_IO_PORT_05_PIN_5 = 0x0505, ///< IO port 5 pin 5
150 BSP_IO_PORT_05_PIN_6 = 0x0506, ///< IO port 5 pin 6
151 BSP_IO_PORT_05_PIN_7 = 0x0507, ///< IO port 5 pin 7
152
153 BSP_IO_PORT_06_PIN_0 = 0x0600, ///< IO port 6 pin 0
154 BSP_IO_PORT_06_PIN_1 = 0x0601, ///< IO port 6 pin 1
155 BSP_IO_PORT_06_PIN_2 = 0x0602, ///< IO port 6 pin 2
156 BSP_IO_PORT_06_PIN_3 = 0x0603, ///< IO port 6 pin 3
157 BSP_IO_PORT_06_PIN_4 = 0x0604, ///< IO port 6 pin 4
158 BSP_IO_PORT_06_PIN_5 = 0x0605, ///< IO port 6 pin 5
159 BSP_IO_PORT_06_PIN_6 = 0x0606, ///< IO port 6 pin 6
160 BSP_IO_PORT_06_PIN_7 = 0x0607, ///< IO port 6 pin 7
161
162 BSP_IO_PORT_07_PIN_0 = 0x0700, ///< IO port 7 pin 0
163 BSP_IO_PORT_07_PIN_1 = 0x0701, ///< IO port 7 pin 1
164 BSP_IO_PORT_07_PIN_2 = 0x0702, ///< IO port 7 pin 2
165 BSP_IO_PORT_07_PIN_3 = 0x0703, ///< IO port 7 pin 3
166 BSP_IO_PORT_07_PIN_4 = 0x0704, ///< IO port 7 pin 4
167 BSP_IO_PORT_07_PIN_5 = 0x0705, ///< IO port 7 pin 5
168 BSP_IO_PORT_07_PIN_6 = 0x0706, ///< IO port 7 pin 6
169 BSP_IO_PORT_07_PIN_7 = 0x0707, ///< IO port 7 pin 7
170
171 BSP_IO_PORT_08_PIN_0 = 0x0800, ///< IO port 8 pin 0
172 BSP_IO_PORT_08_PIN_1 = 0x0801, ///< IO port 8 pin 1
173 BSP_IO_PORT_08_PIN_2 = 0x0802, ///< IO port 8 pin 2
174 BSP_IO_PORT_08_PIN_3 = 0x0803, ///< IO port 8 pin 3
175 BSP_IO_PORT_08_PIN_4 = 0x0804, ///< IO port 8 pin 4
176 BSP_IO_PORT_08_PIN_5 = 0x0805, ///< IO port 8 pin 5
177 BSP_IO_PORT_08_PIN_6 = 0x0806, ///< IO port 8 pin 6
178 BSP_IO_PORT_08_PIN_7 = 0x0807, ///< IO port 8 pin 7
179
180 BSP_IO_PORT_09_PIN_0 = 0x0900, ///< IO port 9 pin 0
181 BSP_IO_PORT_09_PIN_1 = 0x0901, ///< IO port 9 pin 1
182 BSP_IO_PORT_09_PIN_2 = 0x0902, ///< IO port 9 pin 2
183 BSP_IO_PORT_09_PIN_3 = 0x0903, ///< IO port 9 pin 3
184 BSP_IO_PORT_09_PIN_4 = 0x0904, ///< IO port 9 pin 4
185 BSP_IO_PORT_09_PIN_5 = 0x0905, ///< IO port 9 pin 5
186 BSP_IO_PORT_09_PIN_6 = 0x0906, ///< IO port 9 pin 6
187 BSP_IO_PORT_09_PIN_7 = 0x0907, ///< IO port 9 pin 7
188
189 BSP_IO_PORT_10_PIN_0 = 0x0A00, ///< IO port 10 pin 0
190 BSP_IO_PORT_10_PIN_1 = 0x0A01, ///< IO port 10 pin 1
191 BSP_IO_PORT_10_PIN_2 = 0x0A02, ///< IO port 10 pin 2
192 BSP_IO_PORT_10_PIN_3 = 0x0A03, ///< IO port 10 pin 3
193 BSP_IO_PORT_10_PIN_4 = 0x0A04, ///< IO port 10 pin 4
194 BSP_IO_PORT_10_PIN_5 = 0x0A05, ///< IO port 10 pin 5
195 BSP_IO_PORT_10_PIN_6 = 0x0A06, ///< IO port 10 pin 6
196 BSP_IO_PORT_10_PIN_7 = 0x0A07, ///< IO port 10 pin 7
197
198 BSP_IO_PORT_11_PIN_0 = 0x0B00, ///< IO port 11 pin 0
199 BSP_IO_PORT_11_PIN_1 = 0x0B01, ///< IO port 11 pin 1
200 BSP_IO_PORT_11_PIN_2 = 0x0B02, ///< IO port 11 pin 2
201 BSP_IO_PORT_11_PIN_3 = 0x0B03, ///< IO port 11 pin 3
202 BSP_IO_PORT_11_PIN_4 = 0x0B04, ///< IO port 11 pin 4
203 BSP_IO_PORT_11_PIN_5 = 0x0B05, ///< IO port 11 pin 5
204 BSP_IO_PORT_11_PIN_6 = 0x0B06, ///< IO port 11 pin 6
205 BSP_IO_PORT_11_PIN_7 = 0x0B07, ///< IO port 11 pin 7
206
207 BSP_IO_PORT_12_PIN_0 = 0x0C00, ///< IO port 12 pin 0
208 BSP_IO_PORT_12_PIN_1 = 0x0C01, ///< IO port 12 pin 1
209 BSP_IO_PORT_12_PIN_2 = 0x0C02, ///< IO port 12 pin 2
210 BSP_IO_PORT_12_PIN_3 = 0x0C03, ///< IO port 12 pin 3
211 BSP_IO_PORT_12_PIN_4 = 0x0C04, ///< IO port 12 pin 4
212 BSP_IO_PORT_12_PIN_5 = 0x0C05, ///< IO port 12 pin 5
213 BSP_IO_PORT_12_PIN_6 = 0x0C06, ///< IO port 12 pin 6
214 BSP_IO_PORT_12_PIN_7 = 0x0C07, ///< IO port 12 pin 7
215
216 BSP_IO_PORT_13_PIN_0 = 0x0D00, ///< IO port 13 pin 0
217 BSP_IO_PORT_13_PIN_1 = 0x0D01, ///< IO port 13 pin 1
218 BSP_IO_PORT_13_PIN_2 = 0x0D02, ///< IO port 13 pin 2
219 BSP_IO_PORT_13_PIN_3 = 0x0D03, ///< IO port 13 pin 3
220 BSP_IO_PORT_13_PIN_4 = 0x0D04, ///< IO port 13 pin 4
221 BSP_IO_PORT_13_PIN_5 = 0x0D05, ///< IO port 13 pin 5
222 BSP_IO_PORT_13_PIN_6 = 0x0D06, ///< IO port 13 pin 6
223 BSP_IO_PORT_13_PIN_7 = 0x0D07, ///< IO port 13 pin 7
224
225 BSP_IO_PORT_14_PIN_0 = 0x0E00, ///< IO port 14 pin 0
226 BSP_IO_PORT_14_PIN_1 = 0x0E01, ///< IO port 14 pin 1
227 BSP_IO_PORT_14_PIN_2 = 0x0E02, ///< IO port 14 pin 2
228 BSP_IO_PORT_14_PIN_3 = 0x0E03, ///< IO port 14 pin 3
229 BSP_IO_PORT_14_PIN_4 = 0x0E04, ///< IO port 14 pin 4
230 BSP_IO_PORT_14_PIN_5 = 0x0E05, ///< IO port 14 pin 5
231 BSP_IO_PORT_14_PIN_6 = 0x0E06, ///< IO port 14 pin 6
232 BSP_IO_PORT_14_PIN_7 = 0x0E07, ///< IO port 14 pin 7
233
234 BSP_IO_PORT_15_PIN_0 = 0x0F00, ///< IO port 15 pin 0
235 BSP_IO_PORT_15_PIN_1 = 0x0F01, ///< IO port 15 pin 1
236 BSP_IO_PORT_15_PIN_2 = 0x0F02, ///< IO port 15 pin 2
237 BSP_IO_PORT_15_PIN_3 = 0x0F03, ///< IO port 15 pin 3
238 BSP_IO_PORT_15_PIN_4 = 0x0F04, ///< IO port 15 pin 4
239 BSP_IO_PORT_15_PIN_5 = 0x0F05, ///< IO port 15 pin 5
240 BSP_IO_PORT_15_PIN_6 = 0x0F06, ///< IO port 15 pin 6
241 BSP_IO_PORT_15_PIN_7 = 0x0F07, ///< IO port 15 pin 7
242
243 BSP_IO_PORT_16_PIN_0 = 0x1000, ///< IO port 16 pin 0
244 BSP_IO_PORT_16_PIN_1 = 0x1001, ///< IO port 16 pin 1
245 BSP_IO_PORT_16_PIN_2 = 0x1002, ///< IO port 16 pin 2
246 BSP_IO_PORT_16_PIN_3 = 0x1003, ///< IO port 16 pin 3
247 BSP_IO_PORT_16_PIN_4 = 0x1004, ///< IO port 16 pin 4
248 BSP_IO_PORT_16_PIN_5 = 0x1005, ///< IO port 16 pin 5
249 BSP_IO_PORT_16_PIN_6 = 0x1006, ///< IO port 16 pin 6
250 BSP_IO_PORT_16_PIN_7 = 0x1007, ///< IO port 16 pin 7
251
252 BSP_IO_PORT_17_PIN_0 = 0x1100, ///< IO port 17 pin 0
253 BSP_IO_PORT_17_PIN_1 = 0x1101, ///< IO port 17 pin 1
254 BSP_IO_PORT_17_PIN_2 = 0x1102, ///< IO port 17 pin 2
255 BSP_IO_PORT_17_PIN_3 = 0x1103, ///< IO port 17 pin 3
256 BSP_IO_PORT_17_PIN_4 = 0x1104, ///< IO port 17 pin 4
257 BSP_IO_PORT_17_PIN_5 = 0x1105, ///< IO port 17 pin 5
258 BSP_IO_PORT_17_PIN_6 = 0x1106, ///< IO port 17 pin 6
259 BSP_IO_PORT_17_PIN_7 = 0x1107, ///< IO port 17 pin 7
260
261 BSP_IO_PORT_18_PIN_0 = 0x1200, ///< IO port 18 pin 0
262 BSP_IO_PORT_18_PIN_1 = 0x1201, ///< IO port 18 pin 1
263 BSP_IO_PORT_18_PIN_2 = 0x1202, ///< IO port 18 pin 2
264 BSP_IO_PORT_18_PIN_3 = 0x1203, ///< IO port 18 pin 3
265 BSP_IO_PORT_18_PIN_4 = 0x1204, ///< IO port 18 pin 4
266 BSP_IO_PORT_18_PIN_5 = 0x1205, ///< IO port 18 pin 5
267 BSP_IO_PORT_18_PIN_6 = 0x1206, ///< IO port 18 pin 6
268 BSP_IO_PORT_18_PIN_7 = 0x1207, ///< IO port 18 pin 7
269
270 BSP_IO_PORT_19_PIN_0 = 0x1300, ///< IO port 19 pin 0
271 BSP_IO_PORT_19_PIN_1 = 0x1301, ///< IO port 19 pin 1
272 BSP_IO_PORT_19_PIN_2 = 0x1302, ///< IO port 19 pin 2
273 BSP_IO_PORT_19_PIN_3 = 0x1303, ///< IO port 19 pin 3
274 BSP_IO_PORT_19_PIN_4 = 0x1304, ///< IO port 19 pin 4
275 BSP_IO_PORT_19_PIN_5 = 0x1305, ///< IO port 19 pin 5
276 BSP_IO_PORT_19_PIN_6 = 0x1306, ///< IO port 19 pin 6
277 BSP_IO_PORT_19_PIN_7 = 0x1307, ///< IO port 19 pin 7
278
279 BSP_IO_PORT_20_PIN_0 = 0x1400, ///< IO port 20 pin 0
280 BSP_IO_PORT_20_PIN_1 = 0x1401, ///< IO port 20 pin 1
281 BSP_IO_PORT_20_PIN_2 = 0x1402, ///< IO port 20 pin 2
282 BSP_IO_PORT_20_PIN_3 = 0x1403, ///< IO port 20 pin 3
283 BSP_IO_PORT_20_PIN_4 = 0x1404, ///< IO port 20 pin 4
284 BSP_IO_PORT_20_PIN_5 = 0x1405, ///< IO port 20 pin 5
285 BSP_IO_PORT_20_PIN_6 = 0x1406, ///< IO port 20 pin 6
286 BSP_IO_PORT_20_PIN_7 = 0x1407, ///< IO port 20 pin 7
287
288 BSP_IO_PORT_21_PIN_0 = 0x1500, ///< IO port 21 pin 0
289 BSP_IO_PORT_21_PIN_1 = 0x1501, ///< IO port 21 pin 1
290 BSP_IO_PORT_21_PIN_2 = 0x1502, ///< IO port 21 pin 2
291 BSP_IO_PORT_21_PIN_3 = 0x1503, ///< IO port 21 pin 3
292 BSP_IO_PORT_21_PIN_4 = 0x1504, ///< IO port 21 pin 4
293 BSP_IO_PORT_21_PIN_5 = 0x1505, ///< IO port 21 pin 5
294 BSP_IO_PORT_21_PIN_6 = 0x1506, ///< IO port 21 pin 6
295 BSP_IO_PORT_21_PIN_7 = 0x1507, ///< IO port 21 pin 7
296
297 BSP_IO_PORT_22_PIN_0 = 0x1600, ///< IO port 22 pin 0
298 BSP_IO_PORT_22_PIN_1 = 0x1601, ///< IO port 22 pin 1
299 BSP_IO_PORT_22_PIN_2 = 0x1602, ///< IO port 22 pin 2
300 BSP_IO_PORT_22_PIN_3 = 0x1603, ///< IO port 22 pin 3
301 BSP_IO_PORT_22_PIN_4 = 0x1604, ///< IO port 22 pin 4
302 BSP_IO_PORT_22_PIN_5 = 0x1605, ///< IO port 22 pin 5
303 BSP_IO_PORT_22_PIN_6 = 0x1606, ///< IO port 22 pin 6
304 BSP_IO_PORT_22_PIN_7 = 0x1607, ///< IO port 22 pin 7
305
306 BSP_IO_PORT_23_PIN_0 = 0x1700, ///< IO port 23 pin 0
307 BSP_IO_PORT_23_PIN_1 = 0x1701, ///< IO port 23 pin 1
308 BSP_IO_PORT_23_PIN_2 = 0x1702, ///< IO port 23 pin 2
309 BSP_IO_PORT_23_PIN_3 = 0x1703, ///< IO port 23 pin 3
310 BSP_IO_PORT_23_PIN_4 = 0x1704, ///< IO port 23 pin 4
311 BSP_IO_PORT_23_PIN_5 = 0x1705, ///< IO port 23 pin 5
312 BSP_IO_PORT_23_PIN_6 = 0x1706, ///< IO port 23 pin 6
313 BSP_IO_PORT_23_PIN_7 = 0x1707, ///< IO port 23 pin 7
314
315 BSP_IO_PORT_24_PIN_0 = 0x1800, ///< IO port 24 pin 0
316 BSP_IO_PORT_24_PIN_1 = 0x1801, ///< IO port 24 pin 1
317 BSP_IO_PORT_24_PIN_2 = 0x1802, ///< IO port 24 pin 2
318 BSP_IO_PORT_24_PIN_3 = 0x1803, ///< IO port 24 pin 3
319 BSP_IO_PORT_24_PIN_4 = 0x1804, ///< IO port 24 pin 4
320 BSP_IO_PORT_24_PIN_5 = 0x1805, ///< IO port 24 pin 5
321 BSP_IO_PORT_24_PIN_6 = 0x1806, ///< IO port 24 pin 6
322 BSP_IO_PORT_24_PIN_7 = 0x1807, ///< IO port 24 pin 7
323
324 BSP_IO_PORT_25_PIN_0 = 0x1900, ///< IO port 25 pin 0
325 BSP_IO_PORT_25_PIN_1 = 0x1901, ///< IO port 25 pin 1
326 BSP_IO_PORT_25_PIN_2 = 0x1902, ///< IO port 25 pin 2
327 BSP_IO_PORT_25_PIN_3 = 0x1903, ///< IO port 25 pin 3
328 BSP_IO_PORT_25_PIN_4 = 0x1904, ///< IO port 25 pin 4
329 BSP_IO_PORT_25_PIN_5 = 0x1905, ///< IO port 25 pin 5
330 BSP_IO_PORT_25_PIN_6 = 0x1906, ///< IO port 25 pin 6
331 BSP_IO_PORT_25_PIN_7 = 0x1907, ///< IO port 25 pin 7
332
333 BSP_IO_PORT_26_PIN_0 = 0x1A00, ///< IO port 26 pin 0
334 BSP_IO_PORT_26_PIN_1 = 0x1A01, ///< IO port 26 pin 1
335 BSP_IO_PORT_26_PIN_2 = 0x1A02, ///< IO port 26 pin 2
336 BSP_IO_PORT_26_PIN_3 = 0x1A03, ///< IO port 26 pin 3
337 BSP_IO_PORT_26_PIN_4 = 0x1A04, ///< IO port 26 pin 4
338 BSP_IO_PORT_26_PIN_5 = 0x1A05, ///< IO port 26 pin 5
339 BSP_IO_PORT_26_PIN_6 = 0x1A06, ///< IO port 26 pin 6
340 BSP_IO_PORT_26_PIN_7 = 0x1A07, ///< IO port 26 pin 7
341
342 BSP_IO_PORT_27_PIN_0 = 0x1B00, ///< IO port 27 pin 0
343 BSP_IO_PORT_27_PIN_1 = 0x1B01, ///< IO port 27 pin 1
344 BSP_IO_PORT_27_PIN_2 = 0x1B02, ///< IO port 27 pin 2
345 BSP_IO_PORT_27_PIN_3 = 0x1B03, ///< IO port 27 pin 3
346 BSP_IO_PORT_27_PIN_4 = 0x1B04, ///< IO port 27 pin 4
347 BSP_IO_PORT_27_PIN_5 = 0x1B05, ///< IO port 27 pin 5
348 BSP_IO_PORT_27_PIN_6 = 0x1B06, ///< IO port 27 pin 6
349 BSP_IO_PORT_27_PIN_7 = 0x1B07, ///< IO port 27 pin 7
350
351 BSP_IO_PORT_28_PIN_0 = 0x1C00, ///< IO port 28 pin 0
352 BSP_IO_PORT_28_PIN_1 = 0x1C01, ///< IO port 28 pin 1
353 BSP_IO_PORT_28_PIN_2 = 0x1C02, ///< IO port 28 pin 2
354 BSP_IO_PORT_28_PIN_3 = 0x1C03, ///< IO port 28 pin 3
355 BSP_IO_PORT_28_PIN_4 = 0x1C04, ///< IO port 28 pin 4
356 BSP_IO_PORT_28_PIN_5 = 0x1C05, ///< IO port 28 pin 5
357 BSP_IO_PORT_28_PIN_6 = 0x1C06, ///< IO port 28 pin 6
358 BSP_IO_PORT_28_PIN_7 = 0x1C07, ///< IO port 28 pin 7
359
360 BSP_IO_PORT_29_PIN_0 = 0x1D00, ///< IO port 29 pin 0
361 BSP_IO_PORT_29_PIN_1 = 0x1D01, ///< IO port 29 pin 1
362 BSP_IO_PORT_29_PIN_2 = 0x1D02, ///< IO port 29 pin 2
363 BSP_IO_PORT_29_PIN_3 = 0x1D03, ///< IO port 29 pin 3
364 BSP_IO_PORT_29_PIN_4 = 0x1D04, ///< IO port 29 pin 4
365 BSP_IO_PORT_29_PIN_5 = 0x1D05, ///< IO port 29 pin 5
366 BSP_IO_PORT_29_PIN_6 = 0x1D06, ///< IO port 29 pin 6
367 BSP_IO_PORT_29_PIN_7 = 0x1D07, ///< IO port 29 pin 7
368
369 BSP_IO_PORT_30_PIN_0 = 0x1E00, ///< IO port 30 pin 0
370 BSP_IO_PORT_30_PIN_1 = 0x1E01, ///< IO port 30 pin 1
371 BSP_IO_PORT_30_PIN_2 = 0x1E02, ///< IO port 30 pin 2
372 BSP_IO_PORT_30_PIN_3 = 0x1E03, ///< IO port 30 pin 3
373 BSP_IO_PORT_30_PIN_4 = 0x1E04, ///< IO port 30 pin 4
374 BSP_IO_PORT_30_PIN_5 = 0x1E05, ///< IO port 30 pin 5
375 BSP_IO_PORT_30_PIN_6 = 0x1E06, ///< IO port 30 pin 6
376 BSP_IO_PORT_30_PIN_7 = 0x1E07, ///< IO port 30 pin 7
377
378 BSP_IO_PORT_31_PIN_0 = 0x1F00, ///< IO port 31 pin 0
379 BSP_IO_PORT_31_PIN_1 = 0x1F01, ///< IO port 31 pin 1
380 BSP_IO_PORT_31_PIN_2 = 0x1F02, ///< IO port 31 pin 2
381 BSP_IO_PORT_31_PIN_3 = 0x1F03, ///< IO port 31 pin 3
382 BSP_IO_PORT_31_PIN_4 = 0x1F04, ///< IO port 31 pin 4
383 BSP_IO_PORT_31_PIN_5 = 0x1F05, ///< IO port 31 pin 5
384 BSP_IO_PORT_31_PIN_6 = 0x1F06, ///< IO port 31 pin 6
385 BSP_IO_PORT_31_PIN_7 = 0x1F07, ///< IO port 31 pin 7
386
387 BSP_IO_PORT_32_PIN_0 = 0x2000, ///< IO port 32 pin 0
388 BSP_IO_PORT_32_PIN_1 = 0x2001, ///< IO port 32 pin 1
389 BSP_IO_PORT_32_PIN_2 = 0x2002, ///< IO port 32 pin 2
390 BSP_IO_PORT_32_PIN_3 = 0x2003, ///< IO port 32 pin 3
391 BSP_IO_PORT_32_PIN_4 = 0x2004, ///< IO port 32 pin 4
392 BSP_IO_PORT_32_PIN_5 = 0x2005, ///< IO port 32 pin 5
393 BSP_IO_PORT_32_PIN_6 = 0x2006, ///< IO port 32 pin 6
394 BSP_IO_PORT_32_PIN_7 = 0x2007, ///< IO port 32 pin 7
395
396 BSP_IO_PORT_33_PIN_0 = 0x2100, ///< IO port 33 pin 0
397 BSP_IO_PORT_33_PIN_1 = 0x2101, ///< IO port 33 pin 1
398 BSP_IO_PORT_33_PIN_2 = 0x2102, ///< IO port 33 pin 2
399 BSP_IO_PORT_33_PIN_3 = 0x2103, ///< IO port 33 pin 3
400 BSP_IO_PORT_33_PIN_4 = 0x2104, ///< IO port 33 pin 4
401 BSP_IO_PORT_33_PIN_5 = 0x2105, ///< IO port 33 pin 5
402 BSP_IO_PORT_33_PIN_6 = 0x2106, ///< IO port 33 pin 6
403 BSP_IO_PORT_33_PIN_7 = 0x2107, ///< IO port 33 pin 7
404
405 BSP_IO_PORT_34_PIN_0 = 0x2200, ///< IO port 34 pin 0
406 BSP_IO_PORT_34_PIN_1 = 0x2201, ///< IO port 34 pin 1
407 BSP_IO_PORT_34_PIN_2 = 0x2202, ///< IO port 34 pin 2
408 BSP_IO_PORT_34_PIN_3 = 0x2203, ///< IO port 34 pin 3
409 BSP_IO_PORT_34_PIN_4 = 0x2204, ///< IO port 34 pin 4
410 BSP_IO_PORT_34_PIN_5 = 0x2205, ///< IO port 34 pin 5
411 BSP_IO_PORT_34_PIN_6 = 0x2206, ///< IO port 34 pin 6
412 BSP_IO_PORT_34_PIN_7 = 0x2207, ///< IO port 34 pin 7
413 } bsp_io_port_pin_t;
414
415 /** Offset for pin safety region access */
416 typedef enum e_bsp_io_region
417 {
418 BSP_IO_REGION_NOT_SAFE = 0, ///< Non safety region
419 BSP_IO_REGION_SAFE = BSP_FEATURE_BSP_IO_REGION_ADDRESS_DIFF_SELECTABLE, ///< Safety region
420 BSP_IO_REGION_NOT_SAFE_DEDICATED = BSP_FEATURE_BSP_IO_REGION_ADDRESS_DIFF_DEDICATED, ///< Non safety dedicated region
421 } bsp_io_region_t;
422
423 /***********************************************************************************************************************
424 * Exported global variables
425 **********************************************************************************************************************/
426 extern volatile uint32_t g_protect_port_counter;
427
428 /***********************************************************************************************************************
429 * Exported global functions (to be accessed by other files)
430 **********************************************************************************************************************/
431
432 /***********************************************************************************************************************
433 * Inline Functions
434 **********************************************************************************************************************/
435
436 /*******************************************************************************************************************//**
437 * Set the output level of the pin in the specified region.
438 *
439 * @param[in] region The target IO region
440 * @param[in] pin The pin
441 **********************************************************************************************************************/
R_BSP_PinSet(bsp_io_region_t region,bsp_io_port_pin_t pin)442 __STATIC_INLINE void R_BSP_PinSet (bsp_io_region_t region, bsp_io_port_pin_t pin)
443 {
444 #if BSP_FEATURE_IOPORT_HAS_NONSAFETY_DEDICATED_PORT
445 if (region == BSP_IO_REGION_NOT_SAFE_DEDICATED)
446 {
447 /* Casting to a uint8_t type is valid because only the lower 8 bits of pin(uint16_t) are extracted by masking on
448 * the right side. */
449 R_PORT_NSR->P[pin >> 8] |=
450 (uint8_t) (1UL << (pin & BSP_IO_PRV_8BIT_MASK));
451 }
452 else
453 #endif
454 {
455 /* Casting to a uint8_t type is valid because only the lower 8 bits of pin(uint16_t) are extracted by masking on
456 * the right side. */
457 ((R_PORT_COMMON_Type *) (BSP_FEATURE_BSP_IO_SELECTABLE_NON_SAFETY_BASE + region))->P[pin >>
458 BSP_IO_PRV_PORT_OFFSET] |=
459 (uint8_t) (1UL << (pin & BSP_IO_PRV_8BIT_MASK));
460 }
461 }
462
463 /*******************************************************************************************************************//**
464 * Clear the output level of the pin in the specified region.
465 *
466 * @param[in] region The target IO region
467 * @param[in] pin The pin
468 **********************************************************************************************************************/
R_BSP_PinClear(bsp_io_region_t region,bsp_io_port_pin_t pin)469 __STATIC_INLINE void R_BSP_PinClear (bsp_io_region_t region, bsp_io_port_pin_t pin)
470 {
471 #if BSP_FEATURE_IOPORT_HAS_NONSAFETY_DEDICATED_PORT
472 if (region == BSP_IO_REGION_NOT_SAFE_DEDICATED)
473 {
474 /* Casting to a uint8_t type is valid because only the lower 8 bits of pin(uint16_t) are extracted by masking on
475 * the right side. */
476 R_PORT_NSR->P[pin >> 8] &=
477 (uint8_t) (~(1UL << (pin & BSP_IO_PRV_8BIT_MASK)));
478 }
479 else
480 #endif
481 {
482 /* Casting to a uint8_t type is valid because only the lower 8 bits of pin(uint16_t) are extracted by masking on
483 * the right side. */
484 ((R_PORT_COMMON_Type *) (BSP_FEATURE_BSP_IO_SELECTABLE_NON_SAFETY_BASE + region))->P[pin >>
485 BSP_IO_PRV_PORT_OFFSET] &=
486 (uint8_t) (~(1UL << (pin & BSP_IO_PRV_8BIT_MASK)));
487 }
488 }
489
490 /*******************************************************************************************************************//**
491 * Toggle the output level of the pin in the specified region.
492 *
493 * @param[in] region The target IO region
494 * @param[in] pin The pin
495 **********************************************************************************************************************/
R_BSP_PinToggle(bsp_io_region_t region,bsp_io_port_pin_t pin)496 __STATIC_INLINE void R_BSP_PinToggle (bsp_io_region_t region, bsp_io_port_pin_t pin)
497 {
498 #if BSP_FEATURE_IOPORT_HAS_NONSAFETY_DEDICATED_PORT
499 if (region == BSP_IO_REGION_NOT_SAFE_DEDICATED)
500 {
501 /* Casting to a uint8_t type is valid because only the lower 8 bits of pin(uint16_t) are extracted by masking on
502 * the right side. */
503 R_PORT_NSR->P[pin >> 8] ^=
504 (uint8_t) (1UL << (pin & BSP_IO_PRV_8BIT_MASK));
505 }
506 else
507 #endif
508 {
509 /* Casting to a uint8_t type is valid because only the lower 8 bits of pin(uint16_t) are extracted by masking on
510 * the right side. */
511 ((R_PORT_COMMON_Type *) (BSP_FEATURE_BSP_IO_SELECTABLE_NON_SAFETY_BASE + region))->P[pin >>
512 BSP_IO_PRV_PORT_OFFSET] ^=
513 (uint8_t) (1UL << (pin & BSP_IO_PRV_8BIT_MASK));
514 }
515 }
516
517 /*******************************************************************************************************************//**
518 * Read the input level of the pin in the specified region.
519 *
520 * @param[in] region The target IO region
521 * @param[in] pin The pin
522 *
523 * @retval Current input level
524 **********************************************************************************************************************/
R_BSP_FastPinRead(bsp_io_region_t region,bsp_io_port_pin_t pin)525 __STATIC_INLINE uint32_t R_BSP_FastPinRead (bsp_io_region_t region, bsp_io_port_pin_t pin)
526 {
527 #if BSP_FEATURE_IOPORT_HAS_NONSAFETY_DEDICATED_PORT
528 if (region == BSP_IO_REGION_NOT_SAFE_DEDICATED)
529 {
530 return (uint32_t) ((R_PORT_NSR->PIN[pin >> 8]) >>
531 (pin & BSP_IO_PRV_8BIT_MASK)) & 0x00000001UL;
532 }
533 #endif
534
535 return (uint32_t) ((((R_PORT_COMMON_Type *) (BSP_FEATURE_BSP_IO_SELECTABLE_NON_SAFETY_BASE + region))->PIN[pin >>
536 BSP_IO_PRV_PORT_OFFSET
537 ]) >>
538 (pin & BSP_IO_PRV_8BIT_MASK)) & 0x00000001UL;
539 }
540
541 /*******************************************************************************************************************//**
542 * Set the output value of the port in the specified region. All pins in the port must be set to the same IO region to
543 * use this function.
544 *
545 * @param[in] region The target IO region
546 * @param[in] port The port
547 * @param[in] set_value The setting value
548 **********************************************************************************************************************/
R_BSP_PortWrite(bsp_io_region_t region,bsp_io_port_t port,uint8_t set_value)549 __STATIC_INLINE void R_BSP_PortWrite (bsp_io_region_t region, bsp_io_port_t port, uint8_t set_value)
550 {
551 #if BSP_FEATURE_IOPORT_HAS_NONSAFETY_DEDICATED_PORT
552 if (region == BSP_IO_REGION_NOT_SAFE_DEDICATED)
553 {
554 R_PORT_NSR->P[port >> 8] = set_value;
555 }
556 else
557 #endif
558 {
559 ((R_PORT_COMMON_Type *) (BSP_FEATURE_BSP_IO_SELECTABLE_NON_SAFETY_BASE + region))->P[port >>
560 BSP_IO_PRV_PORT_OFFSET] =
561 set_value;
562 }
563 }
564
565 /*******************************************************************************************************************//**
566 * Read the input value of the port in the specified region. All pins in the port must be set to the same IO region to
567 * use this function.
568 *
569 * @param[in] region The target IO region
570 * @param[in] port The port
571 *
572 * @retval Current input value
573 **********************************************************************************************************************/
R_BSP_PortRead(bsp_io_region_t region,bsp_io_port_t port)574 __STATIC_INLINE uint32_t R_BSP_PortRead (bsp_io_region_t region, bsp_io_port_t port)
575 {
576 #if BSP_FEATURE_IOPORT_HAS_NONSAFETY_DEDICATED_PORT
577 if (region == BSP_IO_REGION_NOT_SAFE_DEDICATED)
578 {
579 return (uint32_t) (R_PORT_NSR->PIN[port >> 8]);
580 }
581 #endif
582
583 return (uint32_t) (((R_PORT_COMMON_Type *) (BSP_FEATURE_BSP_IO_SELECTABLE_NON_SAFETY_BASE + region))->PIN[port >>
584 BSP_IO_PRV_PORT_OFFSET
585 ]);
586 }
587
588 /*******************************************************************************************************************//**
589 * Enable access to the PFS registers. Uses a reference counter to protect against interrupts that could occur
590 * via multiple threads or an ISR re-entering this code.
591 **********************************************************************************************************************/
R_BSP_PinAccessEnable(void)592 __STATIC_INLINE void R_BSP_PinAccessEnable (void)
593 {
594 #if BSP_CFG_PORT_PROTECT
595
596 /** Get the current state of interrupts */
597 FSP_CRITICAL_SECTION_DEFINE;
598 FSP_CRITICAL_SECTION_ENTER;
599
600 /** If this is first entry then allow writing of PFS. */
601 if (0 == g_protect_port_counter)
602 {
603 /** Disable protection using PRCR register. */
604
605 /** When writing to the PRCR register the upper 8-bits must be the correct key. Set lower bits to 0 to
606 * disable writes. */
607 R_RWP_NS->PRCRN = ((R_RWP_NS->PRCRN | BSP_IO_PRV_PRCR_KEY) | BSP_IO_REG_PROTECT_GPIO);
608 R_RWP_S->PRCRS = ((R_RWP_S->PRCRS | BSP_IO_PRV_PRCR_KEY) | BSP_IO_REG_PROTECT_GPIO);
609 }
610
611 /** Increment the protect counter */
612 g_protect_port_counter++;
613
614 /** Restore the interrupt state */
615 FSP_CRITICAL_SECTION_EXIT;
616 #endif
617 }
618
619 /*******************************************************************************************************************//**
620 * Disable access to the PFS registers. Uses a reference counter to protect against interrupts that could occur via
621 * multiple threads or an ISR re-entering this code.
622 **********************************************************************************************************************/
R_BSP_PinAccessDisable(void)623 __STATIC_INLINE void R_BSP_PinAccessDisable (void)
624 {
625 #if BSP_CFG_PORT_PROTECT
626
627 /** Get the current state of interrupts */
628 FSP_CRITICAL_SECTION_DEFINE;
629 FSP_CRITICAL_SECTION_ENTER;
630
631 /** Is it safe to disable PFS register? */
632 if (0 != g_protect_port_counter)
633 {
634 /* Decrement the protect counter */
635 g_protect_port_counter--;
636 }
637
638 /** Is it safe to disable writing of PFS? */
639 if (0 == g_protect_port_counter)
640 {
641 /** Enable protection using PRCR register. */
642
643 /** When writing to the PRCR register the upper 8-bits must be the correct key. Set lower bits to 0 to
644 * disable writes. */
645 R_RWP_NS->PRCRN = ((R_RWP_NS->PRCRN | BSP_IO_PRV_PRCR_KEY) & (uint16_t) (~BSP_IO_REG_PROTECT_GPIO));
646 R_RWP_S->PRCRS = ((R_RWP_S->PRCRS | BSP_IO_PRV_PRCR_KEY) & (uint16_t) (~BSP_IO_REG_PROTECT_GPIO));
647 }
648
649 /** Restore the interrupt state */
650 FSP_CRITICAL_SECTION_EXIT;
651 #endif
652 }
653
654 /*******************************************************************************************************************//**
655 * Read IO region of the pin.
656 *
657 * @param[in] pin The pin
658 *
659 * @retval BSP_IO_REGION_SAFE IO region of the pin is safety
660 * @retval BSP_IO_REGION_NOT_SAFE IO region of the pin is non-safety
661 * @retval BSP_IO_REGION_NOT_SAFE_DEDICATED IO region of the pin is non-safety (dedicated)
662 *
663 * This function can be given as an argument to pin/port access functions described below. When used in a function
664 * starting with R_BSP_Port, any one pin in the port should be given as an argument to this function.
665 * R_BSP_PinSet(), R_BSP_PinClear(), R_BSP_PinToggle(), R_BSP_FastPinRead(), R_BSP_PortWrite(), R_BSP_PortRead()
666 *
667 * @note This function can be used to get the region of a specified pin, but the overhead should be considered if this
668 * function is executed each time the pin is accessed. When accessing the same pin repeatedly, it is recommended
669 * that the value obtained by this function be held in a variable beforehand, and the value of the variable be
670 * used as the region argument of the pin access function.
671 **********************************************************************************************************************/
R_BSP_IoRegionGet(bsp_io_port_pin_t pin)672 __STATIC_INLINE bsp_io_region_t R_BSP_IoRegionGet (bsp_io_port_pin_t pin)
673 {
674 uint32_t aselp = 0;
675
676 /* Casting to a uint32_t type is valid because the range of values represented by uint32_t is not over in the
677 * calculation process of the right-hand side. */
678 #if BSP_FEATURE_IOPORT_HAS_NONSAFETY_DEDICATED_PORT
679 if (BSP_FEATURE_BSP_IO_SELECTABLE_NON_SAFETY_PORT > (uint32_t) (pin >> BSP_IO_PRV_PORT_OFFSET))
680 {
681 aselp =
682 ((uint32_t) ((R_PORT_SRS->RSELP[pin >> BSP_IO_PRV_PORT_OFFSET]) >> (pin & BSP_IO_PRV_8BIT_MASK)) &
683 0x00000001UL);
684 }
685 else
686 {
687 aselp = (uint32_t) BSP_IO_REGION_NOT_SAFE_DEDICATED;
688 }
689 #else
690 aselp =
691 ((uint32_t) ((R_PTADR->RSELP[pin >> BSP_IO_PRV_PORT_OFFSET]) >> (pin & BSP_IO_PRV_8BIT_MASK)) & 0x00000001UL);
692 #endif
693
694 if (0U == aselp)
695 {
696 return BSP_IO_REGION_SAFE;
697 }
698 else if (1U == aselp)
699 {
700 return BSP_IO_REGION_NOT_SAFE;
701 }
702 else
703 {
704 return BSP_IO_REGION_NOT_SAFE_DEDICATED;
705 }
706 }
707
708 /** @} (end addtogroup BSP_IO) */
709
710 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
711 FSP_FOOTER
712
713 #endif
714