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