|
From: | Dinesh Pandey |
Subject: | Re: [lwip-users] LWIP on LPC1788 uEZ 2.1 |
Date: | Thu, 22 Oct 2015 20:21:49 +0530 |
Hi, I've a big problem with echo example running in my LPC1788
(DK-57VTS-LPC1788 FDI). I'm using uEZ 2.1 framework and this is my code
(taken here: http://www.ultimaserial.com/avr_lwip_tcp.html) :
#include <sockets.h>
#include <tcp.h>
#include <uEZ.h>
#include <http.h>
#include <init.h>
#include <lwip/ip_addr.h>
#include "lwip/sys.h"
#include "lwip/api.h"
char mydata[1024];
static struct tcp_pcb *ptel_pcb;
int err;
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/tcp.h"
static struct tcp_pcb *echo_pcb;
enum echo_states
{
ES_NONE = 0,
ES_ACCEPTED,
ES_RECEIVED,
ES_CLOSING
};
struct echo_state
{
u8_t state;
u8_t retries;
struct tcp_pcb *pcb;
/* pbuf (chain) to recycle */
struct pbuf *p;
};
struct ip_addr ipaddr_local;
struct ip_addr ipmask_local;
/*
IP4_ADDR(&ipaddr_local, 192,168,1,3);
IP4_ADDR(&ipmask_local, 255,255,255,0);
err = tcp_bind(echo_pcb, &ipaddr_local, 7);
*/
err_t echo_accept(void *arg, struct tcp_pcb *newpcb, err_t err);
err_t echo_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err);
void echo_error(void *arg, err_t err);
err_t echo_poll(void *arg, struct tcp_pcb *tpcb);
err_t echo_sent(void *arg, struct tcp_pcb *tpcb, u16_t len);
void echo_send(struct tcp_pcb *tpcb, struct echo_state *es);
void echo_close(struct tcp_pcb *tpcb, struct echo_state *es);
static void close_conn(struct tcp_pcb *pcb){
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_close(pcb);
}
static err_t echo_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t
err){
int i;
int len;
char *pc;
if (err == ERR_OK && p != NULL) {
/* Inform TCP that we have taken the data. */
tcp_recved(pcb, p->tot_len);
//pointer to the pay load
pc=(char *)p->payload;
//size of the pay load
len =p->tot_len;
//copy to our own buffer
for (i=0; i<len; i++)mydata[i]= pc[i];
//Close TCP when receiving "X"
if (mydata[0]=='X')close_conn(pcb);
//Free the packet buffer
pbuf_free(p);
//check output buffer capacity
if (len >tcp_sndbuf(pcb)) len= tcp_sndbuf(pcb);
//Send out the data
err = tcp_write(pcb, mydata, len, 0);
tcp_sent(pcb, NULL); /* No need to call back */
} else {
pbuf_free(p);
}
if (err == ERR_OK && p == NULL) {
close_conn(pcb);
}
return ERR_OK;
}
static err_t echo_accept(void *arg, struct tcp_pcb *pcb, err_t err){
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
tcp_setprio(pcb, TCP_PRIO_MIN);
tcp_recv(pcb, echo_recv);
tcp_err(pcb, NULL); //Don't care about error here
tcp_poll(pcb, NULL, 4); //No polling here
return ERR_OK;
}
unsigned int _ServerTask(T_uezTask aMyTask, void *aParameters){
struct tcp_pcb *ptel_pcb;
ptel_pcb = tcp_new();
IP4_ADDR(&ipaddr_local, 192,168,1,3);
IP4_ADDR(&ipmask_local, 255,255,255,0);
err = tcp_bind(echo_pcb, &ipaddr_local, 7);
while (1){
ptel_pcb = tcp_listen(ptel_pcb);
tcp_accept(ptel_pcb, echo_accept);
}
}
void server_setup(){
T_uezTask server_task;
lwip_init();
if (!(UEZTaskCreate((T_uezTaskFunction)_ServerTask, "ServerTask", 4096, 0,
UEZ_PRIORITY_LOW, &server_task) == UEZ_ERROR_NONE)) {
printf("ERROR\n");
}
}
What is wrong? Does exists a simple example test running on uEZ or
externally?
--
View this message in context: http://lwip.100.n7.nabble.com/LWIP-on-LPC1788-uEZ-2-1-tp25235.html
Sent from the lwip-users mailing list archive at Nabble.com.
_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users
[Prev in Thread] | Current Thread | [Next in Thread] |