am_hal_tpiu.h 6.9 KB

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