mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-22 21:23:07 +03:00
Merge remote-tracking branch 'remotes/esp8266/master'
This commit is contained in:
commit
44af3d5e89
@ -219,14 +219,12 @@ void loop(void);
|
|||||||
void yield(void);
|
void yield(void);
|
||||||
void optimistic_yield(uint32_t interval_us);
|
void optimistic_yield(uint32_t interval_us);
|
||||||
|
|
||||||
// Get the bit location within the hardware port of the given virtual pin.
|
|
||||||
// This comes from the pins_*.c file for the active board configuration.
|
|
||||||
#define digitalPinToPort(pin) (0)
|
#define digitalPinToPort(pin) (0)
|
||||||
#define digitalPinToBitMask(pin) (1UL << (pin))
|
#define digitalPinToBitMask(pin) (1UL << (pin))
|
||||||
#define digitalPinToTimer(pin) (0)
|
#define digitalPinToTimer(pin) (0)
|
||||||
#define portOutputRegister(port) ((volatile uint32_t*) GPO)
|
#define portOutputRegister(port) ((volatile uint32_t*) &GPO)
|
||||||
#define portInputRegister(port) ((volatile uint32_t*) GPI)
|
#define portInputRegister(port) ((volatile uint32_t*) &GPI)
|
||||||
#define portModeRegister(port) ((volatile uint32_t*) GPE)
|
#define portModeRegister(port) ((volatile uint32_t*) &GPE)
|
||||||
|
|
||||||
#define NOT_A_PIN -1
|
#define NOT_A_PIN -1
|
||||||
#define NOT_A_PORT -1
|
#define NOT_A_PORT -1
|
||||||
|
@ -617,18 +617,15 @@ size_t HardwareSerial::write(uint8_t c) {
|
|||||||
size_t room = uart_get_tx_fifo_room(_uart);
|
size_t room = uart_get_tx_fifo_room(_uart);
|
||||||
if(room > 0 && _tx_buffer->empty()) {
|
if(room > 0 && _tx_buffer->empty()) {
|
||||||
uart_transmit_char(_uart, c);
|
uart_transmit_char(_uart, c);
|
||||||
if(room < 10) {
|
|
||||||
uart_arm_tx_interrupt(_uart);
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(_tx_buffer->room() == 0) {
|
while(_tx_buffer->room() == 0) {
|
||||||
yield();
|
yield();
|
||||||
uart_arm_tx_interrupt(_uart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_tx_buffer->write(c);
|
_tx_buffer->write(c);
|
||||||
|
uart_arm_tx_interrupt(_uart);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,10 @@ void __throw_length_error(char const*) {
|
|||||||
void __throw_bad_alloc() {
|
void __throw_bad_alloc() {
|
||||||
panic();
|
panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void __throw_logic_error(const char* str) {
|
||||||
|
panic();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: rebuild windows toolchain to make this unnecessary:
|
// TODO: rebuild windows toolchain to make this unnecessary:
|
||||||
|
@ -42,9 +42,6 @@ class cbuf {
|
|||||||
if(_end >= _begin) {
|
if(_end >= _begin) {
|
||||||
return _size - (_end - _begin) - 1;
|
return _size - (_end - _begin) - 1;
|
||||||
}
|
}
|
||||||
if(_begin == _end) {
|
|
||||||
return _size;
|
|
||||||
}
|
|
||||||
return _begin - _end - 1;
|
return _begin - _end - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +59,7 @@ class cbuf {
|
|||||||
if(getSize() == 0) return -1;
|
if(getSize() == 0) return -1;
|
||||||
|
|
||||||
char result = *_begin;
|
char result = *_begin;
|
||||||
if(++_begin == _bufend) _begin = _buf;
|
_begin = wrap_if_bufend(_begin + 1);
|
||||||
return static_cast<int>(result);
|
return static_cast<int>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +75,7 @@ class cbuf {
|
|||||||
dst += top_size;
|
dst += top_size;
|
||||||
}
|
}
|
||||||
memcpy(dst, _begin, size_to_read);
|
memcpy(dst, _begin, size_to_read);
|
||||||
_begin += size_to_read;
|
_begin = wrap_if_bufend(_begin + size_to_read);
|
||||||
if(_begin == _bufend) _begin = _buf;
|
|
||||||
return size_read;
|
return size_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +83,7 @@ class cbuf {
|
|||||||
if(room() == 0) return 0;
|
if(room() == 0) return 0;
|
||||||
|
|
||||||
*_end = c;
|
*_end = c;
|
||||||
if(++_end == _bufend) _end = _buf;
|
_end = wrap_if_bufend(_end + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,8 +99,7 @@ class cbuf {
|
|||||||
src += top_size;
|
src += top_size;
|
||||||
}
|
}
|
||||||
memcpy(_end, src, size_to_write);
|
memcpy(_end, src, size_to_write);
|
||||||
_end += size_to_write;
|
_end = wrap_if_bufend(_end + size_to_write);
|
||||||
if(_end == _bufend) _end = _buf;
|
|
||||||
return size_written;
|
return size_written;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,6 +109,10 @@ class cbuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline char* wrap_if_bufend(char* ptr) {
|
||||||
|
return (ptr == _bufend) ? _buf : ptr;
|
||||||
|
}
|
||||||
|
|
||||||
size_t _size;
|
size_t _size;
|
||||||
char* _buf;
|
char* _buf;
|
||||||
char* _bufend;
|
char* _bufend;
|
||||||
|
@ -78,7 +78,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
|
|||||||
(__extension__({ \
|
(__extension__({ \
|
||||||
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
|
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
|
||||||
ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \
|
ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \
|
||||||
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset); \
|
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local)-__offset); \
|
||||||
uint8_t __result = ((*__addr32) >> (__offset * 8)); \
|
uint8_t __result = ((*__addr32) >> (__offset * 8)); \
|
||||||
__result; \
|
__result; \
|
||||||
}))
|
}))
|
||||||
@ -87,7 +87,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
|
|||||||
(__extension__({ \
|
(__extension__({ \
|
||||||
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
|
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
|
||||||
ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \
|
ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \
|
||||||
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local) - __offset); \
|
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local) - __offset); \
|
||||||
uint16_t __result = ((*__addr32) >> (__offset * 8)); \
|
uint16_t __result = ((*__addr32) >> (__offset * 8)); \
|
||||||
__result; \
|
__result; \
|
||||||
}))
|
}))
|
||||||
|
@ -71,7 +71,14 @@ void loop() {
|
|||||||
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
|
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
|
||||||
"Host: " + host + "\r\n" +
|
"Host: " + host + "\r\n" +
|
||||||
"Connection: close\r\n\r\n");
|
"Connection: close\r\n\r\n");
|
||||||
delay(10);
|
int timeout = millis() + 5000;
|
||||||
|
while (client.available() == 0) {
|
||||||
|
if (timeout - millis() < 0) {
|
||||||
|
Serial.println(">>> Client Timeout !");
|
||||||
|
client.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Read all the lines of the reply from server and print them to Serial
|
// Read all the lines of the reply from server and print them to Serial
|
||||||
while(client.available()){
|
while(client.available()){
|
||||||
|
@ -207,7 +207,7 @@ public:
|
|||||||
size = (size < max_size) ? size : max_size;
|
size = (size < max_size) ? size : max_size;
|
||||||
DEBUGV(":urd %d, %d, %d\r\n", size, _rx_buf->len, _rx_buf_offset);
|
DEBUGV(":urd %d, %d, %d\r\n", size, _rx_buf->len, _rx_buf_offset);
|
||||||
|
|
||||||
os_memcpy(dst, reinterpret_cast<char*>(_rx_buf->payload) + _rx_buf_offset, size);
|
memcpy(dst, reinterpret_cast<char*>(_rx_buf->payload) + _rx_buf_offset, size);
|
||||||
_consume(size);
|
_consume(size);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
@ -249,7 +249,7 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
size_t will_copy = (left_to_copy < free_cur) ? left_to_copy : free_cur;
|
size_t will_copy = (left_to_copy < free_cur) ? left_to_copy : free_cur;
|
||||||
os_memcpy(reinterpret_cast<char*>(_tx_buf_cur->payload) + used_cur, data, will_copy);
|
memcpy(reinterpret_cast<char*>(_tx_buf_cur->payload) + used_cur, data, will_copy);
|
||||||
_tx_buf_offset += will_copy;
|
_tx_buf_offset += will_copy;
|
||||||
left_to_copy -= will_copy;
|
left_to_copy -= will_copy;
|
||||||
data += will_copy;
|
data += will_copy;
|
||||||
@ -259,18 +259,20 @@ public:
|
|||||||
|
|
||||||
void send(ip_addr_t* addr = 0, uint16_t port = 0)
|
void send(ip_addr_t* addr = 0, uint16_t port = 0)
|
||||||
{
|
{
|
||||||
size_t orig_size = _tx_buf_head->tot_len;
|
|
||||||
|
|
||||||
size_t data_size = _tx_buf_offset;
|
size_t data_size = _tx_buf_offset;
|
||||||
size_t size_adjustment = orig_size - data_size;
|
pbuf* tx_copy = pbuf_alloc(PBUF_TRANSPORT, data_size, PBUF_RAM);
|
||||||
for (pbuf* p = _tx_buf_head; p; p = p->next)
|
uint8_t* dst = reinterpret_cast<uint8_t*>(tx_copy->payload);
|
||||||
{
|
for (pbuf* p = _tx_buf_head; p; p = p->next) {
|
||||||
p->tot_len -= size_adjustment;
|
size_t will_copy = (data_size < p->len) ? data_size : p->len;
|
||||||
if (!p->next)
|
memcpy(dst, p->payload, will_copy);
|
||||||
{
|
dst += will_copy;
|
||||||
p->len = p->tot_len;
|
data_size -= will_copy;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
pbuf_free(_tx_buf_head);
|
||||||
|
_tx_buf_head = 0;
|
||||||
|
_tx_buf_cur = 0;
|
||||||
|
_tx_buf_offset = 0;
|
||||||
|
|
||||||
|
|
||||||
if (!addr) {
|
if (!addr) {
|
||||||
addr = &_dest_addr;
|
addr = &_dest_addr;
|
||||||
@ -282,30 +284,16 @@ public:
|
|||||||
_pcb->ttl = _multicast_ttl;
|
_pcb->ttl = _multicast_ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
udp_sendto(_pcb, _tx_buf_head, addr, port);
|
udp_sendto(_pcb, tx_copy, addr, port);
|
||||||
|
|
||||||
_pcb->ttl = old_ttl;
|
_pcb->ttl = old_ttl;
|
||||||
|
pbuf_free(tx_copy);
|
||||||
for (pbuf* p = _tx_buf_head; p; p = p->next)
|
|
||||||
{
|
|
||||||
p->tot_len += size_adjustment;
|
|
||||||
if (!p->next)
|
|
||||||
{
|
|
||||||
p->len = p->tot_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pbuf_free(_tx_buf_head);
|
|
||||||
_tx_buf_head = 0;
|
|
||||||
_tx_buf_cur = 0;
|
|
||||||
_tx_buf_offset = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void _reserve(size_t size)
|
void _reserve(size_t size)
|
||||||
{
|
{
|
||||||
const size_t pbuf_unit_size = 512;
|
const size_t pbuf_unit_size = 128;
|
||||||
if (!_tx_buf_head)
|
if (!_tx_buf_head)
|
||||||
{
|
{
|
||||||
_tx_buf_head = pbuf_alloc(PBUF_TRANSPORT, pbuf_unit_size, PBUF_RAM);
|
_tx_buf_head = pbuf_alloc(PBUF_TRANSPORT, pbuf_unit_size, PBUF_RAM);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user