Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

lwip task start

Posted by Maurizio on May 21, 2008
Hi all,
I'm doing a demo on udp lwip working for Str91x with Rowley. My demo is not getting send packages udp, in my opinion there is a problem when the FreeRTOS launches task. Below is my code, to understand how to launch the task I have taken inspiration from demo WebServer included in the package FreeRTOS 5.
someone can help me? it's my code ok?

===========================================MAIN.C=========
......
#ifdef STACK_LWIP
/* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/
vlwIPInit();
sys_set_state(( signed portCHAR * ) "httpd", lwipBASIC_SERVER_STACK_SIZE );
sys_thread_new( vBasicWEBServer, ( void * ) NULL, ( tskIDLE_PRIORITY + 2 )basicwebWEBSERVER_PRIORITY );
sys_set_default_state();
#endif
.......

=========================================UDP_SENDER.H========
......................
#ifndef UDP_SENDER_H
#define UDP_SENDER_H

#include <91x_type.h>

/*------------------------------------------------------------------------------*/
/* MACROS */
/*------------------------------------------------------------------------------*/
#define basicudp_SENDER_PRIORITY ( tskIDLE_PRIORITY + 2 )

/* The port on which we listen. */
#define webUDP_PORT( 1234 )

/* Delay on close error. */
#define webSHORT_DELAY( 10 / portTICK_RATE_MS )

/* The IP address being used. */
#define emacIPADDR010
#define emacIPADDR1 200
#define emacIPADDR2 200
#define emacIPADDR3 2

/* The gateway address being used. */
#define emacGATEWAY_ADDR0 10
#define emacGATEWAY_ADDR1 200
#define emacGATEWAY_ADDR2 200
#define emacGATEWAY_ADDR3 1

/* The network mask being used. */
#define emacNET_MASK0 255
#define emacNET_MASK1 255
#define emacNET_MASK2 255
#define emacNET_MASK3 252

#define STATIC_IP 1
#define DHCP_IP 2

#define lwipBASIC_SERVER_STACK_SIZE250

/*------------------------------------------------------------------------------*/
/* PROTOTYPES */
/*------------------------------------------------------------------------------*/
/* The function that implements the WEB server task. */
void vBasicUDPSender( void *pvParameters );

/* Initialisation required by lwIP. */
void vlwIPInit( void );

#endif

=========================================UDP_SENDER.C==========================

#define basicwebWEBSERVER_PRIORITY ( tskIDLE_PRIORITY + 2 )
#define lwipTCP_STACK_SIZE600

/* Standard includes. */
#include <stdio.h>
#include <string.h>
#include <91x_type.h>

/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"

/* Demo includes. */
#include "lwIPWebServer/BasicWEB.h"
#include "udpecho-sender.h"
/* lwIP includes. */
#include "lwip/api.h"
#include "lwip/tcpip.h"
#include "lwip/memp.h"
#include "lwip/stats.h"
#include "Dnetif/loopif.h"
//#include "lcd.h"
#include "httpd.h"

//#define lwipTCP_STACK_SIZE600
//XXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include "lwip/udp.h"
#include "lwip/mem.h"
#include "lwip/debug.h"
/*------------------------------------------------------------------------------*/
/* GLOBALS */
/*------------------------------------------------------------------------------*/
static struct netif EMAC_if;

/*------------------------------------------------------------------------------*/
/* FUNCTIONS */
/*------------------------------------------------------------------------------*/
void vlwIPInit( void )
{
/* Initialize lwIP and its interface layer. */
sys_init();
mem_init();
memp_init();
pbuf_init();
netif_init();
ip_init();
sys_set_state(( signed portCHAR * ) "lwIP", lwipTCP_STACK_SIZE);
udp_init();
sys_set_default_state();
}

void udp_echo_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
{

if (p != NULL)
{
/* send received packet back to sender */

udp_sendto(pcb, p, addr, port);
/* free the pbuf */
pbuf_free(p);
}
}


void udp_echo_init(void)
{
struct udp_pcb * pcb;

/* get new pcb */
pcb = udp_new();
if (pcb == NULL) {
LWIP_DEBUGF(UDP_DEBUG, ("udp_new failed!\n"));
return;
}

/* bind to any IP address on port 7 */
if (udp_bind(pcb, IP_ADDR_ANY, UDP_PORT) != ERR_OK) {
LWIP_DEBUGF(UDP_DEBUG, ("udp_bind failed!\n"));
return;
}

/* set udp_echo_recv() as callback function
for received packets */
udp_recv(pcb, udp_echo_recv, NULL);
}

void vBasicWEBServer( void *pvParameters )
{
struct ip_addr xIpAddr, xNetMast, xGateway;
extern err_t ethernetif_init( struct netif *netif );

/* Parameters are not used - suppress compiler error. */
( void ) pvParameters;

/* Create and configure the EMAC interface. */
IP4_ADDR( &xIpAddr, emacIPADDR0, emacIPADDR1, emacIPADDR2, emacIPADDR3 );
IP4_ADDR( &xNetMast, emacNET_MASK0, emacNET_MASK1, emacNET_MASK2, emacNET_MASK3 );
IP4_ADDR( &xGateway, emacGATEWAY_ADDR0, emacGATEWAY_ADDR1, emacGATEWAY_ADDR2, emacGATEWAY_ADDR3 );
netif_add( &EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input );

/* make it the default interface */
netif_set_default( &EMAC_if );

/* bring it up */
netif_set_up(&EMAC_if);

/* Initialize HTTP */
udp_echo_init();//httpd_init();

/* Nothing else to do. No point hanging around. */
vTaskDelete( NULL );
}

......................


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS