]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_K22F/device/MK22F51212/fsl_bitaccess.h
2 ** ###################################################################
3 ** Version: rev. 2.5, 2014-05-06
7 ** Register bit field access macros.
9 ** Copyright (c) 2014 Freescale Semiconductor, Inc.
10 ** All rights reserved.
12 ** Redistribution and use in source and binary forms, with or without modification,
13 ** are permitted provided that the following conditions are met:
15 ** o Redistributions of source code must retain the above copyright notice, this list
16 ** of conditions and the following disclaimer.
18 ** o Redistributions in binary form must reproduce the above copyright notice, this
19 ** list of conditions and the following disclaimer in the documentation and/or
20 ** other materials provided with the distribution.
22 ** o Neither the name of Freescale Semiconductor, Inc. nor the names of its
23 ** contributors may be used to endorse or promote products derived from this
24 ** software without specific prior written permission.
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
30 ** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33 ** ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 ** http: www.freescale.com
38 ** mail: support@freescale.com
41 ** - rev. 1.0 (2013-07-23)
43 ** - rev. 1.1 (2013-09-17)
44 ** RM rev. 0.4 update.
45 ** - rev. 2.0 (2013-10-29)
46 ** Register accessor macros added to the memory map.
47 ** Symbols for Processor Expert memory map compatibility added to the memory map.
48 ** Startup file for gcc has been updated according to CMSIS 3.2.
49 ** System initialization updated.
50 ** - rev. 2.1 (2013-10-30)
51 ** Definition of BITBAND macros updated to support peripherals with 32-bit acces disabled.
52 ** - rev. 2.2 (2013-12-20)
53 ** Update according to reference manual rev. 0.6,
54 ** - rev. 2.3 (2014-01-13)
55 ** Update according to reference manual rev. 0.61,
56 ** - rev. 2.4 (2014-02-10)
57 ** The declaration of clock configurations has been moved to separate header file system_MK22F51212.h
58 ** - rev. 2.5 (2014-05-06)
59 ** Update according to reference manual rev. 1.0,
60 ** Update of system and startup files.
61 ** Module access macro module_BASES replaced by module_BASE_PTRS.
63 ** ###################################################################
67 #ifndef _FSL_BITACCESS_H
68 #define _FSL_BITACCESS_H 1
74 * @brief Macro to access a single bit of a 32-bit peripheral register (bit band region
75 * 0x40000000 to 0x400FFFFF) using the bit-band alias region access.
76 * @param Reg Register to access.
77 * @param Bit Bit number to access.
78 * @return Value of the targeted bit in the bit band region.
80 #define BITBAND_ACCESS32(Reg,Bit) (*((uint32_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit))))))
83 * @brief Macro to access a single bit of a 16-bit peripheral register (bit band region
84 * 0x40000000 to 0x400FFFFF) using the bit-band alias region access.
85 * @param Reg Register to access.
86 * @param Bit Bit number to access.
87 * @return Value of the targeted bit in the bit band region.
89 #define BITBAND_ACCESS16(Reg,Bit) (*((uint16_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit))))))
92 * @brief Macro to access a single bit of an 8-bit peripheral register (bit band region
93 * 0x40000000 to 0x400FFFFF) using the bit-band alias region access.
94 * @param Reg Register to access.
95 * @param Bit Bit number to access.
96 * @return Value of the targeted bit in the bit band region.
98 #define BITBAND_ACCESS8(Reg,Bit) (*((uint8_t volatile*)(0x42000000u + (32u*((uint32_t)(Reg) - (uint32_t)0x40000000u)) + (4u*((uint32_t)(Bit))))))
101 * Macros for single instance registers
104 #define BF_SET(reg, field) HW_##reg##_SET(BM_##reg##_##field)
105 #define BF_CLR(reg, field) HW_##reg##_CLR(BM_##reg##_##field)
106 #define BF_TOG(reg, field) HW_##reg##_TOG(BM_##reg##_##field)
108 #define BF_SETV(reg, field, v) HW_##reg##_SET(BF_##reg##_##field(v))
109 #define BF_CLRV(reg, field, v) HW_##reg##_CLR(BF_##reg##_##field(v))
110 #define BF_TOGV(reg, field, v) HW_##reg##_TOG(BF_##reg##_##field(v))
112 #define BV_FLD(reg, field, sym) BF_##reg##_##field(BV_##reg##_##field##__##sym)
113 #define BV_VAL(reg, field, sym) BV_##reg##_##field##__##sym
115 #define BF_RD(reg, field) HW_##reg.B.field
116 #define BF_WR(reg, field, v) BW_##reg##_##field(v)
118 #define BF_CS1(reg, f1, v1) \
119 (HW_##reg##_CLR(BM_##reg##_##f1), \
120 HW_##reg##_SET(BF_##reg##_##f1(v1)))
122 #define BF_CS2(reg, f1, v1, f2, v2) \
123 (HW_##reg##_CLR(BM_##reg##_##f1 | \
125 HW_##reg##_SET(BF_##reg##_##f1(v1) | \
126 BF_##reg##_##f2(v2)))
128 #define BF_CS3(reg, f1, v1, f2, v2, f3, v3) \
129 (HW_##reg##_CLR(BM_##reg##_##f1 | \
132 HW_##reg##_SET(BF_##reg##_##f1(v1) | \
133 BF_##reg##_##f2(v2) | \
134 BF_##reg##_##f3(v3)))
136 #define BF_CS4(reg, f1, v1, f2, v2, f3, v3, f4, v4) \
137 (HW_##reg##_CLR(BM_##reg##_##f1 | \
141 HW_##reg##_SET(BF_##reg##_##f1(v1) | \
142 BF_##reg##_##f2(v2) | \
143 BF_##reg##_##f3(v3) | \
144 BF_##reg##_##f4(v4)))
146 #define BF_CS5(reg, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) \
147 (HW_##reg##_CLR(BM_##reg##_##f1 | \
152 HW_##reg##_SET(BF_##reg##_##f1(v1) | \
153 BF_##reg##_##f2(v2) | \
154 BF_##reg##_##f3(v3) | \
155 BF_##reg##_##f4(v4) | \
156 BF_##reg##_##f5(v5)))
158 #define BF_CS6(reg, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) \
159 (HW_##reg##_CLR(BM_##reg##_##f1 | \
165 HW_##reg##_SET(BF_##reg##_##f1(v1) | \
166 BF_##reg##_##f2(v2) | \
167 BF_##reg##_##f3(v3) | \
168 BF_##reg##_##f4(v4) | \
169 BF_##reg##_##f5(v5) | \
170 BF_##reg##_##f6(v6)))
172 #define BF_CS7(reg, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) \
173 (HW_##reg##_CLR(BM_##reg##_##f1 | \
180 HW_##reg##_SET(BF_##reg##_##f1(v1) | \
181 BF_##reg##_##f2(v2) | \
182 BF_##reg##_##f3(v3) | \
183 BF_##reg##_##f4(v4) | \
184 BF_##reg##_##f5(v5) | \
185 BF_##reg##_##f6(v6) | \
186 BF_##reg##_##f7(v7)))
188 #define BF_CS8(reg, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) \
189 (HW_##reg##_CLR(BM_##reg##_##f1 | \
197 HW_##reg##_SET(BF_##reg##_##f1(v1) | \
198 BF_##reg##_##f2(v2) | \
199 BF_##reg##_##f3(v3) | \
200 BF_##reg##_##f4(v4) | \
201 BF_##reg##_##f5(v5) | \
202 BF_##reg##_##f6(v6) | \
203 BF_##reg##_##f7(v7) | \
204 BF_##reg##_##f8(v8)))
207 * Macros for multiple instance registers
210 #define BF_SETn(reg, n, field) HW_##reg##_SET(n, BM_##reg##_##field)
211 #define BF_CLRn(reg, n, field) HW_##reg##_CLR(n, BM_##reg##_##field)
212 #define BF_TOGn(reg, n, field) HW_##reg##_TOG(n, BM_##reg##_##field)
214 #define BF_SETVn(reg, n, field, v) HW_##reg##_SET(n, BF_##reg##_##field(v))
215 #define BF_CLRVn(reg, n, field, v) HW_##reg##_CLR(n, BF_##reg##_##field(v))
216 #define BF_TOGVn(reg, n, field, v) HW_##reg##_TOG(n, BF_##reg##_##field(v))
218 #define BV_FLDn(reg, n, field, sym) BF_##reg##_##field(BV_##reg##_##field##__##sym)
219 #define BV_VALn(reg, n, field, sym) BV_##reg##_##field##__##sym
221 #define BF_RDn(reg, n, field) HW_##reg(n).B.field
222 #define BF_WRn(reg, n, field, v) BW_##reg##_##field(n, v)
224 #define BF_CS1n(reg, n, f1, v1) \
225 (HW_##reg##_CLR(n, (BM_##reg##_##f1)), \
226 HW_##reg##_SET(n, (BF_##reg##_##f1(v1))))
228 #define BF_CS2n(reg, n, f1, v1, f2, v2) \
229 (HW_##reg##_CLR(n, (BM_##reg##_##f1 | \
231 HW_##reg##_SET(n, (BF_##reg##_##f1(v1) | \
232 BF_##reg##_##f2(v2))))
234 #define BF_CS3n(reg, n, f1, v1, f2, v2, f3, v3) \
235 (HW_##reg##_CLR(n, (BM_##reg##_##f1 | \
238 HW_##reg##_SET(n, (BF_##reg##_##f1(v1) | \
239 BF_##reg##_##f2(v2) | \
240 BF_##reg##_##f3(v3))))
242 #define BF_CS4n(reg, n, f1, v1, f2, v2, f3, v3, f4, v4) \
243 (HW_##reg##_CLR(n, (BM_##reg##_##f1 | \
247 HW_##reg##_SET(n, (BF_##reg##_##f1(v1) | \
248 BF_##reg##_##f2(v2) | \
249 BF_##reg##_##f3(v3) | \
250 BF_##reg##_##f4(v4))))
252 #define BF_CS5n(reg, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) \
253 (HW_##reg##_CLR(n, (BM_##reg##_##f1 | \
258 HW_##reg##_SET(n, (BF_##reg##_##f1(v1) | \
259 BF_##reg##_##f2(v2) | \
260 BF_##reg##_##f3(v3) | \
261 BF_##reg##_##f4(v4) | \
262 BF_##reg##_##f5(v5))))
264 #define BF_CS6n(reg, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) \
265 (HW_##reg##_CLR(n, (BM_##reg##_##f1 | \
271 HW_##reg##_SET(n, (BF_##reg##_##f1(v1) | \
272 BF_##reg##_##f2(v2) | \
273 BF_##reg##_##f3(v3) | \
274 BF_##reg##_##f4(v4) | \
275 BF_##reg##_##f5(v5) | \
276 BF_##reg##_##f6(v6))))
278 #define BF_CS7n(reg, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) \
279 (HW_##reg##_CLR(n, (BM_##reg##_##f1 | \
286 HW_##reg##_SET(n, (BF_##reg##_##f1(v1) | \
287 BF_##reg##_##f2(v2) | \
288 BF_##reg##_##f3(v3) | \
289 BF_##reg##_##f4(v4) | \
290 BF_##reg##_##f5(v5) | \
291 BF_##reg##_##f6(v6) | \
292 BF_##reg##_##f7(v7))))
294 #define BF_CS8n(reg, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) \
295 (HW_##reg##_CLR(n, (BM_##reg##_##f1 | \
303 HW_##reg##_SET(n, (BF_##reg##_##f1(v1) | \
304 BF_##reg##_##f2(v2) | \
305 BF_##reg##_##f3(v3) | \
306 BF_##reg##_##f4(v4) | \
307 BF_##reg##_##f5(v5) | \
308 BF_##reg##_##f6(v6) | \
309 BF_##reg##_##f7(v7) | \
310 BF_##reg##_##f8(v8))))
313 * Macros for single instance MULTI-BLOCK registers
316 #define BFn_SET(reg, blk, field) HW_##reg##_SET(blk, BM_##reg##_##field)
317 #define BFn_CLR(reg, blk, field) HW_##reg##_CLR(blk, BM_##reg##_##field)
318 #define BFn_TOG(reg, blk, field) HW_##reg##_TOG(blk, BM_##reg##_##field)
320 #define BFn_SETV(reg, blk, field, v) HW_##reg##_SET(blk, BF_##reg##_##field(v))
321 #define BFn_CLRV(reg, blk, field, v) HW_##reg##_CLR(blk, BF_##reg##_##field(v))
322 #define BFn_TOGV(reg, blk, field, v) HW_##reg##_TOG(blk, BF_##reg##_##field(v))
324 #define BVn_FLD(reg, field, sym) BF_##reg##_##field(BV_##reg##_##field##__##sym)
325 #define BVn_VAL(reg, field, sym) BV_##reg##_##field##__##sym
327 #define BFn_RD(reg, blk, field) HW_##reg(blk).B.field
328 #define BFn_WR(reg, blk, field, v) BW_##reg##_##field(blk, v)
330 #define BFn_CS1(reg, blk, f1, v1) \
331 (HW_##reg##_CLR(blk, BM_##reg##_##f1), \
332 HW_##reg##_SET(blk, BF_##reg##_##f1(v1)))
334 #define BFn_CS2(reg, blk, f1, v1, f2, v2) \
335 (HW_##reg##_CLR(blk, BM_##reg##_##f1 | \
337 HW_##reg##_SET(blk, BF_##reg##_##f1(v1) | \
338 BF_##reg##_##f2(v2)))
340 #define BFn_CS3(reg, blk, f1, v1, f2, v2, f3, v3) \
341 (HW_##reg##_CLR(blk, BM_##reg##_##f1 | \
344 HW_##reg##_SET(blk, BF_##reg##_##f1(v1) | \
345 BF_##reg##_##f2(v2) | \
346 BF_##reg##_##f3(v3)))
348 #define BFn_CS4(reg, blk, f1, v1, f2, v2, f3, v3, f4, v4) \
349 (HW_##reg##_CLR(blk, BM_##reg##_##f1 | \
353 HW_##reg##_SET(blk, BF_##reg##_##f1(v1) | \
354 BF_##reg##_##f2(v2) | \
355 BF_##reg##_##f3(v3) | \
356 BF_##reg##_##f4(v4)))
358 #define BFn_CS5(reg, blk, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) \
359 (HW_##reg##_CLR(blk, BM_##reg##_##f1 | \
364 HW_##reg##_SET(blk, BF_##reg##_##f1(v1) | \
365 BF_##reg##_##f2(v2) | \
366 BF_##reg##_##f3(v3) | \
367 BF_##reg##_##f4(v4) | \
368 BF_##reg##_##f5(v5)))
370 #define BFn_CS6(reg, blk, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) \
371 (HW_##reg##_CLR(blk, BM_##reg##_##f1 | \
377 HW_##reg##_SET(blk, BF_##reg##_##f1(v1) | \
378 BF_##reg##_##f2(v2) | \
379 BF_##reg##_##f3(v3) | \
380 BF_##reg##_##f4(v4) | \
381 BF_##reg##_##f5(v5) | \
382 BF_##reg##_##f6(v6)))
384 #define BFn_CS7(reg, blk, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) \
385 (HW_##reg##_CLR(blk, BM_##reg##_##f1 | \
392 HW_##reg##_SET(blk, BF_##reg##_##f1(v1) | \
393 BF_##reg##_##f2(v2) | \
394 BF_##reg##_##f3(v3) | \
395 BF_##reg##_##f4(v4) | \
396 BF_##reg##_##f5(v5) | \
397 BF_##reg##_##f6(v6) | \
398 BF_##reg##_##f7(v7)))
400 #define BFn_CS8(reg, blk, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) \
401 (HW_##reg##_CLR(blk, BM_##reg##_##f1 | \
409 HW_##reg##_SET(blk, BF_##reg##_##f1(v1) | \
410 BF_##reg##_##f2(v2) | \
411 BF_##reg##_##f3(v3) | \
412 BF_##reg##_##f4(v4) | \
413 BF_##reg##_##f5(v5) | \
414 BF_##reg##_##f6(v6) | \
415 BF_##reg##_##f7(v7) | \
416 BF_##reg##_##f8(v8)))
419 * Macros for MULTI-BLOCK multiple instance registers
422 #define BFn_SETn(reg, blk, n, field) HW_##reg##_SET(blk, n, BM_##reg##_##field)
423 #define BFn_CLRn(reg, blk, n, field) HW_##reg##_CLR(blk, n, BM_##reg##_##field)
424 #define BFn_TOGn(reg, blk, n, field) HW_##reg##_TOG(blk, n, BM_##reg##_##field)
426 #define BFn_SETVn(reg, blk, n, field, v) HW_##reg##_SET(blk, n, BF_##reg##_##field(v))
427 #define BFn_CLRVn(reg, blk, n, field, v) HW_##reg##_CLR(blk, n, BF_##reg##_##field(v))
428 #define BFn_TOGVn(reg, blk, n, field, v) HW_##reg##_TOG(blk, n, BF_##reg##_##field(v))
430 #define BVn_FLDn(reg, blk, n, field, sym) BF_##reg##_##field(BV_##reg##_##field##__##sym)
431 #define BVn_VALn(reg, blk, n, field, sym) BV_##reg##_##field##__##sym
433 #define BFn_RDn(reg, blk, n, field) HW_##reg(n).B.field
434 #define BFn_WRn(reg, blk, n, field, v) BW_##reg##_##field(n, v)
436 #define BFn_CS1n(reg, blk, n, f1, v1) \
437 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1)), \
438 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1))))
440 #define BFn_CS2n(reg, blk, n, f1, v1, f2, v2) \
441 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1 | \
443 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1) | \
444 BF_##reg##_##f2(v2))))
446 #define BFn_CS3n(reg, blk, n, f1, v1, f2, v2, f3, v3) \
447 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1 | \
450 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1) | \
451 BF_##reg##_##f2(v2) | \
452 BF_##reg##_##f3(v3))))
454 #define BFn_CS4n(reg, blk, n, f1, v1, f2, v2, f3, v3, f4, v4) \
455 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1 | \
459 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1) | \
460 BF_##reg##_##f2(v2) | \
461 BF_##reg##_##f3(v3) | \
462 BF_##reg##_##f4(v4))))
464 #define BFn_CS5n(reg, blk, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) \
465 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1 | \
470 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1) | \
471 BF_##reg##_##f2(v2) | \
472 BF_##reg##_##f3(v3) | \
473 BF_##reg##_##f4(v4) | \
474 BF_##reg##_##f5(v5))))
476 #define BFn_CS6n(reg, blk, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) \
477 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1 | \
483 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1) | \
484 BF_##reg##_##f2(v2) | \
485 BF_##reg##_##f3(v3) | \
486 BF_##reg##_##f4(v4) | \
487 BF_##reg##_##f5(v5) | \
488 BF_##reg##_##f6(v6))))
490 #define BFn_CS7n(reg, blk, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) \
491 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1 | \
498 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1) | \
499 BF_##reg##_##f2(v2) | \
500 BF_##reg##_##f3(v3) | \
501 BF_##reg##_##f4(v4) | \
502 BF_##reg##_##f5(v5) | \
503 BF_##reg##_##f6(v6) | \
504 BF_##reg##_##f7(v7))))
506 #define BFn_CS8n(reg, blk, n, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) \
507 (HW_##reg##_CLR(blk, n, (BM_##reg##_##f1 | \
515 HW_##reg##_SET(blk, n, (BF_##reg##_##f1(v1) | \
516 BF_##reg##_##f2(v2) | \
517 BF_##reg##_##f3(v3) | \
518 BF_##reg##_##f4(v4) | \
519 BF_##reg##_##f5(v5) | \
520 BF_##reg##_##f6(v6) | \
521 BF_##reg##_##f7(v7) | \
522 BF_##reg##_##f8(v8))))
524 #endif /* _FSL_BITACCESS_H */
526 /******************************************************************************/