SEGGER.h 11 KB

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