SEGGER.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * SPDX-FileCopyrightText: 1995-2021 SEGGER Microcontroller GmbH
  3. *
  4. * SPDX-License-Identifier: BSD-1-Clause
  5. *
  6. * SPDX-FileContributor: 2023 Espressif Systems (Shanghai) CO LTD
  7. */
  8. /*********************************************************************
  9. * SEGGER Microcontroller GmbH *
  10. * The Embedded Experts *
  11. **********************************************************************
  12. * *
  13. * (c) 1995 - 2021 SEGGER Microcontroller GmbH *
  14. * *
  15. * www.segger.com Support: support@segger.com *
  16. * *
  17. **********************************************************************
  18. * *
  19. * SEGGER SystemView * Real-time application analysis *
  20. * *
  21. **********************************************************************
  22. * *
  23. * All rights reserved. *
  24. * *
  25. * SEGGER strongly recommends to not make any changes *
  26. * to or modify the source code of this software in order to stay *
  27. * compatible with the SystemView and RTT protocol, and J-Link. *
  28. * *
  29. * Redistribution and use in source and binary forms, with or *
  30. * without modification, are permitted provided that the following *
  31. * condition is met: *
  32. * *
  33. * o Redistributions of source code must retain the above copyright *
  34. * notice, this condition and the following disclaimer. *
  35. * *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  37. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
  38. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
  39. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
  40. * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
  41. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
  42. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
  43. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
  44. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  45. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
  46. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
  47. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
  48. * DAMAGE. *
  49. * *
  50. **********************************************************************
  51. * *
  52. * SystemView version: 3.42 *
  53. * *
  54. **********************************************************************
  55. ----------------------------------------------------------------------
  56. File : SEGGER.h
  57. Purpose : Global types etc & general purpose utility functions
  58. Revision: $Rev: 18102 $
  59. ---------------------------END-OF-HEADER------------------------------
  60. */
  61. #ifndef SEGGER_H // Guard against multiple inclusion
  62. #define SEGGER_H
  63. #include <stdarg.h> // For va_list.
  64. #include "Global.h" // Type definitions: U8, U16, U32, I8, I16, I32
  65. #if defined(__cplusplus)
  66. extern "C" { /* Make sure we have C-declarations in C++ programs */
  67. #endif
  68. /*********************************************************************
  69. *
  70. * Keywords/specifiers
  71. *
  72. **********************************************************************
  73. */
  74. #ifndef INLINE
  75. #if (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__))
  76. //
  77. // Other known compilers.
  78. //
  79. #define INLINE inline
  80. #else
  81. #if (defined(_WIN32) && !defined(__clang__))
  82. //
  83. // Microsoft VC6 and newer.
  84. // Force inlining without cost checking.
  85. //
  86. #define INLINE __forceinline
  87. #elif defined(__GNUC__) || defined(__clang__)
  88. //
  89. // Force inlining with GCC + clang
  90. //
  91. #define INLINE inline __attribute__((always_inline))
  92. #elif (defined(__CC_ARM))
  93. //
  94. // Force inlining with ARMCC (Keil)
  95. //
  96. #define INLINE __inline
  97. #else
  98. //
  99. // Unknown compilers.
  100. //
  101. #define INLINE
  102. #endif
  103. #endif
  104. #endif
  105. /*********************************************************************
  106. *
  107. * Function-like macros
  108. *
  109. **********************************************************************
  110. */
  111. #define SEGGER_COUNTOF(a) (sizeof((a))/sizeof((a)[0]))
  112. #define SEGGER_MIN(a,b) (((a) < (b)) ? (a) : (b))
  113. #define SEGGER_MAX(a,b) (((a) > (b)) ? (a) : (b))
  114. #ifndef SEGGER_USE_PARA // Some compiler complain about unused parameters.
  115. #define SEGGER_USE_PARA(Para) (void)Para // This works for most compilers.
  116. #endif
  117. #define SEGGER_ADDR2PTR(Type, Addr) (/*lint -e(923) -e(9078)*/((Type*)((PTR_ADDR)(Addr)))) // Allow cast from address to pointer.
  118. #define SEGGER_PTR2ADDR(p) (/*lint -e(923) -e(9078)*/((PTR_ADDR)(p))) // Allow cast from pointer to address.
  119. #define SEGGER_PTR2PTR(Type, p) (/*lint -e(740) -e(826) -e(9079) -e(9087)*/((Type*)(p))) // Allow cast from one pointer type to another (ignore different size).
  120. #define SEGGER_PTR_DISTANCE(p0, p1) (SEGGER_PTR2ADDR(p0) - SEGGER_PTR2ADDR(p1))
  121. /*********************************************************************
  122. *
  123. * Defines
  124. *
  125. **********************************************************************
  126. */
  127. #define SEGGER_PRINTF_FLAG_ADJLEFT (1 << 0)
  128. #define SEGGER_PRINTF_FLAG_SIGNFORCE (1 << 1)
  129. #define SEGGER_PRINTF_FLAG_SIGNSPACE (1 << 2)
  130. #define SEGGER_PRINTF_FLAG_PRECEED (1 << 3)
  131. #define SEGGER_PRINTF_FLAG_ZEROPAD (1 << 4)
  132. #define SEGGER_PRINTF_FLAG_NEGATIVE (1 << 5)
  133. /*********************************************************************
  134. *
  135. * Types
  136. *
  137. **********************************************************************
  138. */
  139. typedef struct {
  140. char* pBuffer;
  141. int BufferSize;
  142. int Cnt;
  143. } SEGGER_BUFFER_DESC;
  144. typedef struct {
  145. unsigned int CacheLineSize; // 0: No Cache. Most Systems such as ARM9 use a 32 bytes cache line size.
  146. void (*pfDMB) (void); // Optional DMB function for Data Memory Barrier to make sure all memory operations are completed.
  147. void (*pfClean) (void *p, unsigned long NumBytes); // Optional clean function for cached memory.
  148. void (*pfInvalidate)(void *p, unsigned long NumBytes); // Optional invalidate function for cached memory.
  149. } SEGGER_CACHE_CONFIG;
  150. typedef struct SEGGER_SNPRINTF_CONTEXT_struct SEGGER_SNPRINTF_CONTEXT;
  151. struct SEGGER_SNPRINTF_CONTEXT_struct {
  152. void* pContext; // Application specific context.
  153. SEGGER_BUFFER_DESC* pBufferDesc; // Buffer descriptor to use for output.
  154. void (*pfFlush)(SEGGER_SNPRINTF_CONTEXT* pContext); // Callback executed once the buffer is full. Callback decides if the buffer gets cleared to store more or not.
  155. };
  156. typedef struct {
  157. void (*pfStoreChar) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, char c);
  158. int (*pfPrintUnsigned) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, U32 v, unsigned Base, char Flags, int Width, int Precision);
  159. int (*pfPrintInt) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, I32 v, unsigned Base, char Flags, int Width, int Precision);
  160. } SEGGER_PRINTF_API;
  161. typedef void (*SEGGER_pFormatter)(SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, const SEGGER_PRINTF_API* pApi, va_list* pParamList, char Lead, int Width, int Precision);
  162. typedef struct SEGGER_PRINTF_FORMATTER {
  163. struct SEGGER_PRINTF_FORMATTER* pNext; // Pointer to next formatter.
  164. SEGGER_pFormatter pfFormatter; // Formatter function.
  165. char Specifier; // Format specifier.
  166. } SEGGER_PRINTF_FORMATTER;
  167. typedef struct {
  168. U32 (*pfGetHPTimestamp)(void); // Mandatory, pfGetHPTimestamp
  169. int (*pfGetUID) (U8 abUID[16]); // Optional, pfGetUID
  170. } SEGGER_BSP_API;
  171. /*********************************************************************
  172. *
  173. * Utility functions
  174. *
  175. **********************************************************************
  176. */
  177. //
  178. // Memory operations.
  179. //
  180. void SEGGER_ARM_memcpy(void* pDest, const void* pSrc, int NumBytes);
  181. void SEGGER_memcpy (void* pDest, const void* pSrc, unsigned NumBytes);
  182. void SEGGER_memxor (void* pDest, const void* pSrc, unsigned NumBytes);
  183. //
  184. // String functions.
  185. //
  186. int SEGGER_atoi (const char* s);
  187. int SEGGER_isalnum (int c);
  188. int SEGGER_isalpha (int c);
  189. unsigned SEGGER_strlen (const char* s);
  190. int SEGGER_tolower (int c);
  191. int SEGGER_strcasecmp (const char* sText1, const char* sText2);
  192. int SEGGER_strncasecmp(const char *sText1, const char *sText2, unsigned Count);
  193. //
  194. // Buffer/printf related.
  195. //
  196. void SEGGER_StoreChar (SEGGER_BUFFER_DESC* pBufferDesc, char c);
  197. void SEGGER_PrintUnsigned(SEGGER_BUFFER_DESC* pBufferDesc, U32 v, unsigned Base, int Precision);
  198. void SEGGER_PrintInt (SEGGER_BUFFER_DESC* pBufferDesc, I32 v, unsigned Base, int Precision);
  199. int SEGGER_snprintf (char* pBuffer, int BufferSize, const char* sFormat, ...);
  200. int SEGGER_vsnprintf (char* pBuffer, int BufferSize, const char* sFormat, va_list ParamList);
  201. int SEGGER_vsnprintfEx (SEGGER_SNPRINTF_CONTEXT* pContext, const char* sFormat, va_list ParamList);
  202. int SEGGER_PRINTF_AddFormatter (SEGGER_PRINTF_FORMATTER* pFormatter, SEGGER_pFormatter pfFormatter, char c);
  203. void SEGGER_PRINTF_AddDoubleFormatter (void);
  204. void SEGGER_PRINTF_AddIPFormatter (void);
  205. void SEGGER_PRINTF_AddBLUEFormatter (void);
  206. void SEGGER_PRINTF_AddCONNECTFormatter(void);
  207. void SEGGER_PRINTF_AddSSLFormatter (void);
  208. void SEGGER_PRINTF_AddSSHFormatter (void);
  209. void SEGGER_PRINTF_AddHTMLFormatter (void);
  210. //
  211. // BSP abstraction API.
  212. //
  213. int SEGGER_BSP_GetUID (U8 abUID[16]);
  214. int SEGGER_BSP_GetUID32(U32* pUID);
  215. void SEGGER_BSP_SetAPI (const SEGGER_BSP_API* pAPI);
  216. void SEGGER_BSP_SeedUID (void);
  217. //
  218. // Other API.
  219. //
  220. void SEGGER_VERSION_GetString(char acText[8], unsigned Version);
  221. #if defined(__cplusplus)
  222. } /* Make sure we have C-declarations in C++ programs */
  223. #endif
  224. #endif // Avoid multiple inclusion
  225. /*************************** End of file ****************************/