-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlynkDebug.cpp
executable file
·149 lines (115 loc) · 2.59 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
/**
* @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 "BlynkDebug.h"
#if defined(BLYNK_USE_AVR_WDT)
#include <Arduino.h>
#include <avr/wdt.h>
size_t BlynkFreeRam()
{
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
void wdt_init(void)
{
MCUSR = 0;
wdt_disable();
return;
}
void BlynkReset()
{
wdt_enable(WDTO_15MS);
delay(50);
void(*resetFunc)(void) = 0;
resetFunc();
for(;;) {} // To make compiler happy
}
#elif defined(__AVR__)
#include <Arduino.h>
size_t BlynkFreeRam()
{
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void BlynkReset()
{
void(*resetFunc)(void) = 0;
resetFunc();
for(;;) {}
}
#elif defined(ESP8266)
#include <Arduino.h>
size_t BlynkFreeRam()
{
return ESP.getFreeHeap();
}
void BlynkReset()
{
ESP.restart();
for(;;) {}
}
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#include <Arduino.h>
size_t BlynkFreeRam()
{
return 0;
}
void BlynkReset()
{
NVIC_SystemReset();
for(;;) {}
}
#elif defined (PARTICLE) || defined(SPARK)
#include "application.h"
size_t BlynkFreeRam()
{
return 0;
}
void BlynkReset()
{
System.reset();
for(;;) {} // To make compiler happy
}
#elif defined(__STM32F1__) || defined(__STM32F3__)
#include <Arduino.h>
#include <libmaple/nvic.h>
size_t BlynkFreeRam()
{
return 0;
}
void BlynkReset()
{
nvic_sys_reset();
for(;;) {}
}
// TODO:
//#elif defined (TEENSYDUINO)
//#elif defined (__STM32F4__)
//#elif defined (ARDUINO_ARCH_ARC32)
//#elif defined (__RFduino__) || defined (__Simblee__)
#else
#if defined(BLYNK_DEBUG_ALL)
#warning "Need to implement board-specific utilities"
#endif
size_t BlynkFreeRam()
{
return 0;
}
void BlynkReset()
{
for(;;) {} // To make compiler happy
}
#endif
void BlynkFatal()
{
delay(10000L);
BlynkReset();
}