SEGGER.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*********************************************************************
  2. * SEGGER Microcontroller GmbH & Co. KG *
  3. * The Embedded Experts *
  4. **********************************************************************
  5. * *
  6. * (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
  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 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. * conditions are met: *
  25. * *
  26. * o Redistributions of source code must retain the above copyright *
  27. * notice, this list of conditions and the following disclaimer. *
  28. * *
  29. * o Redistributions in binary form must reproduce the above *
  30. * copyright notice, this list of conditions and the following *
  31. * disclaimer in the documentation and/or other materials provided *
  32. * with the distribution. *
  33. * *
  34. * o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
  35. * nor the names of its contributors may be used to endorse or *
  36. * promote products derived from this software without specific *
  37. * prior written permission. *
  38. * *
  39. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
  40. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
  41. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
  42. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
  43. * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
  44. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
  45. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
  46. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
  47. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
  48. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
  49. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
  50. * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
  51. * DAMAGE. *
  52. * *
  53. **********************************************************************
  54. * *
  55. * SystemView version: V2.52a *
  56. * *
  57. **********************************************************************
  58. ----------------------------------------------------------------------
  59. File : SEGGER.h
  60. Purpose : Global types etc & general purpose utility functions
  61. ---------------------------END-OF-HEADER------------------------------
  62. */
  63. #ifndef SEGGER_H // Guard against multiple inclusion
  64. #define SEGGER_H
  65. #include <stdarg.h>
  66. #include "Global.h" // Type definitions: U8, U16, U32, I8, I16, I32
  67. #if defined(__cplusplus)
  68. extern "C" { /* Make sure we have C-declarations in C++ programs */
  69. #endif
  70. /*********************************************************************
  71. *
  72. * Keywords/specifiers
  73. *
  74. **********************************************************************
  75. */
  76. #ifndef INLINE
  77. #ifdef _WIN32
  78. //
  79. // Microsoft VC6 and newer.
  80. // Force inlining without cost checking.
  81. //
  82. #define INLINE __forceinline
  83. #else
  84. #if (defined(__GNUC__))
  85. //
  86. // Force inlining with GCC
  87. //
  88. #define INLINE inline __attribute__((always_inline))
  89. #elif (defined(__CC_ARM))
  90. //
  91. // Force inlining with ARMCC (Keil)
  92. //
  93. #define INLINE __inline
  94. #elif (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__))
  95. //
  96. // Other known compilers.
  97. //
  98. #define INLINE inline
  99. #else
  100. //
  101. // Unknown compilers.
  102. //
  103. #define INLINE
  104. #endif
  105. #endif
  106. #endif
  107. /*********************************************************************
  108. *
  109. * Function-like macros
  110. *
  111. **********************************************************************
  112. */
  113. #define SEGGER_COUNTOF(a) (sizeof((a))/sizeof((a)[0]))
  114. #define SEGGER_MIN(a,b) (((a) < (b)) ? (a) : (b))
  115. #define SEGGER_MAX(a,b) (((a) > (b)) ? (a) : (b))
  116. #ifndef SEGGER_USE_PARA // Some compiler complain about unused parameters.
  117. #define SEGGER_USE_PARA(Para) (void)Para // This works for most compilers.
  118. #endif
  119. /*********************************************************************
  120. *
  121. * Defines
  122. *
  123. **********************************************************************
  124. */
  125. #define SEGGER_PRINTF_FLAG_ADJLEFT (1 << 0)
  126. #define SEGGER_PRINTF_FLAG_SIGNFORCE (1 << 1)
  127. #define SEGGER_PRINTF_FLAG_SIGNSPACE (1 << 2)
  128. #define SEGGER_PRINTF_FLAG_PRECEED (1 << 3)
  129. #define SEGGER_PRINTF_FLAG_ZEROPAD (1 << 4)
  130. #define SEGGER_PRINTF_FLAG_NEGATIVE (1 << 5)
  131. /*********************************************************************
  132. *
  133. * Types
  134. *
  135. **********************************************************************
  136. */
  137. typedef struct {
  138. char* pBuffer;
  139. int BufferSize;
  140. int Cnt;
  141. } SEGGER_BUFFER_DESC;
  142. typedef struct {
  143. int CacheLineSize; // 0: No Cache. Most Systems such as ARM9 use a 32 bytes cache line size.
  144. void (*pfDMB) (void); // Optional DMB function for Data Memory Barrier to make sure all memory operations are completed.
  145. void (*pfClean) (void *p, unsigned NumBytes); // Optional clean function for cached memory.
  146. void (*pfInvalidate)(void *p, unsigned NumBytes); // Optional invalidate function for cached memory.
  147. } SEGGER_CACHE_CONFIG;
  148. typedef struct SEGGER_SNPRINTF_CONTEXT_struct SEGGER_SNPRINTF_CONTEXT;
  149. struct SEGGER_SNPRINTF_CONTEXT_struct {
  150. void* pContext; // Application specific context.
  151. SEGGER_BUFFER_DESC* pBufferDesc; // Buffer descriptor to use for output.
  152. 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.
  153. };
  154. typedef struct {
  155. void (*pfStoreChar) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, char c);
  156. int (*pfPrintUnsigned) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, U32 v, unsigned Base, char Flags, int Width, int Precision);
  157. int (*pfPrintInt) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, I32 v, unsigned Base, char Flags, int Width, int Precision);
  158. } SEGGER_PRINTF_API;
  159. 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);
  160. typedef struct SEGGER_PRINTF_FORMATTER {
  161. struct SEGGER_PRINTF_FORMATTER* pNext; // Pointer to next formatter.
  162. SEGGER_pFormatter pfFormatter; // Formatter function.
  163. char Specifier; // Format specifier.
  164. } SEGGER_PRINTF_FORMATTER;
  165. /*********************************************************************
  166. *
  167. * Utility functions
  168. *
  169. **********************************************************************
  170. */
  171. //
  172. // Memory operations.
  173. //
  174. void SEGGER_ARM_memcpy(void* pDest, const void* pSrc, int NumBytes);
  175. void SEGGER_memcpy (void* pDest, const void* pSrc, int NumBytes);
  176. void SEGGER_memxor (void* pDest, const void* pSrc, unsigned NumBytes);
  177. //
  178. // String functions.
  179. //
  180. int SEGGER_atoi (const char* s);
  181. int SEGGER_isalnum (int c);
  182. int SEGGER_isalpha (int c);
  183. unsigned SEGGER_strlen (const char* s);
  184. int SEGGER_tolower (int c);
  185. int SEGGER_strcasecmp(const char* sText1, const char* sText2);
  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_AddHTMLFormatter (void);
  199. #if defined(__cplusplus)
  200. } /* Make sure we have C-declarations in C++ programs */
  201. #endif
  202. #endif // Avoid multiple inclusion
  203. /*************************** End of file ****************************/