mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Fixed issue with Cosm sketch
This commit is contained in:
parent
abd9db126b
commit
bd72512a59
Binary file not shown.
Binary file not shown.
@ -298,8 +298,8 @@ static err_t atcp_recv_cb(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
|||||||
err_t err) {
|
err_t err) {
|
||||||
struct ttcp* ttcp = arg;
|
struct ttcp* ttcp = arg;
|
||||||
|
|
||||||
INFO_TCP("pcb:%p pbuf: %p err:%d\n", pcb, p, err);
|
|
||||||
if (err == ERR_OK && p != NULL) {
|
if (err == ERR_OK && p != NULL) {
|
||||||
|
INFO_TCP("pcb:%p pbuf: %p err:%d len:%d\n", pcb, p, err, p->tot_len);
|
||||||
DATA_LED_ON();
|
DATA_LED_ON();
|
||||||
/* for print_stats() */
|
/* for print_stats() */
|
||||||
ttcp->recved += p->tot_len;
|
ttcp->recved += p->tot_len;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include "ard_utils.h"
|
#include "ard_utils.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define MAX_PBUF_STORED 50
|
#define MAX_PBUF_STORED 30
|
||||||
|
|
||||||
tData pBufStore[MAX_PBUF_STORED][MAX_SOCK_NUM];
|
tData pBufStore[MAX_PBUF_STORED][MAX_SOCK_NUM];
|
||||||
|
|
||||||
@ -31,12 +31,20 @@ void insert_pBuf(struct pbuf* q, uint8_t sock, void* _pcb)
|
|||||||
if (q == NULL)
|
if (q == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (pBufStore[headBuf][sock].data != NULL)
|
||||||
|
{
|
||||||
|
WARN("Overwriting buffer %p idx:%d!\n", pBufStore[headBuf][sock].data, headBuf);
|
||||||
|
// to avoid memory leak free the oldest buffer
|
||||||
|
freetDataIdx(headBuf, sock);
|
||||||
|
}
|
||||||
|
|
||||||
u8_t* p = (u8_t*)calloc(q->tot_len,sizeof(u8_t));
|
u8_t* p = (u8_t*)calloc(q->tot_len,sizeof(u8_t));
|
||||||
if(p != NULL) {
|
if(p != NULL) {
|
||||||
if (pbuf_copy_partial(q, p, q->tot_len,0) != q->tot_len) {
|
if (pbuf_copy_partial(q, p, q->tot_len,0) != q->tot_len) {
|
||||||
free(p);
|
WARN("pbuf_copy_partial failed: src:%p, dst:%p, len:%d\n", q, p, q->tot_len);
|
||||||
p = NULL;
|
free(p);
|
||||||
return;
|
p = NULL;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pBufStore[headBuf][sock].data = p;
|
pBufStore[headBuf][sock].data = p;
|
||||||
@ -48,7 +56,7 @@ void insert_pBuf(struct pbuf* q, uint8_t sock, void* _pcb)
|
|||||||
if (headBuf == MAX_PBUF_STORED)
|
if (headBuf == MAX_PBUF_STORED)
|
||||||
headBuf = 0;
|
headBuf = 0;
|
||||||
if (headBuf == tailBuf)
|
if (headBuf == tailBuf)
|
||||||
WARN("Overwriting data!");
|
WARN("Overwriting data [%d-%d]!\n", headBuf, tailBuf);
|
||||||
INFO_UTIL("Insert: %p:%d-%d [%d,%d]\n", p, q->tot_len, p[0], headBuf, tailBuf);
|
INFO_UTIL("Insert: %p:%d-%d [%d,%d]\n", p, q->tot_len, p[0], headBuf, tailBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,22 +69,52 @@ tData* get_pBuf(uint8_t sock)
|
|||||||
if (IS_BUF_AVAIL())
|
if (IS_BUF_AVAIL())
|
||||||
{
|
{
|
||||||
tData* p = &(pBufStore[tailBuf][sock]);
|
tData* p = &(pBufStore[tailBuf][sock]);
|
||||||
INFO_UTIL("%p [%d,%d]\n", p, headBuf, tailBuf);
|
INFO_UTIL_VER("%p [%d,%d]\n", p, headBuf, tailBuf);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freetData(void * buf)
|
void freetData(void * buf, uint8_t sock)
|
||||||
{
|
{
|
||||||
if (buf==NULL)
|
if (buf==NULL)
|
||||||
|
{
|
||||||
|
WARN("Buf == NULL!");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pBufStore[tailBuf][sock].data = NULL;
|
||||||
|
pBufStore[tailBuf][sock].len = 0;
|
||||||
|
pBufStore[tailBuf][sock].idx = 0;
|
||||||
|
pBufStore[tailBuf][sock].pcb = 0;
|
||||||
|
|
||||||
if (++tailBuf == MAX_PBUF_STORED)
|
if (++tailBuf == MAX_PBUF_STORED)
|
||||||
tailBuf = 0;
|
tailBuf = 0;
|
||||||
|
INFO_UTIL("%p [%d,%d]\n", buf, headBuf, tailBuf);
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void freetDataIdx(uint8_t idxBuf, uint8_t sock)
|
||||||
|
{
|
||||||
|
if (idxBuf >=MAX_PBUF_STORED)
|
||||||
|
{
|
||||||
|
WARN("idxBuf out of range: %d\n", idxBuf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void * buf = pBufStore[idxBuf][sock].data;
|
||||||
|
|
||||||
|
INFO_UTIL("%p idx:%d\n", buf, idxBuf);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
pBufStore[idxBuf][sock].data = 0;
|
||||||
|
pBufStore[idxBuf][sock].len = 0;
|
||||||
|
pBufStore[idxBuf][sock].idx = 0;
|
||||||
|
pBufStore[idxBuf][sock].pcb = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ack_recved(void* pcb, int len);
|
void ack_recved(void* pcb, int len);
|
||||||
|
|
||||||
bool isAvailTcpDataByte(uint8_t sock)
|
bool isAvailTcpDataByte(uint8_t sock)
|
||||||
@ -85,10 +123,10 @@ bool isAvailTcpDataByte(uint8_t sock)
|
|||||||
|
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
{
|
{
|
||||||
INFO_UTIL("check:%d %d %p\n",p->idx, p->len, p->data);
|
INFO_UTIL_VER("check:%d %d %p\n",p->idx, p->len, p->data);
|
||||||
if (p->idx == p->len)
|
if (p->idx == p->len)
|
||||||
{
|
{
|
||||||
freetData(p->data);
|
freetData(p->data, sock);
|
||||||
ack_recved(p->pcb, p->len);
|
ack_recved(p->pcb, p->len);
|
||||||
INFO_UTIL("Free %p other buf %d tail:%d head:%d\n",
|
INFO_UTIL("Free %p other buf %d tail:%d head:%d\n",
|
||||||
p->data, IS_BUF_AVAIL(), tailBuf, headBuf);
|
p->data, IS_BUF_AVAIL(), tailBuf, headBuf);
|
||||||
@ -116,12 +154,12 @@ bool getTcpDataByte(uint8_t sock, uint8_t* payload, uint8_t peek)
|
|||||||
*payload = buf[p->idx];
|
*payload = buf[p->idx];
|
||||||
else
|
else
|
||||||
*payload = buf[p->idx++];
|
*payload = buf[p->idx++];
|
||||||
INFO_UTIL("get:%d %p %d\n",p->idx, p->data, *payload);
|
INFO_UTIL_VER("get:%d %p %d\n",p->idx, p->data, *payload);
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
//dealloc current buffer
|
//dealloc current buffer
|
||||||
INFO_UTIL("Free %p\n", p->data);
|
INFO_UTIL("Free %p\n", p->data);
|
||||||
freetData(p->data);
|
freetData(p->data, sock);
|
||||||
ack_recved(p->pcb, p->len);
|
ack_recved(p->pcb, p->len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +185,7 @@ bool freeTcpData(uint8_t sock)
|
|||||||
p = get_pBuf(sock);
|
p = get_pBuf(sock);
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
{
|
{
|
||||||
freetData(p->data);
|
freetData(p->data, sock);
|
||||||
ack_recved(p->pcb, p->len);
|
ack_recved(p->pcb, p->len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#define LED2_DN() gpio_clr_gpio_pin(LED2_GPIO)
|
#define LED2_DN() gpio_clr_gpio_pin(LED2_GPIO)
|
||||||
#define LED2_TL() gpio_tgl_gpio_pin(LED2_GPIO)
|
#define LED2_TL() gpio_tgl_gpio_pin(LED2_GPIO)
|
||||||
|
|
||||||
#define _DEBUG_
|
|
||||||
#ifdef _DEBUG_
|
#ifdef _DEBUG_
|
||||||
#define SIGN0_UP LED0_UP
|
#define SIGN0_UP LED0_UP
|
||||||
#define SIGN0_DN LED0_DN
|
#define SIGN0_DN LED0_DN
|
||||||
@ -232,7 +231,9 @@ void insert_pBuf(struct pbuf* q, uint8_t sock, void* _pcb);
|
|||||||
|
|
||||||
tData* get_pBuf(uint8_t sock);
|
tData* get_pBuf(uint8_t sock);
|
||||||
|
|
||||||
void freetData(void * buf);
|
void freetData(void * buf, uint8_t sock);
|
||||||
|
|
||||||
|
void freetDataIdx(uint8_t idxBuf, uint8_t sock);
|
||||||
|
|
||||||
bool isBufAvail();
|
bool isBufAvail();
|
||||||
|
|
||||||
|
@ -55,12 +55,21 @@ if ((enableDebug & INFO_SPI_FLAG)&&(verboseDebug & INFO_SPI_FLAG)) \
|
|||||||
#define INFO_UTIL(msg, args...) do { \
|
#define INFO_UTIL(msg, args...) do { \
|
||||||
if (enableDebug & INFO_UTIL_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \
|
if (enableDebug & INFO_UTIL_FLAG) printk("I-[%s] " msg , __func__ , ##args ); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define INFO_UTIL_VER(msg, args...) do { \
|
||||||
|
if ((enableDebug & INFO_UTIL_FLAG)&&(verboseDebug & INFO_UTIL_FLAG)) \
|
||||||
|
printk("I-[%s] " msg , __func__ , ##args ); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define INFO_INIT(msg, args...) do {}while(0);
|
#define INFO_INIT(msg, args...) do {}while(0);
|
||||||
#define INFO_TCP(msg, args...) do {}while(0);
|
#define INFO_TCP(msg, args...) do {}while(0);
|
||||||
#define INFO_TCP_VER(msg, args...) do { }while(0);
|
#define INFO_TCP_VER(msg, args...) do { }while(0);
|
||||||
#define INFO_SPI(msg, args...) do {}while(0);
|
#define INFO_SPI(msg, args...) do {}while(0);
|
||||||
|
#define INFO_SPI_VER(msg, args...) do { }while(0);
|
||||||
#define INFO_UTIL(msg, args...) do {}while(0);
|
#define INFO_UTIL(msg, args...) do {}while(0);
|
||||||
|
#define INFO_UTIL_VER(msg, args...) do { }while(0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _APP_DEBUG_
|
#ifdef _APP_DEBUG_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user