Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Joele committed Jun 6, 2016
2 parents 9818958 + 32bd42b commit c37d665
Show file tree
Hide file tree
Showing 112 changed files with 3,297 additions and 1,001 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ script:
- install_libraries
- echo -e "travis_fold:end:sketch_test_env_prepare"
- echo -e "travis_fold:start:sketch_test"
- build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR "-l $HOME/Arduino/libraries"
- build_sketches $HOME/arduino_ide $TRAVIS_BUILD_DIR/libraries "-l $HOME/Arduino/libraries"
- echo -e "travis_fold:end:sketch_test"
- echo -e "travis_fold:start:size_report"
- cat size.log
Expand Down
374 changes: 332 additions & 42 deletions boards.txt

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions bootloaders/eboot/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "flash.h"
#include "eboot_command.h"

Expand All @@ -17,6 +18,20 @@
extern void ets_wdt_enable(void);
extern void ets_wdt_disable(void);

int print_version(const uint32_t flash_addr)
{
uint32_t ver;
if (SPIRead(flash_addr + APP_START_OFFSET + sizeof(image_header_t) + sizeof(section_header_t), &ver, sizeof(ver))) {
return 1;
}
const char* __attribute__ ((aligned (4))) fmtt = "v%08x\n\0\0";
uint32_t fmt[2];
fmt[0] = ((uint32_t*) fmtt)[0];
fmt[1] = ((uint32_t*) fmtt)[1];
ets_printf((const char*) fmt, ver);
return 0;
}

int load_app_from_flash_raw(const uint32_t flash_addr)
{
image_header_t image_header;
Expand Down Expand Up @@ -114,6 +129,8 @@ void main()
{
int res = 9;
struct eboot_command cmd;

print_version(0);

if (eboot_command_read(&cmd) == 0) {
// valid command was passed via RTC_MEM
Expand Down
Binary file modified bootloaders/eboot/eboot.elf
Binary file not shown.
1 change: 0 additions & 1 deletion cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ extern "C" {
#define MSBFIRST 1

//Interrupt Modes
#define DISABLED 0x00
#define RISING 0x01
#define FALLING 0x02
#define CHANGE 0x03
Expand Down
31 changes: 31 additions & 0 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
esp_yield();
}

bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
{
if (size + offset > 512) {
return false;
} else {
return system_rtc_mem_read(64 + offset, data, size);
}
}

bool EspClass::rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size)
{
if (size + offset > 512) {
return false;
} else {
return system_rtc_mem_write(64 + offset, data, size);
}
}

extern "C" void __real_system_restart_local();
void EspClass::reset(void)
{
Expand Down Expand Up @@ -140,6 +158,19 @@ uint32_t EspClass::getChipId(void)
return system_get_chip_id();
}

extern "C" uint32_t core_version;
extern "C" const char* core_release;

String EspClass::getCoreVersion()
{
if (core_release != NULL) {
return String(core_release);
}
char buf[12];
snprintf(buf, sizeof(buf), "%08x", core_version);
return String(buf);
}

const char * EspClass::getSdkVersion(void)
{
return system_get_sdk_version();
Expand Down
4 changes: 4 additions & 0 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class EspClass {

void deepSleep(uint32_t time_us, RFMode mode = RF_DEFAULT);

bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
bool rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size);

void reset();
void restart();

Expand All @@ -103,6 +106,7 @@ class EspClass {
uint32_t getChipId();

const char * getSdkVersion();
String getCoreVersion();

uint8_t getBootVersion();
uint8_t getBootMode();
Expand Down
6 changes: 6 additions & 0 deletions cores/esp8266/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ bool FS::begin() {
return _impl->begin();
}

void FS::end() {
if (_impl) {
_impl->end();
}
}

bool FS::format() {
if (!_impl) {
return false;
Expand Down
7 changes: 5 additions & 2 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class FS
FS(FSImplPtr impl) : _impl(impl) { }

bool begin();

void end();

bool format();
bool info(FSInfo& info);

Expand All @@ -127,6 +128,7 @@ class FS

} // namespace fs

#ifndef FS_NO_GLOBALS
using fs::FS;
using fs::File;
using fs::Dir;
Expand All @@ -135,7 +137,8 @@ using fs::SeekSet;
using fs::SeekCur;
using fs::SeekEnd;
using fs::FSInfo;
#endif //FS_NO_GLOBALS

extern FS SPIFFS;
extern fs::FS SPIFFS;

#endif //FS_H
1 change: 1 addition & 0 deletions cores/esp8266/FSImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class DirImpl {
class FSImpl {
public:
virtual bool begin() = 0;
virtual void end() = 0;
virtual bool format() = 0;
virtual bool info(FSInfo& info) = 0;
virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;
Expand Down
11 changes: 6 additions & 5 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ extern "C" {
extern "C" uint32_t _SPIFFS_start;

UpdaterClass::UpdaterClass()
: _error(0)
: _async(false)
, _error(0)
, _buffer(0)
, _bufferLen(0)
, _size(0)
Expand Down Expand Up @@ -202,13 +203,13 @@ bool UpdaterClass::end(bool evenIfRemaining){

bool UpdaterClass::_writeBuffer(){

yield();
if(!_async) yield();
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
yield();
if(!_async) yield();
if (result) {
result = ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
}
yield();
if(!_async) yield();

if (!result) {
_error = UPDATE_ERROR_WRITE;
Expand Down Expand Up @@ -240,7 +241,7 @@ size_t UpdaterClass::write(uint8_t *data, size_t len) {
return len - left;
}
left -= toBuff;
yield();
if(!_async) yield();
}
//lets see whats left
memcpy(_buffer + _bufferLen, data + (len - left), left);
Expand Down
6 changes: 6 additions & 0 deletions cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class UpdaterClass {
*/
bool begin(size_t size, int command = U_FLASH);

/*
Run Updater from asynchronous callbacs
*/
void runAsync(bool async){ _async = async; }

/*
Writes a buffer to the flash and increments the address
Returns the amount written
Expand Down Expand Up @@ -143,6 +148,7 @@ class UpdaterClass {
bool _verifyHeader(uint8_t data);
bool _verifyEnd();

bool _async;
uint8_t _error;
uint8_t *_buffer;
size_t _bufferLen;
Expand Down
5 changes: 5 additions & 0 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ void __throw_logic_error(const char* str)
{
panic();
}

void __throw_out_of_range(const char* str)
{
panic();
}
}

// TODO: rebuild windows toolchain to make this unnecessary:
Expand Down
22 changes: 19 additions & 3 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,25 @@ extern "C" {
#include "user_interface.h"
#include "cont.h"
}
#include <core_version.h>

#define LOOP_TASK_PRIORITY 1
#define LOOP_QUEUE_SIZE 1

#define OPTIMISTIC_YIELD_TIME_US 16000

struct rst_info resetInfo;

extern "C" {
extern const uint32_t __attribute__((section(".ver_number"))) core_version = ARDUINO_ESP8266_GIT_VER;
const char* core_release =
#ifdef ARDUINO_ESP8266_RELEASE
ARDUINO_ESP8266_RELEASE;
#else
NULL;
#endif
} // extern "C"

int atexit(void (*func)()) {
return 0;
}
Expand Down Expand Up @@ -119,18 +131,22 @@ static void loop_task(os_event_t *events) {
}

static void do_global_ctors(void) {
void (**p)(void);
for(p = &__init_array_start; p != &__init_array_end; ++p)
(*p)();
void (**p)(void) = &__init_array_end;
while (p != &__init_array_start)
(*--p)();
}

extern "C" void __gdb_init() {}
extern "C" void gdb_init(void) __attribute__ ((weak, alias("__gdb_init")));

extern "C" void __gdb_do_break(){}
extern "C" void gdb_do_break(void) __attribute__ ((weak, alias("__gdb_do_break")));

void init_done() {
system_set_os_print(1);
gdb_init();
do_global_ctors();
printf("\n%08x\n", core_version);
esp_schedule();
}

Expand Down
5 changes: 5 additions & 0 deletions cores/esp8266/core_esp8266_postmortem.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "cont.h"

extern void __real_system_restart_local();
extern void gdb_do_break();

extern cont_t g_cont;

static const char* s_panic_file = 0;
Expand Down Expand Up @@ -184,11 +186,14 @@ void __assert_func(const char *file, int line, const char *func, const char *wha
s_panic_file = file;
s_panic_line = line;
s_panic_func = func;
gdb_do_break();
}

void __panic_func(const char* file, int line, const char* func) {
s_panic_file = file;
s_panic_line = line;
s_panic_func = func;
gdb_do_break();
abort();
}

15 changes: 15 additions & 0 deletions cores/esp8266/core_esp8266_si2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,18 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
}
return 0;
}

uint8_t twi_status(){
if (SCL_READ()==0) return I2C_SCL_HELD_LOW; //SCL held low by another device, no procedure available to recover
int clockCount = 20;

while (SDA_READ()==0 && clockCount>0){ //if SDA low, read the bits slaves have to sent to a max
twi_read_bit();
if (SCL_READ()==0) return I2C_SCL_HELD_LOW_AFTER_READ; //I2C bus error. SCL held low beyond slave clock stretch time
}

if (SDA_READ()==0) return I2C_SDA_HELD_LOW; //I2C bus error. SDA line held low by slave/another_master after n bits.

if(!twi_write_start()) return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master?
else return I2C_OK; //all ok
}
4 changes: 2 additions & 2 deletions cores/esp8266/core_esp8266_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void timer1_attachInterrupt(timercallback userFunc) {
ETS_FRC1_INTR_ENABLE();
}

void timer1_detachInterrupt() {
void ICACHE_RAM_ATTR timer1_detachInterrupt() {
timer1_user_cb = 0;
TEIE &= ~TEIE1;//edge int disable
ETS_FRC1_INTR_DISABLE();
Expand Down Expand Up @@ -95,7 +95,7 @@ void timer0_attachInterrupt(timercallback userFunc) {
ETS_CCOMPARE0_ENABLE();
}

void timer0_detachInterrupt() {
void ICACHE_RAM_ATTR timer0_detachInterrupt() {
timer0_user_cb = NULL;
ETS_CCOMPARE0_DISABLE();
}
6 changes: 6 additions & 0 deletions cores/esp8266/core_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define ARDUINO_ESP8266_GIT_VER 0x00000000

// ARDUINO_ESP8266_RELEASE is defined for released versions as a string containing the version name, i.e. "2_3_0_RC1"
// ARDUINO_ESP8266_RELEASE is used in the core internally. Please use ESP.getCoreVersion() function instead.

// ARDUINO_ESP8266_RELEASE_<version number> are defined for releases, for use in #ifdef... constructs
2 changes: 2 additions & 0 deletions cores/esp8266/esp8266_peri.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ extern uint8_t esp8266_gpioToFn[16];
#define RTCIC ESP8266_REG(0x724) //RTC INT Clear
#define RTCIE ESP8266_REG(0x728) //RTC INT Enable

#define RTC_USER_MEM ((volatile uint32_t*)0x60001200)

//IO SWAP Register
#define IOSWAP ESP8266_DREG(0x28)
#define IOSWAPU 0 //Swaps UART
Expand Down
8 changes: 8 additions & 0 deletions cores/esp8266/spiffs_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ class SPIFFSImpl : public FSImpl
return _tryMount();
}

void end() override
{
if (SPIFFS_mounted(&_fs) == 0) {
return;
}
SPIFFS_unmount(&_fs);
}

bool format() override
{
if (_size == 0) {
Expand Down
7 changes: 7 additions & 0 deletions cores/esp8266/twi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@
extern "C" {
#endif

#define I2C_OK 0
#define I2C_SCL_HELD_LOW 1
#define I2C_SCL_HELD_LOW_AFTER_READ 2
#define I2C_SDA_HELD_LOW 3
#define I2C_SDA_HELD_LOW_AFTER_INIT 4

void twi_init(unsigned char sda, unsigned char scl);
void twi_stop(void);
void twi_setClock(unsigned int freq);
void twi_setClockStretchLimit(uint32_t limit);
uint8_t twi_writeTo(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop);
uint8_t twi_readFrom(unsigned char address, unsigned char * buf, unsigned int len, unsigned char sendStop);
uint8_t twi_status();

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit c37d665

Please sign in to comment.