mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-16 00:43:00 +03:00
Experimental: add new WiFi (pseudo) modes: WIFI_SHUTDOWN & WIFI_RESUME (#6356)
* add new WiFimodes: WIFI_SHUTDOWN & WIFI_RESUME with example * restore WiFi.onWiFiModeChange()
This commit is contained in:
@ -21,36 +21,15 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "coredecls.h"
|
||||
#include "eboot_command.h"
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
static uint32_t crc_update(uint32_t crc, const uint8_t *data, size_t length)
|
||||
{
|
||||
uint32_t i;
|
||||
bool bit;
|
||||
uint8_t c;
|
||||
|
||||
while (length--) {
|
||||
c = *data++;
|
||||
for (i = 0x80; i > 0; i >>= 1) {
|
||||
bit = crc & 0x80000000;
|
||||
if (c & i) {
|
||||
bit = !bit;
|
||||
}
|
||||
crc <<= 1;
|
||||
if (bit) {
|
||||
crc ^= 0x04c11db7;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
static uint32_t eboot_command_calculate_crc32(const struct eboot_command* cmd)
|
||||
{
|
||||
return crc_update(0xffffffff, (const uint8_t*) cmd,
|
||||
offsetof(struct eboot_command, crc32));
|
||||
return crc32((const uint8_t*) cmd, offsetof(struct eboot_command, crc32));
|
||||
}
|
||||
|
||||
int eboot_command_read(struct eboot_command* cmd)
|
||||
|
@ -8,6 +8,7 @@ extern "C" {
|
||||
|
||||
// TODO: put declarations here, get rid of -Wno-implicit-function-declaration
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <cont.h> // g_pcont declaration
|
||||
|
||||
@ -20,6 +21,7 @@ void settimeofday_cb (void (*cb)(void));
|
||||
void disable_extra4k_at_link_time (void) __attribute__((noinline));
|
||||
|
||||
uint32_t sqrt32 (uint32_t n);
|
||||
uint32_t crc32 (const void* data, size_t length, uint32_t crc = 0xffffffff);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
42
cores/esp8266/crc32.cpp
Normal file
42
cores/esp8266/crc32.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
crc32.cpp
|
||||
|
||||
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "coredecls.h"
|
||||
|
||||
// moved from core_esp8266_eboot_command.cpp
|
||||
uint32_t crc32 (const void* data, size_t length, uint32_t crc /*= 0xffffffff*/)
|
||||
{
|
||||
const uint8_t* ldata = (const uint8_t*)data;
|
||||
while (length--)
|
||||
{
|
||||
uint8_t c = *ldata++;
|
||||
for (uint32_t i = 0x80; i > 0; i >>= 1)
|
||||
{
|
||||
bool bit = crc & 0x80000000;
|
||||
if (c & i)
|
||||
bit = !bit;
|
||||
crc <<= 1;
|
||||
if (bit)
|
||||
crc ^= 0x04c11db7;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
Reference in New Issue
Block a user