This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlynkDebug.cpp
335 lines (260 loc) · 6.33 KB
/
BlynkDebug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/**
* @file BlynkDebug.cpp
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Jan 2015
* @brief Debug utilities for Arduino
*/
#include <Blynk/BlynkDebug.h>
#if defined(ARDUINO) && defined(__AVR__) && defined(BLYNK_USE_AVR_WDT)
#include <Arduino.h>
#include <avr/wdt.h>
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
MCUSR = 0;
wdt_disable();
}
void BlynkReset()
{
wdt_enable(WDTO_15MS);
delay(50);
void(*resetFunc)(void) = 0;
resetFunc();
for(;;) {} // To make compiler happy
}
size_t BlynkFreeRam()
{
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO) && defined(__AVR__)
#include <Arduino.h>
void BlynkReset()
{
void(*resetFunc)(void) = 0;
resetFunc();
for(;;) {}
}
size_t BlynkFreeRam()
{
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO) && defined(ESP8266)
#include <Arduino.h>
size_t BlynkFreeRam()
{
return ESP.getFreeHeap();
}
void BlynkReset()
{
ESP.restart();
for(;;) {}
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#include <Arduino.h>
extern "C" char *sbrk(int i);
size_t BlynkFreeRam()
{
char stack_dummy = 0;
return &stack_dummy - sbrk(0);
}
void BlynkReset()
{
NVIC_SystemReset();
for(;;) {}
}
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined (ARDUINO_ARCH_ARC32)
millis_time_t BlynkMillis()
{
// TODO: Remove workaround for Intel Curie
// https://forum.arduino.cc/index.php?topic=391836.0
noInterrupts();
uint64_t t = millis();
interrupts();
return t;
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_RESET
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(ARDUINO) && (defined(__STM32F1__) || defined(__STM32F3__))
#include <Arduino.h>
#include <libmaple/nvic.h>
void BlynkReset()
{
nvic_sys_reset();
for(;;) {}
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined (PARTICLE) || defined(SPARK)
#include "application.h"
void BlynkReset()
{
System.reset();
for(;;) {} // To make compiler happy
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(__MBED__)
#if 1
//KH
#include <Timer.h>
#include <Ticker.h>
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
}
void BlynkDelay(millis_time_t ms)
{
delay(ms);
}
millis_time_t BlynkMillis()
{
return millis();
}
#else
#include "mbed.h"
static Timer blynk_millis_timer;
static Ticker blynk_waker;
static
void blynk_wake()
{
}
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
blynk_waker.attach(&blynk_wake, 2.0);
blynk_millis_timer.start();
}
void BlynkDelay(millis_time_t ms)
{
wait_ms(ms);
}
millis_time_t BlynkMillis()
{
return blynk_millis_timer.read_ms();
}
#endif
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_RESET
#elif defined(LINUX) && defined(RASPBERRY)
#include <stdlib.h>
#include <wiringPi.h>
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
wiringPiSetupGpio();
}
void BlynkReset()
{
exit(1);
for(;;) {} // To make compiler happy
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#elif defined(LINUX)
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
static millis_time_t blynk_startup_time = 0;
BLYNK_CONSTRUCTOR
static void BlynkSystemInit()
{
blynk_startup_time = BlynkMillis();
}
void BlynkReset()
{
exit(1);
for(;;) {} // To make compiler happy
}
void BlynkDelay(millis_time_t ms)
{
usleep(ms * 1000);
}
millis_time_t BlynkMillis()
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts );
return ( ts.tv_sec * 1000 + ts.tv_nsec / 1000000L ) - blynk_startup_time;
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#elif defined(TI_CC3220)
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <ti/devices/cc32xx/inc/hw_types.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/drivers/net/wifi/device.h>
#include <ti/devices/cc32xx/driverlib/prcm.h>
void BlynkReset()
{
sl_Stop(200);
for(;;) {
PRCMHibernateCycleTrigger();
}
}
void BlynkDelay(millis_time_t ms)
{
usleep(ms * 1000);
}
millis_time_t BlynkMillis()
{
return Clock_getTicks();
}
#define _BLYNK_USE_DEFAULT_FREE_RAM
#else
#if defined(BLYNK_DEBUG_ALL)
#warning "Need to implement board-specific utilities"
#endif
#define _BLYNK_USE_DEFAULT_FREE_RAM
#define _BLYNK_USE_DEFAULT_RESET
#define _BLYNK_USE_DEFAULT_MILLIS
#define _BLYNK_USE_DEFAULT_DELAY
#endif
#ifdef _BLYNK_USE_DEFAULT_DELAY
void BlynkDelay(millis_time_t ms)
{
return delay(ms);
}
#endif
#ifdef _BLYNK_USE_DEFAULT_MILLIS
millis_time_t BlynkMillis()
{
return millis();
}
#endif
#ifdef _BLYNK_USE_DEFAULT_FREE_RAM
size_t BlynkFreeRam()
{
return 0;
}
#endif
#ifdef _BLYNK_USE_DEFAULT_RESET
void BlynkReset()
{
for(;;) {} // To make compiler happy
}
#endif
void BlynkFatal()
{
BlynkDelay(10000L);
BlynkReset();
}