Skip to content

Commit

Permalink
Merge remote-tracking branch 'esp8266/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Me No Dev committed Nov 25, 2015
2 parents 20f372a + 56a3733 commit 324576f
Show file tree
Hide file tree
Showing 44 changed files with 2,180 additions and 687 deletions.
10 changes: 10 additions & 0 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ uint32_t EspClass::getFlashChipSizeByChipId(void) {
case 0x1340EF: // W25Q40
return (512_kB);

// BergMicro
case 0x1640E0: // BG25Q32
return (4_MB);
case 0x1540E0: // BG25Q16
return (2_MB);
case 0x1440E0: // BG25Q80
return (1_MB);
case 0x1340E0: // BG25Q40
return (512_kB);

default:
return 0;
}
Expand Down
68 changes: 68 additions & 0 deletions cores/esp8266/StreamString.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
StreamString.cpp
Copyright (c) 2015 Markus Sattler. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <Arduino.h>
#include "StreamString.h"

size_t StreamString::write(const uint8_t *buffer, size_t size) {
if(reserve(length() + size + 1)) {
for(size_t i = 0; i < size; i++) {
if(write(*buffer)) {
buffer++;
} else {
return i;
}
}

}
return 0;
}

size_t StreamString::write(uint8_t data) {
return concat((char) data);
}

int StreamString::available() {
return length();
}

int StreamString::read() {
if(length()) {
char c = charAt(0);
remove(0, 1);
return c;

}
return -1;
}

int StreamString::peek() {
if(length()) {
char c = charAt(0);
return c;
}
return -1;
}

void StreamString::flush() {
}

40 changes: 40 additions & 0 deletions cores/esp8266/StreamString.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
StreamString.h
Copyright (c) 2015 Markus Sattler. All rights reserved.
This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef STREAMSTRING_H_
#define STREAMSTRING_H_


class StreamString: public Stream, public String {

size_t write(const uint8_t *buffer, size_t size);
size_t write(uint8_t data);

int available();
int read();
int peek();
void flush();

};


#endif /* STREAMSTRING_H_ */
15 changes: 8 additions & 7 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
*/

#include <stdlib.h>
#include <assert.h>
#include <debug.h>
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
}


void *operator new(size_t size) {
size = ((size + 3) & ~((size_t)0x3));
return os_malloc(size);
Expand All @@ -47,27 +49,26 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));

void __cxa_pure_virtual(void) {
abort();
panic();
}

void __cxa_deleted_virtual(void) {
abort();
panic();
}

namespace std {
void __throw_bad_function_call() {
abort();
panic();
}

void __throw_length_error(char const*) {
abort();
panic();
}

void __throw_bad_alloc() {
abort();
panic();
}
}

// TODO: rebuild windows toolchain to make this unnecessary:
void* __dso_handle;

14 changes: 3 additions & 11 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];

static uint32_t g_micros_at_task_start;


extern "C" void abort() {
do {
*((int*)0) = 0;
} while(true);
}

extern "C" void esp_yield() {
if (cont_can_yield(&g_cont)) {
cont_yield(&g_cont);
Expand All @@ -89,7 +82,7 @@ extern "C" void __yield() {
esp_yield();
}
else {
abort();
panic();
}
}

Expand Down Expand Up @@ -117,9 +110,8 @@ static void loop_wrapper() {
static void loop_task(os_event_t *events) {
g_micros_at_task_start = system_get_time();
cont_run(&g_cont, &loop_wrapper);
if(cont_check(&g_cont) != 0) {
ets_printf("\r\nsketch stack overflow detected\r\n");
abort();
if (cont_check(&g_cont) != 0) {
panic();
}
}

Expand Down
36 changes: 35 additions & 1 deletion cores/esp8266/core_esp8266_postmortem.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "debug.h"
#include "ets_sys.h"
#include "user_interface.h"
#include "esp8266_peri.h"
Expand All @@ -30,6 +31,11 @@
extern void __real_system_restart_local();
extern cont_t g_cont;

static const char* s_panic_file = 0;
static int s_panic_line = 0;
static const char* s_panic_func = 0;

static bool s_abort_called = false;

void uart_write_char_d(char c);
static void uart0_write_char_d(char c);
Expand All @@ -56,7 +62,13 @@ void __wrap_system_restart_local() {

ets_install_putc1(&uart_write_char_d);

if (rst_info.reason == REASON_EXCEPTION_RST) {
if (s_panic_line) {
ets_printf("\nPanic %s:%d %s\n", s_panic_file, s_panic_line, s_panic_func);
}
else if (s_abort_called) {
ets_printf("Abort called\n");
}
else if (rst_info.reason == REASON_EXCEPTION_RST) {
ets_printf("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n",
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
}
Expand Down Expand Up @@ -158,3 +170,25 @@ static void uart1_write_char_d(char c) {
}
USF(1) = c;
}
void abort() __attribute__((noreturn));

void abort(){
// cause exception
s_abort_called = true;
do {
*((int*)0) = 0;
} while(true);
}

void __assert_func(const char *file, int line, const char *func, const char *what) {
s_panic_file = file;
s_panic_line = line;
s_panic_func = func;
}

void __panic_func(const char* file, int line, const char* func) {
s_panic_file = file;
s_panic_line = line;
s_panic_func = func;
abort();
}
14 changes: 14 additions & 0 deletions cores/esp8266/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define ARD_DEBUG_H

#include <stddef.h>
#include <stdint.h>

//#define DEBUGV(...) ets_printf(__VA_ARGS__)

#ifndef DEBUGV
Expand All @@ -14,4 +16,16 @@ void hexdump(uint8_t *mem, uint32_t len, uint8_t cols = 16);
void hexdump(uint8_t *mem, uint32_t len, uint8_t cols);
#endif

#ifdef __cplusplus
extern "C" {
#endif

void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn));
#define panic() __panic_func(__FILE__, __LINE__, __func__)

#ifdef __cplusplus
}
#endif


#endif//ARD_DEBUG_H
1 change: 1 addition & 0 deletions cores/esp8266/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ int gettimeofday(struct timeval *tp, void *tzp)
tp->tv_sec = (s_bootTime + millis()) / 1000;
tp->tv_usec = micros() * 1000;
}
return 0;
}
Loading

0 comments on commit 324576f

Please sign in to comment.