AM263Px MCU+ SDK: sdlr.h Source File

| AM263Px MCU+ SDK 26.00.00 |

sdlr.h
Go to the documentation of this file.
1 /* ============================================================================
2 * Copyright (c) Texas Instruments Incorporated 2022
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
40 /* Register layer central -- contains field-manipulation macro definitions */
41
42 #ifndef SDLR_H
43 #define SDLR_H
44 #include <stdint.h>
45
46 /* the "expression" macros */
47
48 /* the Field MaKe macro */
49 #define SDL_FMK(PER_REG_FIELD, val) \
50 (((val) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK)
51
52 /* the Field EXTract macro */
53 #define SDL_FEXT(reg, PER_REG_FIELD) \
54 (((reg) & SDL_##PER_REG_FIELD##_MASK) >> SDL_##PER_REG_FIELD##_SHIFT)
55
56 /* the Field INSert macro */
57 #define SDL_FINS(reg, PER_REG_FIELD, val) \
58 ((reg) = ((reg) & ~SDL_##PER_REG_FIELD##_MASK) \
59 | (((val) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK))
60
61
62 /* the "token" macros */
63
64 /* the Field MaKe (Token) macro */
65 #define SDL_FMKT(PER_REG_FIELD, TOKEN) \
66 (((SDL_##PER_REG_FIELD##_##TOKEN) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK)
67
68 /* the Field INSert (Token) macro */
69 #define SDL_FINST(reg, PER_REG_FIELD, TOKEN) \
70 ((reg) = ((reg) & ~SDL_##PER_REG_FIELD##_MASK) \
71 | (((SDL_##PER_REG_FIELD##_##TOKEN) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK))
72
73
74 /* the "raw" macros */
75 #define kw_val (1u) \
76
77 /* the Field MaKe (Raw) macro */
78 #define SDL_FMKR(msb, lsb, val) \
79 (((val) & ((((uint32_t)1U) << ((msb) - (lsb) + ((uint32_t)1U))) - ((uint32_t)1U))) << (lsb))
80
81 /* the Field EXTract (Raw) macro */
82 #define SDL_FEXTR(reg, msb, lsb) \
83 (((reg) >> (lsb)) & ((((uint32_t)1U) << ((msb) - (lsb) + ((uint32_t)1U))) - ((uint32_t)1U)))
84
85 /* the Field INSert (Raw) macro */
86 #define SDL_FINSR(reg, msb, lsb, val) \
87 ((reg) = ((reg) & (~(((((uint32_t)1U) << ((msb) - (lsb) + ((uint32_t)1U))) - ((uint32_t)1U)) << (lsb)))) \
88 | SDL_FMKR((msb), (lsb), (val)))
89
99 #define SDL_REG_RD(p) (*(p))
100
108 #define SDL_REG_WR(p, v) (*(p) = (v))
109
118 #define SDL_REG32_RD(p) (SDL_REG32_RD_RAW((volatile uint32_t *) (p)))
119
127 #define SDL_REG32_WR(p, v) (SDL_REG32_WR_RAW( \
128 (volatile uint32_t *) (p), (uint32_t) (v)))
129
138 #define SDL_REG16_RD(p) (SDL_REG16_RD_RAW((volatile uint16_t *) (p)))
139
147 #define SDL_REG16_WR(p, v) (SDL_REG16_WR_RAW( \
148 (volatile uint16_t *) (p), (uint16_t) (v)))
149
158 #define SDL_REG8_RD(p) (SDL_REG8_RD_RAW((volatile uint8_t *) (p)))
159
167 #define SDL_REG8_WR(p, v) (SDL_REG8_WR_RAW( \
168 (volatile uint8_t *) (p), (uint8_t) (v)))
169
179 #define SDL_REG32_RD_OFF(p, off) (SDL_REG32_RD_OFF_RAW( \
180 (volatile uint32_t *) (p), \
181 (uint32_t) (off)))
182
192 #define SDL_REG32_WR_OFF(p, off, v) (SDL_REG32_WR_OFF_RAW( \
193 (volatile uint32_t *) (p), \
194 (uint32_t) (off), \
195 (uint32_t) (v)))
196
207 #define SDL_REG32_FEXT(p, fld) (SDL_REG32_FEXT_RAW( \
208 ((volatile uint32_t *) (p)), \
209 ((uint32_t) SDL_##fld##_MASK), \
210 ((uint32_t) SDL_##fld##_SHIFT)))
211
222 #define SDL_REG16_FEXT(p, fld) (SDL_REG16_FEXT_RAW( \
223 ((volatile uint16_t *) (p)), \
224 ((uint16_t) SDL_##fld##_MASK), \
225 ((uint32_t) SDL_##fld##_SHIFT)))
226
237 #define SDL_REG8_FEXT(p, fld) (SDL_REG8_FEXT_RAW( \
238 ((volatile uint8_t *) (p)), \
239 ((uint8_t) SDL_##fld##_MASK), \
240 ((uint32_t) SDL_##fld##_SHIFT)))
241
251 #define SDL_REG32_FINS(p, fld, v) (SDL_REG32_FINS_RAW( \
252 ((volatile uint32_t *) (p)), \
253 ((uint32_t) SDL_##fld##_MASK), \
254 ((uint32_t) SDL_##fld##_SHIFT), \
255 ((uint32_t) v)))
256
266 #define SDL_REG16_FINS(p, fld, v) (SDL_REG16_FINS_RAW( \
267 ((volatile uint16_t *) (p)), \
268 ((uint16_t) SDL_##fld##_MASK), \
269 ((uint32_t) SDL_##fld##_SHIFT), \
270 ((uint16_t) v)))
271
281 #define SDL_REG8_FINS(p, fld, v) (SDL_REG8_FINS_RAW( \
282 ((volatile uint8_t *) (p)), \
283 ((uint8_t) SDL_##fld##_MASK), \
284 ((uint32_t) SDL_##fld##_SHIFT), \
285 ((uint8_t) v)))
286
287 /* ========================================================================== */
288 /* Function Declarations */
289 /* ========================================================================== */
290
299 static inline uint32_t SDL_REG32_RD_RAW(volatile const uint32_t * const p);
300 static inline uint32_t SDL_REG32_RD_RAW(volatile const uint32_t * const p)
301 {
302 return (*p);
303 }
304
312 static inline void SDL_REG32_WR_RAW(volatile uint32_t * const p, uint32_t v);
313 static inline void SDL_REG32_WR_RAW(volatile uint32_t * const p, uint32_t v)
314 {
315 *p = v;
316 return;
317 }
318
327 static inline uint16_t SDL_REG16_RD_RAW(volatile const uint16_t * const p);
328 static inline uint16_t SDL_REG16_RD_RAW(volatile const uint16_t * const p)
329 {
330 return (*p);
331 }
332
340 static inline void SDL_REG16_WR_RAW(volatile uint16_t * const p, uint16_t v);
341 static inline void SDL_REG16_WR_RAW(volatile uint16_t * const p, uint16_t v)
342 {
343 *p = v;
344 return;
345 }
346
355 static inline uint8_t SDL_REG8_RD_RAW(volatile const uint8_t * const p);
356 static inline uint8_t SDL_REG8_RD_RAW(volatile const uint8_t * const p)
357 {
358 return (*p);
359 }
360
368 static inline void SDL_REG8_WR_RAW(volatile uint8_t * const p, uint8_t v);
369 static inline void SDL_REG8_WR_RAW(volatile uint8_t * const p, uint8_t v)
370 {
371 *p = v;
372 return;
373 }
374
384 static inline uint32_t SDL_REG32_RD_OFF_RAW(volatile const uint32_t *p, uint32_t off);
385 static inline uint32_t SDL_REG32_RD_OFF_RAW(volatile const uint32_t *p, uint32_t off)
386 {
387 uintptr_t pOff = ((uintptr_t) p) + off;
388 return (*(volatile const uint32_t *)(pOff));
389 }
390
400 static inline void SDL_REG32_WR_OFF_RAW(volatile uint32_t *const p,
401 uint32_t off,
402 uint32_t v);
403 static inline void SDL_REG32_WR_OFF_RAW(volatile uint32_t *const p,
404 uint32_t off,
405 uint32_t v)
406 {
407 uintptr_t pOff = ((uintptr_t) p) + off;
408 (*(volatile uint32_t *)(pOff)) = (v);
409 return;
410 }
411
422 static inline uint32_t SDL_REG32_FEXT_RAW(volatile const uint32_t * const p,
423 uint32_t mask,
424 uint32_t shift);
425 static inline uint32_t SDL_REG32_FEXT_RAW(volatile const uint32_t * const p,
426 uint32_t mask,
427 uint32_t shift)
428 {
429 uint32_t regVal = SDL_REG32_RD_RAW(p);
430 regVal = (regVal & mask) >> shift;
431 return (regVal);
432 }
433
444 static inline uint16_t SDL_REG16_FEXT_RAW(volatile const uint16_t * const p,
445 uint16_t mask,
446 uint32_t shift);
447 static inline uint16_t SDL_REG16_FEXT_RAW(volatile const uint16_t * const p,
448 uint16_t mask,
449 uint32_t shift)
450 {
451 uint16_t regVal = SDL_REG16_RD_RAW(p);
452 regVal = (regVal & mask) >> shift;
453 return (regVal);
454 }
455
466 static inline uint8_t SDL_REG8_FEXT_RAW(volatile const uint8_t * const p,
467 uint8_t mask,
468 uint32_t shift);
469 static inline uint8_t SDL_REG8_FEXT_RAW(volatile const uint8_t * const p,
470 uint8_t mask,
471 uint32_t shift)
472 {
473 uint8_t regVal = SDL_REG8_RD_RAW(p);
474 regVal = (regVal & mask) >> shift;
475 return (regVal);
476 }
477
487 static inline void SDL_REG32_FINS_RAW(volatile uint32_t * const p,
488 uint32_t mask,
489 uint32_t shift,
490 uint32_t v);
491 static inline void SDL_REG32_FINS_RAW(volatile uint32_t * const p,
492 uint32_t mask,
493 uint32_t shift,
494 uint32_t v)
495 {
496 uint32_t regVal = SDL_REG32_RD_RAW(p);
497 regVal = (regVal & ~(mask));
498 regVal |= (v << shift) & mask;
499 SDL_REG32_WR_RAW(p, regVal);
500 return;
501 }
502
512 static inline void SDL_REG16_FINS_RAW(volatile uint16_t * const p,
513 uint16_t mask,
514 uint32_t shift,
515 uint16_t v);
516 static inline void SDL_REG16_FINS_RAW(volatile uint16_t * const p,
517 uint16_t mask,
518 uint32_t shift,
519 uint16_t v)
520 {
521 uint16_t regVal = SDL_REG16_RD_RAW(p);
522 regVal = (regVal & ~(mask));
523 regVal |= (v << shift) & mask;
524 SDL_REG16_WR_RAW(p, regVal);
525 return;
526 }
527
537 static inline void SDL_REG8_FINS_RAW(volatile uint8_t * const p,
538 uint8_t mask,
539 uint32_t shift,
540 uint8_t v);
541 static inline void SDL_REG8_FINS_RAW(volatile uint8_t * const p,
542 uint8_t mask,
543 uint32_t shift,
544 uint8_t v)
545 {
546 uint8_t regVal = SDL_REG8_RD_RAW(p);
547 regVal = (regVal & ~(mask));
548 regVal |= (v << shift) & mask;
549 SDL_REG8_WR_RAW(p, regVal);
550 return;
551 }
552
553 #endif /* SDLR_H_ */
SDL_REG8_RD_RAW
static uint8_t SDL_REG8_RD_RAW(volatile const uint8_t *const p)
This function reads a 8-bit value from a hardware register and returns the value.
Definition: sdlr.h:356
SDL_REG32_WR_OFF_RAW
static void SDL_REG32_WR_OFF_RAW(volatile uint32_t *const p, uint32_t off, uint32_t v)
This function writes a 32-bit value to a hardware register with an offset.
Definition: sdlr.h:403
SDL_REG8_FINS_RAW
static void SDL_REG8_FINS_RAW(volatile uint8_t *const p, uint8_t mask, uint32_t shift, uint8_t v)
This function reads a 8 bit register, modifies specific set of bits and writes back to the register.
Definition: sdlr.h:541
SDL_REG32_RD_OFF_RAW
static uint32_t SDL_REG32_RD_OFF_RAW(volatile const uint32_t *p, uint32_t off)
This function reads a 32-bit value from a hardware register with an offset and returns the value.
Definition: sdlr.h:385
SDL_REG16_RD_RAW
static uint16_t SDL_REG16_RD_RAW(volatile const uint16_t *const p)
This function reads a 16-bit value from a hardware register and returns the value.
Definition: sdlr.h:328
SDL_REG16_FINS_RAW
static void SDL_REG16_FINS_RAW(volatile uint16_t *const p, uint16_t mask, uint32_t shift, uint16_t v)
This function reads a 16 bit register, modifies specific set of bits and writes back to the register.
Definition: sdlr.h:516
SDL_REG16_FEXT_RAW
static uint16_t SDL_REG16_FEXT_RAW(volatile const uint16_t *const p, uint16_t mask, uint32_t shift)
This function reads a 16 bit register, masks specific set of bits and returns the left shifted value.
Definition: sdlr.h:447
SDL_REG16_WR_RAW
static void SDL_REG16_WR_RAW(volatile uint16_t *const p, uint16_t v)
This function writes a 16-bit value to a hardware register.
Definition: sdlr.h:341
SDL_REG8_WR_RAW
static void SDL_REG8_WR_RAW(volatile uint8_t *const p, uint8_t v)
This function writes a 8-bit value to a hardware register.
Definition: sdlr.h:369
SDL_REG32_RD_RAW
static uint32_t SDL_REG32_RD_RAW(volatile const uint32_t *const p)
This function reads a 32-bit value from a hardware register and returns the value.
Definition: sdlr.h:300
SDL_REG32_FINS_RAW
static void SDL_REG32_FINS_RAW(volatile uint32_t *const p, uint32_t mask, uint32_t shift, uint32_t v)
This function reads a 32 bit register, modifies specific set of bits and writes back to the register.
Definition: sdlr.h:491
SDL_REG8_FEXT_RAW
static uint8_t SDL_REG8_FEXT_RAW(volatile const uint8_t *const p, uint8_t mask, uint32_t shift)
This function reads a 8 bit register, masks specific set of bits and returns the left shifted value.
Definition: sdlr.h:469
SDL_REG32_WR_RAW
static void SDL_REG32_WR_RAW(volatile uint32_t *const p, uint32_t v)
This function writes a 32-bit value to a hardware register.
Definition: sdlr.h:313
SDL_REG32_FEXT_RAW
static uint32_t SDL_REG32_FEXT_RAW(volatile const uint32_t *const p, uint32_t mask, uint32_t shift)
This function reads a 32 bit register, masks specific set of bits and returns the left shifted value.
Definition: sdlr.h:425