1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

Merge remote-tracking branch 'remotes/esp8266/esp8266' into esp8266

This commit is contained in:
Markus Sattler 2015-07-16 12:28:38 +02:00
commit c6dc58a311
11 changed files with 71 additions and 43 deletions

View File

@ -218,6 +218,7 @@ Libraries that don't rely on low-level access to AVR registers should work well.
- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy. - [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy.
- [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266. - [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266.
- [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB. - [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB.
- [ST7735](https://github.com/nzmichaelh/Adafruit-ST7735-Library) - Adafruit's ST7735 library modified to be compatible with esp8266. Just make sure to modify the pins in the examples as they are still AVR specific.
#### Upload via serial port #### #### Upload via serial port ####
Pick the correct serial port. Pick the correct serial port.

View File

@ -39,6 +39,7 @@ extern "C" {
#include "twi.h" #include "twi.h"
void yield(void); void yield(void);
void optimistic_yield(void);
#define HIGH 0x1 #define HIGH 0x1
#define LOW 0x0 #define LOW 0x0

View File

@ -552,13 +552,17 @@ bool HardwareSerial::isRxEnabled(void) {
} }
int HardwareSerial::available(void) { int HardwareSerial::available(void) {
if(_uart == 0) int result = 0;
return 0;
if(_uart->rxEnabled) { if (_uart != NULL && _uart->rxEnabled) {
return static_cast<int>(_rx_buffer->getSize()); result = static_cast<int>(_rx_buffer->getSize());
} else {
return 0;
} }
if (!result) {
optimistic_yield();
}
return result;
} }
int HardwareSerial::peek(void) { int HardwareSerial::peek(void) {

View File

@ -34,6 +34,8 @@ extern "C" {
#define LOOP_TASK_PRIORITY 0 #define LOOP_TASK_PRIORITY 0
#define LOOP_QUEUE_SIZE 1 #define LOOP_QUEUE_SIZE 1
#define OPTIMISTIC_YIELD_TIME_US 16000
struct rst_info resetInfo; struct rst_info resetInfo;
int atexit(void (*func)()) { int atexit(void (*func)()) {
@ -62,11 +64,8 @@ extern void (*__init_array_end)(void);
cont_t g_cont __attribute__ ((aligned (16))); cont_t g_cont __attribute__ ((aligned (16)));
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE]; static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
static uint32_t g_micros_at_task_start; static uint32_t g_micros_at_last_task_yield;
extern "C" uint32_t esp_micros_at_task_start() {
return g_micros_at_task_start;
}
extern "C" void abort() { extern "C" void abort() {
while(1) { while(1) {
@ -74,6 +73,7 @@ extern "C" void abort() {
} }
extern "C" void esp_yield() { extern "C" void esp_yield() {
g_micros_at_last_task_yield = system_get_time();
cont_yield(&g_cont); cont_yield(&g_cont);
} }
@ -87,6 +87,14 @@ extern "C" void __yield() {
} }
extern "C" void yield(void) __attribute__ ((weak, alias("__yield"))); extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
extern "C" void optimistic_yield(void) {
if (!ETS_INTR_WITHINISR() &&
(system_get_time() - g_micros_at_last_task_yield) > OPTIMISTIC_YIELD_TIME_US)
{
__yield();
}
}
static void loop_wrapper() { static void loop_wrapper() {
static bool setup_done = false; static bool setup_done = false;
if(!setup_done) { if(!setup_done) {
@ -99,7 +107,7 @@ static void loop_wrapper() {
} }
static void loop_task(os_event_t *events) { static void loop_task(os_event_t *events) {
g_micros_at_task_start = system_get_time(); g_micros_at_last_task_yield = system_get_time();
cont_run(&g_cont, &loop_wrapper); cont_run(&g_cont, &loop_wrapper);
if(cont_check(&g_cont) != 0) { if(cont_check(&g_cont) != 0) {
ets_printf("\r\nheap collided with sketch stack\r\n"); ets_printf("\r\nheap collided with sketch stack\r\n");

View File

@ -1,9 +1,9 @@
/* /*
si2c.c - Software I2C library for esp8266 si2c.c - Software I2C library for esp8266
Copyright (c) 2015 Hristo Gochkov. All rights reserved. Copyright (c) 2015 Hristo Gochkov. All rights reserved.
This file is part of the esp8266 core for Arduino environment. This file is part of the esp8266 core for Arduino environment.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
@ -26,10 +26,10 @@ unsigned char twi_dcount = 18;
static unsigned char twi_sda, twi_scl; static unsigned char twi_sda, twi_scl;
#define SDA_LOW() (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low) #define SDA_LOW() (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low)
#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high) #define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
#define SDA_READ() ((GPI & (1 << twi_sda)) != 0) #define SDA_READ() ((GPI & (1 << twi_sda)) != 0)
#define SCL_LOW() (GPES = (1 << twi_scl)) #define SCL_LOW() (GPES = (1 << twi_scl))
#define SCL_HIGH() (GPEC = (1 << twi_scl)) #define SCL_HIGH() (GPEC = (1 << twi_scl))
#define SCL_READ() ((GPI & (1 << twi_scl)) != 0) #define SCL_READ() ((GPI & (1 << twi_scl)) != 0)
#ifndef FCPU80 #ifndef FCPU80
@ -37,9 +37,9 @@ static unsigned char twi_sda, twi_scl;
#endif #endif
#if F_CPU == FCPU80 #if F_CPU == FCPU80
#define TWI_CLOCK_STRETCH 200 #define TWI_CLOCK_STRETCH 800
#else #else
#define TWI_CLOCK_STRETCH 400 #define TWI_CLOCK_STRETCH 1600
#endif #endif
void twi_setClock(unsigned int freq){ void twi_setClock(unsigned int freq){
@ -99,7 +99,7 @@ static bool twi_write_stop(void){
twi_delay(twi_dcount); twi_delay(twi_dcount);
SDA_HIGH(); SDA_HIGH();
twi_delay(twi_dcount); twi_delay(twi_dcount);
return true; return true;
} }
@ -166,7 +166,8 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
unsigned int i; unsigned int i;
if(!twi_write_start()) return 4;//line busy if(!twi_write_start()) return 4;//line busy
if(!twi_write_byte(((address << 1) | 1) & 0xFF)) return 2;//received NACK on transmit of address if(!twi_write_byte(((address << 1) | 1) & 0xFF)) return 2;//received NACK on transmit of address
for(i=0; i<len; i++) buf[i] = twi_read_byte(false); for(i=0; i<(len-1); i++) buf[i] = twi_read_byte(false);
buf[len-1] = twi_read_byte(true);
if(sendStop) twi_write_stop(); if(sendStop) twi_write_stop();
i = 0; i = 0;
while(SDA_READ() == 0 && (i++) < 10){ while(SDA_READ() == 0 && (i++) < 10){

View File

@ -25,7 +25,7 @@
const char* ssid = "**********"; const char* ssid = "**********";
const char* password = "**********"; const char* password = "**********";
WiFiServer server(21); WiFiServer server(23);
WiFiClient serverClients[MAX_SRV_CLIENTS]; WiFiClient serverClients[MAX_SRV_CLIENTS];
void setup() { void setup() {
@ -45,7 +45,7 @@ void setup() {
Serial1.print("Ready! Use 'telnet "); Serial1.print("Ready! Use 'telnet ");
Serial1.print(WiFi.localIP()); Serial1.print(WiFi.localIP());
Serial1.println(" 21' to connect"); Serial1.println(" 23' to connect");
} }
void loop() { void loop() {

View File

@ -177,20 +177,17 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
return _client->write(reinterpret_cast<const char*>(buf), size); return _client->write(reinterpret_cast<const char*>(buf), size);
} }
extern "C" uint32_t esp_micros_at_task_start();
int WiFiClient::available() int WiFiClient::available()
{ {
static uint32_t lastPollTime = 0; int result = 0;
if (!_client)
return 0;
if (lastPollTime > esp_micros_at_task_start()) if (_client) {
yield(); result = _client->getSize();
}
lastPollTime = micros(); if (!result) {
optimistic_yield();
int result = _client->getSize(); }
return result; return result;
} }

View File

@ -84,8 +84,6 @@ bool WiFiServer::getNoDelay(){
return tcp_nagle_disabled(_pcb); return tcp_nagle_disabled(_pcb);
} }
extern "C" uint32_t esp_micros_at_task_start();
bool WiFiServer::hasClient(){ bool WiFiServer::hasClient(){
if (_unclaimed) return true; if (_unclaimed) return true;
return false; return false;
@ -93,8 +91,6 @@ bool WiFiServer::hasClient(){
WiFiClient WiFiServer::available(byte* status) WiFiClient WiFiServer::available(byte* status)
{ {
static uint32_t lastPollTime = 0;
if (_unclaimed) if (_unclaimed)
{ {
WiFiClient result(_unclaimed); WiFiClient result(_unclaimed);
@ -103,9 +99,7 @@ WiFiClient WiFiServer::available(byte* status)
return result; return result;
} }
if (lastPollTime > esp_micros_at_task_start()) optimistic_yield();
yield();
lastPollTime = micros();
return WiFiClient(); return WiFiClient();
} }

View File

@ -116,9 +116,17 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
/* return number of bytes available in the current packet, /* return number of bytes available in the current packet,
will return zero if parsePacket hasn't been called yet */ will return zero if parsePacket hasn't been called yet */
int WiFiUDP::available() { int WiFiUDP::available() {
if (!_ctx) int result = 0;
return 0;
return static_cast<int>(_ctx->getSize()); if (_ctx) {
result = static_cast<int>(_ctx->getSize());
}
if (!result) {
optimistic_yield();
}
return result;
} }
/* Release any resources being used by this WiFiUDP instance */ /* Release any resources being used by this WiFiUDP instance */

View File

@ -161,7 +161,13 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){
} }
int TwoWire::available(void){ int TwoWire::available(void){
return rxBufferLength - rxBufferIndex; int result = rxBufferLength - rxBufferIndex;
if (!result) {
optimistic_yield();
}
return result;
} }
int TwoWire::read(void){ int TwoWire::read(void){

View File

@ -61,6 +61,14 @@ typedef void (*int_handler_t)(void*);
#define ETS_INTR_DISABLE(inum) \ #define ETS_INTR_DISABLE(inum) \
ets_isr_mask((1<<inum)) ets_isr_mask((1<<inum))
inline bool ETS_INTR_WITHINISR()
{
uint32_t ps;
__asm__ __volatile__("rsr %0,ps":"=a" (ps));
// PS.EXCM and PS.UM bit checks
return ((ps & ((1 << 4) | (1 << 5))) > 0);
}
inline uint32_t ETS_INTR_ENABLED(void) inline uint32_t ETS_INTR_ENABLED(void)
{ {
uint32_t enabled; uint32_t enabled;