AM62Px MCU+ SDK  09.02.01
sdlr.h
Go to the documentation of this file.
1 /* ============================================================================
2  * Copyright (c) Texas Instruments Incorporated 2022-2023
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 /* the "expression" macros */
46 
47 /* the Field MaKe macro */
48 #define SDL_FMK(PER_REG_FIELD, val) \
49  (((val) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK)
50 
51 /* the Field EXTract macro */
52 #define SDL_FEXT(reg, PER_REG_FIELD) \
53  (((reg) & SDL_##PER_REG_FIELD##_MASK) >> SDL_##PER_REG_FIELD##_SHIFT)
54 
55 /* the Field INSert macro */
56 #define SDL_FINS(reg, PER_REG_FIELD, val) \
57  ((reg) = ((reg) & ~SDL_##PER_REG_FIELD##_MASK) \
58  | (((val) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK))
59 
60 
61 /* the "token" macros */
62 
63 /* the Field MaKe (Token) macro */
64 #define SDL_FMKT(PER_REG_FIELD, TOKEN) \
65  (((SDL_##PER_REG_FIELD##_##TOKEN) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK)
66 
67 /* the Field INSert (Token) macro */
68 #define SDL_FINST(reg, PER_REG_FIELD, TOKEN) \
69  ((reg) = ((reg) & ~SDL_##PER_REG_FIELD##_MASK) \
70  | (((SDL_##PER_REG_FIELD##_##TOKEN) << SDL_##PER_REG_FIELD##_SHIFT) & SDL_##PER_REG_FIELD##_MASK))
71 
72 
73 /* the "raw" macros */
74 #define kw_val (1u) \
75 
76 /* the Field MaKe (Raw) macro */
77 #define SDL_FMKR(msb, lsb, val) \
78  (((val) & ((((uint32_t)1U) << ((msb) - (lsb) + ((uint32_t)1U))) - ((uint32_t)1U))) << (lsb))
79 
80 /* the Field EXTract (Raw) macro */
81 #define SDL_FEXTR(reg, msb, lsb) \
82  (((reg) >> (lsb)) & ((((uint32_t)1U) << ((msb) - (lsb) + ((uint32_t)1U))) - ((uint32_t)1U)))
83 
84 /* the Field INSert (Raw) macro */
85 #define SDL_FINSR(reg, msb, lsb, val) \
86  ((reg) = ((reg) & (~(((((uint32_t)1U) << ((msb) - (lsb) + ((uint32_t)1U))) - ((uint32_t)1U)) << (lsb)))) \
87  | SDL_FMKR((msb), (lsb), (val)))
88 
98 #define SDL_REG_RD(p) (*(p))
99 
107 #define SDL_REG_WR(p, v) (*(p) = (v))
108 
117 #define SDL_REG32_RD(p) (SDL_REG32_RD_RAW((volatile uint32_t *) (p)))
118 
126 #define SDL_REG32_WR(p, v) (SDL_REG32_WR_RAW( \
127  (volatile uint32_t *) (p), (uint32_t) (v)))
128 
137 #define SDL_REG16_RD(p) (SDL_REG16_RD_RAW((volatile uint16_t *) (p)))
138 
146 #define SDL_REG16_WR(p, v) (SDL_REG16_WR_RAW( \
147  (volatile uint16_t *) (p), (uint16_t) (v)))
148 
157 #define SDL_REG8_RD(p) (SDL_REG8_RD_RAW((volatile uint8_t *) (p)))
158 
166 #define SDL_REG8_WR(p, v) (SDL_REG8_WR_RAW( \
167  (volatile uint8_t *) (p), (uint8_t) (v)))
168 
178 #define SDL_REG32_RD_OFF(p, off) (SDL_REG32_RD_OFF_RAW( \
179  (volatile uint32_t *) (p), \
180  (uint32_t) (off)))
181 
191 #define SDL_REG32_WR_OFF(p, off, v) (SDL_REG32_WR_OFF_RAW( \
192  (volatile uint32_t *) (p), \
193  (uint32_t) (off), \
194  (uint32_t) (v)))
195 
206 #define SDL_REG32_FEXT(p, fld) (SDL_REG32_FEXT_RAW( \
207  ((volatile uint32_t *) (p)), \
208  ((uint32_t) SDL_##fld##_MASK), \
209  ((uint32_t) SDL_##fld##_SHIFT)))
210 
221 #define SDL_REG16_FEXT(p, fld) (SDL_REG16_FEXT_RAW( \
222  ((volatile uint16_t *) (p)), \
223  ((uint16_t) SDL_##fld##_MASK), \
224  ((uint32_t) SDL_##fld##_SHIFT)))
225 
236 #define SDL_REG8_FEXT(p, fld) (SDL_REG8_FEXT_RAW( \
237  ((volatile uint8_t *) (p)), \
238  ((uint8_t) SDL_##fld##_MASK), \
239  ((uint32_t) SDL_##fld##_SHIFT)))
240 
250 #define SDL_REG32_FINS(p, fld, v) (SDL_REG32_FINS_RAW( \
251  ((volatile uint32_t *) (p)), \
252  ((uint32_t) SDL_##fld##_MASK), \
253  ((uint32_t) SDL_##fld##_SHIFT), \
254  ((uint32_t) v)))
255 
265 #define SDL_REG16_FINS(p, fld, v) (SDL_REG16_FINS_RAW( \
266  ((volatile uint16_t *) (p)), \
267  ((uint16_t) SDL_##fld##_MASK), \
268  ((uint32_t) SDL_##fld##_SHIFT), \
269  ((uint16_t) v)))
270 
280 #define SDL_REG8_FINS(p, fld, v) (SDL_REG8_FINS_RAW( \
281  ((volatile uint8_t *) (p)), \
282  ((uint8_t) SDL_##fld##_MASK), \
283  ((uint32_t) SDL_##fld##_SHIFT), \
284  ((uint8_t) v)))
285 
286 /* ========================================================================== */
287 /* Function Declarations */
288 /* ========================================================================== */
289 
298 static inline uint32_t SDL_REG32_RD_RAW(volatile const uint32_t * const p);
299 static inline uint32_t SDL_REG32_RD_RAW(volatile const uint32_t * const p)
300 {
301  return (*p);
302 }
303 
311 static inline void SDL_REG32_WR_RAW(volatile uint32_t * const p, uint32_t v);
312 static inline void SDL_REG32_WR_RAW(volatile uint32_t * const p, uint32_t v)
313 {
314  *p = v;
315  return;
316 }
317 
326 static inline uint16_t SDL_REG16_RD_RAW(volatile const uint16_t * const p);
327 static inline uint16_t SDL_REG16_RD_RAW(volatile const uint16_t * const p)
328 {
329  return (*p);
330 }
331 
339 static inline void SDL_REG16_WR_RAW(volatile uint16_t * const p, uint16_t v);
340 static inline void SDL_REG16_WR_RAW(volatile uint16_t * const p, uint16_t v)
341 {
342  *p = v;
343  return;
344 }
345 
354 static inline uint8_t SDL_REG8_RD_RAW(volatile const uint8_t * const p);
355 static inline uint8_t SDL_REG8_RD_RAW(volatile const uint8_t * const p)
356 {
357  return (*p);
358 }
359 
367 static inline void SDL_REG8_WR_RAW(volatile uint8_t * const p, uint8_t v);
368 static inline void SDL_REG8_WR_RAW(volatile uint8_t * const p, uint8_t v)
369 {
370  *p = v;
371  return;
372 }
373 
383 static inline uint32_t SDL_REG32_RD_OFF_RAW(volatile const uint32_t *p, uint32_t off);
384 static inline uint32_t SDL_REG32_RD_OFF_RAW(volatile const uint32_t *p, uint32_t off)
385 {
386  uintptr_t pOff = ((uintptr_t) p) + off;
387  return (*(volatile const uint32_t *)(pOff));
388 }
389 
399 static inline void SDL_REG32_WR_OFF_RAW(volatile uint32_t *const p,
400  uint32_t off,
401  uint32_t v);
402 static inline void SDL_REG32_WR_OFF_RAW(volatile uint32_t *const p,
403  uint32_t off,
404  uint32_t v)
405 {
406  uintptr_t pOff = ((uintptr_t) p) + off;
407  (*(volatile uint32_t *)(pOff)) = (v);
408  return;
409 }
410 
421 static inline uint32_t SDL_REG32_FEXT_RAW(volatile const uint32_t * const p,
422  uint32_t mask,
423  uint32_t shift);
424 static inline uint32_t SDL_REG32_FEXT_RAW(volatile const uint32_t * const p,
425  uint32_t mask,
426  uint32_t shift)
427 {
428  uint32_t regVal = SDL_REG32_RD_RAW(p);
429  regVal = (regVal & mask) >> shift;
430  return (regVal);
431 }
432 
443 static inline uint16_t SDL_REG16_FEXT_RAW(volatile const uint16_t * const p,
444  uint16_t mask,
445  uint32_t shift);
446 static inline uint16_t SDL_REG16_FEXT_RAW(volatile const uint16_t * const p,
447  uint16_t mask,
448  uint32_t shift)
449 {
450  uint16_t regVal = SDL_REG16_RD_RAW(p);
451  regVal = (regVal & mask) >> shift;
452  return (regVal);
453 }
454 
465 static inline uint8_t SDL_REG8_FEXT_RAW(volatile const uint8_t * const p,
466  uint8_t mask,
467  uint32_t shift);
468 static inline uint8_t SDL_REG8_FEXT_RAW(volatile const uint8_t * const p,
469  uint8_t mask,
470  uint32_t shift)
471 {
472  uint8_t regVal = SDL_REG8_RD_RAW(p);
473  regVal = (regVal & mask) >> shift;
474  return (regVal);
475 }
476 
486 static inline void SDL_REG32_FINS_RAW(volatile uint32_t * const p,
487  uint32_t mask,
488  uint32_t shift,
489  uint32_t v);
490 static inline void SDL_REG32_FINS_RAW(volatile uint32_t * const p,
491  uint32_t mask,
492  uint32_t shift,
493  uint32_t v)
494 {
495  uint32_t regVal = SDL_REG32_RD_RAW(p);
496  regVal = (regVal & ~(mask));
497  regVal |= (v << shift) & mask;
498  SDL_REG32_WR_RAW(p, regVal);
499  return;
500 }
501 
511 static inline void SDL_REG16_FINS_RAW(volatile uint16_t * const p,
512  uint16_t mask,
513  uint32_t shift,
514  uint16_t v);
515 static inline void SDL_REG16_FINS_RAW(volatile uint16_t * const p,
516  uint16_t mask,
517  uint32_t shift,
518  uint16_t v)
519 {
520  uint16_t regVal = SDL_REG16_RD_RAW(p);
521  regVal = (regVal & ~(mask));
522  regVal |= (v << shift) & mask;
523  SDL_REG16_WR_RAW(p, regVal);
524  return;
525 }
526 
536 static inline void SDL_REG8_FINS_RAW(volatile uint8_t * const p,
537  uint8_t mask,
538  uint32_t shift,
539  uint8_t v);
540 static inline void SDL_REG8_FINS_RAW(volatile uint8_t * const p,
541  uint8_t mask,
542  uint32_t shift,
543  uint8_t v)
544 {
545  uint8_t regVal = SDL_REG8_RD_RAW(p);
546  regVal = (regVal & ~(mask));
547  regVal |= (v << shift) & mask;
548  SDL_REG8_WR_RAW(p, regVal);
549  return;
550 }
551 
552 #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:355
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:402
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:540
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:384
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:327
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:515
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:446
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:340
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:368
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:299
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:490
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:468
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:312
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:424