Skip to content

Commit 5baed40

Browse files
committed
Merge pull request #8 from esp8266/esp8266
Esp8266
2 parents 8ba054c + 6f05da4 commit 5baed40

File tree

16 files changed

+493
-89
lines changed

16 files changed

+493
-89
lines changed

cores/esp8266/Esp.h

+15-6
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,22 @@ typedef enum {
4545
#define cli() ets_intr_lock() // IRQ Disable
4646
#define sei() ets_intr_unlock() // IRQ Enable
4747

48-
enum WakeMode {
49-
WAKE_RF_DEFAULT = 0, // RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
50-
WAKE_RFCAL = 1, // RF_CAL after deep-sleep wake up, there will be large current.
51-
WAKE_NO_RFCAL = 2, // no RF_CAL after deep-sleep wake up, there will only be small current.
52-
WAKE_RF_DISABLED = 4 // disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
48+
enum RFMode {
49+
RF_DEFAULT = 0, // RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
50+
RF_CAL = 1, // RF_CAL after deep-sleep wake up, there will be large current.
51+
RF_NO_CAL = 2, // no RF_CAL after deep-sleep wake up, there will only be small current.
52+
RF_DISABLED = 4 // disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
5353
};
5454

55+
#define RF_MODE(mode) extern "C" int __get_rf_mode() { return mode; }
56+
57+
// compatibility definitions
58+
#define WakeMode RFMode
59+
#define WAKE_RF_DEFAULT RF_DEFAULT
60+
#define WAKE_RFCAL RF_CAL
61+
#define WAKE_NO_RFCAL RF_NO_CAL
62+
#define WAKE_RF_DISABLED RF_DISABLED
63+
5564
typedef enum {
5665
FM_QIO = 0x00,
5766
FM_QOUT = 0x01,
@@ -72,7 +81,7 @@ class EspClass {
7281
void wdtDisable();
7382
void wdtFeed();
7483

75-
void deepSleep(uint32_t time_us, WakeMode mode = WAKE_RF_DEFAULT);
84+
void deepSleep(uint32_t time_us, RFMode mode = RF_DEFAULT);
7685

7786
void reset();
7887
void restart();

cores/esp8266/abi.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ namespace std {
5858
void __throw_bad_function_call() {
5959
abort();
6060
}
61+
62+
void __throw_length_error(char const*) {
63+
abort();
64+
}
65+
66+
void __throw_bad_alloc() {
67+
abort();
68+
}
6169
}
6270

6371
// TODO: rebuild windows toolchain to make this unnecessary:

cores/esp8266/cont.S

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ cont_resume:
106106

107107
cont_norm:
108108
/* calculate pointer to cont_ctx.struct_start from sp */
109-
l32i a2, a1, 8
109+
l32i a2, a1, 4
110110
/* sp <- cont_ctx.sp_ret */
111111
l32i a1, a2, 4
112112

cores/esp8266/cont.h

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ typedef struct cont_ {
3333
unsigned* sp_yield;
3434

3535
unsigned* stack_end;
36+
unsigned unused1;
37+
unsigned unused2;
3638
unsigned stack_guard1;
3739

3840
unsigned stack[CONT_STACKSIZE / 4];

cores/esp8266/cont_util.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
void cont_init(cont_t* cont) {
2626
cont->stack_guard1 = CONT_STACKGUARD;
2727
cont->stack_guard2 = CONT_STACKGUARD;
28-
cont->stack_end = cont->stack + (sizeof(cont->stack) / 4 - 1);
28+
cont->stack_end = cont->stack + (sizeof(cont->stack) / 4);
2929
cont->struct_start = (unsigned*) cont;
3030
}
3131

cores/esp8266/core_esp8266_main.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void preloop_update_frequency() {
5959
extern void (*__init_array_start)(void);
6060
extern void (*__init_array_end)(void);
6161

62-
static cont_t g_cont;
62+
cont_t g_cont __attribute__ ((aligned (16)));
6363
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
6464

6565
static uint32_t g_micros_at_task_start;
@@ -118,9 +118,15 @@ void init_done() {
118118
esp_schedule();
119119
}
120120

121+
extern "C" int __get_rf_mode() __attribute__((weak));
122+
extern "C" int __get_rf_mode()
123+
{
124+
return 0; // default mode
125+
}
126+
121127
extern "C" {
122128
void user_rf_pre_init() {
123-
129+
system_phy_set_rfoption(__get_rf_mode());
124130
}
125131
}
126132

@@ -129,9 +135,6 @@ void user_init(void) {
129135
uart_div_modify(0, UART_CLK_FREQ / (74480));
130136

131137
system_rtc_mem_read(0, &resetInfo, sizeof(struct rst_info));
132-
if(resetInfo.reason == REASON_WDT_RST || resetInfo.reason == REASON_EXCEPTION_RST) {
133-
os_printf("Last Reset:\n - flag=%d\n - Fatal exception (%d):\n - epc1=0x%08x,epc2=0x%08x,epc3=0x%08x,excvaddr=0x%08x,depc=0x%08x\n", resetInfo.reason, resetInfo.exccause, resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc);
134-
}
135138
struct rst_info info = { 0 };
136139
system_rtc_mem_write(0, &info, sizeof(struct rst_info));
137140

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
postmortem.c - output of debug info on sketch crash
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
This file is part of the esp8266 core for Arduino environment.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
22+
#include <stdint.h>
23+
#include <stddef.h>
24+
#include <stdbool.h>
25+
#include "ets_sys.h"
26+
#include "user_interface.h"
27+
#include "esp8266_peri.h"
28+
#include "cont.h"
29+
30+
extern void __real_system_restart_local();
31+
extern cont_t g_cont;
32+
33+
static void uart0_write_char_d(char c);
34+
static void print_stack(uint32_t start, uint32_t end);
35+
static void print_pcs(uint32_t start, uint32_t end);
36+
37+
void __wrap_system_restart_local() {
38+
register uint32_t sp asm("a1");
39+
40+
struct rst_info rst_info = {0};
41+
system_rtc_mem_read(0, &rst_info, sizeof(rst_info));
42+
if (rst_info.reason != REASON_SOFT_WDT_RST &&
43+
rst_info.reason != REASON_EXCEPTION_RST &&
44+
rst_info.reason != REASON_WDT_RST)
45+
{
46+
return;
47+
}
48+
49+
ets_install_putc1(&uart0_write_char_d);
50+
51+
if (rst_info.reason == REASON_EXCEPTION_RST) {
52+
ets_printf("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
53+
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
54+
}
55+
56+
uint32_t cont_stack_start = (uint32_t) &(g_cont.stack);
57+
uint32_t cont_stack_end = (uint32_t) g_cont.stack_end;
58+
uint32_t stack_end;
59+
60+
// amount of stack taken by interrupt or exception handler
61+
// and everything up to __wrap_system_restart_local
62+
// (determined empirically, might break)
63+
uint32_t offset = 0;
64+
if (rst_info.reason == REASON_SOFT_WDT_RST) {
65+
offset = 0x1b0;
66+
}
67+
else if (rst_info.reason == REASON_EXCEPTION_RST) {
68+
offset = 0x1a0;
69+
}
70+
else if (rst_info.reason == REASON_WDT_RST) {
71+
offset = 0x10;
72+
}
73+
74+
if (sp > cont_stack_start && sp < cont_stack_end) {
75+
ets_printf("\nctx: cont \n");
76+
stack_end = cont_stack_end;
77+
}
78+
else {
79+
ets_printf("\nctx: sys \n");
80+
stack_end = 0x3fffffb0;
81+
// it's actually 0x3ffffff0, but the stuff below ets_run
82+
// is likely not really relevant to the crash
83+
}
84+
85+
ets_printf("sp: %08x end: %08x offset: %04x\n", sp, stack_end, offset);
86+
87+
// print_pcs(sp + offset, stack_end);
88+
print_stack(sp + offset, stack_end);
89+
delayMicroseconds(10000);
90+
__real_system_restart_local();
91+
}
92+
93+
94+
static void print_stack(uint32_t start, uint32_t end) {
95+
ets_printf("\n>>>stack>>>\n");
96+
for (uint32_t pos = start; pos < end; pos += 0x10) {
97+
uint32_t* values = (uint32_t*)(pos);
98+
99+
// rough indicator: stack frames usually have SP saved as the second word
100+
bool looksLikeStackFrame = (values[2] == pos + 0x10);
101+
102+
ets_printf("%08x: %08x %08x %08x %08x %c\n",
103+
pos, values[0], values[1], values[2], values[3], (looksLikeStackFrame)?'<':' ');
104+
}
105+
ets_printf("<<<stack<<<\n");
106+
}
107+
108+
static void print_pcs(uint32_t start, uint32_t end) {
109+
uint32_t n = 0;
110+
ets_printf("\n>>>pc>>>\n");
111+
for (uint32_t pos = start; pos < end; pos += 16, ++n) {
112+
uint32_t* sf = (uint32_t*) pos;
113+
114+
uint32_t pc_ret = sf[3];
115+
uint32_t sp_ret = sf[2];
116+
if (pc_ret < 0x40000000 || pc_ret > 0x40f00000 || sp_ret != pos + 16)
117+
continue;
118+
ets_printf("%08x\n", pc_ret);
119+
}
120+
ets_printf("<<<pc<<<\n");
121+
}
122+
123+
void uart0_write_char_d(char c) {
124+
while (((USS(0) >> USTXC) & 0xff) >= 0x7e) { }
125+
126+
if (c == '\n') {
127+
USF(0) = '\r';
128+
}
129+
USF(0) = c;
130+
}

cores/esp8266/debug.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
// #define DEBUGV(...) ets_printf(__VA_ARGS__)
66
#define DEBUGV(...)
77

8+
#ifdef __cplusplus
89
void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16);
9-
10+
#else
11+
void hexdump(uint8_t *mem, uint32_t len, uint8_t cols);
12+
#endif
1013

1114
#endif//ARD_DEBUG_H

cores/esp8266/libc_replacements.c

+2-69
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "osapi.h"
3737
#include "mem.h"
3838
#include "user_interface.h"
39+
#include "debug.h"
3940

4041
void* malloc(size_t size) {
4142
size = ((size + 3) & ~((size_t)0x3));
@@ -471,75 +472,7 @@ int isblank(int c) {
471472
static int errno_var = 0;
472473

473474
int* ICACHE_FLASH_ATTR __errno(void) {
474-
os_printf("__errno is called last error: %d (not current)\n", errno_var);
475+
DEBUGV("__errno is called last error: %d (not current)\n", errno_var);
475476
return &errno_var;
476477
}
477478

478-
// ##########################################################################
479-
// __ieee754 functions
480-
// ##########################################################################
481-
482-
double ICACHE_FLASH_ATTR __ieee754_sinh(double x) {
483-
return sinh(x);
484-
}
485-
486-
double ICACHE_FLASH_ATTR __ieee754_hypot(double x, double y) {
487-
return hypot(x, y);
488-
}
489-
490-
float ICACHE_FLASH_ATTR __ieee754_hypotf(float x, float y) {
491-
return hypotf(x, y);
492-
}
493-
494-
float ICACHE_FLASH_ATTR __ieee754_logf(float x) {
495-
return logf(x);
496-
}
497-
498-
double ICACHE_FLASH_ATTR __ieee754_log10(double x) {
499-
return log10(x);
500-
}
501-
502-
double ICACHE_FLASH_ATTR __ieee754_exp(double x) {
503-
return exp(x);
504-
}
505-
506-
double ICACHE_FLASH_ATTR __ieee754_cosh(double x) {
507-
return cosh(x);
508-
}
509-
510-
float ICACHE_FLASH_ATTR __ieee754_expf(float x) {
511-
return expf(x);
512-
}
513-
514-
float ICACHE_FLASH_ATTR __ieee754_log10f(float x) {
515-
return log10f(x);
516-
}
517-
518-
double ICACHE_FLASH_ATTR __ieee754_atan2(double x, double y) {
519-
return atan2(x, y);
520-
}
521-
522-
float ICACHE_FLASH_ATTR __ieee754_sqrtf(float x) {
523-
return sqrtf(x);
524-
}
525-
526-
float ICACHE_FLASH_ATTR __ieee754_sinhf(float x) {
527-
return sinhf(x);
528-
}
529-
530-
double ICACHE_FLASH_ATTR __ieee754_log(double x) {
531-
return log(x);
532-
}
533-
534-
double ICACHE_FLASH_ATTR __ieee754_sqrt(double x) {
535-
return sqrt(x);
536-
}
537-
538-
float ICACHE_FLASH_ATTR __ieee754_coshf(float x) {
539-
return coshf(x);
540-
}
541-
542-
float ICACHE_FLASH_ATTR __ieee754_atan2f(float x, float y) {
543-
return atan2f(x, y);
544-
}
545-

libraries/ESP8266WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ void setup() {
5555
/* You can remove the password parameter if you want the AP to be open. */
5656
WiFi.softAP(ssid, password);
5757

58-
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
59-
60-
Serial.println("done");
6158
IPAddress myIP = WiFi.softAPIP();
6259
Serial.print("AP IP address: ");
6360
Serial.println(myIP);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <ESP8266WiFi.h>
2+
#include <ESP8266WiFiMesh.h>
3+
4+
/* Create the mesh node object */
5+
ESP8266WiFiMesh mesh_node = ESP8266WiFiMesh(ESP.getChipId(), manageRequest);
6+
7+
/**
8+
* Callback for when other nodes send you data
9+
*
10+
* @request The string received from another node in the mesh
11+
* @returns The string to send back to the other node
12+
*/
13+
String manageRequest(String request)
14+
{
15+
/* Print out received message */
16+
Serial.print("received: ");
17+
Serial.println(request);
18+
19+
/* return a string to send back */
20+
return String("Hello world response.");
21+
}
22+
23+
void setup()
24+
{
25+
Serial.begin(115200);
26+
delay(10);
27+
28+
Serial.println();
29+
Serial.println();
30+
Serial.println("Setting up mesh node...");
31+
32+
/* Initialise the mesh node */
33+
mesh_node.begin();
34+
}
35+
36+
void loop()
37+
{
38+
/* Accept any incoming connections */
39+
mesh_node.acceptRequest();
40+
41+
/* Scan for other nodes and send them a message */
42+
mesh_node.attemptScan("Hello world request.");
43+
delay(1000);
44+
}

0 commit comments

Comments
 (0)