8000 Merge branch 'master' into WIP-upstream-umm_malloc · esp8266/Arduino@2a1b722 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a1b722

Browse files
authored
Merge branch 'master' into WIP-upstream-umm_malloc
2 parents 47563cd + ffe5476 commit 2a1b722

20 files changed

+1010
-262
lines changed

cores/esp8266/Arduino.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,13 @@ long secureRandom(long);
275275
long secureRandom(long, long);
276276
long map(long, long, long, long, long);
277277

278-
extern "C" void configTime(long timezone, int daylightOffset_sec,
279-
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
278+
void configTime(int timezone, int daylightOffset_sec, const char* server1,
279+
const char* server2 = nullptr, const char* server3 = nullptr);
280280

281-
#endif
281+
void configTime(const char* tz, const char* server1,
282+
const char* server2 = nullptr, const char* server3 = nullptr);
283+
284+
#endif // __cplusplus
282285

283286
#include "pins_arduino.h"
284287

cores/esp8266/TZ.h

Lines changed: 475 additions & 0 deletions
Large diffs are not rendered by default.

cores/esp8266/time.cpp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818

19+
#include <stdlib.h>
1920
#include <time.h>
2021
#include <sys/time.h>
2122
#include <sys/reent.h>
@@ -55,25 +56,12 @@ static void setServer(int id, const char* name_or_ip)
5556
{
5657
if (name_or_ip)
5758
{
58-
//TODO: check whether server is given by name or IP
59+
// per current configuration,
60+
// lwIP can receive an IP address or a fqdn
5961
sntp_setservername(id, (char*) name_or_ip);
6062
}
6163
}
6264

63-
64-
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
65-
{
66-
sntp_stop();
67-
68-
setServer(0, server1);
69-
setServer(1, server2);
70-
setServer(2, server3);
71-
72-
sntp_set_timezone_in_seconds(timezone_sec);
73-
sntp_set_daylight(daylightOffset_sec);
74-
sntp_init();
75-
}
76-
7765
int clock_gettime(clockid_t unused, struct timespec *tp)
7866
{
7967
(void) unused;
@@ -108,4 +96,33 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
10896
return 0;
10997
}
11098

111-
};
99+
}; // extern "C"
100+
101+
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
102+
{
103+
sntp_stop();
104+
105+
setServer(0, server1);
106+
setServer(1, server2);
107+
setServer(2, server3);
108+
109+
sntp_set_timezone_in_seconds(timezone_sec);
110+
sntp_set_daylight(daylightOffset_sec);
111+
sntp_init();
112+
}
113+
114+
void configTime(const char* tz, const char* server1, const char* server2, const char* server3)
115+
{
116+
sntp_stop();
117+
118+
setServer(0, server1);
119+
setServer(1, server2);
120+
setServer(2, server3);
121+
122+
char tzram[strlen_P(tz) + 1];
123+
memcpy_P(tzram, tz, sizeof(tzram));
124+
setenv("TZ", tzram, 1/*overwrite*/);
125+
tzset();
126+
127+
sntp_init();
128+
}

doc/filesystem.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,18 @@ use esptool.py.
175175

176176
- Download the tool: https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.4.0/ESP8266FS-0.4.0.zip
177177
- In your Arduino sketchbook directory, create ``tools`` directory if
178-
it doesn't exist yet
178+
it doesn't exist yet.
179179
- Unpack the tool into ``tools`` directory (the path will look like
180180
``<home_dir>/Arduino/tools/ESP8266FS/tool/esp8266fs.jar``)
181181
If upgrading, overwrite the existing JAR file with the newer version.
182-
- Restart Arduino IDE
183-
- Open a sketch (or create a new one and save it)
184-
- Go to sketch directory (choose Sketch > Show Sketch Folder)
182+
- Restart Arduino IDE.
183+
- Open a sketch (or create a new one and save it).
184+
- Go to sketch directory (choose Sketch > Show Sketch Folder).
185185
- Create a directory named ``data`` and any files you want in the file
186-
system there
187-
- Make sure you have selected a board, port, and closed Serial Monitor
186+
system there.
187+
- Make sure you have selected a board, port, and closed Serial Monitor.
188+
- If your board requires you to press a button (or other action) to enter
189+
bootload mode for flashing a sketch, do that now.
188190
- Select Tools > ESP8266 Sketch Data Upload. This should start
189191
uploading the files into ESP8266 flash file system. When done, IDE
190192
status bar will display ``SPIFFS Image Uploaded`` message.

doc/reference.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
Reference
22
=========
33

4+
Interrupts
5+
----------
6+
7+
Interrupts can be used on the ESP8266, but they must be used with care
8+
and have several limitations:
9+
10+
* Interrupt callback functions must be in IRAM, because the flash may be
11+
in the middle of other operations when they occur. Do this by adding
12+
the ``ICACHE_RAM_ATTR`` attribute on the function definition. If this
13+
attribute is not present, the sketch will crash when it attempts to
14+
``attachInterrupt`` with an error message.
15+
16+
.. code:: cpp
17+
18+
ICACHE_RAM_ATTR void gpio_change_handler(void *data) {...
19+
20+
* Interrupts must not call ``delay()`` or ``yield()``, or call any routines
21+
which internally use ``delay()`` or ``yield()`` either.
22+
23+
* Long-running (>1ms) tasks in interrupts will cause instabilty or crashes.
24+
WiFi and other portions of the core can become unstable if interrupts
25+
are blocked by a long-running interrupt. If you have much to do, you can
26+
set a volatile global flag that your main ``loop()`` can check each pass
27+
or use a scheduled function (which will be called outside of the interrupt
28+
context when it is safe) to do long-running work.
29+
30+
* Memory operations can be dangerous and should be avoided in interrupts.
31+
Calls to ``new`` or ``malloc`` should be minimized because they may require
32+
a long running time if memory is fragmented. Calls to ``realloc`` and
33+
``free`` must NEVER be called. Using any routines or objects which call
34+
``free`` or ``realloc`` themselves is also forbidden for the same reason.
35+
This means that ``String``, ``std::string``, ``std::vector`` and other
36+
classes which use contiguous memory that may be resized must be used with
37+
extreme care (ensuring strings aren't changed, vector elements aren't
38+
added, etc.).
39+
440
Digital IO
541
----------
642

0 commit comments

Comments
 (0)
0