trace.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**************************************************************************//**
  2. * @file
  3. * @brief SWO Trace API (for eAProfiler)
  4. * @author Energy Micro AS
  5. * @version 2.0.1
  6. ******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. * 4. The source and compiled code may only be used on Energy Micro "EFM32"
  21. * microcontrollers and "EFR4" radios.
  22. *
  23. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  24. * obligation to support this Software. Energy Micro AS is providing the
  25. * Software "AS IS", with no express or implied warranties of any kind,
  26. * including, but not limited to, any implied warranties of merchantability
  27. * or fitness for any particular purpose or warranties against infringement
  28. * of any proprietary rights of a third party.
  29. *
  30. * Energy Micro AS will not be liable for any consequential, incidental, or
  31. * special damages, or any other relief, or for any claim by any third party,
  32. * arising from your use of this Software.
  33. *
  34. *****************************************************************************/
  35. #ifndef __TRACE_H
  36. #define __TRACE_H
  37. /***************************************************************************//**
  38. * @addtogroup BSP
  39. * @{
  40. ******************************************************************************/
  41. #include <stdbool.h>
  42. #include <stdint.h>
  43. #include "em_msc.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. void TRACE_ETMSetup(void);
  48. void TRACE_SWOSetup(void);
  49. bool TRACE_ProfilerSetup(void);
  50. #define USER_PAGE 0x0FE00000UL
  51. /**************************************************************************//**
  52. * @brief Set or clear word in user page which enables or disables SWO
  53. * for TRACE_ProfilerSetup. If TRACE_ProfilerEnable(false) has been run,
  54. * no example project will enable SWO trace.
  55. * @param[in] enable
  56. * @note Add "em_msc.c" to build to use this function.
  57. *****************************************************************************/
  58. __STATIC_INLINE void TRACE_ProfilerEnable(bool enable)
  59. {
  60. uint32_t data;
  61. volatile uint32_t *userpage = (uint32_t *) USER_PAGE;
  62. /* Check that configuration needs to change */
  63. data = *userpage;
  64. if(enable)
  65. {
  66. if(data == 0xFFFFFFFF)
  67. {
  68. return;
  69. }
  70. }
  71. else
  72. {
  73. if(data == 0x00000000)
  74. {
  75. return;
  76. }
  77. }
  78. /* Initialize MSC */
  79. MSC_Init();
  80. /* Write enble or disable trigger word into flash */
  81. if(enable)
  82. {
  83. data = 0xFFFFFFFF;
  84. MSC_ErasePage((uint32_t *)USER_PAGE);
  85. MSC_WriteWord((uint32_t *)USER_PAGE, (void *) &data, 4);
  86. }
  87. else
  88. {
  89. data = 0x00000000;
  90. MSC_ErasePage((uint32_t *)USER_PAGE);
  91. MSC_WriteWord((uint32_t *)USER_PAGE, (void *) &data, 4);
  92. }
  93. }
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. /** @} (end group BSP) */
  98. #endif