mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-02 14:22:55 +03:00
Migrate from astyle to clang-format (#8464)
This commit is contained in:
committed by
Max Prokhorov
parent
46190b61f1
commit
19b7a29720
@ -10,12 +10,12 @@
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
||||
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
||||
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
||||
// but actually the LED is on; this is because
|
||||
// it is active low on the ESP-01)
|
||||
delay(1000); // Wait for a second
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <PolledTimeout.h>
|
||||
|
||||
void ledOn() {
|
||||
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
||||
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
||||
}
|
||||
|
||||
void ledOff() {
|
||||
@ -38,7 +38,7 @@ void ledToggle() {
|
||||
}
|
||||
|
||||
|
||||
esp8266::polledTimeout::periodicFastUs halfPeriod(500000); //use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace
|
||||
esp8266::polledTimeout::periodicFastUs halfPeriod(500000); // use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace
|
||||
|
||||
// the setup function runs only once at start
|
||||
void setup() {
|
||||
@ -50,43 +50,37 @@ void setup() {
|
||||
Serial.printf("periodic/oneShotFastUs::timeMax() = %u us\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::timeMax());
|
||||
Serial.printf("periodic/oneShotFastNs::timeMax() = %u ns\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::timeMax());
|
||||
|
||||
#if 0 // 1 for debugging polledTimeout
|
||||
#if 0 // 1 for debugging polledTimeout
|
||||
Serial.printf("periodic/oneShotMs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicMs::rangeCompensate);
|
||||
Serial.printf("periodic/oneShotFastMs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastMs::rangeCompensate);
|
||||
Serial.printf("periodic/oneShotFastUs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastUs::rangeCompensate);
|
||||
Serial.printf("periodic/oneShotFastNs::rangeCompensate = %u\n", (uint32_t)esp8266::polledTimeout::periodicFastNs::rangeCompensate);
|
||||
#endif
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
||||
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
||||
|
||||
using esp8266::polledTimeout::oneShotMs; //import the type to the local namespace
|
||||
using esp8266::polledTimeout::oneShotMs; // import the type to the local namespace
|
||||
|
||||
//STEP1; turn the led ON
|
||||
// STEP1; turn the led ON
|
||||
ledOn();
|
||||
|
||||
//STEP2: wait for ON timeout
|
||||
// STEP2: wait for ON timeout
|
||||
oneShotMs timeoutOn(2000);
|
||||
while (!timeoutOn) {
|
||||
yield();
|
||||
}
|
||||
while (!timeoutOn) { yield(); }
|
||||
|
||||
//STEP3: turn the led OFF
|
||||
// STEP3: turn the led OFF
|
||||
ledOff();
|
||||
|
||||
//STEP4: wait for OFF timeout to assure the led is kept off for this time before exiting setup
|
||||
// STEP4: wait for OFF timeout to assure the led is kept off for this time before exiting setup
|
||||
oneShotMs timeoutOff(2000);
|
||||
while (!timeoutOff) {
|
||||
yield();
|
||||
}
|
||||
while (!timeoutOff) { yield(); }
|
||||
|
||||
//Done with STEPs, do other stuff
|
||||
halfPeriod.reset(); //halfPeriod is global, so it gets inited on sketch start. Clear it here to make it ready for loop, where it's actually used.
|
||||
// Done with STEPs, do other stuff
|
||||
halfPeriod.reset(); // halfPeriod is global, so it gets inited on sketch start. Clear it here to make it ready for loop, where it's actually used.
|
||||
}
|
||||
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
if (halfPeriod) {
|
||||
ledToggle();
|
||||
}
|
||||
if (halfPeriod) { ledToggle(); }
|
||||
}
|
||||
|
@ -5,25 +5,25 @@
|
||||
using namespace experimental::CBListImplentation;
|
||||
|
||||
class exampleClass {
|
||||
public:
|
||||
exampleClass() {};
|
||||
public:
|
||||
exampleClass(){};
|
||||
|
||||
using exCallBack = std::function<void(int)>;
|
||||
using exHandler = CallBackList<exCallBack>::CallBackHandler;
|
||||
using exCallBack = std::function<void(int)>;
|
||||
using exHandler = CallBackList<exCallBack>::CallBackHandler;
|
||||
|
||||
CallBackList<exCallBack> myHandlers;
|
||||
CallBackList<exCallBack> myHandlers;
|
||||
|
||||
exHandler setHandler(exCallBack cb) {
|
||||
return myHandlers.add(cb);
|
||||
}
|
||||
exHandler setHandler(exCallBack cb) {
|
||||
return myHandlers.add(cb);
|
||||
}
|
||||
|
||||
void removeHandler(exHandler hnd) {
|
||||
myHandlers.remove(hnd);
|
||||
}
|
||||
void removeHandler(exHandler hnd) {
|
||||
myHandlers.remove(hnd);
|
||||
}
|
||||
|
||||
void trigger(int t) {
|
||||
myHandlers.execute(t);
|
||||
}
|
||||
void trigger(int t) {
|
||||
myHandlers.execute(t);
|
||||
}
|
||||
};
|
||||
|
||||
exampleClass myExample;
|
||||
@ -60,5 +60,4 @@ void setup() {
|
||||
});
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
|
@ -21,25 +21,24 @@ void setup() {
|
||||
uint32_t ptr = (uint32_t)corruptme;
|
||||
// Find a page aligned spot inside the array
|
||||
ptr += 2 * SPI_FLASH_SEC_SIZE;
|
||||
ptr &= ~(SPI_FLASH_SEC_SIZE - 1); // Sectoralign
|
||||
ptr &= ~(SPI_FLASH_SEC_SIZE - 1); // Sectoralign
|
||||
uint32_t sector = ((((uint32_t)ptr - 0x40200000) / SPI_FLASH_SEC_SIZE));
|
||||
|
||||
// Create a sector with 1 bit set (i.e. fake corruption)
|
||||
uint32_t *space = (uint32_t*)calloc(SPI_FLASH_SEC_SIZE, 1);
|
||||
uint32_t *space = (uint32_t *)calloc(SPI_FLASH_SEC_SIZE, 1);
|
||||
space[42] = 64;
|
||||
|
||||
// Write it into flash at the spot in question
|
||||
spi_flash_erase_sector(sector);
|
||||
spi_flash_write(sector * SPI_FLASH_SEC_SIZE, (uint32_t*)space, SPI_FLASH_SEC_SIZE);
|
||||
spi_flash_write(sector * SPI_FLASH_SEC_SIZE, (uint32_t *)space, SPI_FLASH_SEC_SIZE);
|
||||
Serial.printf("CRC check: %s\n", ESP.checkFlashCRC() ? "OK" : "ERROR");
|
||||
|
||||
Serial.printf("...Correcting the flash...\n");
|
||||
memset(space, 0, SPI_FLASH_SEC_SIZE);
|
||||
spi_flash_erase_sector(sector);
|
||||
spi_flash_write(sector * SPI_FLASH_SEC_SIZE, (uint32_t*)space, SPI_FLASH_SEC_SIZE);
|
||||
spi_flash_write(sector * SPI_FLASH_SEC_SIZE, (uint32_t *)space, SPI_FLASH_SEC_SIZE);
|
||||
Serial.printf("CRC check: %s\n", ESP.checkFlashCRC() ? "OK" : "ERROR");
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
|
@ -20,7 +20,10 @@ void loop() {
|
||||
|
||||
Serial.printf("Flash ide size: %u bytes\n", ideSize);
|
||||
Serial.printf("Flash ide speed: %u Hz\n", ESP.getFlashChipSpeed());
|
||||
Serial.printf("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
|
||||
Serial.printf("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT"
|
||||
: ideMode == FM_DIO ? "DIO"
|
||||
: ideMode == FM_DOUT ? "DOUT"
|
||||
: "UNKNOWN"));
|
||||
|
||||
if (ideSize != realSize) {
|
||||
Serial.println("Flash Chip configuration wrong!\n");
|
||||
|
@ -81,5 +81,4 @@ void setup() {
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
|
@ -39,17 +39,15 @@ void setup() {
|
||||
// PWM-Locked generator: https://github.com/esp8266/Arduino/pull/7231
|
||||
enablePhaseLockedWaveform();
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
||||
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
||||
analogWriteRange(1000);
|
||||
|
||||
using esp8266::polledTimeout::oneShotMs; //import the type to the local namespace
|
||||
using esp8266::polledTimeout::oneShotMs; // import the type to the local namespace
|
||||
|
||||
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
||||
digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
|
||||
|
||||
oneShotMs timeoutOn(2000);
|
||||
while (!timeoutOn) {
|
||||
yield();
|
||||
}
|
||||
while (!timeoutOn) { yield(); }
|
||||
|
||||
stepPeriod.reset();
|
||||
}
|
||||
|
@ -52,53 +52,40 @@ void tryit(int blocksize) {
|
||||
calculation of multiple elements combined with the rounding up for the
|
||||
8-byte alignment of each allocation can make for some tricky calculations.
|
||||
*/
|
||||
int rawMemoryMaxFreeBlockSize = ESP.getMaxFreeBlockSize();
|
||||
int rawMemoryMaxFreeBlockSize = ESP.getMaxFreeBlockSize();
|
||||
// Remove the space for overhead component of the blocks*sizeof(void*) array.
|
||||
int maxFreeBlockSize = rawMemoryMaxFreeBlockSize - UMM_OVERHEAD_ADJUST;
|
||||
// Initial estimate to use all of the MaxFreeBlock with multiples of 8 rounding up.
|
||||
blocks = maxFreeBlockSize /
|
||||
(((blocksize + UMM_OVERHEAD_ADJUST + 7) & ~7) + sizeof(void*));
|
||||
blocks = maxFreeBlockSize / (((blocksize + UMM_OVERHEAD_ADJUST + 7) & ~7) + sizeof(void*));
|
||||
/*
|
||||
While we allowed for the 8-byte alignment overhead for blocks*blocksize we
|
||||
were unable to compensate in advance for the later 8-byte aligning needed
|
||||
for the blocks*sizeof(void*) allocation. Thus blocks may be off by one count.
|
||||
We now validate the estimate and adjust as needed.
|
||||
*/
|
||||
int rawMemoryEstimate =
|
||||
blocks * ((blocksize + UMM_OVERHEAD_ADJUST + 7) & ~7) +
|
||||
((blocks * sizeof(void*) + UMM_OVERHEAD_ADJUST + 7) & ~7);
|
||||
if (rawMemoryMaxFreeBlockSize < rawMemoryEstimate) {
|
||||
--blocks;
|
||||
}
|
||||
int rawMemoryEstimate = blocks * ((blocksize + UMM_OVERHEAD_ADJUST + 7) & ~7) + ((blocks * sizeof(void*) + UMM_OVERHEAD_ADJUST + 7) & ~7);
|
||||
if (rawMemoryMaxFreeBlockSize < rawMemoryEstimate) { --blocks; }
|
||||
Serial.printf("\nFilling memory with blocks of %d bytes each\n", blocksize);
|
||||
stats("before");
|
||||
|
||||
p = (void**)malloc(sizeof(void*) * blocks);
|
||||
for (int i = 0; i < blocks; i++) {
|
||||
p[i] = malloc(blocksize);
|
||||
}
|
||||
for (int i = 0; i < blocks; i++) { p[i] = malloc(blocksize); }
|
||||
stats("array and blocks allocation");
|
||||
|
||||
for (int i = 0; i < blocks; i += 2) {
|
||||
if (p[i]) {
|
||||
free(p[i]);
|
||||
}
|
||||
if (p[i]) { free(p[i]); }
|
||||
p[i] = nullptr;
|
||||
}
|
||||
stats("freeing every other blocks");
|
||||
|
||||
for (int i = 0; i < (blocks - 1); i += 4) {
|
||||
if (p[i + 1]) {
|
||||
free(p[i + 1]);
|
||||
}
|
||||
if (p[i + 1]) { free(p[i + 1]); }
|
||||
p[i + 1] = nullptr;
|
||||
}
|
||||
stats("freeing every other remaining blocks");
|
||||
|
||||
for (int i = 0; i < blocks; i++) {
|
||||
if (p[i]) {
|
||||
free(p[i]);
|
||||
}
|
||||
if (p[i]) { free(p[i]); }
|
||||
}
|
||||
stats("freeing array");
|
||||
|
||||
@ -158,5 +145,4 @@ void setup() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
|
@ -21,7 +21,7 @@ namespace TypeCast = experimental::TypeConversion;
|
||||
https://github.com/esp8266/Arduino/issues/1143
|
||||
https://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html
|
||||
*/
|
||||
constexpr char masterKey[] PROGMEM = "w86vn@rpfA O+S"; // Use 8 random characters or more
|
||||
constexpr char masterKey[] PROGMEM = "w86vn@rpfA O+S"; // Use 8 random characters or more
|
||||
|
||||
void setup() {
|
||||
// Prevents the flash memory from being worn out, see: https://github.com/esp8266/Arduino/issues/1054 .
|
||||
@ -42,18 +42,18 @@ void loop() {
|
||||
String exampleData = F("Hello Crypto World!");
|
||||
Serial.println(String(F("This is our example data: ")) + exampleData);
|
||||
|
||||
uint8_t resultArray[SHA256::NATURAL_LENGTH] { 0 };
|
||||
uint8_t derivedKey[ENCRYPTION_KEY_LENGTH] { 0 };
|
||||
uint8_t resultArray[SHA256::NATURAL_LENGTH]{ 0 };
|
||||
uint8_t derivedKey[ENCRYPTION_KEY_LENGTH]{ 0 };
|
||||
|
||||
static uint32_t encryptionCounter = 0;
|
||||
|
||||
|
||||
// Generate the salt to use for HKDF
|
||||
uint8_t hkdfSalt[16] { 0 };
|
||||
uint8_t hkdfSalt[16]{ 0 };
|
||||
getNonceGenerator()(hkdfSalt, sizeof hkdfSalt);
|
||||
|
||||
// Generate the key to use for HMAC and encryption
|
||||
HKDF hkdfInstance(FPSTR(masterKey), (sizeof masterKey) - 1, hkdfSalt, sizeof hkdfSalt); // (sizeof masterKey) - 1 removes the terminating null value of the c-string
|
||||
HKDF hkdfInstance(FPSTR(masterKey), (sizeof masterKey) - 1, hkdfSalt, sizeof hkdfSalt); // (sizeof masterKey) - 1 removes the terminating null value of the c-string
|
||||
hkdfInstance.produce(derivedKey, sizeof derivedKey);
|
||||
|
||||
// Hash
|
||||
@ -71,8 +71,8 @@ void loop() {
|
||||
|
||||
// Authenticated Encryption with Associated Data (AEAD)
|
||||
String dataToEncrypt = F("This data is not encrypted.");
|
||||
uint8_t resultingNonce[12] { 0 }; // The nonce is always 12 bytes
|
||||
uint8_t resultingTag[16] { 0 }; // The tag is always 16 bytes
|
||||
uint8_t resultingNonce[12]{ 0 }; // The nonce is always 12 bytes
|
||||
uint8_t resultingTag[16]{ 0 }; // The tag is always 16 bytes
|
||||
|
||||
Serial.println(String(F("\nThis is the data to encrypt: ")) + dataToEncrypt);
|
||||
|
||||
|
@ -19,12 +19,12 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Esp.h>
|
||||
#include <user_interface.h>
|
||||
#include <coredecls.h> // g_pcont - only needed for this debug demo
|
||||
#include <coredecls.h> // g_pcont - only needed for this debug demo
|
||||
#include <StackThunk.h>
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char* ssid = STASSID;
|
||||
@ -39,7 +39,7 @@ extern "C" {
|
||||
#define thunk_ets_uart_printf ets_uart_printf
|
||||
|
||||
#else
|
||||
int thunk_ets_uart_printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
||||
int thunk_ets_uart_printf(const char* format, ...) __attribute__((format(printf, 1, 2)));
|
||||
// Second stack thunked helper - this macro creates the global function thunk_ets_uart_printf
|
||||
make_stack_thunk(ets_uart_printf);
|
||||
#endif
|
||||
@ -47,10 +47,10 @@ extern "C" {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setup(void) {
|
||||
WiFi.persistent(false); // w/o this a flash write occurs at every boot
|
||||
WiFi.persistent(false); // w/o this a flash write occurs at every boot
|
||||
WiFi.mode(WIFI_OFF);
|
||||
Serial.begin(115200);
|
||||
delay(20); // This delay helps when using the 'Modified Serial monitor' otherwise it is not needed.
|
||||
delay(20); // This delay helps when using the 'Modified Serial monitor' otherwise it is not needed.
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println(F("The Hardware Watchdog Timer Demo is starting ..."));
|
||||
@ -77,9 +77,7 @@ void setup(void) {
|
||||
disable_extra4k_at_link_time();
|
||||
#endif
|
||||
|
||||
Serial.printf_P(PSTR("This example was built with%s an extra 4K of heap space (g_pcont == 0x%08lX)\r\n"),
|
||||
((uintptr_t)0x3FFFC000 < (uintptr_t)g_pcont) ? "" : "out",
|
||||
(uintptr_t)g_pcont);
|
||||
Serial.printf_P(PSTR("This example was built with%s an extra 4K of heap space (g_pcont == 0x%08lX)\r\n"), ((uintptr_t)0x3FFFC000 < (uintptr_t)g_pcont) ? "" : "out", (uintptr_t)g_pcont);
|
||||
#if defined(DEBUG_ESP_HWDT) || defined(DEBUG_ESP_HWDT_NOEXTRA4K)
|
||||
Serial.print(F("and with the HWDT"));
|
||||
#if defined(DEBUG_ESP_HWDT_NOEXTRA4K)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <esp8266_undocumented.h>
|
||||
void crashMeIfYouCan(void)__attribute__((weak));
|
||||
void crashMeIfYouCan(void) __attribute__((weak));
|
||||
int divideA_B(int a, int b);
|
||||
|
||||
int* nullPointer = NULL;
|
||||
@ -14,7 +14,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.printf_P(PSTR("Restart, ESP.restart(); ...\r\n"));
|
||||
ESP.restart();
|
||||
break;
|
||||
case 's': {
|
||||
case 's':
|
||||
{
|
||||
uint32_t startTime = millis();
|
||||
out.printf_P(PSTR("Now crashing with Software WDT. This will take about 3 seconds.\r\n"));
|
||||
ets_install_putc1(ets_putc);
|
||||
@ -32,7 +33,9 @@ void processKey(Print& out, int hotKey) {
|
||||
"mov.n a4, %2\n\t"
|
||||
"mov.n a5, %3\n\t"
|
||||
"mov.n a6, %4\n\t"
|
||||
: : "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa) : "memory");
|
||||
:
|
||||
: "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa)
|
||||
: "memory");
|
||||
// Could not find these in the stack dump, unless interrupts were enabled.
|
||||
{
|
||||
uint32_t startTime = millis();
|
||||
@ -74,10 +77,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.println(F("by the compiler after detecting a divide by zero."));
|
||||
out.printf_P(PSTR("This should not print %d\n"), divideA_B_bp(1, 0));
|
||||
break;
|
||||
case '\r':
|
||||
out.println();
|
||||
case '\n':
|
||||
break;
|
||||
case '\r': out.println();
|
||||
case '\n': break;
|
||||
case '?':
|
||||
out.println();
|
||||
out.println(F("Press a key + <enter>"));
|
||||
|
@ -35,7 +35,7 @@ void setup() {
|
||||
WiFi.forceSleepBegin();
|
||||
delay(500);
|
||||
|
||||
i2s_rxtx_begin(true, false); // Enable I2S RX
|
||||
i2s_rxtx_begin(true, false); // Enable I2S RX
|
||||
i2s_set_rate(11025);
|
||||
|
||||
delay(1000);
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
// Set your network here
|
||||
@ -26,7 +26,7 @@ WiFiUDP udp;
|
||||
const IPAddress listener = { 192, 168, 1, 2 };
|
||||
const int port = 8266;
|
||||
|
||||
int16_t buffer[100][2]; // Temp staging for samples
|
||||
int16_t buffer[100][2]; // Temp staging for samples
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@ -48,7 +48,7 @@ void setup() {
|
||||
Serial.print("My IP: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
i2s_rxtx_begin(true, false); // Enable I2S RX
|
||||
i2s_rxtx_begin(true, false); // Enable I2S RX
|
||||
i2s_set_rate(11025);
|
||||
|
||||
Serial.print("\nStart the listener on ");
|
||||
@ -60,21 +60,16 @@ void setup() {
|
||||
udp.beginPacket(listener, port);
|
||||
udp.write("I2S Receiver\r\n");
|
||||
udp.endPacket();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint32_t cnt = 0;
|
||||
// Each loop will send 100 raw samples (400 bytes)
|
||||
// UDP needs to be < TCP_MSS which can be 500 bytes in LWIP2
|
||||
for (int i = 0; i < 100; i++) {
|
||||
i2s_read_sample(&buffer[i][0], &buffer[i][1], true);
|
||||
}
|
||||
for (int i = 0; i < 100; i++) { i2s_read_sample(&buffer[i][0], &buffer[i][1], true); }
|
||||
udp.beginPacket(listener, port);
|
||||
udp.write((uint8_t*)buffer, sizeof(buffer));
|
||||
udp.write((uint8_t *)buffer, sizeof(buffer));
|
||||
udp.endPacket();
|
||||
cnt++;
|
||||
if ((cnt % 100) == 0) {
|
||||
Serial.printf("%" PRIu32 "\n", cnt);
|
||||
}
|
||||
if ((cnt % 100) == 0) { Serial.printf("%" PRIu32 "\n", cnt); }
|
||||
}
|
||||
|
@ -18,9 +18,9 @@
|
||||
#if defined(UMM_HEAP_IRAM)
|
||||
|
||||
#if defined(CORE_MOCK)
|
||||
#define XCHAL_INSTRAM1_VADDR 0x40100000
|
||||
#define XCHAL_INSTRAM1_VADDR 0x40100000
|
||||
#else
|
||||
#include <sys/config.h> // For config/core-isa.h
|
||||
#include <sys/config.h> // For config/core-isa.h
|
||||
#endif
|
||||
|
||||
// durable - as in long life, persisting across reboots.
|
||||
@ -58,8 +58,7 @@ extern struct rst_info resetInfo;
|
||||
XOR sum on the IRAM data (or just a section of the IRAM data).
|
||||
*/
|
||||
inline bool is_iram_valid(void) {
|
||||
return (REASON_WDT_RST <= resetInfo.reason &&
|
||||
REASON_SOFT_RESTART >= resetInfo.reason);
|
||||
return (REASON_WDT_RST <= resetInfo.reason && REASON_SOFT_RESTART >= resetInfo.reason);
|
||||
}
|
||||
|
||||
|
||||
@ -70,16 +69,13 @@ void setup() {
|
||||
delay(10);
|
||||
Serial.printf_P(PSTR("\r\nSetup ...\r\n"));
|
||||
|
||||
if (!is_iram_valid()) {
|
||||
DURABLE->bootCounter = 0;
|
||||
}
|
||||
if (!is_iram_valid()) { DURABLE->bootCounter = 0; }
|
||||
|
||||
DURABLE->bootCounter++;
|
||||
|
||||
Serial.printf("Number of reboots at %u\r\n", DURABLE->bootCounter);
|
||||
Serial.printf("\r\nSome less than direct, ways to restart:\r\n");
|
||||
processKey(Serial, '?');
|
||||
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
@ -109,11 +105,8 @@ extern "C" void umm_init_iram(void) {
|
||||
uintptr_t sec_heap = (uintptr_t)_text_end + 32;
|
||||
sec_heap &= ~7;
|
||||
size_t sec_heap_sz = 0xC000UL - (sec_heap - (uintptr_t)XCHAL_INSTRAM1_VADDR);
|
||||
sec_heap_sz -= IRAM_RESERVE_SZ; // Shrink IRAM heap
|
||||
if (0xC000UL > sec_heap_sz) {
|
||||
|
||||
umm_init_iram_ex((void *)sec_heap, sec_heap_sz, true);
|
||||
}
|
||||
sec_heap_sz -= IRAM_RESERVE_SZ; // Shrink IRAM heap
|
||||
if (0xC000UL > sec_heap_sz) { umm_init_iram_ex((void *)sec_heap, sec_heap_sz, true); }
|
||||
}
|
||||
|
||||
#else
|
||||
@ -125,6 +118,5 @@ void setup() {
|
||||
Serial.println("\r\n\r\nThis sketch requires Tools Option: 'MMU: 16KB cache + 48KB IRAM and 2nd Heap (shared)'");
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
}
|
||||
void loop(void) {}
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <esp8266_undocumented.h>
|
||||
void crashMeIfYouCan(void)__attribute__((weak));
|
||||
void crashMeIfYouCan(void) __attribute__((weak));
|
||||
int divideA_B(int a, int b);
|
||||
|
||||
int* nullPointer = NULL;
|
||||
@ -14,7 +14,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.printf_P(PSTR("Restart, ESP.restart(); ...\r\n"));
|
||||
ESP.restart();
|
||||
break;
|
||||
case 's': {
|
||||
case 's':
|
||||
{
|
||||
uint32_t startTime = millis();
|
||||
out.printf_P(PSTR("Now crashing with Software WDT. This will take about 3 seconds.\r\n"));
|
||||
ets_install_putc1(ets_putc);
|
||||
@ -32,7 +33,9 @@ void processKey(Print& out, int hotKey) {
|
||||
"mov.n a4, %2\n\t"
|
||||
"mov.n a5, %3\n\t"
|
||||
"mov.n a6, %4\n\t"
|
||||
: : "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa) : "memory");
|
||||
:
|
||||
: "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa), "r"(0xaaaaaaaa)
|
||||
: "memory");
|
||||
// Could not find these in the stack dump, unless interrupts were enabled.
|
||||
{
|
||||
uint32_t startTime = millis();
|
||||
@ -74,10 +77,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.println(F("by the compiler after detecting a divide by zero."));
|
||||
out.printf_P(PSTR("This should not print %d\n"), divideA_B_bp(1, 0));
|
||||
break;
|
||||
case '\r':
|
||||
out.println();
|
||||
case '\n':
|
||||
break;
|
||||
case '\r': out.println();
|
||||
case '\n': break;
|
||||
case '?':
|
||||
out.println();
|
||||
out.println(F("Press a key + <enter>"));
|
||||
|
@ -38,14 +38,14 @@
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <coredecls.h> // crc32()
|
||||
#include <coredecls.h> // crc32()
|
||||
#include <PolledTimeout.h>
|
||||
#include <include/WiFiState.h> // WiFiState structure details
|
||||
#include <include/WiFiState.h> // WiFiState structure details
|
||||
|
||||
//#define DEBUG // prints WiFi connection info to serial, uncomment if you want WiFi messages
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINTLN(x) Serial.println(x)
|
||||
#define DEBUG_PRINT(x) Serial.print(x)
|
||||
#define DEBUG_PRINTLN(x) Serial.println(x)
|
||||
#define DEBUG_PRINT(x) Serial.print(x)
|
||||
#else
|
||||
#define DEBUG_PRINTLN(x)
|
||||
#define DEBUG_PRINT(x)
|
||||
@ -63,9 +63,9 @@ ADC_MODE(ADC_VCC); // allows you to monitor the internal VCC level; it varies w
|
||||
// don't connect anything to the analog input pin(s)!
|
||||
|
||||
// enter your WiFi configuration below
|
||||
const char* AP_SSID = "SSID"; // your router's SSID here
|
||||
const char* AP_SSID = "SSID"; // your router's SSID here
|
||||
const char* AP_PASS = "password"; // your router's password here
|
||||
IPAddress staticIP(0, 0, 0, 0); // parameters below are for your static IP address, if used
|
||||
IPAddress staticIP(0, 0, 0, 0); // parameters below are for your static IP address, if used
|
||||
IPAddress gateway(0, 0, 0, 0);
|
||||
IPAddress subnet(0, 0, 0, 0);
|
||||
IPAddress dns1(0, 0, 0, 0);
|
||||
@ -85,7 +85,7 @@ uint32_t timeout = 30E3; // 30 second timeout on the WiFi connection
|
||||
// This structure is stored in RTC memory to save the WiFi state and reset count (number of Deep Sleeps),
|
||||
// and it reconnects twice as fast as the first connection; it's used several places in this demo
|
||||
struct nv_s {
|
||||
WiFiState wss; // core's WiFi save state
|
||||
WiFiState wss; // core's WiFi save state
|
||||
|
||||
struct {
|
||||
uint32_t crc32;
|
||||
@ -94,29 +94,29 @@ struct nv_s {
|
||||
} rtcData;
|
||||
};
|
||||
|
||||
static nv_s* nv = (nv_s*)RTC_USER_MEM; // user RTC RAM area
|
||||
static nv_s* nv = (nv_s*)RTC_USER_MEM; // user RTC RAM area
|
||||
|
||||
uint32_t resetCount = 0; // keeps track of the number of Deep Sleep tests / resets
|
||||
|
||||
const uint32_t blinkDelay = 100; // fast blink rate for the LED when waiting for the user
|
||||
const uint32_t blinkDelay = 100; // fast blink rate for the LED when waiting for the user
|
||||
esp8266::polledTimeout::periodicMs blinkLED(blinkDelay); // LED blink delay without delay()
|
||||
esp8266::polledTimeout::oneShotMs altDelay(blinkDelay); // tight loop to simulate user code
|
||||
esp8266::polledTimeout::oneShotMs wifiTimeout(timeout); // 30 second timeout on WiFi connection
|
||||
esp8266::polledTimeout::oneShotMs altDelay(blinkDelay); // tight loop to simulate user code
|
||||
esp8266::polledTimeout::oneShotMs wifiTimeout(timeout); // 30 second timeout on WiFi connection
|
||||
// use fully qualified type and avoid importing all ::esp8266 namespace to the global namespace
|
||||
|
||||
void wakeupCallback() { // unlike ISRs, you can do a print() from a callback function
|
||||
testPoint_LOW; // testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW
|
||||
printMillis(); // show time difference across sleep; millis is wrong as the CPU eventually stops
|
||||
testPoint_LOW; // testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW
|
||||
printMillis(); // show time difference across sleep; millis is wrong as the CPU eventually stops
|
||||
Serial.println(F("Woke from Light Sleep - this is the callback"));
|
||||
}
|
||||
|
||||
void setup() {
|
||||
#ifdef TESTPOINT
|
||||
pinMode(testPointPin, OUTPUT); // test point for Light Sleep and Deep Sleep tests
|
||||
testPoint_LOW; // Deep Sleep reset doesn't clear GPIOs, testPoint LOW shows boot time
|
||||
testPoint_LOW; // Deep Sleep reset doesn't clear GPIOs, testPoint LOW shows boot time
|
||||
#endif
|
||||
pinMode(LED, OUTPUT); // activity and status indicator
|
||||
digitalWrite(LED, LOW); // turn on the LED
|
||||
pinMode(LED, OUTPUT); // activity and status indicator
|
||||
digitalWrite(LED, LOW); // turn on the LED
|
||||
pinMode(WAKE_UP_PIN, INPUT_PULLUP); // polled to advance tests, interrupt for Forced Light Sleep
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
@ -124,17 +124,15 @@ void setup() {
|
||||
String resetCause = ESP.getResetReason();
|
||||
Serial.println(resetCause);
|
||||
resetCount = 0;
|
||||
if ((resetCause == "External System") || (resetCause == "Power on")) {
|
||||
Serial.println(F("I'm awake and starting the Low Power tests"));
|
||||
}
|
||||
if ((resetCause == "External System") || (resetCause == "Power on")) { Serial.println(F("I'm awake and starting the Low Power tests")); }
|
||||
|
||||
// Read previous resets (Deep Sleeps) from RTC memory, if any
|
||||
uint32_t crcOfData = crc32((uint8_t*) &nv->rtcData.rstCount, sizeof(nv->rtcData.rstCount));
|
||||
uint32_t crcOfData = crc32((uint8_t*)&nv->rtcData.rstCount, sizeof(nv->rtcData.rstCount));
|
||||
if ((crcOfData = nv->rtcData.crc32) && (resetCause == "Deep-Sleep Wake")) {
|
||||
resetCount = nv->rtcData.rstCount; // read the previous reset count
|
||||
resetCount++;
|
||||
}
|
||||
nv->rtcData.rstCount = resetCount; // update the reset count & CRC
|
||||
nv->rtcData.rstCount = resetCount; // update the reset count & CRC
|
||||
updateRTCcrc();
|
||||
|
||||
if (resetCount == 1) { // show that millis() is cleared across the Deep Sleep reset
|
||||
@ -164,7 +162,7 @@ void loop() {
|
||||
} else if (resetCount == 4) {
|
||||
resetTests();
|
||||
}
|
||||
} //end of loop()
|
||||
} // end of loop()
|
||||
|
||||
void runTest1() {
|
||||
Serial.println(F("\n1st test - running with WiFi unconfigured"));
|
||||
@ -181,13 +179,13 @@ void runTest2() {
|
||||
Serial.println(F("The amperage will drop in 7 seconds."));
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("press the switch to continue"));
|
||||
waitPushbutton(true, 90); /* This is using a special feature: below 100 mS blink delay,
|
||||
the LED blink delay is padding 100 mS time with 'program cycles' to fill the 100 mS.
|
||||
At 90 mS delay, 90% of the blink time is delay(), and 10% is 'your program running'.
|
||||
Below 90% you'll see a difference in the average amperage: less delay() = more amperage.
|
||||
At 100 mS and above it's essentially all delay() time. On an oscilloscope you'll see the
|
||||
time between beacons at > 67 mA more often with less delay() percentage. You can change
|
||||
the '90' mS to other values to see the effect it has on Automatic Modem Sleep. */
|
||||
waitPushbutton(true, 90); /* This is using a special feature: below 100 mS blink delay,
|
||||
the LED blink delay is padding 100 mS time with 'program cycles' to fill the 100 mS.
|
||||
At 90 mS delay, 90% of the blink time is delay(), and 10% is 'your program running'.
|
||||
Below 90% you'll see a difference in the average amperage: less delay() = more amperage.
|
||||
At 100 mS and above it's essentially all delay() time. On an oscilloscope you'll see the
|
||||
time between beacons at > 67 mA more often with less delay() percentage. You can change
|
||||
the '90' mS to other values to see the effect it has on Automatic Modem Sleep. */
|
||||
} else {
|
||||
Serial.println(F("no WiFi connection, test skipped"));
|
||||
}
|
||||
@ -201,10 +199,10 @@ void runTest3() {
|
||||
// delay(10); // it doesn't always go to sleep unless you delay(10); yield() wasn't reliable
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("press the switch to continue"));
|
||||
waitPushbutton(true, 99); /* Using the same < 100 mS feature. If you drop the delay below 100, you
|
||||
will see the effect of program time vs. delay() time on minimum amperage. Above ~ 97 (97% of the
|
||||
time in delay) there is little change in amperage, so you need to spend maximum time in delay()
|
||||
to get minimum amperage.*/
|
||||
waitPushbutton(true, 99); /* Using the same < 100 mS feature. If you drop the delay below 100, you
|
||||
will see the effect of program time vs. delay() time on minimum amperage. Above ~ 97 (97% of the
|
||||
time in delay) there is little change in amperage, so you need to spend maximum time in delay()
|
||||
to get minimum amperage.*/
|
||||
}
|
||||
|
||||
void runTest4() {
|
||||
@ -215,13 +213,11 @@ void runTest4() {
|
||||
// and WiFi reconnects after the forceSleepWake more quickly
|
||||
digitalWrite(LED, LOW); // visual cue that we're reconnecting WiFi
|
||||
uint32_t wifiBegin = millis();
|
||||
WiFi.forceSleepWake(); // reconnect with previous STA mode and connection settings
|
||||
WiFi.forceSleepWake(); // reconnect with previous STA mode and connection settings
|
||||
WiFi.setSleepMode(WIFI_LIGHT_SLEEP, 3); // Automatic Light Sleep, DTIM listen interval = 3
|
||||
// at higher DTIM intervals you'll have a hard time establishing and maintaining a connection
|
||||
wifiTimeout.reset(timeout);
|
||||
while (((!WiFi.localIP()) || (WiFi.status() != WL_CONNECTED)) && (!wifiTimeout)) {
|
||||
yield();
|
||||
}
|
||||
while (((!WiFi.localIP()) || (WiFi.status() != WL_CONNECTED)) && (!wifiTimeout)) { yield(); }
|
||||
if ((WiFi.status() == WL_CONNECTED) && WiFi.localIP()) {
|
||||
// won't go into Automatic Sleep without an active WiFi connection
|
||||
float reConn = (millis() - wifiBegin);
|
||||
@ -229,9 +225,9 @@ void runTest4() {
|
||||
Serial.printf("%1.2f seconds\n", reConn / 1000);
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("long press of the switch to continue"));
|
||||
waitPushbutton(true, 350); /* Below 100 mS delay it only goes into 'Automatic Modem Sleep',
|
||||
and below ~ 350 mS delay() the 'Automatic Light Sleep' is less frequent. Above 500 mS
|
||||
delay() doesn't make significant improvement in power savings. */
|
||||
waitPushbutton(true, 350); /* Below 100 mS delay it only goes into 'Automatic Modem Sleep',
|
||||
and below ~ 350 mS delay() the 'Automatic Light Sleep' is less frequent. Above 500 mS
|
||||
delay() doesn't make significant improvement in power savings. */
|
||||
} else {
|
||||
Serial.println(F("no WiFi connection, test skipped"));
|
||||
}
|
||||
@ -241,61 +237,61 @@ void runTest5() {
|
||||
Serial.println(F("\n5th test - Timed Light Sleep, wake in 10 seconds"));
|
||||
Serial.println(F("Press the button when you're ready to proceed"));
|
||||
waitPushbutton(true, blinkDelay);
|
||||
WiFi.mode(WIFI_OFF); // you must turn the modem off; using disconnect won't work
|
||||
readVoltage(); // read internal VCC
|
||||
printMillis(); // show millis() across sleep, including Serial.flush()
|
||||
WiFi.mode(WIFI_OFF); // you must turn the modem off; using disconnect won't work
|
||||
readVoltage(); // read internal VCC
|
||||
printMillis(); // show millis() across sleep, including Serial.flush()
|
||||
digitalWrite(LED, HIGH); // turn the LED off so they know the CPU isn't running
|
||||
testPoint_HIGH; // testPoint LOW in callback tracks delay from testPoint HIGH to LOW
|
||||
extern os_timer_t *timer_list;
|
||||
testPoint_HIGH; // testPoint LOW in callback tracks delay from testPoint HIGH to LOW
|
||||
extern os_timer_t* timer_list;
|
||||
timer_list = nullptr; // stop (but don't disable) the 4 OS timers
|
||||
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
|
||||
gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_UP_PIN), GPIO_PIN_INTR_LOLEVEL); // GPIO wakeup (optional)
|
||||
// only LOLEVEL or HILEVEL interrupts work, no edge, that's an SDK or CPU limitation
|
||||
wifi_fpm_set_wakeup_cb(wakeupCallback); // set wakeup callback
|
||||
wifi_fpm_set_wakeup_cb(wakeupCallback); // set wakeup callback
|
||||
// the callback is optional, but without it the modem will wake in 10 seconds then delay(10 seconds)
|
||||
// with the callback the sleep time is only 10 seconds total, no extra delay() afterward
|
||||
wifi_fpm_open();
|
||||
wifi_fpm_do_sleep(10E6); // Sleep range = 10000 ~ 268,435,454 uS (0xFFFFFFE, 2^28-1)
|
||||
delay(10e3 + 1); // delay needs to be 1 mS longer than sleep or it only goes into Modem Sleep
|
||||
wifi_fpm_do_sleep(10E6); // Sleep range = 10000 ~ 268,435,454 uS (0xFFFFFFE, 2^28-1)
|
||||
delay(10e3 + 1); // delay needs to be 1 mS longer than sleep or it only goes into Modem Sleep
|
||||
Serial.println(F("Woke up!")); // the interrupt callback hits before this is executed
|
||||
}
|
||||
|
||||
void runTest6() {
|
||||
Serial.println(F("\n6th test - Forced Light Sleep, wake with GPIO interrupt"));
|
||||
Serial.flush();
|
||||
WiFi.mode(WIFI_OFF); // you must turn the modem off; using disconnect won't work
|
||||
WiFi.mode(WIFI_OFF); // you must turn the modem off; using disconnect won't work
|
||||
digitalWrite(LED, HIGH); // turn the LED off so they know the CPU isn't running
|
||||
readVoltage(); // read internal VCC
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("CPU going to sleep, pull WAKE_UP_PIN low to wake it (press the switch)"));
|
||||
printMillis(); // show millis() across sleep, including Serial.flush()
|
||||
printMillis(); // show millis() across sleep, including Serial.flush()
|
||||
testPoint_HIGH; // testPoint tracks latency from WAKE_UP_PIN LOW to testPoint LOW in callback
|
||||
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
|
||||
gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_UP_PIN), GPIO_PIN_INTR_LOLEVEL);
|
||||
// only LOLEVEL or HILEVEL interrupts work, no edge, that's an SDK or CPU limitation
|
||||
wifi_fpm_set_wakeup_cb(wakeupCallback); // Set wakeup callback (optional)
|
||||
wifi_fpm_set_wakeup_cb(wakeupCallback); // Set wakeup callback (optional)
|
||||
wifi_fpm_open();
|
||||
wifi_fpm_do_sleep(0xFFFFFFF); // only 0xFFFFFFF, any other value and it won't disconnect the RTC timer
|
||||
delay(10); // it goes to sleep during this delay() and waits for an interrupt
|
||||
wifi_fpm_do_sleep(0xFFFFFFF); // only 0xFFFFFFF, any other value and it won't disconnect the RTC timer
|
||||
delay(10); // it goes to sleep during this delay() and waits for an interrupt
|
||||
Serial.println(F("Woke up!")); // the interrupt callback hits before this is executed*/
|
||||
}
|
||||
|
||||
void runTest7() {
|
||||
Serial.println(F("\n7th test - Deep Sleep for 10 seconds, reset and wake with RF_DEFAULT"));
|
||||
initWiFi(); // initialize WiFi since we turned it off in the last test
|
||||
initWiFi(); // initialize WiFi since we turned it off in the last test
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("press the switch to continue"));
|
||||
while (!digitalRead(WAKE_UP_PIN)) { // wait for them to release the switch from the previous test
|
||||
delay(10);
|
||||
}
|
||||
delay(50); // debounce time for the switch, pushbutton released
|
||||
delay(50); // debounce time for the switch, pushbutton released
|
||||
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
|
||||
digitalWrite(LED, LOW); // turn the LED on, at least briefly
|
||||
//WiFi.shutdown(nv->wss); // Forced Modem Sleep for a more Instant Deep Sleep,
|
||||
// and no extended RFCAL as it goes into Deep Sleep
|
||||
digitalWrite(LED, LOW); // turn the LED on, at least briefly
|
||||
// WiFi.shutdown(nv->wss); // Forced Modem Sleep for a more Instant Deep Sleep,
|
||||
// and no extended RFCAL as it goes into Deep Sleep
|
||||
Serial.println(F("going into Deep Sleep now..."));
|
||||
printMillis(); // show time difference across sleep
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleep(10E6, WAKE_RF_DEFAULT); // good night! D0 fires a reset in 10 seconds...
|
||||
printMillis(); // show time difference across sleep
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleep(10E6, WAKE_RF_DEFAULT); // good night! D0 fires a reset in 10 seconds...
|
||||
// if you do ESP.deepSleep(0, mode); it needs a RESET to come out of sleep (RTC is disconnected)
|
||||
// maximum timed Deep Sleep interval ~ 3 to 4 hours depending on the RTC timer, see the README
|
||||
// the 2 uA GPIO amperage during Deep Sleep can't drive the LED so it's not lit now, although
|
||||
@ -308,12 +304,12 @@ void runTest8() {
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("press the switch to continue"));
|
||||
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
|
||||
//WiFi.shutdown(nv->wss); // Forced Modem Sleep for a more Instant Deep Sleep,
|
||||
// and no extended RFCAL as it goes into Deep Sleep
|
||||
// WiFi.shutdown(nv->wss); // Forced Modem Sleep for a more Instant Deep Sleep,
|
||||
// and no extended RFCAL as it goes into Deep Sleep
|
||||
Serial.println(F("going into Deep Sleep now..."));
|
||||
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleep(10E6, WAKE_RFCAL); // good night! D0 fires a reset in 10 seconds...
|
||||
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleep(10E6, WAKE_RFCAL); // good night! D0 fires a reset in 10 seconds...
|
||||
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
|
||||
}
|
||||
|
||||
@ -322,11 +318,11 @@ void runTest9() {
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("press the switch to continue"));
|
||||
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
|
||||
WiFi.shutdown(nv->wss); // Forced Modem Sleep for a more Instant Deep Sleep
|
||||
WiFi.shutdown(nv->wss); // Forced Modem Sleep for a more Instant Deep Sleep
|
||||
Serial.println(F("going into Deep Sleep now..."));
|
||||
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleepInstant(10E6, WAKE_NO_RFCAL); // good night! D0 fires a reset in 10 seconds...
|
||||
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleepInstant(10E6, WAKE_NO_RFCAL); // good night! D0 fires a reset in 10 seconds...
|
||||
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
|
||||
}
|
||||
|
||||
@ -335,11 +331,11 @@ void runTest10() {
|
||||
readVoltage(); // read internal VCC
|
||||
Serial.println(F("press the switch to continue"));
|
||||
waitPushbutton(false, blinkDelay); // set true if you want to see Automatic Modem Sleep
|
||||
//WiFi.forceSleepBegin(); // Forced Modem Sleep for a more Instant Deep Sleep
|
||||
// WiFi.forceSleepBegin(); // Forced Modem Sleep for a more Instant Deep Sleep
|
||||
Serial.println(F("going into Deep Sleep now..."));
|
||||
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleepInstant(10E6, WAKE_RF_DISABLED); // good night! D0 fires a reset in 10 seconds...
|
||||
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
|
||||
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
|
||||
ESP.deepSleepInstant(10E6, WAKE_RF_DISABLED); // good night! D0 fires a reset in 10 seconds...
|
||||
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
|
||||
}
|
||||
|
||||
@ -361,25 +357,25 @@ void waitPushbutton(bool usesDelay, unsigned int delayTime) { // loop until the
|
||||
}
|
||||
yield(); // this would be a good place for ArduinoOTA.handle();
|
||||
}
|
||||
} else { // long delay() for the 3 modes that need it, but it misses quick switch presses
|
||||
while (digitalRead(WAKE_UP_PIN)) { // wait for a pushbutton press
|
||||
} else { // long delay() for the 3 modes that need it, but it misses quick switch presses
|
||||
while (digitalRead(WAKE_UP_PIN)) { // wait for a pushbutton press
|
||||
digitalWrite(LED, !digitalRead(LED)); // toggle the activity LED
|
||||
delay(delayTime); // another good place for ArduinoOTA.handle();
|
||||
delay(delayTime); // another good place for ArduinoOTA.handle();
|
||||
if (delayTime < 100) {
|
||||
altDelay.reset(100 - delayTime); // pad the time < 100 mS with some real CPU cycles
|
||||
while (!altDelay) { // this simulates 'your program running', not delay() time
|
||||
while (!altDelay) { // this simulates 'your program running', not delay() time
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(50); // debounce time for the switch, pushbutton pressed
|
||||
delay(50); // debounce time for the switch, pushbutton pressed
|
||||
while (!digitalRead(WAKE_UP_PIN)) { // now wait for them to release the pushbutton
|
||||
delay(10);
|
||||
}
|
||||
delay(50); // debounce time for the switch, pushbutton released
|
||||
}
|
||||
|
||||
void readVoltage() { // read internal VCC
|
||||
void readVoltage() { // read internal VCC
|
||||
float volts = ESP.getVcc();
|
||||
Serial.printf("The internal VCC reads %1.2f volts\n", volts / 1000);
|
||||
}
|
||||
@ -391,18 +387,18 @@ void printMillis() {
|
||||
}
|
||||
|
||||
void updateRTCcrc() { // updates the reset count CRC
|
||||
nv->rtcData.crc32 = crc32((uint8_t*) &nv->rtcData.rstCount, sizeof(nv->rtcData.rstCount));
|
||||
nv->rtcData.crc32 = crc32((uint8_t*)&nv->rtcData.rstCount, sizeof(nv->rtcData.rstCount));
|
||||
}
|
||||
|
||||
void initWiFi() {
|
||||
digitalWrite(LED, LOW); // give a visual indication that we're alive but busy with WiFi
|
||||
digitalWrite(LED, LOW); // give a visual indication that we're alive but busy with WiFi
|
||||
uint32_t wifiBegin = millis(); // how long does it take to connect
|
||||
if ((crc32((uint8_t*) &nv->rtcData.rstCount + 1, sizeof(nv->wss)) && !WiFi.shutdownValidCRC(nv->wss))) {
|
||||
if ((crc32((uint8_t*)&nv->rtcData.rstCount + 1, sizeof(nv->wss)) && !WiFi.shutdownValidCRC(nv->wss))) {
|
||||
// if good copy of wss, overwrite invalid (primary) copy
|
||||
memcpy((uint32_t*) &nv->wss, (uint32_t*) &nv->rtcData.rstCount + 1, sizeof(nv->wss));
|
||||
memcpy((uint32_t*)&nv->wss, (uint32_t*)&nv->rtcData.rstCount + 1, sizeof(nv->wss));
|
||||
}
|
||||
if (WiFi.shutdownValidCRC(nv->wss)) { // if we have a valid WiFi saved state
|
||||
memcpy((uint32_t*) &nv->rtcData.rstCount + 1, (uint32_t*) &nv->wss, sizeof(nv->wss)); // save a copy of it
|
||||
if (WiFi.shutdownValidCRC(nv->wss)) { // if we have a valid WiFi saved state
|
||||
memcpy((uint32_t*)&nv->rtcData.rstCount + 1, (uint32_t*)&nv->wss, sizeof(nv->wss)); // save a copy of it
|
||||
Serial.println(F("resuming WiFi"));
|
||||
}
|
||||
if (!(WiFi.resumeFromShutdown(nv->wss))) { // couldn't resume, or no valid saved WiFi state yet
|
||||
@ -411,7 +407,7 @@ void initWiFi() {
|
||||
with other WiFi devices on your network. */
|
||||
WiFi.persistent(false); // don't store the connection each time to save wear on the flash
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.setOutputPower(10); // reduce RF output power, increase if it won't connect
|
||||
WiFi.setOutputPower(10); // reduce RF output power, increase if it won't connect
|
||||
WiFi.config(staticIP, gateway, subnet); // if using static IP, enter parameters at the top
|
||||
WiFi.begin(AP_SSID, AP_PASS);
|
||||
Serial.print(F("connecting to WiFi "));
|
||||
@ -420,9 +416,7 @@ void initWiFi() {
|
||||
DEBUG_PRINTLN(WiFi.macAddress());
|
||||
}
|
||||
wifiTimeout.reset(timeout);
|
||||
while (((!WiFi.localIP()) || (WiFi.status() != WL_CONNECTED)) && (!wifiTimeout)) {
|
||||
yield();
|
||||
}
|
||||
while (((!WiFi.localIP()) || (WiFi.status() != WL_CONNECTED)) && (!wifiTimeout)) { yield(); }
|
||||
if ((WiFi.status() == WL_CONNECTED) && WiFi.localIP()) {
|
||||
DEBUG_PRINTLN(F("WiFi connected"));
|
||||
Serial.print(F("WiFi connect time = "));
|
||||
|
@ -4,20 +4,20 @@
|
||||
#include <umm_malloc/umm_heap_select.h>
|
||||
|
||||
#if defined(CORE_MOCK)
|
||||
#define XCHAL_INSTRAM1_VADDR 0x40100000
|
||||
#define XCHAL_INSTRAM1_VADDR 0x40100000
|
||||
#else
|
||||
#include <sys/config.h> // For config/core-isa.h
|
||||
#include <sys/config.h> // For config/core-isa.h
|
||||
#endif
|
||||
|
||||
uint32_t timed_byte_read(char *pc, uint32_t * o);
|
||||
uint32_t timed_byte_read2(char *pc, uint32_t * o);
|
||||
uint32_t timed_byte_read(char *pc, uint32_t *o);
|
||||
uint32_t timed_byte_read2(char *pc, uint32_t *o);
|
||||
int divideA_B(int a, int b);
|
||||
|
||||
int* nullPointer = NULL;
|
||||
int *nullPointer = NULL;
|
||||
|
||||
char *probe_b = NULL;
|
||||
char *probe_b = NULL;
|
||||
short *probe_s = NULL;
|
||||
char *probe_c = (char *)0x40110000;
|
||||
char *probe_c = (char *)0x40110000;
|
||||
short *unaligned_probe_s = NULL;
|
||||
|
||||
uint32_t read_var = 0x11223344;
|
||||
@ -33,7 +33,7 @@ uint32_t read_var = 0x11223344;
|
||||
uint32_t *gobble;
|
||||
size_t gobble_sz;
|
||||
|
||||
#elif (MMU_IRAM_SIZE > 32*1024)
|
||||
#elif (MMU_IRAM_SIZE > 32 * 1024)
|
||||
uint32_t gobble[4 * 1024] IRAM_ATTR;
|
||||
constexpr size_t gobble_sz = sizeof(gobble);
|
||||
|
||||
@ -42,7 +42,7 @@ uint32_t gobble[256] IRAM_ATTR;
|
||||
constexpr size_t gobble_sz = sizeof(gobble);
|
||||
#endif
|
||||
|
||||
bool isValid(uint32_t *probe) {
|
||||
bool isValid(uint32_t *probe) {
|
||||
bool rc = true;
|
||||
if (NULL == probe) {
|
||||
ets_uart_printf("\nNULL memory pointer %p ...\n", probe);
|
||||
@ -54,7 +54,8 @@ bool isValid(uint32_t *probe) {
|
||||
uint32_t saveData = *probe;
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
*probe = BIT(i);
|
||||
asm volatile("" ::: "memory");
|
||||
asm volatile("" ::
|
||||
: "memory");
|
||||
uint32_t val = *probe;
|
||||
if (val != BIT(i)) {
|
||||
ets_uart_printf(" Read 0x%08X != Wrote 0x%08X\n", val, (uint32_t)BIT(i));
|
||||
@ -68,7 +69,7 @@ bool isValid(uint32_t *probe) {
|
||||
}
|
||||
|
||||
|
||||
void dump_mem32(const void * addr, const size_t len) {
|
||||
void dump_mem32(const void *addr, const size_t len) {
|
||||
uint32_t *addr32 = (uint32_t *)addr;
|
||||
ets_uart_printf("\n");
|
||||
if ((uintptr_t)addr32 & 3) {
|
||||
@ -77,9 +78,7 @@ void dump_mem32(const void * addr, const size_t len) {
|
||||
}
|
||||
for (size_t i = 0; i < len;) {
|
||||
ets_uart_printf("%p: ", &addr32[i]);
|
||||
do {
|
||||
ets_uart_printf(" 0x%08x", addr32[i]);
|
||||
} while (i++, (i & 3) && (i < len));
|
||||
do { ets_uart_printf(" 0x%08x", addr32[i]); } while (i++, (i & 3) && (i < len));
|
||||
ets_uart_printf("\n");
|
||||
}
|
||||
ets_uart_printf("\n");
|
||||
@ -87,7 +86,7 @@ void dump_mem32(const void * addr, const size_t len) {
|
||||
|
||||
extern "C" void _text_end(void);
|
||||
// extern void *_text_end;
|
||||
void print_mmu_status(Print& oStream) {
|
||||
void print_mmu_status(Print &oStream) {
|
||||
oStream.println();
|
||||
oStream.printf_P(PSTR("MMU Configuration"));
|
||||
oStream.println();
|
||||
@ -137,7 +136,7 @@ void setup() {
|
||||
{
|
||||
HeapSelectIram ephemeral;
|
||||
// Serial.printf_P(PSTR("ESP.getFreeHeap(): %u\n"), ESP.getFreeHeap());
|
||||
gobble_sz = ESP.getFreeHeap() - UMM_OVERHEAD_ADJUST; // - 4096;
|
||||
gobble_sz = ESP.getFreeHeap() - UMM_OVERHEAD_ADJUST; // - 4096;
|
||||
gobble = (uint32_t *)malloc(gobble_sz);
|
||||
}
|
||||
Serial.printf_P(PSTR("\r\nmalloc() from IRAM Heap:\r\n"));
|
||||
@ -152,9 +151,7 @@ void setup() {
|
||||
#if (MMU_IRAM_SIZE > 0x8000) || defined(MMU_IRAM_HEAP) || defined(MMU_SEC_HEAP)
|
||||
if (isValid(gobble)) {
|
||||
// Put something in our new memory
|
||||
for (size_t i = 0; i < (gobble_sz / 4); i++) {
|
||||
gobble[i] = (uint32_t)&gobble[i];
|
||||
}
|
||||
for (size_t i = 0; i < (gobble_sz / 4); i++) { gobble[i] = (uint32_t)&gobble[i]; }
|
||||
|
||||
// Now is it there?
|
||||
dump_mem32(gobble, 32);
|
||||
@ -170,12 +167,12 @@ void setup() {
|
||||
probe_b = (char *)gobble;
|
||||
probe_s = (short *)((uintptr_t)gobble);
|
||||
unaligned_probe_s = (short *)((uintptr_t)gobble + 1);
|
||||
|
||||
}
|
||||
|
||||
void processKey(Print& out, int hotKey) {
|
||||
void processKey(Print &out, int hotKey) {
|
||||
switch (hotKey) {
|
||||
case 't': {
|
||||
case 't':
|
||||
{
|
||||
uint32_t tmp;
|
||||
out.printf_P(PSTR("Test how much time is added by exception handling"));
|
||||
out.println();
|
||||
@ -227,7 +224,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.printf_P(PSTR("Read Byte from iRAM, 0x%02X at %p"), probe_b[0], probe_b);
|
||||
out.println();
|
||||
break;
|
||||
case 'B': {
|
||||
case 'B':
|
||||
{
|
||||
out.printf_P(PSTR("Load/Store exception by writing byte to iRAM"));
|
||||
out.println();
|
||||
char val = 0x55;
|
||||
@ -246,7 +244,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.printf_P(PSTR("Read short from iRAM, 0x%04X at %p"), probe_s[0], probe_s);
|
||||
out.println();
|
||||
break;
|
||||
case 'S': {
|
||||
case 'S':
|
||||
{
|
||||
out.printf_P(PSTR("Load/Store exception by writing short to iRAM"));
|
||||
out.println();
|
||||
short int val = 0x0AA0;
|
||||
@ -272,10 +271,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.printf_P(PSTR("This should not print %d"), divideA_B(1, 0));
|
||||
out.println();
|
||||
break;
|
||||
case '\r':
|
||||
out.println();
|
||||
case '\n':
|
||||
break;
|
||||
case '\r': out.println();
|
||||
case '\n': break;
|
||||
case '?':
|
||||
out.println();
|
||||
out.println(F("Press a key + <enter>"));
|
||||
|
@ -15,11 +15,11 @@
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
// initial time (possibly given by an external RTC)
|
||||
#define RTC_UTC_TEST 1510592825 // 1510592825 = Monday 13 November 2017 17:07:05 UTC
|
||||
#define RTC_UTC_TEST 1510592825 // 1510592825 = Monday 13 November 2017 17:07:05 UTC
|
||||
|
||||
|
||||
// This database is autogenerated from IANA timezone database
|
||||
@ -44,17 +44,17 @@
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <coredecls.h> // settimeofday_cb()
|
||||
#include <coredecls.h> // settimeofday_cb()
|
||||
#include <Schedule.h>
|
||||
#include <PolledTimeout.h>
|
||||
|
||||
#include <time.h> // time() ctime()
|
||||
#include <sys/time.h> // struct timeval
|
||||
#include <time.h> // time() ctime()
|
||||
#include <sys/time.h> // struct timeval
|
||||
|
||||
#include <sntp.h> // sntp_servermode_dhcp()
|
||||
#include <sntp.h> // sntp_servermode_dhcp()
|
||||
|
||||
// for testing purpose:
|
||||
extern "C" int clock_gettime(clockid_t unused, struct timespec *tp);
|
||||
extern "C" int clock_gettime(clockid_t unused, struct timespec* tp);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
@ -64,14 +64,14 @@ static time_t now;
|
||||
static uint32_t now_ms, now_us;
|
||||
|
||||
static esp8266::polledTimeout::periodicMs showTimeNow(60000);
|
||||
static int time_machine_days = 0; // 0 = present
|
||||
static int time_machine_days = 0; // 0 = present
|
||||
static bool time_machine_running = false;
|
||||
static bool time_machine_run_once = false;
|
||||
|
||||
// OPTIONAL: change SNTP startup delay
|
||||
// a weak function is already defined and returns 0 (RFC violation)
|
||||
// it can be redefined:
|
||||
//uint32_t sntp_startup_delay_MS_rfc_not_less_than_60000 ()
|
||||
// uint32_t sntp_startup_delay_MS_rfc_not_less_than_60000 ()
|
||||
//{
|
||||
// //info_sntp_startup_delay_MS_rfc_not_less_than_60000_has_been_called = true;
|
||||
// return 60000; // 60s (or lwIP's original default: (random() % 5000))
|
||||
@ -80,7 +80,7 @@ static bool time_machine_run_once = false;
|
||||
// OPTIONAL: change SNTP update delay
|
||||
// a weak function is already defined and returns 1 hour
|
||||
// it can be redefined:
|
||||
//uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 ()
|
||||
// uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 ()
|
||||
//{
|
||||
// //info_sntp_update_delay_MS_rfc_not_less_than_15000_has_been_called = true;
|
||||
// return 15000; // 15s
|
||||
@ -92,9 +92,15 @@ static bool time_machine_run_once = false;
|
||||
|
||||
void printTm(const char* what, const tm* tm) {
|
||||
Serial.print(what);
|
||||
PTM(isdst); PTM(yday); PTM(wday);
|
||||
PTM(year); PTM(mon); PTM(mday);
|
||||
PTM(hour); PTM(min); PTM(sec);
|
||||
PTM(isdst);
|
||||
PTM(yday);
|
||||
PTM(wday);
|
||||
PTM(year);
|
||||
PTM(mon);
|
||||
PTM(mday);
|
||||
PTM(hour);
|
||||
PTM(min);
|
||||
PTM(sec);
|
||||
}
|
||||
|
||||
void showTime() {
|
||||
@ -135,7 +141,7 @@ void showTime() {
|
||||
Serial.println((uint32_t)now);
|
||||
|
||||
// timezone and demo in the future
|
||||
Serial.printf("timezone: %s\n", getenv("TZ") ? : "(none)");
|
||||
Serial.printf("timezone: %s\n", getenv("TZ") ?: "(none)");
|
||||
|
||||
// human readable
|
||||
Serial.print("ctime: ");
|
||||
@ -152,9 +158,7 @@ void showTime() {
|
||||
} else {
|
||||
Serial.printf("%s ", sntp.toString().c_str());
|
||||
}
|
||||
Serial.printf("- IPv6: %s - Reachability: %o\n",
|
||||
sntp.isV6() ? "Yes" : "No",
|
||||
sntp_getreachability(i));
|
||||
Serial.printf("- IPv6: %s - Reachability: %o\n", sntp.isV6() ? "Yes" : "No", sntp_getreachability(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,12 +172,8 @@ void showTime() {
|
||||
while (true) {
|
||||
gettimeofday(&tv, nullptr);
|
||||
if (tv.tv_sec != prevtv.tv_sec) {
|
||||
Serial.printf("time(): %u gettimeofday(): %u.%06u seconds are unchanged\n",
|
||||
(uint32_t)prevtime,
|
||||
(uint32_t)prevtv.tv_sec, (uint32_t)prevtv.tv_usec);
|
||||
Serial.printf("time(): %u gettimeofday(): %u.%06u <-- seconds have changed\n",
|
||||
(uint32_t)(prevtime = time(nullptr)),
|
||||
(uint32_t)tv.tv_sec, (uint32_t)tv.tv_usec);
|
||||
Serial.printf("time(): %u gettimeofday(): %u.%06u seconds are unchanged\n", (uint32_t)prevtime, (uint32_t)prevtv.tv_sec, (uint32_t)prevtv.tv_usec);
|
||||
Serial.printf("time(): %u gettimeofday(): %u.%06u <-- seconds have changed\n", (uint32_t)(prevtime = time(nullptr)), (uint32_t)tv.tv_sec, (uint32_t)tv.tv_usec);
|
||||
break;
|
||||
}
|
||||
prevtv = tv;
|
||||
@ -194,10 +194,8 @@ void time_is_set(bool from_sntp /* <= this parameter is optional */) {
|
||||
} else {
|
||||
time_machine_running = from_sntp && !time_machine_run_once;
|
||||
}
|
||||
if (time_machine_running) {
|
||||
Serial.printf("\n-- \n-- Starting time machine demo to show libc's "
|
||||
"automatic DST handling\n-- \n");
|
||||
}
|
||||
if (time_machine_running) { Serial.printf("\n-- \n-- Starting time machine demo to show libc's "
|
||||
"automatic DST handling\n-- \n"); }
|
||||
}
|
||||
|
||||
Serial.print("settimeofday(");
|
||||
@ -212,9 +210,7 @@ void time_is_set(bool from_sntp /* <= this parameter is optional */) {
|
||||
if (time_machine_running) {
|
||||
now = time(nullptr);
|
||||
const tm* tm = localtime(&now);
|
||||
Serial.printf(": future=%3ddays: DST=%s - ",
|
||||
time_machine_days,
|
||||
tm->tm_isdst ? "true " : "false");
|
||||
Serial.printf(": future=%3ddays: DST=%s - ", time_machine_days, tm->tm_isdst ? "true " : "false");
|
||||
Serial.print(ctime(&now));
|
||||
gettimeofday(&tv, nullptr);
|
||||
constexpr int days = 30;
|
||||
@ -261,10 +257,10 @@ void setup() {
|
||||
|
||||
// Former configTime is still valid, here is the call for 7 hours to the west
|
||||
// with an enabled 30mn DST
|
||||
//configTime(7 * 3600, 3600 / 2, "pool.ntp.org");
|
||||
// configTime(7 * 3600, 3600 / 2, "pool.ntp.org");
|
||||
|
||||
// OPTIONAL: disable obtaining SNTP servers from DHCP
|
||||
//sntp_servermode_dhcp(0); // 0: disable obtaining SNTP servers from DHCP (enabled by default)
|
||||
// sntp_servermode_dhcp(0); // 0: disable obtaining SNTP servers from DHCP (enabled by default)
|
||||
|
||||
// Give now a chance to the settimeofday callback,
|
||||
// because it is *always* deferred to the next yield()/loop()-call.
|
||||
@ -280,7 +276,5 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (showTimeNow) {
|
||||
showTime();
|
||||
}
|
||||
if (showTimeNow) { showTime(); }
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ void setup() {
|
||||
delay(1000);
|
||||
|
||||
// Read struct from RTC memory
|
||||
if (ESP.rtcUserMemoryRead(0, (uint32_t*) &rtcData, sizeof(rtcData))) {
|
||||
if (ESP.rtcUserMemoryRead(0, (uint32_t *)&rtcData, sizeof(rtcData))) {
|
||||
Serial.println("Read: ");
|
||||
printMemory();
|
||||
Serial.println();
|
||||
uint32_t crcOfData = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
|
||||
uint32_t crcOfData = calculateCRC32((uint8_t *)&rtcData.data[0], sizeof(rtcData.data));
|
||||
Serial.print("CRC32 of data: ");
|
||||
Serial.println(crcOfData, HEX);
|
||||
Serial.print("CRC32 read from RTC: ");
|
||||
@ -51,13 +51,11 @@ void setup() {
|
||||
}
|
||||
|
||||
// Generate new data set for the struct
|
||||
for (size_t i = 0; i < sizeof(rtcData.data); i++) {
|
||||
rtcData.data[i] = random(0, 128);
|
||||
}
|
||||
for (size_t i = 0; i < sizeof(rtcData.data); i++) { rtcData.data[i] = random(0, 128); }
|
||||
// Update CRC32 of data
|
||||
rtcData.crc32 = calculateCRC32((uint8_t*) &rtcData.data[0], sizeof(rtcData.data));
|
||||
rtcData.crc32 = calculateCRC32((uint8_t *)&rtcData.data[0], sizeof(rtcData.data));
|
||||
// Write struct to RTC memory
|
||||
if (ESP.rtcUserMemoryWrite(0, (uint32_t*) &rtcData, sizeof(rtcData))) {
|
||||
if (ESP.rtcUserMemoryWrite(0, (uint32_t *)&rtcData, sizeof(rtcData))) {
|
||||
Serial.println("Write: ");
|
||||
printMemory();
|
||||
Serial.println();
|
||||
@ -67,8 +65,7 @@ void setup() {
|
||||
ESP.deepSleep(5e6);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
|
||||
uint32_t calculateCRC32(const uint8_t *data, size_t length) {
|
||||
uint32_t crc = 0xffffffff;
|
||||
@ -76,19 +73,15 @@ uint32_t calculateCRC32(const uint8_t *data, size_t length) {
|
||||
uint8_t c = *data++;
|
||||
for (uint32_t i = 0x80; i > 0; i >>= 1) {
|
||||
bool bit = crc & 0x80000000;
|
||||
if (c & i) {
|
||||
bit = !bit;
|
||||
}
|
||||
if (c & i) { bit = !bit; }
|
||||
crc <<= 1;
|
||||
if (bit) {
|
||||
crc ^= 0x04c11db7;
|
||||
}
|
||||
if (bit) { crc ^= 0x04c11db7; }
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
//prints all rtcData, including the leading crc32
|
||||
// prints all rtcData, including the leading crc32
|
||||
void printMemory() {
|
||||
char buf[3];
|
||||
uint8_t *ptr = (uint8_t *)&rtcData;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#define TIMEOUT (10000UL) // Maximum time to wait for serial activity to start
|
||||
#define TIMEOUT (10000UL) // Maximum time to wait for serial activity to start
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
@ -13,9 +13,7 @@ void setup() {
|
||||
Serial.printf("\nDetected baudrate is %lu, switching to that baudrate now...\n", detectedBaudrate);
|
||||
|
||||
// Wait for printf to finish
|
||||
while (Serial.availableForWrite() != UART_TX_FIFO_SIZE) {
|
||||
yield();
|
||||
}
|
||||
while (Serial.availableForWrite() != UART_TX_FIFO_SIZE) { yield(); }
|
||||
|
||||
// Clear Tx buffer to avoid extra characters being printed
|
||||
Serial.flush();
|
||||
@ -29,6 +27,4 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,18 +11,18 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define SSBAUD 115200 // logger on console for humans
|
||||
#define BAUD 3000000 // hardware serial stress test
|
||||
#define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX
|
||||
#define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize()
|
||||
#define SSBAUD 115200 // logger on console for humans
|
||||
#define BAUD 3000000 // hardware serial stress test
|
||||
#define BUFFER_SIZE 4096 // may be useless to use more than 2*SERIAL_SIZE_RX
|
||||
#define SERIAL_SIZE_RX 1024 // Serial.setRxBufferSize()
|
||||
|
||||
#define FAKE_INCREASED_AVAILABLE 100 // test readBytes's timeout
|
||||
#define FAKE_INCREASED_AVAILABLE 100 // test readBytes's timeout
|
||||
|
||||
#define TIMEOUT 5000
|
||||
#define DEBUG(x...) //x
|
||||
#define DEBUG(x...) // x
|
||||
|
||||
uint8_t buf [BUFFER_SIZE];
|
||||
uint8_t temp [BUFFER_SIZE];
|
||||
uint8_t buf[BUFFER_SIZE];
|
||||
uint8_t temp[BUFFER_SIZE];
|
||||
bool reading = true;
|
||||
size_t testReadBytesTimeout = 0;
|
||||
|
||||
@ -37,31 +37,22 @@ static uint64_t timeout;
|
||||
Stream* logger;
|
||||
|
||||
void error(const char* what) {
|
||||
logger->printf("\nerror: %s after %ld minutes\nread idx: %d\nwrite idx: %d\ntotal: %ld\nlast read: %d\nmaxavail: %d\n",
|
||||
what, (long)((millis() - start_ms) / 60000), in_idx, out_idx, (long)in_total, (int)local_receive_size, maxavail);
|
||||
if (Serial.hasOverrun()) {
|
||||
logger->printf("overrun!\n");
|
||||
}
|
||||
logger->printf("\nerror: %s after %ld minutes\nread idx: %d\nwrite idx: %d\ntotal: %ld\nlast read: %d\nmaxavail: %d\n", what, (long)((millis() - start_ms) / 60000), in_idx, out_idx, (long)in_total, (int)local_receive_size, maxavail);
|
||||
if (Serial.hasOverrun()) { logger->printf("overrun!\n"); }
|
||||
logger->printf("should be (size=%d idx=%d..%d):\n ", BUFFER_SIZE, in_idx, in_idx + local_receive_size - 1);
|
||||
for (size_t i = in_idx; i < in_idx + local_receive_size; i++) {
|
||||
logger->printf("%02x(%c) ", buf[i], (unsigned char)((buf[i] > 31 && buf[i] < 128) ? buf[i] : '.'));
|
||||
}
|
||||
for (size_t i = in_idx; i < in_idx + local_receive_size; i++) { logger->printf("%02x(%c) ", buf[i], (unsigned char)((buf[i] > 31 && buf[i] < 128) ? buf[i] : '.')); }
|
||||
logger->print("\n\nis: ");
|
||||
for (size_t i = 0; i < local_receive_size; i++) {
|
||||
logger->printf("%02x(%c) ", temp[i], (unsigned char)((temp[i] > 31 && temp[i] < 128) ? temp[i] : '.'));
|
||||
}
|
||||
for (size_t i = 0; i < local_receive_size; i++) { logger->printf("%02x(%c) ", temp[i], (unsigned char)((temp[i] > 31 && temp[i] < 128) ? temp[i] : '.')); }
|
||||
logger->println("\n\n");
|
||||
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
while (true) { delay(1000); }
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.begin(BAUD);
|
||||
Serial.swap(); // RX=GPIO13 TX=GPIO15
|
||||
Serial.swap(); // RX=GPIO13 TX=GPIO15
|
||||
Serial.setRxBufferSize(SERIAL_SIZE_RX);
|
||||
|
||||
// using HardwareSerial0 pins,
|
||||
@ -75,26 +66,22 @@ void setup() {
|
||||
|
||||
int baud = Serial.baudRate();
|
||||
logger->printf(ESP.getFullVersion().c_str());
|
||||
logger->printf("\n\nBAUD: %d - CoreRxBuffer: %d bytes - TestBuffer: %d bytes\n",
|
||||
baud, SERIAL_SIZE_RX, BUFFER_SIZE);
|
||||
logger->printf("\n\nBAUD: %d - CoreRxBuffer: %d bytes - TestBuffer: %d bytes\n", baud, SERIAL_SIZE_RX, BUFFER_SIZE);
|
||||
|
||||
size_for_1sec = baud / 10; // 8n1=10baudFor8bits
|
||||
size_for_1sec = baud / 10; // 8n1=10baudFor8bits
|
||||
logger->printf("led changes state every %zd bytes (= 1 second)\n", size_for_1sec);
|
||||
logger->printf("press 's' to stop reading, not writing (induces overrun)\n");
|
||||
logger->printf("press 't' to toggle timeout testing on readBytes\n");
|
||||
|
||||
// prepare send/compare buffer
|
||||
for (size_t i = 0; i < sizeof buf; i++) {
|
||||
buf[i] = (uint8_t)i;
|
||||
}
|
||||
for (size_t i = 0; i < sizeof buf; i++) { buf[i] = (uint8_t)i; }
|
||||
|
||||
// bind RX and TX
|
||||
USC0(0) |= (1 << UCLBE);
|
||||
|
||||
while (Serial.read() == -1);
|
||||
if (Serial.hasOverrun()) {
|
||||
logger->print("overrun?\n");
|
||||
}
|
||||
while (Serial.read() == -1)
|
||||
;
|
||||
if (Serial.hasOverrun()) { logger->print("overrun?\n"); }
|
||||
|
||||
timeout = (start_ms = last_ms = millis()) + TIMEOUT;
|
||||
logger->println("setup done");
|
||||
@ -103,59 +90,35 @@ void setup() {
|
||||
void loop() {
|
||||
size_t maxlen = Serial.availableForWrite();
|
||||
// check remaining space in buffer
|
||||
if (maxlen > BUFFER_SIZE - out_idx) {
|
||||
maxlen = BUFFER_SIZE - out_idx;
|
||||
}
|
||||
if (maxlen > BUFFER_SIZE - out_idx) { maxlen = BUFFER_SIZE - out_idx; }
|
||||
// check if not cycling more than buffer size relatively to input
|
||||
size_t in_out = out_idx == in_idx ?
|
||||
BUFFER_SIZE :
|
||||
(in_idx + BUFFER_SIZE - out_idx - 1) % BUFFER_SIZE;
|
||||
if (maxlen > in_out) {
|
||||
maxlen = in_out;
|
||||
}
|
||||
size_t in_out = out_idx == in_idx ? BUFFER_SIZE : (in_idx + BUFFER_SIZE - out_idx - 1) % BUFFER_SIZE;
|
||||
if (maxlen > in_out) { maxlen = in_out; }
|
||||
DEBUG(logger->printf("(aw%i/w%i", Serial.availableForWrite(), maxlen));
|
||||
size_t local_written_size = Serial.write(buf + out_idx, maxlen);
|
||||
DEBUG(logger->printf(":w%i/aw%i/ar%i)\n", local_written_size, Serial.availableForWrite(), Serial.available()));
|
||||
if (local_written_size > maxlen) {
|
||||
error("bad write");
|
||||
}
|
||||
if ((out_idx += local_written_size) == BUFFER_SIZE) {
|
||||
out_idx = 0;
|
||||
}
|
||||
if (local_written_size > maxlen) { error("bad write"); }
|
||||
if ((out_idx += local_written_size) == BUFFER_SIZE) { out_idx = 0; }
|
||||
yield();
|
||||
|
||||
DEBUG(logger->printf("----------\n"));
|
||||
|
||||
if (Serial.hasOverrun()) {
|
||||
logger->printf("rx overrun!\n");
|
||||
}
|
||||
if (Serial.hasRxError()) {
|
||||
logger->printf("rx error!\n");
|
||||
}
|
||||
if (Serial.hasOverrun()) { logger->printf("rx overrun!\n"); }
|
||||
if (Serial.hasRxError()) { logger->printf("rx error!\n"); }
|
||||
|
||||
if (reading) {
|
||||
// receive data
|
||||
maxlen = Serial.available() + testReadBytesTimeout;
|
||||
if (maxlen > maxavail) {
|
||||
maxavail = maxlen;
|
||||
}
|
||||
if (maxlen > maxavail) { maxavail = maxlen; }
|
||||
// check space in temp receive buffer
|
||||
if (maxlen > BUFFER_SIZE - in_idx) {
|
||||
maxlen = BUFFER_SIZE - in_idx;
|
||||
}
|
||||
if (maxlen > BUFFER_SIZE - in_idx) { maxlen = BUFFER_SIZE - in_idx; }
|
||||
DEBUG(logger->printf("(ar%i/r%i", Serial.available(), maxlen));
|
||||
local_receive_size = Serial.readBytes(temp, maxlen);
|
||||
DEBUG(logger->printf(":r%i/ar%i)\n", local_receive_size, Serial.available()));
|
||||
if (local_receive_size > maxlen) {
|
||||
error("bad read");
|
||||
}
|
||||
if (local_receive_size > maxlen) { error("bad read"); }
|
||||
if (local_receive_size) {
|
||||
if (memcmp(buf + in_idx, temp, local_receive_size) != 0) {
|
||||
error("fail");
|
||||
}
|
||||
if ((in_idx += local_receive_size) == BUFFER_SIZE) {
|
||||
in_idx = 0;
|
||||
}
|
||||
if (memcmp(buf + in_idx, temp, local_receive_size) != 0) { error("fail"); }
|
||||
if ((in_idx += local_receive_size) == BUFFER_SIZE) { in_idx = 0; }
|
||||
in_total += local_receive_size;
|
||||
}
|
||||
DEBUG(logger->printf("r(%d) ok\n", local_receive_size));
|
||||
@ -166,21 +129,18 @@ void loop() {
|
||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||
size_for_led = 0;
|
||||
|
||||
if (in_prev == in_total) {
|
||||
error("receiving nothing?\n");
|
||||
}
|
||||
if (in_prev == in_total) { error("receiving nothing?\n"); }
|
||||
|
||||
unsigned long now_ms = millis();
|
||||
int bwkbps_avg = ((((uint64_t)in_total) * 8000) / (now_ms - start_ms)) >> 10;
|
||||
int bwkbps_now = (((in_total - in_prev) * 8000) / (now_ms - last_ms)) >> 10 ;
|
||||
int bwkbps_now = (((in_total - in_prev) * 8000) / (now_ms - last_ms)) >> 10;
|
||||
logger->printf("bwavg=%d bwnow=%d kbps maxavail=%i\n", bwkbps_avg, bwkbps_now, maxavail);
|
||||
|
||||
in_prev = in_total;
|
||||
timeout = (last_ms = now_ms) + TIMEOUT;
|
||||
}
|
||||
|
||||
if (logger->available())
|
||||
switch (logger->read()) {
|
||||
if (logger->available()) switch (logger->read()) {
|
||||
case 's':
|
||||
logger->println("now stopping reading, keeping writing");
|
||||
reading = false;
|
||||
|
@ -5,16 +5,15 @@
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
pinMode(LED_BUILTIN, OUTPUT); // blinkie & sigma-delta mix
|
||||
pinMode(LED_BUILTIN, OUTPUT); // blinkie & sigma-delta mix
|
||||
uint32_t reqFreq = 1000;
|
||||
uint32_t realFreq;
|
||||
|
||||
realFreq = sigmaDeltaSetup(0, reqFreq); // chose a low frequency
|
||||
realFreq = sigmaDeltaSetup(0, reqFreq); // chose a low frequency
|
||||
|
||||
Serial.println();
|
||||
Serial.println("Start Sigma Delta Example\n");
|
||||
Serial.printf("Frequency = %u\n", realFreq);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -36,7 +35,6 @@ void loop() {
|
||||
sigmaDeltaWrite(0, duty);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Serial.println("Detaching builtin led & playing a blinkie\n");
|
||||
|
@ -21,7 +21,7 @@ void checksketch(const char* what, const char* res1, const char* res2) {
|
||||
#endif
|
||||
|
||||
void testStringPtrProgmem() {
|
||||
static const char inProgmem [] PROGMEM = "I am in progmem";
|
||||
static const char inProgmem[] PROGMEM = "I am in progmem";
|
||||
auto inProgmem2 = F("I am too in progmem");
|
||||
|
||||
int heap = (int)ESP.getFreeHeap();
|
||||
@ -110,7 +110,7 @@ void testStreamString() {
|
||||
result.clear();
|
||||
S2Stream input(inputString);
|
||||
// reading stream will consume the string
|
||||
input.setConsume(); // can be omitted, this is the default
|
||||
input.setConsume(); // can be omitted, this is the default
|
||||
|
||||
input.sendSize(result, 1);
|
||||
input.sendSize(result, 2);
|
||||
@ -181,8 +181,7 @@ void setup() {
|
||||
|
||||
testStreamString();
|
||||
|
||||
Serial.printf("sizeof: String:%d Stream:%d StreamString:%d SStream:%d\n",
|
||||
(int)sizeof(String), (int)sizeof(Stream), (int)sizeof(StreamString), (int)sizeof(S2Stream));
|
||||
Serial.printf("sizeof: String:%d Stream:%d StreamString:%d SStream:%d\n", (int)sizeof(String), (int)sizeof(Stream), (int)sizeof(StreamString), (int)sizeof(S2Stream));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -28,60 +28,19 @@ Stream& ehConsolePort(Serial);
|
||||
// UNLESS: You swap the TX pin using the alternate pinout.
|
||||
const uint8_t LED_PIN = 1;
|
||||
|
||||
const char * const RST_REASONS[] = {
|
||||
"REASON_DEFAULT_RST",
|
||||
"REASON_WDT_RST",
|
||||
"REASON_EXCEPTION_RST",
|
||||
"REASON_SOFT_WDT_RST",
|
||||
"REASON_SOFT_RESTART",
|
||||
"REASON_DEEP_SLEEP_AWAKE",
|
||||
"REASON_EXT_SYS_RST"
|
||||
};
|
||||
const char* const RST_REASONS[] = { "REASON_DEFAULT_RST", "REASON_WDT_RST", "REASON_EXCEPTION_RST", "REASON_SOFT_WDT_RST", "REASON_SOFT_RESTART", "REASON_DEEP_SLEEP_AWAKE", "REASON_EXT_SYS_RST" };
|
||||
|
||||
const char * const FLASH_SIZE_MAP_NAMES[] = {
|
||||
"FLASH_SIZE_4M_MAP_256_256",
|
||||
"FLASH_SIZE_2M",
|
||||
"FLASH_SIZE_8M_MAP_512_512",
|
||||
"FLASH_SIZE_16M_MAP_512_512",
|
||||
"FLASH_SIZE_32M_MAP_512_512",
|
||||
"FLASH_SIZE_16M_MAP_1024_1024",
|
||||
"FLASH_SIZE_32M_MAP_1024_1024"
|
||||
};
|
||||
const char* const FLASH_SIZE_MAP_NAMES[] = { "FLASH_SIZE_4M_MAP_256_256", "FLASH_SIZE_2M", "FLASH_SIZE_8M_MAP_512_512", "FLASH_SIZE_16M_MAP_512_512", "FLASH_SIZE_32M_MAP_512_512", "FLASH_SIZE_16M_MAP_1024_1024", "FLASH_SIZE_32M_MAP_1024_1024" };
|
||||
|
||||
const char * const OP_MODE_NAMES[] {
|
||||
"NULL_MODE",
|
||||
"STATION_MODE",
|
||||
"SOFTAP_MODE",
|
||||
"STATIONAP_MODE"
|
||||
};
|
||||
const char* const OP_MODE_NAMES[]{ "NULL_MODE", "STATION_MODE", "SOFTAP_MODE", "STATIONAP_MODE" };
|
||||
|
||||
const char * const AUTH_MODE_NAMES[] {
|
||||
"AUTH_OPEN",
|
||||
"AUTH_WEP",
|
||||
"AUTH_WPA_PSK",
|
||||
"AUTH_WPA2_PSK",
|
||||
"AUTH_WPA_WPA2_PSK",
|
||||
"AUTH_MAX"
|
||||
};
|
||||
const char* const AUTH_MODE_NAMES[]{ "AUTH_OPEN", "AUTH_WEP", "AUTH_WPA_PSK", "AUTH_WPA2_PSK", "AUTH_WPA_WPA2_PSK", "AUTH_MAX" };
|
||||
|
||||
const char * const PHY_MODE_NAMES[] {
|
||||
"",
|
||||
"PHY_MODE_11B",
|
||||
"PHY_MODE_11G",
|
||||
"PHY_MODE_11N"
|
||||
};
|
||||
const char* const PHY_MODE_NAMES[]{ "", "PHY_MODE_11B", "PHY_MODE_11G", "PHY_MODE_11N" };
|
||||
|
||||
const char * const EVENT_NAMES[] {
|
||||
"EVENT_STAMODE_CONNECTED",
|
||||
"EVENT_STAMODE_DISCONNECTED",
|
||||
"EVENT_STAMODE_AUTHMODE_CHANGE",
|
||||
"EVENT_STAMODE_GOT_IP",
|
||||
"EVENT_SOFTAPMODE_STACONNECTED",
|
||||
"EVENT_SOFTAPMODE_STADISCONNECTED",
|
||||
"EVENT_MAX"
|
||||
};
|
||||
const char* const EVENT_NAMES[]{ "EVENT_STAMODE_CONNECTED", "EVENT_STAMODE_DISCONNECTED", "EVENT_STAMODE_AUTHMODE_CHANGE", "EVENT_STAMODE_GOT_IP", "EVENT_SOFTAPMODE_STACONNECTED", "EVENT_SOFTAPMODE_STADISCONNECTED", "EVENT_MAX" };
|
||||
|
||||
const char * const EVENT_REASONS[] {
|
||||
const char* const EVENT_REASONS[]{
|
||||
"",
|
||||
"REASON_UNSPECIFIED",
|
||||
"REASON_AUTH_EXPIRE",
|
||||
@ -108,27 +67,21 @@ const char * const EVENT_REASONS[] {
|
||||
"REASON_CIPHER_SUITE_REJECTED",
|
||||
};
|
||||
|
||||
const char * const EVENT_REASONS_200[] {
|
||||
"REASON_BEACON_TIMEOUT",
|
||||
"REASON_NO_AP_FOUND"
|
||||
};
|
||||
const char* const EVENT_REASONS_200[]{ "REASON_BEACON_TIMEOUT", "REASON_NO_AP_FOUND" };
|
||||
|
||||
void wifi_event_handler_cb(System_Event_t * event) {
|
||||
void wifi_event_handler_cb(System_Event_t* event) {
|
||||
ehConsolePort.print(EVENT_NAMES[event->event]);
|
||||
ehConsolePort.print(" (");
|
||||
|
||||
switch (event->event) {
|
||||
case EVENT_STAMODE_CONNECTED:
|
||||
break;
|
||||
case EVENT_STAMODE_DISCONNECTED:
|
||||
break;
|
||||
case EVENT_STAMODE_AUTHMODE_CHANGE:
|
||||
break;
|
||||
case EVENT_STAMODE_GOT_IP:
|
||||
break;
|
||||
case EVENT_STAMODE_CONNECTED: break;
|
||||
case EVENT_STAMODE_DISCONNECTED: break;
|
||||
case EVENT_STAMODE_AUTHMODE_CHANGE: break;
|
||||
case EVENT_STAMODE_GOT_IP: break;
|
||||
case EVENT_SOFTAPMODE_STACONNECTED:
|
||||
case EVENT_SOFTAPMODE_STADISCONNECTED: {
|
||||
char mac[32] = {0};
|
||||
case EVENT_SOFTAPMODE_STADISCONNECTED:
|
||||
{
|
||||
char mac[32] = { 0 };
|
||||
snprintf(mac, 32, MACSTR ", aid: %d", MAC2STR(event->event_info.sta_connected.mac), event->event_info.sta_connected.aid);
|
||||
|
||||
ehConsolePort.print(mac);
|
||||
@ -139,16 +92,16 @@ void wifi_event_handler_cb(System_Event_t * event) {
|
||||
ehConsolePort.println(")");
|
||||
}
|
||||
|
||||
void print_softap_config(Stream & consolePort, softap_config const& config) {
|
||||
void print_softap_config(Stream& consolePort, softap_config const& config) {
|
||||
consolePort.println();
|
||||
consolePort.println(F("SoftAP Configuration"));
|
||||
consolePort.println(F("--------------------"));
|
||||
|
||||
consolePort.print(F("ssid: "));
|
||||
consolePort.println((char *) config.ssid);
|
||||
consolePort.println((char*)config.ssid);
|
||||
|
||||
consolePort.print(F("password: "));
|
||||
consolePort.println((char *) config.password);
|
||||
consolePort.println((char*)config.password);
|
||||
|
||||
consolePort.print(F("ssid_len: "));
|
||||
consolePort.println(config.ssid_len);
|
||||
@ -173,8 +126,8 @@ void print_softap_config(Stream & consolePort, softap_config const& config) {
|
||||
consolePort.println();
|
||||
}
|
||||
|
||||
void print_system_info(Stream & consolePort) {
|
||||
const rst_info * resetInfo = system_get_rst_info();
|
||||
void print_system_info(Stream& consolePort) {
|
||||
const rst_info* resetInfo = system_get_rst_info();
|
||||
consolePort.print(F("system_get_rst_info() reset reason: "));
|
||||
consolePort.println(RST_REASONS[resetInfo->reason]);
|
||||
|
||||
@ -211,7 +164,7 @@ void print_system_info(Stream & consolePort) {
|
||||
consolePort.println(FLASH_SIZE_MAP_NAMES[system_get_flash_size_map()]);
|
||||
}
|
||||
|
||||
void print_wifi_general(Stream & consolePort) {
|
||||
void print_wifi_general(Stream& consolePort) {
|
||||
consolePort.print(F("wifi_get_channel(): "));
|
||||
consolePort.println(wifi_get_channel());
|
||||
|
||||
@ -219,8 +172,8 @@ void print_wifi_general(Stream & consolePort) {
|
||||
consolePort.println(PHY_MODE_NAMES[wifi_get_phy_mode()]);
|
||||
}
|
||||
|
||||
void secure_softap_config(softap_config * config, const char * ssid, const char * password) {
|
||||
size_t ssidLen = strlen(ssid) < sizeof(config->ssid) ? strlen(ssid) : sizeof(config->ssid);
|
||||
void secure_softap_config(softap_config* config, const char* ssid, const char* password) {
|
||||
size_t ssidLen = strlen(ssid) < sizeof(config->ssid) ? strlen(ssid) : sizeof(config->ssid);
|
||||
size_t passwordLen = strlen(password) < sizeof(config->password) ? strlen(password) : sizeof(config->password);
|
||||
|
||||
memset(config->ssid, 0, sizeof(config->ssid));
|
||||
@ -230,7 +183,7 @@ void secure_softap_config(softap_config * config, const char * ssid, const char
|
||||
memcpy(config->password, password, passwordLen);
|
||||
|
||||
config->ssid_len = ssidLen;
|
||||
config->channel = 1;
|
||||
config->channel = 1;
|
||||
config->authmode = AUTH_WPA2_PSK;
|
||||
// config->ssid_hidden = 1;
|
||||
config->max_connection = 4;
|
||||
@ -293,4 +246,3 @@ void loop() {
|
||||
Serial.println(system_get_time());
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
@ -59,11 +59,10 @@ constexpr char slipFrameMarker = '\xC0';
|
||||
// <0xC0><cmd><payload length><32 bit cksum><payload data ...><0xC0>
|
||||
// Slip packet for ESP_SYNC, minus the frame markers ('\xC0') captured from
|
||||
// esptool using the `--trace` option.
|
||||
const char syncPkt[] PROGMEM =
|
||||
"\x00\x08\x24\x00\x00\x00\x00\x00\x07\x07\x12\x20"
|
||||
"UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU";
|
||||
const char syncPkt[] PROGMEM = "\x00\x08\x24\x00\x00\x00\x00\x00\x07\x07\x12\x20"
|
||||
"UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU";
|
||||
|
||||
constexpr size_t syncPktSz = sizeof(syncPkt) - 1; // Don't compare zero terminator char
|
||||
constexpr size_t syncPktSz = sizeof(syncPkt) - 1; // Don't compare zero terminator char
|
||||
|
||||
//
|
||||
// Use the discovery of an ESP_SYNC packet, to trigger calling UART Download
|
||||
@ -71,9 +70,7 @@ constexpr size_t syncPktSz = sizeof(syncPkt) - 1; // Don't compare zero terminat
|
||||
// the slipFrameMarker.
|
||||
//
|
||||
void proxyEspSync() {
|
||||
if (!uartDownloadEnable) {
|
||||
return;
|
||||
}
|
||||
if (!uartDownloadEnable) { return; }
|
||||
|
||||
byte buf[pktBufSz];
|
||||
|
||||
@ -90,7 +87,7 @@ void proxyEspSync() {
|
||||
}
|
||||
|
||||
// Assume RX FIFO data is garbled and flush all RX data.
|
||||
while (0 <= Serial.read()) {} // Clear FIFO
|
||||
while (0 <= Serial.read()) {} // Clear FIFO
|
||||
|
||||
// If your Serial requirements need a specific timeout value, you would
|
||||
// restore those here.
|
||||
@ -111,8 +108,7 @@ void setup() {
|
||||
// stub, then both devices shift their UART speeds to the command line value.
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println(F(
|
||||
"\r\n\r\n"
|
||||
Serial.println(F("\r\n\r\n"
|
||||
"Boot UART Download Demo - initialization started.\r\n"
|
||||
"\r\n"
|
||||
"For a quick test to see the UART Download work,\r\n"
|
||||
@ -143,20 +139,17 @@ void cmdLoop(Print& oStream, int key) {
|
||||
ESP.restart();
|
||||
break;
|
||||
|
||||
// ...
|
||||
// ...
|
||||
|
||||
case '?':
|
||||
oStream.println(F("\r\nHot key help:"));
|
||||
if (!uartDownloadEnable) {
|
||||
oStream.println(F(" e - Enable monitor for detecting ESP_SYNC from esptool.py"));
|
||||
}
|
||||
if (!uartDownloadEnable) { oStream.println(F(" e - Enable monitor for detecting ESP_SYNC from esptool.py")); }
|
||||
oStream.println(F(" D - Boot into UART download mode"));
|
||||
oStream.println(F(" R - Restart"));
|
||||
oStream.println(F(" ? - This help message\r\n"));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
oStream.println();
|
||||
|
@ -12,11 +12,11 @@
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
const char * SSID = STASSID;
|
||||
const char * PSK = STAPSK;
|
||||
const char* SSID = STASSID;
|
||||
const char* PSK = STAPSK;
|
||||
|
||||
IPAddress staticip(192, 168, 1, 123);
|
||||
IPAddress gateway(192, 168, 1, 254);
|
||||
@ -35,16 +35,14 @@ void setup() {
|
||||
}
|
||||
Serial.println();
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.print(
|
||||
"WL_IDLE_STATUS = 0\n"
|
||||
"WL_NO_SSID_AVAIL = 1\n"
|
||||
"WL_SCAN_COMPLETED = 2\n"
|
||||
"WL_CONNECTED = 3\n"
|
||||
"WL_CONNECT_FAILED = 4\n"
|
||||
"WL_CONNECTION_LOST = 5\n"
|
||||
"WL_WRONG_PASSWORD = 6\n"
|
||||
"WL_DISCONNECTED = 7\n"
|
||||
);
|
||||
Serial.print("WL_IDLE_STATUS = 0\n"
|
||||
"WL_NO_SSID_AVAIL = 1\n"
|
||||
"WL_SCAN_COMPLETED = 2\n"
|
||||
"WL_CONNECTED = 3\n"
|
||||
"WL_CONNECT_FAILED = 4\n"
|
||||
"WL_CONNECTION_LOST = 5\n"
|
||||
"WL_WRONG_PASSWORD = 6\n"
|
||||
"WL_DISCONNECTED = 7\n");
|
||||
}
|
||||
|
||||
void WiFiOn() {
|
||||
@ -65,9 +63,16 @@ void WiFiOff() {
|
||||
void loop() {
|
||||
#define TEST(name, var, varinit, func) \
|
||||
static decltype(func) var = (varinit); \
|
||||
if ((var) != (func)) { var = (func); Serial.printf("**** %s: ", name); Serial.println(var); }
|
||||
if ((var) != (func)) { \
|
||||
var = (func); \
|
||||
Serial.printf("**** %s: ", name); \
|
||||
Serial.println(var); \
|
||||
}
|
||||
|
||||
#define DO(x...) Serial.println(F( #x )); x; break
|
||||
#define DO(x...) \
|
||||
Serial.println(F(#x)); \
|
||||
x; \
|
||||
break
|
||||
|
||||
TEST("Free Heap", freeHeap, 0, ESP.getFreeHeap());
|
||||
TEST("WiFiStatus", status, WL_IDLE_STATUS, WiFi.status());
|
||||
@ -91,7 +96,7 @@ void loop() {
|
||||
case 'n': DO(WiFi.setSleepMode(WIFI_NONE_SLEEP));
|
||||
case 'l': DO(WiFi.setSleepMode(WIFI_LIGHT_SLEEP));
|
||||
case 'm': DO(WiFi.setSleepMode(WIFI_MODEM_SLEEP));
|
||||
case 'S': DO(WiFi.config(staticip, gateway, subnet)); // use static address
|
||||
case 's': DO(WiFi.config(0u, 0u, 0u)); // back to dhcp client
|
||||
case 'S': DO(WiFi.config(staticip, gateway, subnet)); // use static address
|
||||
case 's': DO(WiFi.config(0u, 0u, 0u)); // back to dhcp client
|
||||
}
|
||||
}
|
||||
|
@ -21,51 +21,39 @@
|
||||
|
||||
#pragma GCC push_options
|
||||
// reference
|
||||
#pragma GCC optimize("O0") // We expect -O0 to generate the correct results
|
||||
__attribute__((noinline))
|
||||
void aliasTestReference(uint16_t *x) {
|
||||
#pragma GCC optimize("O0") // We expect -O0 to generate the correct results
|
||||
__attribute__((noinline)) void aliasTestReference(uint16_t *x) {
|
||||
// Without adhearance to strict-aliasing, this sequence of code would fail
|
||||
// when optimized by GCC Version 10.3
|
||||
size_t len = 3;
|
||||
for (size_t u = 0; u < len; u++) {
|
||||
uint16_t x1 = mmu_get_uint16(&x[0]);
|
||||
for (size_t v = 0; v < len; v++) {
|
||||
x[v] = mmu_get_uint16(&x[v]) + x1;
|
||||
}
|
||||
for (size_t v = 0; v < len; v++) { x[v] = mmu_get_uint16(&x[v]) + x1; }
|
||||
}
|
||||
}
|
||||
// Tests
|
||||
#pragma GCC optimize("Os")
|
||||
__attribute__((noinline))
|
||||
void aliasTestOs(uint16_t *x) {
|
||||
__attribute__((noinline)) void aliasTestOs(uint16_t *x) {
|
||||
size_t len = 3;
|
||||
for (size_t u = 0; u < len; u++) {
|
||||
uint16_t x1 = mmu_get_uint16(&x[0]);
|
||||
for (size_t v = 0; v < len; v++) {
|
||||
x[v] = mmu_get_uint16(&x[v]) + x1;
|
||||
}
|
||||
for (size_t v = 0; v < len; v++) { x[v] = mmu_get_uint16(&x[v]) + x1; }
|
||||
}
|
||||
}
|
||||
#pragma GCC optimize("O2")
|
||||
__attribute__((noinline))
|
||||
void aliasTestO2(uint16_t *x) {
|
||||
__attribute__((noinline)) void aliasTestO2(uint16_t *x) {
|
||||
size_t len = 3;
|
||||
for (size_t u = 0; u < len; u++) {
|
||||
uint16_t x1 = mmu_get_uint16(&x[0]);
|
||||
for (size_t v = 0; v < len; v++) {
|
||||
x[v] = mmu_get_uint16(&x[v]) + x1;
|
||||
}
|
||||
for (size_t v = 0; v < len; v++) { x[v] = mmu_get_uint16(&x[v]) + x1; }
|
||||
}
|
||||
}
|
||||
#pragma GCC optimize("O3")
|
||||
__attribute__((noinline))
|
||||
void aliasTestO3(uint16_t *x) {
|
||||
__attribute__((noinline)) void aliasTestO3(uint16_t *x) {
|
||||
size_t len = 3;
|
||||
for (size_t u = 0; u < len; u++) {
|
||||
uint16_t x1 = mmu_get_uint16(&x[0]);
|
||||
for (size_t v = 0; v < len; v++) {
|
||||
x[v] = mmu_get_uint16(&x[v]) + x1;
|
||||
}
|
||||
for (size_t v = 0; v < len; v++) { x[v] = mmu_get_uint16(&x[v]) + x1; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,8 +61,7 @@ void aliasTestO3(uint16_t *x) {
|
||||
// 8-bit access will take longer as it will be processed thought
|
||||
// the exception handler. For this case the -O0 version will appear faster.
|
||||
#pragma GCC optimize("O0")
|
||||
__attribute__((noinline)) IRAM_ATTR
|
||||
uint32_t timedRead_Reference(uint8_t *res) {
|
||||
__attribute__((noinline)) IRAM_ATTR uint32_t timedRead_Reference(uint8_t *res) {
|
||||
// This test case was verified with GCC 10.3
|
||||
// There is a code case that can result in 32-bit wide IRAM load from memory
|
||||
// being optimized down to an 8-bit memory access. In this test case we need
|
||||
@ -88,24 +75,21 @@ uint32_t timedRead_Reference(uint8_t *res) {
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
#pragma GCC optimize("Os")
|
||||
__attribute__((noinline)) IRAM_ATTR
|
||||
uint32_t timedRead_Os(uint8_t *res) {
|
||||
__attribute__((noinline)) IRAM_ATTR uint32_t timedRead_Os(uint8_t *res) {
|
||||
const uint8_t *x = (const uint8_t *)0x40100003ul;
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
*res = mmu_get_uint8(x);
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
#pragma GCC optimize("O2")
|
||||
__attribute__((noinline)) IRAM_ATTR
|
||||
uint32_t timedRead_O2(uint8_t *res) {
|
||||
__attribute__((noinline)) IRAM_ATTR uint32_t timedRead_O2(uint8_t *res) {
|
||||
const uint8_t *x = (const uint8_t *)0x40100003ul;
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
*res = mmu_get_uint8(x);
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
#pragma GCC optimize("O3")
|
||||
__attribute__((noinline)) IRAM_ATTR
|
||||
uint32_t timedRead_O3(uint8_t *res) {
|
||||
__attribute__((noinline)) IRAM_ATTR uint32_t timedRead_O3(uint8_t *res) {
|
||||
const uint8_t *x = (const uint8_t *)0x40100003ul;
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
*res = mmu_get_uint8(x);
|
||||
@ -155,25 +139,21 @@ bool test4_32bit_loads() {
|
||||
|
||||
void printPunFail(uint16_t *ref, uint16_t *x, size_t sz) {
|
||||
Serial.printf(" Expected:");
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
Serial.printf(" %3u", ref[i]);
|
||||
}
|
||||
for (size_t i = 0; i < sz; i++) { Serial.printf(" %3u", ref[i]); }
|
||||
Serial.printf("\r\n Got: ");
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
Serial.printf(" %3u", x[i]);
|
||||
}
|
||||
for (size_t i = 0; i < sz; i++) { Serial.printf(" %3u", x[i]); }
|
||||
Serial.printf("\r\n");
|
||||
}
|
||||
|
||||
bool testPunning() {
|
||||
bool result = true;
|
||||
// Get reference result for verifing test
|
||||
alignas(uint32_t) uint16_t x_ref[] = {1, 2, 3, 0};
|
||||
alignas(uint32_t) uint16_t x_ref[] = { 1, 2, 3, 0 };
|
||||
aliasTestReference(x_ref); // -O0
|
||||
Serial.printf("mmu_get_uint16() strict-aliasing tests with different optimizations:\r\n");
|
||||
|
||||
{
|
||||
alignas(alignof(uint32_t)) uint16_t x[] = {1, 2, 3, 0};
|
||||
alignas(alignof(uint32_t)) uint16_t x[] = { 1, 2, 3, 0 };
|
||||
aliasTestOs(x);
|
||||
Serial.printf(" Option -Os ");
|
||||
if (0 == memcmp(x_ref, x, sizeof(x_ref))) {
|
||||
@ -185,7 +165,7 @@ bool testPunning() {
|
||||
}
|
||||
}
|
||||
{
|
||||
alignas(alignof(uint32_t)) uint16_t x[] = {1, 2, 3, 0};
|
||||
alignas(alignof(uint32_t)) uint16_t x[] = { 1, 2, 3, 0 };
|
||||
aliasTestO2(x);
|
||||
Serial.printf(" Option -O2 ");
|
||||
if (0 == memcmp(x_ref, x, sizeof(x_ref))) {
|
||||
@ -197,7 +177,7 @@ bool testPunning() {
|
||||
}
|
||||
}
|
||||
{
|
||||
alignas(alignof(uint32_t)) uint16_t x[] = {1, 2, 3, 0};
|
||||
alignas(alignof(uint32_t)) uint16_t x[] = { 1, 2, 3, 0 };
|
||||
aliasTestO3(x);
|
||||
Serial.printf(" Option -O3 ");
|
||||
if (0 == memcmp(x_ref, x, sizeof(x_ref))) {
|
||||
@ -215,9 +195,7 @@ bool testPunning() {
|
||||
uint32_t cyclesToRead_nKx32(int n, unsigned int *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
sum += *(x++);
|
||||
}
|
||||
for (int i = 0; i < n * 1024; i++) { sum += *(x++); }
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
@ -235,9 +213,7 @@ uint32_t cyclesToWrite_nKx32(int n, unsigned int *x) {
|
||||
uint32_t cyclesToRead_nKx16(int n, unsigned short *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
sum += *(x++);
|
||||
}
|
||||
for (int i = 0; i < n * 1024; i++) { sum += *(x++); }
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
@ -255,9 +231,7 @@ uint32_t cyclesToWrite_nKx16(int n, unsigned short *x) {
|
||||
uint32_t cyclesToRead_nKxs16(int n, short *x, int32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
int32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
sum += *(x++);
|
||||
}
|
||||
for (int i = 0; i < n * 1024; i++) { sum += *(x++); }
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
@ -272,17 +246,15 @@ uint32_t cyclesToWrite_nKxs16(int n, short *x) {
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
|
||||
uint32_t cyclesToRead_nKx8(int n, unsigned char*x, uint32_t *res) {
|
||||
uint32_t cyclesToRead_nKx8(int n, unsigned char *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
sum += *(x++);
|
||||
}
|
||||
for (int i = 0; i < n * 1024; i++) { sum += *(x++); }
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
|
||||
uint32_t cyclesToWrite_nKx8(int n, unsigned char*x) {
|
||||
uint32_t cyclesToWrite_nKx8(int n, unsigned char *x) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
@ -297,7 +269,7 @@ uint32_t cyclesToRead_nKx16_viaInline(int n, unsigned short *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
sum += mmu_get_uint16(x++); //*(x++);
|
||||
sum += mmu_get_uint16(x++); //*(x++);
|
||||
}
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
@ -318,7 +290,7 @@ uint32_t cyclesToRead_nKxs16_viaInline(int n, short *x, int32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
int32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
sum += mmu_get_int16(x++); //*(x++);
|
||||
sum += mmu_get_int16(x++); //*(x++);
|
||||
}
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
@ -335,17 +307,17 @@ uint32_t cyclesToWrite_nKxs16_viaInline(int n, short *x) {
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
|
||||
uint32_t cyclesToRead_nKx8_viaInline(int n, unsigned char*x, uint32_t *res) {
|
||||
uint32_t cyclesToRead_nKx8_viaInline(int n, unsigned char *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
sum += mmu_get_uint8(x++); //*(x++);
|
||||
sum += mmu_get_uint8(x++); //*(x++);
|
||||
}
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
|
||||
uint32_t cyclesToWrite_nKx8_viaInline(int n, unsigned char*x) {
|
||||
uint32_t cyclesToWrite_nKx8_viaInline(int n, unsigned char *x) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < n * 1024; i++) {
|
||||
@ -363,19 +335,20 @@ bool perfTest_nK(int nK, uint32_t *mem, uint32_t *imem) {
|
||||
bool success = true;
|
||||
int sres, verify_sres;
|
||||
|
||||
Serial.printf("\r\nPerformance numbers for 16 bit access - using inline macros or exception handling for IRAM.\r\n");;
|
||||
t = cyclesToWrite_nKx16(nK, (uint16_t*)mem);
|
||||
Serial.printf("\r\nPerformance numbers for 16 bit access - using inline macros or exception handling for IRAM.\r\n");
|
||||
;
|
||||
t = cyclesToWrite_nKx16(nK, (uint16_t *)mem);
|
||||
Serial.printf("DRAM Memory Write: %7d cycles for %dK by uint16, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKx16(nK, (uint16_t*)mem, &verify_res);
|
||||
t = cyclesToRead_nKx16(nK, (uint16_t *)mem, &verify_res);
|
||||
Serial.printf("DRAM Memory Read: %7d cycles for %dK by uint16, %3d AVG cycles/transfer (sum %08x)\r\n", t, nK, t / (nK * 1024), verify_res);
|
||||
t = cyclesToWrite_nKxs16(nK, (int16_t*)mem);
|
||||
t = cyclesToWrite_nKxs16(nK, (int16_t *)mem);
|
||||
Serial.printf("DRAM Memory Write: %7d cycles for %dK by int16, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKxs16(nK, (int16_t*)mem, &verify_sres);
|
||||
t = cyclesToRead_nKxs16(nK, (int16_t *)mem, &verify_sres);
|
||||
Serial.printf("DRAM Memory Read: %7d cycles for %dK by int16, %3d AVG cycles/transfer (sum %08x)\r\n", t, nK, t / (nK * 1024), verify_sres);
|
||||
|
||||
t = cyclesToWrite_nKx16_viaInline(nK, (uint16_t*)imem);
|
||||
t = cyclesToWrite_nKx16_viaInline(nK, (uint16_t *)imem);
|
||||
Serial.printf("IRAM Memory Write Inline: %7d cycles for %dK by uint16, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKx16_viaInline(nK, (uint16_t*)imem, &res);
|
||||
t = cyclesToRead_nKx16_viaInline(nK, (uint16_t *)imem, &res);
|
||||
Serial.printf("IRAM Memory Read Inline: %7d cycles for %dK by uint16, %3d AVG cycles/transfer (sum %08x) ", t, nK, t / (nK * 1024), res);
|
||||
if (res == verify_res) {
|
||||
Serial.printf("- passed\r\n");
|
||||
@ -384,9 +357,9 @@ bool perfTest_nK(int nK, uint32_t *mem, uint32_t *imem) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
t = cyclesToWrite_nKxs16_viaInline(nK, (int16_t*)imem);
|
||||
t = cyclesToWrite_nKxs16_viaInline(nK, (int16_t *)imem);
|
||||
Serial.printf("IRAM Memory Write Inline: %7d cycles for %dK by int16, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKxs16_viaInline(nK, (int16_t*)imem, &sres);
|
||||
t = cyclesToRead_nKxs16_viaInline(nK, (int16_t *)imem, &sres);
|
||||
Serial.printf("IRAM Memory Read Inline: %7d cycles for %dK by int16, %3d AVG cycles/transfer (sum %08x) ", t, nK, t / (nK * 1024), sres);
|
||||
if (sres == verify_sres) {
|
||||
Serial.printf("- passed\r\n");
|
||||
@ -395,9 +368,9 @@ bool perfTest_nK(int nK, uint32_t *mem, uint32_t *imem) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
t = cyclesToWrite_nKx16(nK, (uint16_t*)imem);
|
||||
t = cyclesToWrite_nKx16(nK, (uint16_t *)imem);
|
||||
Serial.printf("IRAM Memory Write: %7d cycles for %dK by uint16, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKx16(nK, (uint16_t*)imem, &res);
|
||||
t = cyclesToRead_nKx16(nK, (uint16_t *)imem, &res);
|
||||
Serial.printf("IRAM Memory Read: %7d cycles for %dK by uint16, %3d AVG cycles/transfer (sum %08x) ", t, nK, t / (nK * 1024), res);
|
||||
if (res == verify_res) {
|
||||
Serial.printf("- passed\r\n");
|
||||
@ -405,9 +378,9 @@ bool perfTest_nK(int nK, uint32_t *mem, uint32_t *imem) {
|
||||
Serial.printf("!= (sum %08x ) - failed\r\n", verify_res);
|
||||
success = false;
|
||||
}
|
||||
t = cyclesToWrite_nKxs16(nK, (int16_t*)imem);
|
||||
t = cyclesToWrite_nKxs16(nK, (int16_t *)imem);
|
||||
Serial.printf("IRAM Memory Write: %7d cycles for %dK by int16, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKxs16(nK, (int16_t*)imem, &sres);
|
||||
t = cyclesToRead_nKxs16(nK, (int16_t *)imem, &sres);
|
||||
Serial.printf("IRAM Memory Read: %7d cycles for %dK by int16, %3d AVG cycles/transfer (sum %08x) ", t, nK, t / (nK * 1024), sres);
|
||||
if (sres == verify_sres) {
|
||||
Serial.printf("- passed\r\n");
|
||||
@ -416,15 +389,16 @@ bool perfTest_nK(int nK, uint32_t *mem, uint32_t *imem) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
Serial.printf("\r\nPerformance numbers for 8 bit access - using inline macros or exception handling for IRAM access.\r\n");;
|
||||
t = cyclesToWrite_nKx8(nK, (uint8_t*)mem);
|
||||
Serial.printf("\r\nPerformance numbers for 8 bit access - using inline macros or exception handling for IRAM access.\r\n");
|
||||
;
|
||||
t = cyclesToWrite_nKx8(nK, (uint8_t *)mem);
|
||||
Serial.printf("DRAM Memory Write: %7d cycles for %dK by uint8, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKx8(nK, (uint8_t*)mem, &verify_res);
|
||||
t = cyclesToRead_nKx8(nK, (uint8_t *)mem, &verify_res);
|
||||
Serial.printf("DRAM Memory Read: %7d cycles for %dK by uint8, %3d AVG cycles/transfer (sum %08x)\r\n", t, nK, t / (nK * 1024), verify_res);
|
||||
|
||||
t = cyclesToWrite_nKx8_viaInline(nK, (uint8_t*)imem);
|
||||
t = cyclesToWrite_nKx8_viaInline(nK, (uint8_t *)imem);
|
||||
Serial.printf("IRAM Memory Write Inline: %7d cycles for %dK by uint8, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKx8_viaInline(nK, (uint8_t*)imem, &res);
|
||||
t = cyclesToRead_nKx8_viaInline(nK, (uint8_t *)imem, &res);
|
||||
Serial.printf("IRAM Memory Read Inline: %7d cycles for %dK by uint8, %3d AVG cycles/transfer (sum %08x) ", t, nK, t / (nK * 1024), res);
|
||||
if (res == verify_res) {
|
||||
Serial.printf("- passed\r\n");
|
||||
@ -433,9 +407,9 @@ bool perfTest_nK(int nK, uint32_t *mem, uint32_t *imem) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
t = cyclesToWrite_nKx8(nK, (uint8_t*)imem);
|
||||
t = cyclesToWrite_nKx8(nK, (uint8_t *)imem);
|
||||
Serial.printf("IRAM Memory Write: %7d cycles for %dK by uint8, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKx8(nK, (uint8_t*)imem, &res);
|
||||
t = cyclesToRead_nKx8(nK, (uint8_t *)imem, &res);
|
||||
Serial.printf("IRAM Memory Read: %7d cycles for %dK by uint8, %3d AVG cycles/transfer (sum %08x) ", t, nK, t / (nK * 1024), res);
|
||||
if (res == verify_res) {
|
||||
Serial.printf("- passed\r\n");
|
||||
@ -469,9 +443,7 @@ void setup() {
|
||||
Serial.printf("DRAM free: %6d\r\n", ESP.getFreeHeap());
|
||||
uint32_t *mem = (uint32_t *)malloc(2 * 1024 * sizeof(uint32_t));
|
||||
Serial.printf("DRAM buffer: Address %p, free %d\r\n", mem, ESP.getFreeHeap());
|
||||
if (!mem) {
|
||||
return;
|
||||
}
|
||||
if (!mem) { return; }
|
||||
|
||||
// Now request from the IRAM heap
|
||||
#ifdef USE_SET_IRAM_HEAP
|
||||
@ -495,14 +467,13 @@ void setup() {
|
||||
Serial.printf("IRAM buffer: Address %p, free %d\r\n", imem, ESP.getFreeHeap());
|
||||
}
|
||||
#endif
|
||||
if (!imem) {
|
||||
return;
|
||||
}
|
||||
if (!imem) { return; }
|
||||
|
||||
uint32_t res;
|
||||
uint32_t t;
|
||||
int nK = 1;
|
||||
Serial.printf("\r\nPerformance numbers for 32 bit access - no exception handler or inline macros needed.\r\n");;
|
||||
Serial.printf("\r\nPerformance numbers for 32 bit access - no exception handler or inline macros needed.\r\n");
|
||||
;
|
||||
t = cyclesToWrite_nKx32(nK, mem);
|
||||
Serial.printf("DRAM Memory Write: %7d cycles for %dK by uint32, %3d AVG cycles/transfer\r\n", t, nK, t / (nK * 1024));
|
||||
t = cyclesToRead_nKx32(nK, mem, &res);
|
||||
@ -595,8 +566,7 @@ void setup() {
|
||||
uint32_t hmax;
|
||||
uint8_t hfrag;
|
||||
ESP.getHeapStats(&hfree, &hmax, &hfrag);
|
||||
ETS_PRINTF("ESP.getHeapStats(free: %u, max: %u, frag: %u)\n",
|
||||
hfree, hmax, hfrag);
|
||||
ETS_PRINTF("ESP.getHeapStats(free: %u, max: %u, frag: %u)\n", hfree, hmax, hfrag);
|
||||
if (free_iram > UMM_OVERHEAD_ADJUST) {
|
||||
void *all = malloc(free_iram - UMM_OVERHEAD_ADJUST);
|
||||
ETS_PRINTF("%p = malloc(%u)\n", all, free_iram);
|
||||
@ -611,19 +581,22 @@ void setup() {
|
||||
}
|
||||
}
|
||||
|
||||
void processKey(Print& out, int hotKey) {
|
||||
void processKey(Print &out, int hotKey) {
|
||||
switch (hotKey) {
|
||||
case 'd': {
|
||||
case 'd':
|
||||
{
|
||||
HeapSelectDram ephemeral;
|
||||
umm_info(NULL, true);
|
||||
break;
|
||||
}
|
||||
case 'i': {
|
||||
case 'i':
|
||||
{
|
||||
HeapSelectIram ephemeral;
|
||||
umm_info(NULL, true);
|
||||
break;
|
||||
}
|
||||
case 'h': {
|
||||
case 'h':
|
||||
{
|
||||
{
|
||||
HeapSelectIram ephemeral;
|
||||
Serial.printf(PSTR("IRAM ESP.getFreeHeap: %u\n"), ESP.getFreeHeap());
|
||||
@ -638,10 +611,8 @@ void processKey(Print& out, int hotKey) {
|
||||
out.printf_P(PSTR("Restart, ESP.restart(); ...\r\n"));
|
||||
ESP.restart();
|
||||
break;
|
||||
case '\r':
|
||||
out.println();
|
||||
case '\n':
|
||||
break;
|
||||
case '\r': out.println();
|
||||
case '\n': break;
|
||||
case '?':
|
||||
out.println();
|
||||
out.println(F("Press a key + <enter>"));
|
||||
|
@ -2,9 +2,7 @@
|
||||
uint32_t cyclesToRead1Kx32(unsigned int *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
sum += *(x++);
|
||||
}
|
||||
for (int i = 0; i < 1024; i++) { sum += *(x++); }
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
@ -23,9 +21,7 @@ uint32_t cyclesToWrite1Kx32(unsigned int *x) {
|
||||
uint32_t cyclesToRead1Kx16(unsigned short *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
sum += *(x++);
|
||||
}
|
||||
for (int i = 0; i < 1024; i++) { sum += *(x++); }
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
@ -40,17 +36,15 @@ uint32_t cyclesToWrite1Kx16(unsigned short *x) {
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
|
||||
uint32_t cyclesToRead1Kx8(unsigned char*x, uint32_t *res) {
|
||||
uint32_t cyclesToRead1Kx8(unsigned char *x, uint32_t *res) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
sum += *(x++);
|
||||
}
|
||||
for (int i = 0; i < 1024; i++) { sum += *(x++); }
|
||||
*res = sum;
|
||||
return ESP.getCycleCount() - b;
|
||||
}
|
||||
|
||||
uint32_t cyclesToWrite1Kx8(unsigned char*x) {
|
||||
uint32_t cyclesToWrite1Kx8(unsigned char *x) {
|
||||
uint32_t b = ESP.getCycleCount();
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
@ -88,24 +82,24 @@ void setup() {
|
||||
t = cyclesToRead1Kx32(mem, &res);
|
||||
Serial.printf("Physical Memory Read: %d cycles for 4K (sum %08x)\n", t, res);
|
||||
|
||||
t = cyclesToWrite1Kx16((uint16_t*)vm);
|
||||
t = cyclesToWrite1Kx16((uint16_t *)vm);
|
||||
Serial.printf("Virtual Memory Write: %d cycles for 2K by 16\n", t);
|
||||
t = cyclesToWrite1Kx16((uint16_t*)mem);
|
||||
t = cyclesToWrite1Kx16((uint16_t *)mem);
|
||||
Serial.printf("Physical Memory Write: %d cycles for 2K by 16\n", t);
|
||||
|
||||
t = cyclesToRead1Kx16((uint16_t*)vm, &res);
|
||||
t = cyclesToRead1Kx16((uint16_t *)vm, &res);
|
||||
Serial.printf("Virtual Memory Read: %d cycles for 2K by 16 (sum %08x)\n", t, res);
|
||||
t = cyclesToRead1Kx16((uint16_t*)mem, &res);
|
||||
t = cyclesToRead1Kx16((uint16_t *)mem, &res);
|
||||
Serial.printf("Physical Memory Read: %d cycles for 2K by 16 (sum %08x)\n", t, res);
|
||||
|
||||
t = cyclesToWrite1Kx8((uint8_t*)vm);
|
||||
t = cyclesToWrite1Kx8((uint8_t *)vm);
|
||||
Serial.printf("Virtual Memory Write: %d cycles for 1K by 8\n", t);
|
||||
t = cyclesToWrite1Kx8((uint8_t*)mem);
|
||||
t = cyclesToWrite1Kx8((uint8_t *)mem);
|
||||
Serial.printf("Physical Memory Write: %d cycles for 1K by 8\n", t);
|
||||
|
||||
t = cyclesToRead1Kx8((uint8_t*)vm, &res);
|
||||
t = cyclesToRead1Kx8((uint8_t *)vm, &res);
|
||||
Serial.printf("Virtual Memory Read: %d cycles for 1K by 8 (sum %08x)\n", t, res);
|
||||
t = cyclesToRead1Kx8((uint8_t*)mem, &res);
|
||||
t = cyclesToRead1Kx8((uint8_t *)mem, &res);
|
||||
Serial.printf("Physical Memory Read: %d cycles for 1K by 8 (sum %08x)\n", t, res);
|
||||
|
||||
// Let's use external heap to make a big ole' String
|
||||
@ -133,6 +127,4 @@ void setup() {
|
||||
ESP.resetHeap();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
void loop() {}
|
||||
|
Reference in New Issue
Block a user