1 //*****************************************************************************
2 //
3 //  am_hal_tpiu.h
4 //! @file
5 //!
6 //! @brief Definitions and structures for working with the TPIU.
7 //!
8 //! @addtogroup tpiu2 Trace Port Interface Unit (TPIU)
9 //! @ingroup apollo2hal
10 //! @{
11 //
12 //*****************************************************************************
13 
14 //*****************************************************************************
15 //
16 // Copyright (c) 2017, Ambiq Micro
17 // All rights reserved.
18 //
19 // Redistribution and use in source and binary forms, with or without
20 // modification, are permitted provided that the following conditions are met:
21 //
22 // 1. Redistributions of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // 3. Neither the name of the copyright holder nor the names of its
30 // contributors may be used to endorse or promote products derived from this
31 // software without specific prior written permission.
32 //
33 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
37 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 // POSSIBILITY OF SUCH DAMAGE.
44 //
45 // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
46 //
47 //*****************************************************************************
48 #ifndef AM_HAL_TPIU_H
49 #define AM_HAL_TPIU_H
50 
51 #include <stdint.h>
52 
53 //*****************************************************************************
54 //
55 // TPIU bit rate defines.
56 //
57 //*****************************************************************************
58 #define AM_HAL_TPIU_BAUD_57600      (115200 / 2)
59 #define AM_HAL_TPIU_BAUD_115200     (115200 * 1)
60 #define AM_HAL_TPIU_BAUD_230400     (115200 * 2)
61 #define AM_HAL_TPIU_BAUD_460800     (115200 * 4)
62 #define AM_HAL_TPIU_BAUD_500000     (1000000 / 2)
63 #define AM_HAL_TPIU_BAUD_1M         (1000000 * 1)
64 #define AM_HAL_TPIU_BAUD_2M         (1000000 * 2)
65 #define AM_HAL_TPIU_BAUD_DEFAULT    (AM_HAL_TPIU_BAUD_1M)
66 
67 //*****************************************************************************
68 //
69 // TPIU register defines.
70 //
71 //*****************************************************************************
72 #define AM_HAL_TPIU_SSPSR       0xE0040000  //! Supported Parallel Port Sizes
73 #define AM_HAL_TPIU_CSPSR       0xE0040004  //! Current Parallel Port Size
74 #define AM_HAL_TPIU_ACPR        0xE0040010  //! Asynchronous Clock Prescaler
75 #define AM_HAL_TPIU_SPPR        0xE00400F0  //! Selected Pin Protocol
76 #define AM_HAL_TPIU_TYPE        0xE0040FC8  //! TPIU Type
77 
78 //*****************************************************************************
79 //
80 // TPIU ACPR defines.
81 //
82 //*****************************************************************************
83 #define AM_HAL_TPIU_ACPR_SWOSCALER_M    0x0000FFFF  //! SWO baud rate prescalar
84 
85 //*****************************************************************************
86 //
87 // TPIU_SPPR TXMODE defines.
88 //
89 //*****************************************************************************
90 #define AM_HAL_TPIU_SPPR_PARALLEL       0x00000000
91 #define AM_HAL_TPIU_SPPR_MANCHESTER     0x00000001
92 #define AM_HAL_TPIU_SPPR_NRZ            0x00000002
93 
94 //*****************************************************************************
95 //
96 // TPIU Type defines
97 //
98 //*****************************************************************************
99 #define AM_HAL_TPIU_TYPE_NRZVALID       0x00000800
100 #define AM_HAL_TPIU_TYPE_MANCVALID      0x00000400
101 #define AM_HAL_TPIU_TYPE_PTINVALID      0x00000200
102 #define AM_HAL_TPIU_TYPE_FIFOSZ_M       0x000001C0
103 
104 //*****************************************************************************
105 //
106 // TPIU Clock defines
107 //
108 //*****************************************************************************
109 #define AM_HAL_TPIU_TRACECLKIN_6MHZ     AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(0)
110 #define AM_HAL_TPIU_TRACECLKIN_3MHZ     AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(1)
111 #define AM_HAL_TPIU_TRACECLKIN_1_5MHZ   AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(2)
112 #define AM_HAL_TPIU_TRACECLKIN_750KHZ   AM_REG_MCUCTRL_TPIUCTRL_TPIUCLKSEL(3)
113 
114 //*****************************************************************************
115 //
116 //! @brief Structure used for configuring the TPIU
117 //
118 //*****************************************************************************
119 typedef struct
120 {
121     //
122     // If ui32SetItmBaud is non-zero, the ITM frequency is set to the given
123     //  frequency, and is based on a divide-by-8 HFRC TPIU clock.
124     // If zero, other structure members are used to set the TPIU configuration.
125     //
126     uint32_t ui32SetItmBaud;
127 
128     //
129     //! MCU Control TRACECLKIN clock freq.
130     //!
131     //! Valid values for ui32TraceClkIn are:
132     //!
133     //!     AM_HAL_TPIU_TRACECLKIN_6MHZ
134     //!     AM_HAL_TPIU_TRACECLKIN_3MHZ
135     //!     AM_HAL_TPIU_TRACECLKIN_1_5MHZ
136     //!     AM_HAL_TPIU_TRACECLKIN_750KHZ
137     //
138     uint32_t ui32TraceClkIn;
139 
140     //
141     //! Protocol to use for the TPIU
142     //!
143     //! Valid values for ui32PinProtocol are:
144     //!
145     //!     AM_HAL_TPIU_SPPR_PARALLEL
146     //!     AM_HAL_TPIU_SPPR_MANCHESTER
147     //!     AM_HAL_TPIU_SPPR_NRZ
148     //
149     uint32_t ui32PinProtocol;
150 
151     //
152     //! Desired width of the TPIU parallel port
153     //
154     uint32_t ui32ParallelPortSize;
155 
156     //
157     //! Desired Clock prescaler value
158     //
159     uint32_t ui32ClockPrescaler;
160 }
161 am_hal_tpiu_config_t;
162 
163 #ifdef __cplusplus
164 extern "C"
165 {
166 #endif
167 
168 //*****************************************************************************
169 //
170 // External function definitions
171 //
172 //*****************************************************************************
173 extern void am_hal_tpiu_clock_enable(void);
174 extern void am_hal_tpiu_clock_disable(void);
175 extern void am_hal_tpiu_port_width_set(uint32_t ui32PortWidth);
176 extern uint32_t am_hal_tpiu_supported_port_width_get(void);
177 extern uint32_t am_hal_tpiu_port_width_get(void);
178 extern void am_hal_tpiu_configure(am_hal_tpiu_config_t *psConfig);
179 extern void am_hal_tpiu_enable(am_hal_tpiu_config_t *psConfig);
180 extern void am_hal_tpiu_disable(void);
181 
182 #ifdef __cplusplus
183 }
184 #endif
185 
186 #endif // AM_HAL_TPIU_H
187 
188 //*****************************************************************************
189 //
190 // End Doxygen group.
191 //! @}
192 //
193 //*****************************************************************************
194