ESP8266: Correctly integrate into Make system. Does not depend on CONFIG_NET. FIFO should probably be a circular buffer.

This commit is contained in:
Gregory Nutt 2016-05-23 07:48:14 -06:00
parent 074a0a2c94
commit eb1533ffc2
3 changed files with 57 additions and 24 deletions

View File

@ -1,7 +1,7 @@
############################################################################ ############################################################################
# apps/netutils/Makefile # apps/netutils/Makefile
# #
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. # Copyright (C) 2011-2012, 2016 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org> # Author: Gregory Nutt <gnutt@nuttx.org>
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -37,7 +37,7 @@
# Sub-directories # Sub-directories
SUBDIRS = chat json codecs SUBDIRS = chat json codecs esp8266
ifeq ($(CONFIG_NET),y) ifeq ($(CONFIG_NET),y)
SUBDIRS += netlib dhcpc dhcpd discover ftpc ftpd smtp telnetd SUBDIRS += netlib dhcpc dhcpd discover ftpc ftpd smtp telnetd
SUBDIRS += webclient webserver tftpc thttpd xmlrpc pppd SUBDIRS += webclient webserver tftpc thttpd xmlrpc pppd

View File

@ -40,11 +40,7 @@ include $(APPDIR)/Make.defs
# ESP8266 Library # ESP8266 Library
ASRCS = ASRCS =
CSRCS = CSRCS = esp8266.c
ifeq ($(CONFIG_NET_TCP),y)
CSRCS += esp8266.c
endif
AOBJS = $(ASRCS:.S=$(OBJEXT)) AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT))

View File

@ -108,8 +108,8 @@ typedef struct
{ {
sem_t *sem; sem_t *sem;
uint8_t flags; uint8_t flags;
uint16_t in; uint16_t inndx;
uint16_t out; uint16_t outndx;
uint8_t rxbuf[SOCKET_FIFO_SIZE]; uint8_t rxbuf[SOCKET_FIFO_SIZE];
} lesp_socket_t; } lesp_socket_t;
@ -324,17 +324,41 @@ static inline int lesp_read_ipd(void)
len -= size; len -= size;
pthread_mutex_lock(&g_lesp_state.mutex); pthread_mutex_lock(&g_lesp_state.mutex);
while(size --) while (size--)
{ {
uint8_t b = *buf++; int next;
if (sock->in < SOCKET_FIFO_SIZE) uint8_t b;
/* Read the next byte from the buffer */
b = *buf++;
/* Pre-calculate the next 'inndx'. We do this so that we can
* check if the FIFO is full.
*/
next = sock->inndx + 1;
if (next >= SOCKET_FIFO_SIZE)
{ {
int ndx = sock->in; next -= SOCKET_FIFO_SIZE;
sock->rxbuf[ndx] = b; }
sock->in = ndx + 1;
/* Is there space in the circular buffer for another byte? If
* the next 'inndx' would be equal to the 'outndx', then the
* circular buffer is full.
*/
if (next != sock->outndx)
{
/* Yes.. add the byte to the circular buffer */
sock->rxbuf[sock->inndx] = b;
sock->inndx = next;
} }
else else
{ {
/* No.. the we have lost data */
nvdbg("overflow socket 0x%02X\n", b); nvdbg("overflow socket 0x%02X\n", b);
} }
} }
@ -1181,9 +1205,9 @@ int lesp_closesocket(int sockfd)
sockfd); sockfd);
memset(sock, 0, sizeof(lesp_socket_t)); memset(sock, 0, sizeof(lesp_socket_t));
sock->flags = 0; sock->flags = 0;
sock->in = 0; sock->inndx = 0;
sock->out = 0; sock->outndx = 0;
} }
if (ret < 0) if (ret < 0)
@ -1338,7 +1362,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags)
ret = -1; ret = -1;
} }
if (ret >= 0 && sock->in == 0) if (ret >= 0 && sock->inndx == sock->outndx)
{ {
struct timespec ts; struct timespec ts;
@ -1350,7 +1374,7 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags)
{ {
ts.tv_sec += lespTIMEOUT_MS_RECV_S; ts.tv_sec += lespTIMEOUT_MS_RECV_S;
sock->sem = &sem; sock->sem = &sem;
while (ret >= 0 && sock->in == 0) while (ret >= 0 && sock->inndx == sock->outndx)
{ {
pthread_mutex_unlock(&g_lesp_state.mutex); pthread_mutex_unlock(&g_lesp_state.mutex);
ret = sem_timedwait(&sem,&ts); ret = sem_timedwait(&sem,&ts);
@ -1364,11 +1388,24 @@ ssize_t lesp_recv(int sockfd, FAR uint8_t *buf, size_t len, int flags)
if (ret >= 0) if (ret >= 0)
{ {
ret = 0; ret = 0;
while (ret < len && sock->out < sock->in) while (ret < len && sock->outndx != sock->inndx)
{ {
int ndx = sock->out; /* Remove one byte from the circular buffer */
*buf++ = sock->rxbuf[ndx];
sock->out = ndx + 1; int ndx = sock->outndx;
*buf++ = sock->rxbuf[ndx];
/* Increment the circular buffer 'outndx' */
if (++ndx >= SOCKET_FIFO_SIZE)
{
ndx -= SOCKET_FIFO_SIZE;
}
sock->outndx = ndx;
/* Increment the count of bytes returned */
ret++; ret++;
} }
} }