1 //*****************************************************************************
2 //
3 //! @file am_util_regdump.h
4 //!
5 //! @brief Dump specified registers for debug purposes.
6 //!
7 //! This module contains functions for real time (debug) printing of registers
8 //! from peripherals specified in a given bitmask.
9 //!
10 //! @addtogroup regdump RegDump  - Debug Functionality
11 //! @ingroup utils
12 //! @{
13 //
14 //*****************************************************************************
15 
16 //*****************************************************************************
17 //
18 // Copyright (c) 2023, Ambiq Micro, Inc.
19 // All rights reserved.
20 //
21 // Redistribution and use in source and binary forms, with or without
22 // modification, are permitted provided that the following conditions are met:
23 //
24 // 1. Redistributions of source code must retain the above copyright notice,
25 // this list of conditions and the following disclaimer.
26 //
27 // 2. Redistributions in binary form must reproduce the above copyright
28 // notice, this list of conditions and the following disclaimer in the
29 // documentation and/or other materials provided with the distribution.
30 //
31 // 3. Neither the name of the copyright holder nor the names of its
32 // contributors may be used to endorse or promote products derived from this
33 // software without specific prior written permission.
34 //
35 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
36 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
39 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
43 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
44 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45 // POSSIBILITY OF SUCH DAMAGE.
46 //
47 // This is part of revision release_sdk_4_4_0-3c5977e664 of the AmbiqSuite Development Package.
48 //
49 //*****************************************************************************
50 #ifndef AM_UTIL_REGDUMP_H
51 #define AM_UTIL_REGDUMP_H
52 
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57 
58 #include "am_mcu_apollo.h"
59 
60 //
61 //! @name Apollo peripherals
62 //! @{
63 //
64 #define AM_UTIL_REGDUMP_ADC             (1 << 0)
65 #define AM_UTIL_REGDUMP_CLKGEN          (1 << 1)
66 #define AM_UTIL_REGDUMP_CTIMER          (1 << 2)
67 #define AM_UTIL_REGDUMP_GPIO            (1 << 3)
68 #define AM_UTIL_REGDUMP_IOM             (1 << 4)
69 #define AM_UTIL_REGDUMP_IOS             (1 << 5)
70 #define AM_UTIL_REGDUMP_MCUCTRL         (1 << 6)
71 #define AM_UTIL_REGDUMP_RSTGEN          (1 << 7)
72 #define AM_UTIL_REGDUMP_RTC             (1 << 8)
73 #define AM_UTIL_REGDUMP_UART            (1 << 9)
74 #define AM_UTIL_REGDUMP_VCOMP           (1 << 10)
75 #define AM_UTIL_REGDUMP_WDT             (1 << 11)
76 //! @}
77 
78 //
79 //! @name Apollo2 new peripherals
80 //! @{
81 //
82 #define AM_UTIL_REGDUMP_CACHE           (1 << 12)
83 #define AM_UTIL_REGDUMP_PDM             (1 << 13)
84 #define AM_UTIL_REGDUMP_PWRCTRL         (1 << 14)
85 //! @}
86 
87 //
88 //! @name Apollo3 new peripherals
89 //! @{
90 //
91 #define AM_UTIL_REGDUMP_BLE             (1 << 15)
92 #define AM_UTIL_REGDUMP_MSPI            (1 << 16)
93 //! @}
94 
95 
96 #define AM_UTIL_REGDUMP_INFO0           (1 << 24)
97 
98 //
99 //! @name ARM Core blocks
100 //! @{
101 //
102 #define AM_UTIL_REGDUMP_ITM             (1 << 25)
103 #define AM_UTIL_REGDUMP_NVIC            (1 << 26)
104 #define AM_UTIL_REGDUMP_SYSCTRL         (1 << 27)
105 #define AM_UTIL_REGDUMP_SYSTICK         (1 << 28)
106 #define AM_UTIL_REGDUMP_TPIU            (1 << 29)
107 //! @}
108 
109 
110 
111 //*****************************************************************************
112 //
113 //! @name Module mask definitions
114 //! @{
115 //
116 //*****************************************************************************
117 #define AM_UTIL_REGDUMP_APOLLO                  \
118         (   AM_UTIL_REGDUMP_ADC     |           \
119             AM_UTIL_REGDUMP_CLKGEN  |           \
120             AM_UTIL_REGDUMP_CTIMER  |           \
121             AM_UTIL_REGDUMP_GPIO    |           \
122             AM_UTIL_REGDUMP_IOM     |           \
123             AM_UTIL_REGDUMP_IOS     |           \
124             AM_UTIL_REGDUMP_MCUCTRL |           \
125             AM_UTIL_REGDUMP_RSTGEN  |           \
126             AM_UTIL_REGDUMP_RTC     |           \
127             AM_UTIL_REGDUMP_UART    |           \
128             AM_UTIL_REGDUMP_VCOMP   |           \
129             AM_UTIL_REGDUMP_WDT )
130 
131 #define AM_UTIL_REGDUMP_APOLLO2                 \
132         (   AM_UTIL_REGDUMP_CACHE   |           \
133             AM_UTIL_REGDUMP_PDM     |           \
134             AM_UTIL_REGDUMP_PWRCTRL )
135 
136 #define AM_UTIL_REGDUMP_CORE                    \
137         (   AM_UTIL_REGDUMP_ITM     |           \
138             AM_UTIL_REGDUMP_NVIC    |           \
139             AM_UTIL_REGDUMP_SYSCTRL |           \
140             AM_UTIL_REGDUMP_SYSTICK |           \
141             AM_UTIL_REGDUMP_TPIU )
142 //! @}
143 
144 //
145 //! @name Get a register dump of ALL modules in a block.
146 //! @{
147 //
148 #ifdef AM_PART_APOLLO
149 #define AM_UTIL_REGDUMP_ALL                     \
150         (   AM_UTIL_REGDUMP_APOLLO  |           \
151             AM_UTIL_REGDUMP_CORE )
152 #endif // PART_APOLLO
153 
154 #if defined(AM_PART_APOLLO2) || defined(AM_PART_APOLLO3) || defined(AM_PART_APOLLO3P)
155 #define AM_UTIL_REGDUMP_ALL                     \
156         (   AM_UTIL_REGDUMP_APOLLO  |           \
157             AM_UTIL_REGDUMP_APOLLO2 |           \
158             AM_UTIL_REGDUMP_CORE )
159 #endif // PART_APOLLO
160 //! @}
161 
162 //
163 //! Get a register dump of ALL modules in a block.
164 //
165 #define AM_UTIL_REGDUMP_MOD_ALL             0xFFFFFFFF
166 
167 //
168 //! This macro determines a mask given the first and last modules desired. e.g.
169 //!  REGDUMP_MOD_MASK(2,4)       // Dump regs for modules 2, 3, and 4
170 //
171 #define REGDUMP_MOD_MASK(modfirst, modlast)     \
172         (((1 << (modlast - modfirst + 1)) - 1) << modfirst)
173 
174 //
175 //! @name These macros determine a single module.
176 //! @{
177 //!  REGDUMP_MOD2 | REGDUMP_MOD4    // Dump regs for modules 2 and 4 (skip 3)
178 //
179 #define REGDUMP_MOD(n)                  (1 << n)
180 #define REGDUMP_MOD0                    (REGDUMP_MOD(0))
181 #define REGDUMP_MOD1                    (REGDUMP_MOD(1))
182 #define REGDUMP_MOD2                    (REGDUMP_MOD(2))
183 #define REGDUMP_MOD3                    (REGDUMP_MOD(3))
184 #define REGDUMP_MOD4                    (REGDUMP_MOD(4))
185 #define REGDUMP_MOD5                    (REGDUMP_MOD(5))
186 #define REGDUMP_MOD6                    (REGDUMP_MOD(6))
187 #define REGDUMP_MOD7                    (REGDUMP_MOD(7))
188 //! @}
189 
190 //*****************************************************************************
191 //
192 // External function definitions
193 //
194 //*****************************************************************************
195 //*****************************************************************************
196 //
197 //! @brief Register dumping for debug purposes.
198 //!
199 //! This function dumps register values to the print port for debug purposes.
200 //!
201 //! @param ui32PeriphMask = an OR of the mask values to be printed.  e.g.
202 //! AM_UTIL_REGDUMP_IOM | AM_UTIL_REGDUMP_GPIO
203 //!
204 //! @param ui32ModuleMask = A mask representing the modules (for a multi-module
205 //! block such as IOM) to be dumped.  Bit0 represents module 0, etc.
206 //! This parameter is ignored for single-module blocks such as GPIO.
207 //! Pre-defined macros can be used to generate this mask, e.g.
208 //!     REGDUMP_MOD0 | REGDUMP_MOD1 | REGDUMP_MOD2
209 //!     or equivalently
210 //!     REGDUMP_MOD_MAS(0,2)
211 //!
212 //*****************************************************************************
213 extern void am_util_regdump_print(uint32_t ui32PeriphMask, uint32_t ui32ModuleMask);
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif // AM_UTIL_REGDUMP_H
220 
221 //*****************************************************************************
222 //
223 // End Doxygen group.
224 //! @}
225 //
226 //*****************************************************************************
227 
228