Skip to content

Commit 44af3d5

Browse files
committed
Merge remote-tracking branch 'remotes/esp8266/master'
2 parents 02e22b3 + 93aaa86 commit 44af3d5

File tree

7 files changed

+49
-56
lines changed

7 files changed

+49
-56
lines changed

cores/esp8266/Arduino.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,12 @@ void loop(void);
219219
void yield(void);
220220
void optimistic_yield(uint32_t interval_us);
221221

222-
// Get the bit location within the hardware port of the given virtual pin.
223-
// This comes from the pins_*.c file for the active board configuration.
224222
#define digitalPinToPort(pin) (0)
225223
#define digitalPinToBitMask(pin) (1UL << (pin))
226224
#define digitalPinToTimer(pin) (0)
227-
#define portOutputRegister(port) ((volatile uint32_t*) GPO)
228-
#define portInputRegister(port) ((volatile uint32_t*) GPI)
229-
#define portModeRegister(port) ((volatile uint32_t*) GPE)
225+
#define portOutputRegister(port) ((volatile uint32_t*) &GPO)
226+
#define portInputRegister(port) ((volatile uint32_t*) &GPI)
227+
#define portModeRegister(port) ((volatile uint32_t*) &GPE)
230228

231229
#define NOT_A_PIN -1
232230
#define NOT_A_PORT -1

cores/esp8266/HardwareSerial.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,18 +617,15 @@ size_t HardwareSerial::write(uint8_t c) {
617617
size_t room = uart_get_tx_fifo_room(_uart);
618618
if(room > 0 && _tx_buffer->empty()) {
619619
uart_transmit_char(_uart, c);
620-
if(room < 10) {
621-
uart_arm_tx_interrupt(_uart);
622-
}
623620
return 1;
624621
}
625622

626623
while(_tx_buffer->room() == 0) {
627624
yield();
628-
uart_arm_tx_interrupt(_uart);
629625
}
630626

631627
_tx_buffer->write(c);
628+
uart_arm_tx_interrupt(_uart);
632629
return 1;
633630
}
634631

cores/esp8266/abi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ void __throw_length_error(char const*) {
6868
void __throw_bad_alloc() {
6969
panic();
7070
}
71+
72+
void __throw_logic_error(const char* str) {
73+
panic();
74+
}
7175
}
7276

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

cores/esp8266/cbuf.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class cbuf {
4242
if(_end >= _begin) {
4343
return _size - (_end - _begin) - 1;
4444
}
45-
if(_begin == _end) {
46-
return _size;
47-
}
4845
return _begin - _end - 1;
4946
}
5047

@@ -62,7 +59,7 @@ class cbuf {
6259
if(getSize() == 0) return -1;
6360

6461
char result = *_begin;
65-
if(++_begin == _bufend) _begin = _buf;
62+
_begin = wrap_if_bufend(_begin + 1);
6663
return static_cast<int>(result);
6764
}
6865

@@ -78,16 +75,15 @@ class cbuf {
7875
dst += top_size;
7976
}
8077
memcpy(dst, _begin, size_to_read);
81-
_begin += size_to_read;
82-
if(_begin == _bufend) _begin = _buf;
78+
_begin = wrap_if_bufend(_begin + size_to_read);
8379
return size_read;
8480
}
8581

8682
size_t write(char c) {
8783
if(room() == 0) return 0;
8884

8985
*_end = c;
90-
if(++_end == _bufend) _end = _buf;
86+
_end = wrap_if_bufend(_end + 1);
9187
return 1;
9288
}
9389

@@ -103,8 +99,7 @@ class cbuf {
10399
src += top_size;
104100
}
105101
memcpy(_end, src, size_to_write);
106-
_end += size_to_write;
107-
if(_end == _bufend) _end = _buf;
102+
_end = wrap_if_bufend(_end + size_to_write);
108103
return size_written;
109104
}
110105

@@ -114,6 +109,10 @@ class cbuf {
114109
}
115110

116111
private:
112+
inline char* wrap_if_bufend(char* ptr) {
113+
return (ptr == _bufend) ? _buf : ptr;
114+
}
115+
117116
size_t _size;
118117
char* _buf;
119118
char* _bufend;

cores/esp8266/pgmspace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
7878
(__extension__({ \
7979
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
8080
ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \
81-
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset); \
81+
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local)-__offset); \
8282
uint8_t __result = ((*__addr32) >> (__offset * 8)); \
8383
__result; \
8484
}))
@@ -87,7 +87,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
8787
(__extension__({ \
8888
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
8989
ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \
90-
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local) - __offset); \
90+
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local) - __offset); \
9191
uint16_t __result = ((*__addr32) >> (__offset * 8)); \
9292
__result; \
9393
}))

libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ void loop() {
7171
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
7272
"Host: " + host + "\r\n" +
7373
"Connection: close\r\n\r\n");
74-
delay(10);
74+
int timeout = millis() + 5000;
75+
while (client.available() == 0) {
76+
if (timeout - millis() < 0) {
77+
Serial.println(">>> Client Timeout !");
78+
client.stop();
79+
return;
80+
}
81+
}
7582

7683
// Read all the lines of the reply from server and print them to Serial
7784
while(client.available()){

libraries/ESP8266WiFi/src/include/UdpContext.h

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/*
22
UdpContext.h - UDP connection handling on top of lwIP
33
44
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
55
This file is part of the esp8266 core for Arduino environment.
6-
6+
77
This library is free software; you can redistribute it and/or
88
modify it under the terms of the GNU Lesser General Public
99
License as published by the Free Software Foundation; either
@@ -206,10 +206,10 @@ class UdpContext
206206
size_t max_size = _rx_buf->len - _rx_buf_offset;
207207
size = (size < max_size) ? size : max_size;
208208
DEBUGV(":urd %d, %d, %d\r\n", size, _rx_buf->len, _rx_buf_offset);
209-
210-
os_memcpy(dst, reinterpret_cast<char*>(_rx_buf->payload) + _rx_buf_offset, size);
209+
210+
memcpy(dst, reinterpret_cast<char*>(_rx_buf->payload) + _rx_buf_offset, size);
211211
_consume(size);
212-
212+
213213
return size;
214214
}
215215

@@ -236,7 +236,7 @@ class UdpContext
236236
{
237237
_reserve(_tx_buf_offset + size);
238238
}
239-
239+
240240
size_t left_to_copy = size;
241241
while(left_to_copy)
242242
{
@@ -249,7 +249,7 @@ class UdpContext
249249
continue;
250250
}
251251
size_t will_copy = (left_to_copy < free_cur) ? left_to_copy : free_cur;
252-
os_memcpy(reinterpret_cast<char*>(_tx_buf_cur->payload) + used_cur, data, will_copy);
252+
memcpy(reinterpret_cast<char*>(_tx_buf_cur->payload) + used_cur, data, will_copy);
253253
_tx_buf_offset += will_copy;
254254
left_to_copy -= will_copy;
255255
data += will_copy;
@@ -259,18 +259,20 @@ class UdpContext
259259

260260
void send(ip_addr_t* addr = 0, uint16_t port = 0)
261261
{
262-
size_t orig_size = _tx_buf_head->tot_len;
263-
264262
size_t data_size = _tx_buf_offset;
265-
size_t size_adjustment = orig_size - data_size;
266-
for (pbuf* p = _tx_buf_head; p; p = p->next)
267-
{
268-
p->tot_len -= size_adjustment;
269-
if (!p->next)
270-
{
271-
p->len = p->tot_len;
272-
}
263+
pbuf* tx_copy = pbuf_alloc(PBUF_TRANSPORT, data_size, PBUF_RAM);
264+
uint8_t* dst = reinterpret_cast<uint8_t*>(tx_copy->payload);
265+
for (pbuf* p = _tx_buf_head; p; p = p->next) {
266+
size_t will_copy = (data_size < p->len) ? data_size : p->len;
267+
memcpy(dst, p->payload, will_copy);
268+
dst += will_copy;
269+
data_size -= will_copy;
273270
}
271+
pbuf_free(_tx_buf_head);
272+
_tx_buf_head = 0;
273+
_tx_buf_cur = 0;
274+
_tx_buf_offset = 0;
275+
274276

275277
if (!addr) {
276278
addr = &_dest_addr;
@@ -282,30 +284,16 @@ class UdpContext
282284
_pcb->ttl = _multicast_ttl;
283285
}
284286

285-
udp_sendto(_pcb, _tx_buf_head, addr, port);
286-
287+
udp_sendto(_pcb, tx_copy, addr, port);
287288
_pcb->ttl = old_ttl;
288-
289-
for (pbuf* p = _tx_buf_head; p; p = p->next)
290-
{
291-
p->tot_len += size_adjustment;
292-
if (!p->next)
293-
{
294-
p->len = p->tot_len;
295-
}
296-
}
297-
298-
pbuf_free(_tx_buf_head);
299-
_tx_buf_head = 0;
300-
_tx_buf_cur = 0;
301-
_tx_buf_offset = 0;
289+
pbuf_free(tx_copy);
302290
}
303291

304292
private:
305293

306294
void _reserve(size_t size)
307295
{
308-
const size_t pbuf_unit_size = 512;
296+
const size_t pbuf_unit_size = 128;
309297
if (!_tx_buf_head)
310298
{
311299
_tx_buf_head = pbuf_alloc(PBUF_TRANSPORT, pbuf_unit_size, PBUF_RAM);
@@ -357,7 +345,7 @@ class UdpContext
357345
}
358346

359347

360-
static void _s_recv(void *arg,
348+
static void _s_recv(void *arg,
361349
udp_pcb *upcb, pbuf *p,
362350
ip_addr_t *addr, u16_t port)
363351
{

0 commit comments

Comments
 (0)