Skip to content

Commit 273f400

Browse files
authored
Experimental: add new WiFi (pseudo) modes: WIFI_SHUTDOWN & WIFI_RESUME (#6356)
* add new WiFimodes: WIFI_SHUTDOWN & WIFI_RESUME with example * restore WiFi.onWiFiModeChange()
1 parent db46038 commit 273f400

File tree

12 files changed

+568
-63
lines changed

12 files changed

+568
-63
lines changed

cores/esp8266/core_esp8266_eboot_command.cpp

+3-24
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,15 @@
2121

2222
#include <stddef.h>
2323
#include <stdbool.h>
24+
#include "coredecls.h"
2425
#include "eboot_command.h"
2526

26-
extern "C" {
2727

28-
static uint32_t crc_update(uint32_t crc, const uint8_t *data, size_t length)
29-
{
30-
uint32_t i;
31-
bool bit;
32-
uint8_t c;
33-
34-
while (length--) {
35-
c = *data++;
36-
for (i = 0x80; i > 0; i >>= 1) {
37-
bit = crc & 0x80000000;
38-
if (c & i) {
39-
bit = !bit;
40-
}
41-
crc <<= 1;
42-
if (bit) {
43-
crc ^= 0x04c11db7;
44-
}
45-
}
46-
}
47-
return crc;
48-
}
28+
extern "C" {
4929

5030
static uint32_t eboot_command_calculate_crc32(const struct eboot_command* cmd)
5131
{
52-
return crc_update(0xffffffff, (const uint8_t*) cmd,
53-
offsetof(struct eboot_command, crc32));
32+
return crc32((const uint8_t*) cmd, offsetof(struct eboot_command, crc32));
5433
}
5534

5635
int eboot_command_read(struct eboot_command* cmd)

cores/esp8266/coredecls.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88

99
// TODO: put declarations here, get rid of -Wno-implicit-function-declaration
1010

11+
#include <stddef.h>
1112
#include <stdint.h>
1213
#include <cont.h> // g_pcont declaration
1314

@@ -20,6 +21,7 @@ void settimeofday_cb (void (*cb)(void));
2021
void disable_extra4k_at_link_time (void) __attribute__((noinline));
2122

2223
uint32_t sqrt32 (uint32_t n);
24+
uint32_t crc32 (const void* data, size_t length, uint32_t crc = 0xffffffff);
2325

2426
#ifdef __cplusplus
2527
}

cores/esp8266/crc32.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
crc32.cpp
3+
4+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
22+
#include "coredecls.h"
23+
24+
// moved from core_esp8266_eboot_command.cpp
25+
uint32_t crc32 (const void* data, size_t length, uint32_t crc /*= 0xffffffff*/)
26+
{
27+
const uint8_t* ldata = (const uint8_t*)data;
28+
while (length--)
29+
{
30+
uint8_t c = *ldata++;
31+
for (uint32_t i = 0x80; i > 0; i >>= 1)
32+
{
33+
bool bit = crc & 0x80000000;
34+
if (c & i)
35+
bit = !bit;
36+
crc <<= 1;
37+
if (bit)
38+
crc ^= 0x04c11db7;
39+
}
40+
}
41+
return crc;
42+
}

0 commit comments

Comments
 (0)