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.40 * 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 55 #ifndef SEGGER_H // Guard against multiple inclusion 56 #define SEGGER_H 57 58 #include <stdarg.h> // For va_list. 59 #include "Global.h" // Type definitions: U8, U16, U32, I8, I16, I32 60 61 #if defined(__cplusplus) 62 extern "C" { /* Make sure we have C-declarations in C++ programs */ 63 #endif 64 65 /********************************************************************* 66 * 67 * Keywords/specifiers 68 * 69 ********************************************************************** 70 */ 71 72 #ifndef INLINE 73 #if (defined(__ICCARM__) || defined(__RX) || defined(__ICCRX__)) 74 // 75 // Other known compilers. 76 // 77 #define INLINE inline 78 #else 79 #if (defined(_WIN32) && !defined(__clang__)) 80 // 81 // Microsoft VC6 and newer. 82 // Force inlining without cost checking. 83 // 84 #define INLINE __forceinline 85 #elif defined(__GNUC__) || defined(__clang__) 86 // 87 // Force inlining with GCC + clang 88 // 89 #define INLINE inline __attribute__((always_inline)) 90 #elif (defined(__CC_ARM)) 91 // 92 // Force inlining with ARMCC (Keil) 93 // 94 #define INLINE __inline 95 #else 96 // 97 // Unknown compilers. 98 // 99 #define INLINE 100 #endif 101 #endif 102 #endif 103 104 /********************************************************************* 105 * 106 * Function-like macros 107 * 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 115 #ifndef SEGGER_USE_PARA // Some compiler complain about unused parameters. 116 #define SEGGER_USE_PARA(Para) (void)Para // This works for most compilers. 117 #endif 118 119 #define SEGGER_ADDR2PTR(Type, Addr) (/*lint -e(923) -e(9078)*/((Type*)((PTR_ADDR)(Addr)))) // Allow cast from address to pointer. 120 #define SEGGER_PTR2ADDR(p) (/*lint -e(923) -e(9078)*/((PTR_ADDR)(p))) // Allow cast from pointer to address. 121 #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). 122 #define SEGGER_PTR_DISTANCE(p0, p1) (SEGGER_PTR2ADDR(p0) - SEGGER_PTR2ADDR(p1)) 123 124 /********************************************************************* 125 * 126 * Defines 127 * 128 ********************************************************************** 129 */ 130 131 #define SEGGER_PRINTF_FLAG_ADJLEFT (1 << 0) 132 #define SEGGER_PRINTF_FLAG_SIGNFORCE (1 << 1) 133 #define SEGGER_PRINTF_FLAG_SIGNSPACE (1 << 2) 134 #define SEGGER_PRINTF_FLAG_PRECEED (1 << 3) 135 #define SEGGER_PRINTF_FLAG_ZEROPAD (1 << 4) 136 #define SEGGER_PRINTF_FLAG_NEGATIVE (1 << 5) 137 138 /********************************************************************* 139 * 140 * Types 141 * 142 ********************************************************************** 143 */ 144 145 typedef struct { 146 char* pBuffer; 147 int BufferSize; 148 int Cnt; 149 } SEGGER_BUFFER_DESC; 150 151 typedef struct { 152 unsigned int CacheLineSize; // 0: No Cache. Most Systems such as ARM9 use a 32 bytes cache line size. 153 void (*pfDMB) (void); // Optional DMB function for Data Memory Barrier to make sure all memory operations are completed. 154 void (*pfClean) (void *p, unsigned long NumBytes); // Optional clean function for cached memory. 155 void (*pfInvalidate)(void *p, unsigned long NumBytes); // Optional invalidate function for cached memory. 156 } SEGGER_CACHE_CONFIG; 157 158 typedef struct SEGGER_SNPRINTF_CONTEXT_struct SEGGER_SNPRINTF_CONTEXT; 159 160 struct SEGGER_SNPRINTF_CONTEXT_struct { 161 void* pContext; // Application specific context. 162 SEGGER_BUFFER_DESC* pBufferDesc; // Buffer descriptor to use for output. 163 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. 164 }; 165 166 typedef struct { 167 void (*pfStoreChar) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, char c); 168 int (*pfPrintUnsigned) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, U32 v, unsigned Base, char Flags, int Width, int Precision); 169 int (*pfPrintInt) (SEGGER_BUFFER_DESC* pBufferDesc, SEGGER_SNPRINTF_CONTEXT* pContext, I32 v, unsigned Base, char Flags, int Width, int Precision); 170 } SEGGER_PRINTF_API; 171 172 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); 173 174 typedef struct SEGGER_PRINTF_FORMATTER { 175 struct SEGGER_PRINTF_FORMATTER* pNext; // Pointer to next formatter. 176 SEGGER_pFormatter pfFormatter; // Formatter function. 177 char Specifier; // Format specifier. 178 } SEGGER_PRINTF_FORMATTER; 179 180 typedef struct { 181 U32 (*pfGetHPTimestamp)(void); // Mandatory, pfGetHPTimestamp 182 int (*pfGetUID) (U8 abUID[16]); // Optional, pfGetUID 183 } SEGGER_BSP_API; 184 185 /********************************************************************* 186 * 187 * Utility functions 188 * 189 ********************************************************************** 190 */ 191 192 // 193 // Memory operations. 194 // 195 void SEGGER_ARM_memcpy(void* pDest, const void* pSrc, int NumBytes); 196 void SEGGER_memcpy (void* pDest, const void* pSrc, unsigned NumBytes); 197 void SEGGER_memxor (void* pDest, const void* pSrc, unsigned NumBytes); 198 199 // 200 // String functions. 201 // 202 int SEGGER_atoi (const char* s); 203 int SEGGER_isalnum (int c); 204 int SEGGER_isalpha (int c); 205 unsigned SEGGER_strlen (const char* s); 206 int SEGGER_tolower (int c); 207 int SEGGER_strcasecmp (const char* sText1, const char* sText2); 208 int SEGGER_strncasecmp(const char *sText1, const char *sText2, unsigned Count); 209 210 // 211 // Buffer/printf related. 212 // 213 void SEGGER_StoreChar (SEGGER_BUFFER_DESC* pBufferDesc, char c); 214 void SEGGER_PrintUnsigned(SEGGER_BUFFER_DESC* pBufferDesc, U32 v, unsigned Base, int Precision); 215 void SEGGER_PrintInt (SEGGER_BUFFER_DESC* pBufferDesc, I32 v, unsigned Base, int Precision); 216 int SEGGER_snprintf (char* pBuffer, int BufferSize, const char* sFormat, ...); 217 int SEGGER_vsnprintf (char* pBuffer, int BufferSize, const char* sFormat, va_list ParamList); 218 int SEGGER_vsnprintfEx (SEGGER_SNPRINTF_CONTEXT* pContext, const char* sFormat, va_list ParamList); 219 220 int SEGGER_PRINTF_AddFormatter (SEGGER_PRINTF_FORMATTER* pFormatter, SEGGER_pFormatter pfFormatter, char c); 221 void SEGGER_PRINTF_AddDoubleFormatter (void); 222 void SEGGER_PRINTF_AddIPFormatter (void); 223 void SEGGER_PRINTF_AddBLUEFormatter (void); 224 void SEGGER_PRINTF_AddCONNECTFormatter(void); 225 void SEGGER_PRINTF_AddSSLFormatter (void); 226 void SEGGER_PRINTF_AddSSHFormatter (void); 227 void SEGGER_PRINTF_AddHTMLFormatter (void); 228 229 // 230 // BSP abstraction API. 231 // 232 int SEGGER_BSP_GetUID (U8 abUID[16]); 233 int SEGGER_BSP_GetUID32(U32* pUID); 234 void SEGGER_BSP_SetAPI (const SEGGER_BSP_API* pAPI); 235 void SEGGER_BSP_SeedUID (void); 236 237 // 238 // Other API. 239 // 240 void SEGGER_VERSION_GetString(char acText[8], unsigned Version); 241 242 #if defined(__cplusplus) 243 } /* Make sure we have C-declarations in C++ programs */ 244 #endif 245 246 #endif // Avoid multiple inclusion 247 248 /*************************** End of file ****************************/ 249