mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-07 06:01:35 +03:00
Update SDK to 2.0.0
- Update SDK header files and libraries to SDK 2.0.0 plus 2.0.0_16_08_09 patch - Remove mem_manager.o from libmain.a (replaced with umm_malloc) - Disable switch from DIO to QIO mode for certain flash chips (saves IRAM space) - Add user_rf_cal_sector_set; it points to rf_init_data sector. - Change the way rf_init_data is spoofed. This is now done by wrapping spi_flash_read and returning the data we need during startup sequence. - Place lwip library into flash using linker script instead of section attributes (saves IRAM space)
This commit is contained in:
committed by
Ivan Grokhotkov
parent
61787b23af
commit
ae13809c81
@ -92,10 +92,12 @@ void ICACHE_FLASH_ATTR node_remove_from_list(list_node **phead, list_node* pdele
|
||||
} else {
|
||||
if (plist == pdelete){
|
||||
*phead = plist->pnext;
|
||||
pdelete->pnext = NULL;
|
||||
} else {
|
||||
while (plist != NULL) {
|
||||
if (plist->pnext == pdelete){
|
||||
plist->pnext = pdelete->pnext;
|
||||
pdelete->pnext = NULL;
|
||||
}
|
||||
plist = plist->pnext;
|
||||
}
|
||||
@ -269,7 +271,10 @@ static void ICACHE_FLASH_ATTR create_msg(struct dhcps_msg *m)
|
||||
os_memset((char *) m->file, 0, sizeof(m->file));
|
||||
|
||||
os_memset((char *) m->options, 0, sizeof(m->options));
|
||||
os_memcpy((char *) m->options, &magic_cookie, sizeof(magic_cookie));
|
||||
|
||||
//For xiaomi crash bug
|
||||
uint32 magic_cookie1 = magic_cookie;
|
||||
os_memcpy((char *) m->options, &magic_cookie1, sizeof(magic_cookie1));
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
@ -760,11 +765,18 @@ void ICACHE_FLASH_ATTR dhcps_stop(void)
|
||||
//udp_remove(pcb_dhcps);
|
||||
list_node *pnode = NULL;
|
||||
list_node *pback_node = NULL;
|
||||
struct dhcps_pool* dhcp_node = NULL;
|
||||
struct ip_addr ip_zero;
|
||||
|
||||
os_memset(&ip_zero,0x0,sizeof(ip_zero));
|
||||
pnode = plist;
|
||||
while (pnode != NULL) {
|
||||
pback_node = pnode;
|
||||
pnode = pback_node->pnext;
|
||||
node_remove_from_list(&plist, pback_node);
|
||||
dhcp_node = (struct dhcps_pool*)pback_node->pnode;
|
||||
//wifi_softap_dhcps_client_leave(dhcp_node->mac,&dhcp_node->ip,TRUE); // force to delete
|
||||
wifi_softap_set_station_info(dhcp_node->mac, &ip_zero);
|
||||
os_free(pback_node->pnode);
|
||||
pback_node->pnode = NULL;
|
||||
os_free(pback_node);
|
||||
@ -1077,10 +1089,10 @@ uint32 ICACHE_FLASH_ATTR wifi_softap_dhcps_client_update(u8 *bssid, struct ip_ad
|
||||
return IPADDR_ANY;
|
||||
}
|
||||
} else {
|
||||
if (start_ip == end_ip) {
|
||||
if (start_ip > end_ip) {
|
||||
return IPADDR_ANY;
|
||||
}
|
||||
start_ip = htonl((ntohl(start_ip) + 1));
|
||||
//start_ip = htonl((ntohl(start_ip) + 1));
|
||||
flag = TRUE;
|
||||
}
|
||||
}
|
||||
@ -1096,6 +1108,8 @@ uint32 ICACHE_FLASH_ATTR wifi_softap_dhcps_client_update(u8 *bssid, struct ip_ad
|
||||
|
||||
// mac exists and ip exists in other node,delete mac
|
||||
node_remove_from_list(&plist,pmac_node);
|
||||
os_free(pmac_node->pnode);
|
||||
pmac_node->pnode = NULL;
|
||||
os_free(pmac_node);
|
||||
pmac_node = pip_node;
|
||||
os_memcpy(pdhcps_pool->mac, bssid, sizeof(pdhcps_pool->mac));
|
||||
@ -1144,6 +1158,10 @@ uint32 ICACHE_FLASH_ATTR wifi_softap_dhcps_client_update(u8 *bssid, struct ip_ad
|
||||
os_free(pdhcps_pool);
|
||||
return IPADDR_ANY;
|
||||
}
|
||||
if (pdhcps_pool->ip.addr > end_ip) {
|
||||
os_free(pdhcps_pool);
|
||||
return IPADDR_ANY;
|
||||
}
|
||||
os_memcpy(pdhcps_pool->mac, bssid, sizeof(pdhcps_pool->mac));
|
||||
pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER;
|
||||
pdhcps_pool->type = type;
|
||||
|
@ -35,6 +35,8 @@ remot_info premot[linkMax];
|
||||
|
||||
struct espconn_packet pktinfo[2];
|
||||
|
||||
void espconn_init(void);
|
||||
|
||||
static uint8 espconn_tcp_get_buf_count(espconn_buf *pesp_buf);
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_copy_partial
|
||||
@ -266,6 +268,8 @@ espconn_connect(struct espconn *espconn)
|
||||
espconn_msg *plist = NULL;
|
||||
remot_info *pinfo = NULL;
|
||||
|
||||
volatile int tmp = (int) espconn_init;
|
||||
|
||||
if (espconn == NULL) {
|
||||
return ESPCONN_ARG;
|
||||
} else if (espconn ->type != ESPCONN_TCP)
|
||||
@ -336,6 +340,8 @@ espconn_create(struct espconn *espconn)
|
||||
sint8 value = ESPCONN_OK;
|
||||
espconn_msg *plist = NULL;
|
||||
|
||||
volatile int tmp = (int) espconn_init;
|
||||
|
||||
if (espconn == NULL) {
|
||||
return ESPCONN_ARG;
|
||||
} else if (espconn ->type != ESPCONN_UDP){
|
||||
@ -436,6 +442,39 @@ espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length)
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
sint16 ICACHE_FLASH_ATTR espconn_recv(struct espconn *espconn, void *mem, size_t len)
|
||||
{
|
||||
espconn_msg *pnode = NULL;
|
||||
bool value = false;
|
||||
int bytes_used = 0;
|
||||
if (espconn == NULL || mem == NULL || len == 0)
|
||||
return ESPCONN_ARG;
|
||||
|
||||
/*Find the node depend on the espconn message*/
|
||||
value = espconn_find_connection(espconn, &pnode);
|
||||
if (value && espconn->type == ESPCONN_TCP){
|
||||
if (pnode->readbuf != NULL){
|
||||
bytes_used = ringbuf_bytes_used(pnode->readbuf);
|
||||
if (bytes_used != 0) {
|
||||
if (len > bytes_used) {
|
||||
len = bytes_used;
|
||||
}
|
||||
ringbuf_memcpy_from(mem, pnode->readbuf, len);
|
||||
espconn_recv_unhold(pnode->pespconn);
|
||||
return len;
|
||||
} else {
|
||||
return ESPCONN_OK;
|
||||
}
|
||||
} else{
|
||||
return ESPCONN_OK;
|
||||
}
|
||||
} else{
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_sendto
|
||||
* Description : send data for UDP
|
||||
@ -877,6 +916,8 @@ espconn_accept(struct espconn *espconn)
|
||||
sint8 value = ESPCONN_OK;
|
||||
espconn_msg *plist = NULL;
|
||||
|
||||
volatile int tmp = (int) espconn_init;
|
||||
|
||||
if (espconn == NULL) {
|
||||
return ESPCONN_ARG;
|
||||
} else if (espconn ->type != ESPCONN_TCP)
|
||||
|
205
tools/sdk/lwip/src/app/espconn_buf.c
Normal file
205
tools/sdk/lwip/src/app/espconn_buf.c
Normal file
@ -0,0 +1,205 @@
|
||||
/*
|
||||
* espconn_buf.c
|
||||
*
|
||||
* Created on: May 25, 2016
|
||||
* Author: liuhan
|
||||
*/
|
||||
|
||||
#include "lwip/memp.h"
|
||||
#include "lwip/def.h"
|
||||
#include "ets_sys.h"
|
||||
#include "os_type.h"
|
||||
#include "lwip/app/espconn_buf.h"
|
||||
|
||||
|
||||
#ifdef MEMLEAK_DEBUG
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
#if (!defined(lwIP_unlikely))
|
||||
#define lwIP_unlikely(Expression) !!(Expression)
|
||||
#endif
|
||||
|
||||
#define lwIP_ASSERT(Expression) do{if(!(Expression)) {os_printf("%s %d\n", __func__, __LINE__);return;}}while(0)
|
||||
|
||||
ringbuf_t ringbuf_new(size_t capacity)
|
||||
{
|
||||
ringbuf_t rb = (ringbuf_t)os_zalloc(sizeof(struct ringbuf_t));
|
||||
if (rb){
|
||||
rb->size = capacity + 1;
|
||||
rb->buf = (uint8*)os_zalloc(rb->size);
|
||||
if (rb->buf){
|
||||
ringbuf_reset(rb);
|
||||
}else{
|
||||
os_free(rb);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return rb;
|
||||
}
|
||||
|
||||
size_t ringbuf_buffer_size(const struct ringbuf_t *rb)
|
||||
{
|
||||
return rb->size;
|
||||
}
|
||||
|
||||
void ringbuf_reset(ringbuf_t rb)
|
||||
{
|
||||
rb ->head = rb->tail = rb->buf;
|
||||
}
|
||||
|
||||
void ringbuf_free(ringbuf_t *rb)
|
||||
{
|
||||
lwIP_ASSERT(rb && *rb);
|
||||
os_free((*rb)->buf);
|
||||
os_free(*rb);
|
||||
*rb = NULL;
|
||||
}
|
||||
|
||||
size_t ringbuf_capacity(const struct ringbuf_t *rb)
|
||||
{
|
||||
return ringbuf_buffer_size(rb) - 1;
|
||||
}
|
||||
|
||||
static const uint8_t* ringbuf_end(const struct ringbuf_t *rb)
|
||||
{
|
||||
return rb->buf + ringbuf_buffer_size(rb);
|
||||
}
|
||||
|
||||
size_t ringbuf_bytes_free(const struct ringbuf_t *rb)
|
||||
{
|
||||
if (rb->head >= rb->tail){
|
||||
return ringbuf_capacity(rb) - (rb->head - rb->tail);
|
||||
}else{
|
||||
return rb->tail - rb->head -1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ringbuf_bytes_used(const struct ringbuf_t *rb)
|
||||
{
|
||||
return ringbuf_capacity(rb) - ringbuf_bytes_free(rb);
|
||||
}
|
||||
|
||||
int ringbuf_is_full(const struct ringbuf_t *rb)
|
||||
{
|
||||
return ringbuf_bytes_free(rb) == 0;
|
||||
}
|
||||
|
||||
int ringbuf_is_empty(const struct ringbuf_t *rb)
|
||||
{
|
||||
return ringbuf_bytes_free(rb) == ringbuf_capacity(rb);
|
||||
}
|
||||
|
||||
const void* ringbuf_tail(const struct ringbuf_t *rb)
|
||||
{
|
||||
return rb->tail;
|
||||
}
|
||||
const void* ringbuf_head(const struct ringbuf_t *rb)
|
||||
{
|
||||
return rb->head;
|
||||
}
|
||||
|
||||
static uint8_t *ringbuf_nextp(ringbuf_t rb, const uint8_t *p)
|
||||
{
|
||||
lwIP_ASSERT((p >= rb->buf) && (p < ringbuf_end(rb)));
|
||||
return rb->buf + ((++p -rb->buf) % ringbuf_buffer_size(rb));
|
||||
}
|
||||
|
||||
size_t ringbuf_findchr(const struct ringbuf_t *rb, int c, size_t offset)
|
||||
{
|
||||
const uint8_t *bufend = ringbuf_end(rb);
|
||||
size_t bytes_used = ringbuf_bytes_used(rb);
|
||||
if (offset >= bytes_used)
|
||||
return bytes_used;
|
||||
|
||||
const uint8_t *start = rb ->buf + (((rb->tail - rb->buf) + offset) % ringbuf_buffer_size(rb));
|
||||
lwIP_ASSERT(bufend > start);
|
||||
size_t n = LWIP_MIN(bufend - start, bytes_used - offset);
|
||||
const uint8_t *found = (const uint8_t *)memchr(start, c, n);
|
||||
if (found)
|
||||
return offset + (found - start);
|
||||
else
|
||||
return ringbuf_findchr(rb, c, offset + n);
|
||||
}
|
||||
|
||||
size_t ringbuf_memset(ringbuf_t dst, int c, size_t len)
|
||||
{
|
||||
const uint8_t *bufend = ringbuf_end(dst);
|
||||
size_t nwritten = 0;
|
||||
size_t count = LWIP_MIN(len, ringbuf_buffer_size(dst));
|
||||
int overflow = count > ringbuf_bytes_free(dst);
|
||||
|
||||
while (nwritten != count){
|
||||
|
||||
lwIP_ASSERT(bufend > dst->head);
|
||||
size_t n = LWIP_MIN(bufend - dst->head, count - nwritten);
|
||||
os_memset(dst->head, c, n);
|
||||
dst->head += n;
|
||||
nwritten += n;
|
||||
|
||||
if (dst->head == bufend)
|
||||
dst->head = dst->buf;
|
||||
}
|
||||
|
||||
if (overflow){
|
||||
dst->tail = ringbuf_nextp(dst, dst->head);
|
||||
lwIP_ASSERT(ringbuf_is_full(dst));
|
||||
}
|
||||
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
void *ringbuf_memcpy_into(ringbuf_t dst,const void *src, size_t count)
|
||||
{
|
||||
const uint8_t *u8src = src;
|
||||
const uint8_t *bufend = ringbuf_end(dst);
|
||||
int overflow = count > ringbuf_bytes_free(dst);
|
||||
size_t nread = 0;
|
||||
|
||||
while (nread != count){
|
||||
lwIP_ASSERT(bufend > dst->head);
|
||||
size_t n = LWIP_MIN(bufend - dst->head, count - nread);
|
||||
os_memcpy(dst->head, u8src + nread, n);
|
||||
dst->head += n;
|
||||
nread += n;
|
||||
|
||||
if (dst->head == bufend)
|
||||
dst->head = dst->buf;
|
||||
}
|
||||
|
||||
if (overflow) {
|
||||
dst->tail = ringbuf_nextp(dst, dst->head);
|
||||
lwIP_ASSERT(ringbuf_is_full(dst));
|
||||
}
|
||||
|
||||
return dst->head;
|
||||
}
|
||||
|
||||
void *ringbuf_memcpy_from(void *dst,ringbuf_t src, size_t count)
|
||||
{
|
||||
size_t bytes_used = ringbuf_bytes_used(src);
|
||||
|
||||
if (count > bytes_used)
|
||||
return NULL;
|
||||
|
||||
const uint8_t *u8dst = dst;
|
||||
const uint8_t *bufend = ringbuf_end(src);
|
||||
size_t nwritten = 0;
|
||||
|
||||
while (nwritten != count){
|
||||
lwIP_ASSERT(bufend > src->tail);
|
||||
size_t n = LWIP_MIN(bufend - src->tail, count - nwritten);
|
||||
os_memcpy((uint8_t*)u8dst + nwritten, src->tail, n);
|
||||
src->tail += n;
|
||||
nwritten += n;
|
||||
|
||||
if (src->tail == bufend)
|
||||
src->tail = src->buf;
|
||||
}
|
||||
|
||||
lwIP_ASSERT(count + ringbuf_bytes_used(src) == bytes_used);
|
||||
return src->tail;
|
||||
}
|
||||
|
||||
|
||||
|
@ -239,6 +239,10 @@ void ICACHE_FLASH_ATTR espconn_tcp_memp_free(espconn_msg *pmemp)
|
||||
os_free(pmemp->pespconn);
|
||||
pmemp->pespconn = NULL;
|
||||
}
|
||||
|
||||
if (pmemp->readbuf != NULL){
|
||||
ringbuf_free(&pmemp->readbuf);
|
||||
}
|
||||
os_free(pmemp);
|
||||
pmemp = NULL;
|
||||
}
|
||||
@ -397,34 +401,46 @@ espconn_tcp_disconnect_successful(void *arg)
|
||||
static void ICACHE_FLASH_ATTR
|
||||
espconn_Task(os_event_t *events)
|
||||
{
|
||||
espconn_msg *plist = NULL;
|
||||
bool active_flag = false;
|
||||
espconn_msg *task_msg = NULL;
|
||||
struct espconn *pespconn = NULL;
|
||||
|
||||
task_msg = (espconn_msg *) events->par;
|
||||
switch (events->sig) {
|
||||
case SIG_ESPCONN_WRITE: {
|
||||
pespconn = task_msg->pespconn;
|
||||
if (pespconn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pespconn->proto.tcp->write_finish_fn != NULL) {
|
||||
pespconn->proto.tcp->write_finish_fn(pespconn);
|
||||
}
|
||||
/*find the active connection node*/
|
||||
for (plist = plink_active; plist != NULL; plist = plist->pnext){
|
||||
if (task_msg == plist) {
|
||||
active_flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (active_flag){
|
||||
switch (events->sig) {
|
||||
case SIG_ESPCONN_WRITE: {
|
||||
pespconn = task_msg->pespconn;
|
||||
if (pespconn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pespconn->proto.tcp->write_finish_fn != NULL) {
|
||||
pespconn->proto.tcp->write_finish_fn(pespconn);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SIG_ESPCONN_ERRER:
|
||||
/*remove the node from the client's active connection list*/
|
||||
espconn_list_delete(&plink_active, task_msg);
|
||||
espconn_tcp_reconnect(task_msg);
|
||||
break;
|
||||
case SIG_ESPCONN_CLOSE:
|
||||
/*remove the node from the client's active connection list*/
|
||||
espconn_list_delete(&plink_active, task_msg);
|
||||
espconn_tcp_disconnect_successful(task_msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SIG_ESPCONN_ERRER:
|
||||
/*remove the node from the client's active connection list*/
|
||||
espconn_list_delete(&plink_active, task_msg);
|
||||
espconn_tcp_reconnect(task_msg);
|
||||
break;
|
||||
case SIG_ESPCONN_CLOSE:
|
||||
/*remove the node from the client's active connection list*/
|
||||
espconn_list_delete(&plink_active, task_msg);
|
||||
espconn_tcp_disconnect_successful(task_msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -478,9 +494,13 @@ espconn_tcp_sent(void *arg, uint8 *psent, uint16 length)
|
||||
err = tcp_write(pcb, psent, len, 0);
|
||||
|
||||
if (err == ERR_MEM) {
|
||||
len /= 2;
|
||||
if(len < 3)
|
||||
len--;
|
||||
else
|
||||
len /= 2;
|
||||
}
|
||||
} while (err == ERR_MEM && len > 1);
|
||||
|
||||
} while (err == ERR_MEM && len > 0);
|
||||
|
||||
/*Find out what we can send and send it, offset the buffer point for next send*/
|
||||
if (err == ERR_OK) {
|
||||
@ -615,7 +635,37 @@ espconn_recv_unhold(struct espconn *pespconn)
|
||||
}
|
||||
|
||||
//***********Code for WIFI_BLOCK from upper**************
|
||||
sint8 ICACHE_FLASH_ATTR
|
||||
espconn_lock_recv(espconn_msg *plockmsg)
|
||||
{
|
||||
if (plockmsg == NULL || plockmsg->pespconn == NULL) {
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
if (plockmsg->pespconn->recv_callback == NULL){
|
||||
if (plockmsg->readbuf == NULL){
|
||||
plockmsg->readbuf = ringbuf_new(TCP_WND);
|
||||
if (plockmsg->readbuf == NULL)
|
||||
return ESPCONN_MEM;
|
||||
}
|
||||
return espconn_recv_hold(plockmsg->pespconn);
|
||||
}
|
||||
|
||||
return ESPCONN_OK;
|
||||
}
|
||||
|
||||
sint8 ICACHE_FLASH_ATTR
|
||||
espconn_unlock_recv(espconn_msg *punlockmsg)
|
||||
{
|
||||
if (punlockmsg == NULL || punlockmsg->pespconn == NULL) {
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
if (punlockmsg->pespconn->recv_callback != NULL)
|
||||
return espconn_recv_unhold(punlockmsg->pespconn);
|
||||
|
||||
return ESPCONN_OK;
|
||||
}
|
||||
/******************************************************************************
|
||||
* FunctionName : espconn_client_recv
|
||||
* Description : Data has been received on this pcb.
|
||||
@ -631,6 +681,8 @@ espconn_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||
espconn_msg *precv_cb = arg;
|
||||
|
||||
tcp_arg(pcb, arg);
|
||||
/*lock the window because of application layer don't need the data*/
|
||||
espconn_lock_recv(precv_cb);
|
||||
|
||||
if (p != NULL) {
|
||||
/*To update and advertise a larger window*/
|
||||
@ -640,30 +692,38 @@ espconn_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||
precv_cb->recv_holded_buf_Len += p->tot_len;
|
||||
}
|
||||
|
||||
if (err == ERR_OK && p != NULL) {
|
||||
char *pdata = NULL;
|
||||
u16_t length = 0;
|
||||
/*Copy the contents of a packet buffer to an application buffer.
|
||||
*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
pdata = (char *)os_zalloc(p ->tot_len + 1);
|
||||
length = pbuf_copy_partial(p, pdata, p ->tot_len, 0);
|
||||
pbuf_free(p);
|
||||
if (precv_cb->pespconn->recv_callback != NULL){
|
||||
if (err == ERR_OK && p != NULL) {
|
||||
char *pdata = NULL;
|
||||
u16_t length = 0;
|
||||
/*Copy the contents of a packet buffer to an application buffer.
|
||||
*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
pdata = (char *)os_zalloc(p ->tot_len + 1);
|
||||
length = pbuf_copy_partial(p, pdata, p ->tot_len, 0);
|
||||
pbuf_free(p);
|
||||
|
||||
if (length != 0) {
|
||||
/*switch the state of espconn for application process*/
|
||||
precv_cb->pespconn ->state = ESPCONN_READ;
|
||||
precv_cb->pcommon.pcb = pcb;
|
||||
if (precv_cb->pespconn->recv_callback != NULL) {
|
||||
precv_cb->pespconn->recv_callback(precv_cb->pespconn, pdata, length);
|
||||
}
|
||||
/*switch the state of espconn for next packet copy*/
|
||||
if (pcb->state == ESTABLISHED)
|
||||
precv_cb->pespconn ->state = ESPCONN_CONNECT;
|
||||
}
|
||||
if (length != 0) {
|
||||
/*switch the state of espconn for application process*/
|
||||
precv_cb->pespconn ->state = ESPCONN_READ;
|
||||
precv_cb->pcommon.pcb = pcb;
|
||||
precv_cb->pespconn->recv_callback(precv_cb->pespconn, pdata, length);
|
||||
|
||||
/*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
os_free(pdata);
|
||||
pdata = NULL;
|
||||
/*switch the state of espconn for next packet copy*/
|
||||
if (pcb->state == ESTABLISHED)
|
||||
precv_cb->pespconn ->state = ESPCONN_CONNECT;
|
||||
}
|
||||
|
||||
/*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
os_free(pdata);
|
||||
pdata = NULL;
|
||||
}
|
||||
} else{
|
||||
/*unregister receive function*/
|
||||
struct pbuf *pthis = NULL;
|
||||
for (pthis = p; pthis != NULL; pthis = pthis->next) {
|
||||
ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
|
||||
pbuf_free(pthis);
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ERR_OK && p == NULL) {
|
||||
@ -877,6 +937,8 @@ espconn_client_connect(void *arg, struct tcp_pcb *tpcb, err_t err)
|
||||
if (espconn_keepalive_disabled(pcon))
|
||||
espconn_keepalive_enable(tpcb);
|
||||
|
||||
// /*lock the window because of application layer don't need the data*/
|
||||
// espconn_lock_recv(pcon);
|
||||
} else{
|
||||
os_printf("err in host connected (%s)\n",lwip_strerr(err));
|
||||
}
|
||||
@ -1015,6 +1077,9 @@ espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||
|
||||
tcp_arg(pcb, arg);
|
||||
espconn_printf("server has application data received: %d\n", system_get_free_heap_size());
|
||||
/*lock the window because of application layer don't need the data*/
|
||||
espconn_lock_recv(precv_cb);
|
||||
|
||||
if (p != NULL) {
|
||||
/*To update and advertise a larger window*/
|
||||
if(precv_cb->recv_hold_flag == 0)
|
||||
@ -1023,42 +1088,47 @@ espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||
precv_cb->recv_holded_buf_Len += p->tot_len;
|
||||
}
|
||||
|
||||
if (err == ERR_OK && p != NULL) {
|
||||
u8_t *data_ptr = NULL;
|
||||
u32_t data_cntr = 0;
|
||||
/*clear the count for connection timeout*/
|
||||
precv_cb->pcommon.recv_check = 0;
|
||||
/*Copy the contents of a packet buffer to an application buffer.
|
||||
*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
data_ptr = (u8_t *)os_zalloc(p ->tot_len + 1);
|
||||
data_cntr = pbuf_copy_partial(p, data_ptr, p ->tot_len, 0);
|
||||
pbuf_free(p);
|
||||
/*register receive function*/
|
||||
if (precv_cb->pespconn->recv_callback != NULL) {
|
||||
if (err == ERR_OK && p != NULL) {
|
||||
u8_t *data_ptr = NULL;
|
||||
u32_t data_cntr = 0;
|
||||
/*clear the count for connection timeout*/
|
||||
precv_cb->pcommon.recv_check = 0;
|
||||
/*Copy the contents of a packet buffer to an application buffer.
|
||||
*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
data_ptr = (u8_t *) os_zalloc(p ->tot_len + 1);
|
||||
data_cntr = pbuf_copy_partial(p, data_ptr, p->tot_len, 0);
|
||||
pbuf_free(p);
|
||||
|
||||
if (data_cntr != 0) {
|
||||
/*switch the state of espconn for application process*/
|
||||
precv_cb->pespconn ->state = ESPCONN_READ;
|
||||
precv_cb->pcommon.pcb = pcb;
|
||||
if (precv_cb->pespconn->recv_callback != NULL) {
|
||||
precv_cb->pespconn->recv_callback(precv_cb->pespconn, data_ptr, data_cntr);
|
||||
}
|
||||
if (data_cntr != 0) {
|
||||
/*switch the state of espconn for application process*/
|
||||
precv_cb->pespconn->state = ESPCONN_READ;
|
||||
precv_cb->pcommon.pcb = pcb;
|
||||
precv_cb->pespconn->recv_callback(precv_cb->pespconn, data_ptr, data_cntr);
|
||||
|
||||
/*switch the state of espconn for next packet copy*/
|
||||
if (pcb->state == ESTABLISHED)
|
||||
precv_cb->pespconn ->state = ESPCONN_CONNECT;
|
||||
}
|
||||
/*switch the state of espconn for next packet copy*/
|
||||
if (pcb->state == ESTABLISHED)
|
||||
precv_cb->pespconn->state = ESPCONN_CONNECT;
|
||||
}
|
||||
|
||||
/*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
os_free(data_ptr);
|
||||
data_ptr = NULL;
|
||||
espconn_printf("server's application data has been processed: %d\n", system_get_free_heap_size());
|
||||
} else {
|
||||
if (p != NULL) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
espconn_server_close(precv_cb, pcb,0);
|
||||
}
|
||||
/*to prevent memory leaks, ensure that each allocated is deleted*/
|
||||
os_free(data_ptr);
|
||||
data_ptr = NULL;
|
||||
espconn_printf("server's application data has been processed: %d\n", system_get_free_heap_size());
|
||||
}
|
||||
} else {
|
||||
/*unregister receive function*/
|
||||
struct pbuf *pthis = NULL;
|
||||
for (pthis = p; pthis != NULL; pthis = pthis->next) {
|
||||
ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
|
||||
pbuf_free(pthis);
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ERR_OK && p == NULL) {
|
||||
espconn_server_close(precv_cb, pcb, 0);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
@ -1292,6 +1362,8 @@ espconn_tcp_accept(void *arg, struct tcp_pcb *pcb, err_t err)
|
||||
if (espconn_keepalive_disabled(paccept))
|
||||
espconn_keepalive_enable(pcb);
|
||||
|
||||
// /*lock the window because of application layer don't need the data*/
|
||||
// espconn_lock_recv(paccept);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -94,8 +94,8 @@ espconn_udp_sent(void *arg, uint8 *psent, uint16 length)
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
if (1470 < length) {
|
||||
datalen = 1470;
|
||||
if ((IP_FRAG_MAX_MTU - 20 - 8) < length) {
|
||||
datalen = IP_FRAG_MAX_MTU - 20 - 8;
|
||||
} else {
|
||||
datalen = length;
|
||||
}
|
||||
@ -200,8 +200,8 @@ espconn_udp_sendto(void *arg, uint8 *psent, uint16 length)
|
||||
return ESPCONN_ARG;
|
||||
}
|
||||
|
||||
if (1470 < length) {
|
||||
datalen = 1470;
|
||||
if ((IP_FRAG_MAX_MTU - 20 - 8) < length) {
|
||||
datalen = IP_FRAG_MAX_MTU - 20 - 8;
|
||||
} else {
|
||||
datalen = length;
|
||||
}
|
||||
|
Reference in New Issue
Block a user