Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: add new WiFi (pseudo) modes: WIFI_SHUTDOWN & WIFI_RESUME #6356

Merged
merged 17 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions cores/esp8266/core_esp8266_eboot_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
extern "C" {

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)
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/coredecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand Down
42 changes: 42 additions & 0 deletions cores/esp8266/crc32.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
Loading