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