CC35xxDriverLibrary
hw_types.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: hw_types.h
3 *
4 * Description: Common types and macros.
5 *
6 * Copyright (c) 2022 Texas Instruments Incorporated
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2) Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3) Neither the name of the copyright holder nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ******************************************************************************/
35 
36 #ifndef __HW_TYPES_H__
37 #define __HW_TYPES_H__
38 
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 //*****************************************************************************
43 //
44 // Common driverlib types
45 //
46 //*****************************************************************************
47 typedef void (* FPTR_VOID_VOID_T) (void);
48 typedef void (* FPTR_VOID_UINT8_T) (uint8_t);
49 
50 //*****************************************************************************
51 //
52 // This symbol forces simple driverlib functions to be inlined in the code
53 // instead of using function calls.
54 //
55 //*****************************************************************************
56 #ifndef __STATIC_INLINE
57 #define __STATIC_INLINE static inline
58 #endif
59 
60 //*****************************************************************************
61 //
62 // C99 types only allows bitfield defintions on certain datatypes.
63 //
64 //*****************************************************************************
65 typedef unsigned int __UINT32;
66 
67 //*****************************************************************************
68 //
69 // Macros for direct hardware access.
70 //
71 // If using these macros the programmer should be aware of any limitations to
72 // the address accessed i.e. if it supports word and/or byte access.
73 //
74 //*****************************************************************************
75 // Word (32 bit) access to address x
76 // Read example : my32BitVar = HWREG(base_addr + offset) ;
77 // Write example : HWREG(base_addr + offset) = my32BitVar ;
78 #define HWREG(x) \
79  (*((volatile unsigned long *)(x)))
80 
81 // Half word (16 bit) access to address x
82 // Read example : my16BitVar = HWREGH(base_addr + offset) ;
83 // Write example : HWREGH(base_addr + offset) = my16BitVar ;
84 #define HWREGH(x) \
85  (*((volatile unsigned short *)(x)))
86 
87 // Byte (8 bit) access to address x
88 // Read example : my8BitVar = HWREGB(base_addr + offset) ;
89 // Write example : HWREGB(base_addr + offset) = my8BitVar ;
90 #define HWREGB(x) \
91  (*((volatile unsigned char *)(x)))
92 
93 
94 __STATIC_INLINE void _setField(uint32_t fieldVal,
95  uint32_t base,
96  uint32_t reg,
97  uint32_t fieldMask,
98  uint32_t fieldStartBit,
99  uint32_t isWriteOnly)
100 {
101  uint32_t regVal = 0;
102  uint32_t regAddress = base + reg;
103 
104  if (!isWriteOnly)
105  {
106  regVal = HWREG(regAddress);
107  }
108 
109  regVal &= ~(fieldMask);
110  regVal |= ((fieldVal << fieldStartBit) & fieldMask);
111  // check that the the field input & the not mask gives zero
112  //if (0 != (chFieldSetVal & (~fieldMask)))
113  // while(1);
114  HWREG(regAddress) = regVal;
115 }
116 
117 
118 __STATIC_INLINE uint32_t _getField(uint32_t base,
119  uint32_t regOffset,
120  uint32_t fieldMask,
121  uint32_t fieldStartBit)
122 {
123  return ((HWREG(base + regOffset) & fieldMask) >> fieldStartBit);
124 }
125 
126 
127 #endif // __HW_TYPES_H__
#define HWREG(x)
Definition: hw_types.h:78
#define __STATIC_INLINE
Definition: hw_types.h:57
void(* FPTR_VOID_UINT8_T)(uint8_t)
Definition: hw_types.h:48
unsigned int __UINT32
Definition: hw_types.h:65
__STATIC_INLINE uint32_t _getField(uint32_t base, uint32_t regOffset, uint32_t fieldMask, uint32_t fieldStartBit)
Definition: hw_types.h:118
void(* FPTR_VOID_VOID_T)(void)
Definition: hw_types.h:47
__STATIC_INLINE void _setField(uint32_t fieldVal, uint32_t base, uint32_t reg, uint32_t fieldMask, uint32_t fieldStartBit, uint32_t isWriteOnly)
Definition: hw_types.h:94