[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] Using HostName with lwip 1.4.0
From: |
Diecol |
Subject: |
Re: [lwip-users] Using HostName with lwip 1.4.0 |
Date: |
Tue, 11 Jan 2011 10:25:33 -0800 (PST) |
The version that u told me to get! 1.4.0rc1! at savannah..
The error was: undefined reference to.. (the bold worlds)
I'm trying to download the LWIP CVS Source Structure pdf at savannah site
but appear fatal error.
So, I replace in external libs folder of my project the new version ow lwip
and now I'm trying to modifie step by step ;(
If u have a better Ideia, will be great!
If helps.. part of my old code that now I need to update to the lwip
1.4.0rc1:
main.c:
//-----------------------------------------------------------------------------
// Types
//-----------------------------------------------------------------------------
/// Timer for calling lwIP tmr functions without system
typedef struct _timers_info {
unsigned int timer;
unsigned int timer_interval;
void (*timer_func)(void);
} timers_info;
//-----------------------------------------------------------------------------
// Local Define
//-----------------------------------------------------------------------------
/// lwIP tmr functions list
static timers_info timers_table[] = {
/// LWIP_TCP
{ 0, 250, tcp_fasttmr},
{ 0, 500, tcp_slowtmr},
/// LWIP_ARP
{ 0, ARP_TMR_INTERVAL, etharp_tmr},
/// LWIP_DHCP
#if LWIP_DHCP
{ 0, DHCP_COARSE_TIMER_SECS, dhcp_coarse_tmr},
{ 0, DHCP_FINE_TIMER_MSECS, dhcp_fine_tmr},
#endif
};
//-----------------------------------------------------------------------------
// Local variables
//-----------------------------------------------------------------------------
/// Pio pins to configure.
static const Pin pins[] = {PINS_DBGU};
/// EMAC power control pin
#if !defined(BOARD_EMAC_POWER_ALWAYS_ON)
static const Pin emacPwrDn[] = {BOARD_EMAC_PIN_PWRDN};
#endif
/// The PINs' on PHY reset
static const Pin emacRstPins[] = {BOARD_EMAC_RST_PINS};
/// The PINs for EMAC
static const Pin emacPins[] = {BOARD_EMAC_RUN_PINS};
/// PHY address
#define EMAC_PHY_ADDR 31
/// The DM9161 driver instance
static Dm9161 gDm9161;
/// The MAC address used for demo
static const unsigned char MacAddress[6] = {0x00, 0x45, 0x56, 0x78, 0x9a,
0xbc};
//#if !LWIP_DHCP
/// The IP address used for demo (ping ...)
static const unsigned char IpAddress[4] = {192, 168, 0, 30};
/// Set the default router's IP address.
static const unsigned char GateWay[4] = {192, 168, 0, 1};
// The NetMask address
static const unsigned char NetMask[4] = {255, 255, 255, 0};
//#endif
//-----------------------------------------------------------------------------
/// Emac interrupt handler
//-----------------------------------------------------------------------------
static void ISR_Emac(void)
{
EMAC_Handler();
}
//-----------------------------------------------------------------------------
/// Process timing functions
//-----------------------------------------------------------------------------
static void timers_update(void)
{
static unsigned int last_time;
unsigned int cur_time, time_diff, idxtimer;
timers_info * ptmr_inf;
cur_time = sys_get_ms();
if (cur_time >= last_time) {
time_diff = cur_time - last_time;
}
else {
time_diff = 0xFFFFFFFF - last_time + cur_time;
}
if (time_diff) {
last_time = cur_time;
for(idxtimer=0;
idxtimer < (sizeof(timers_table)/sizeof(timers_info));
idxtimer ++) {
ptmr_inf = &timers_table[idxtimer];
ptmr_inf->timer += time_diff;
if (ptmr_inf->timer > ptmr_inf->timer_interval) {
if (ptmr_inf->timer_func)
ptmr_inf->timer_func();
ptmr_inf->timer -= ptmr_inf->timer_interval;
}
}
}
}
//-----------------------------------------------------------------------------
/// Initialize lwIP modules
//-----------------------------------------------------------------------------
static void lwip_init(void)
{
#if LWIP_STATS
stats_init();
#endif
mem_init();
memp_init();
pbuf_init();
etharp_init();
tcp_init();
#if LWIP_UDP
udp_init();
#endif
}
//-----------------------------------------------------------------------------
// Global Functions
//-----------------------------------------------------------------------------
/* The main() function. */
int
main()
{
TRACE_CONFIGURE(DBGU_STANDARD, 115200, MCK);
#if !defined(sdram)
BOARD_ConfigureSdram(BOARD_SDRAM_BUSWIDTH);
#endif
struct ip_addr ipaddr, netmask, gw;
struct netif NetIf, *netif;
u8_t dhcp_state;
Dm9161 *pDm = &gDm9161;
unsigned int errCount = 0;
#if !defined(BOARD_EMAC_POWER_ALWAYS_ON)
// clear PHY power down mode
PIO_Configure(emacPwrDn, 1);
#endif
// Init EMAC driver structure
EMAC_Init(AT91C_ID_EMAC, MacAddress, EMAC_CAF_ENABLE, EMAC_NBC_DISABLE);
// Init DM9161 driver
DM9161_Init(pDm, EMAC_PHY_ADDR);
// Setup EMAC buffers and interrupts
AIC_ConfigureIT(AT91C_ID_EMAC, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
ISR_Emac);
AIC_EnableIT(AT91C_ID_EMAC);
// Initialize system timing
sys_init_timing();
// Initialize lwIP modules
lwip_init();
// Initialize net interface for lwIP
emacif_setmac((u8_t*)MacAddress);
// PHY initialize
if (!DM9161_InitPhy(pDm, BOARD_MCK,
emacRstPins, PIO_LISTSIZE(emacRstPins),
emacPins, PIO_LISTSIZE(emacPins))) {
printf("P: PHY Initialize ERROR!\n\r");
return -1;
}
// Auto Negotiate
if (!DM9161_AutoNegotiate(pDm)) {
printf("P: Auto Negotiate ERROR!\n\r");
return -1;
}
while( DM9161_GetLinkSpeed(pDm, 1) == 0 ) {
errCount++;
}
IP4_ADDR(&gw, new_gateway[0], new_gateway[1], new_gateway[2],
new_gateway[3]);
IP4_ADDR(&ipaddr, new_ip[0], new_ip[1], new_ip[2], new_ip[3]);
IP4_ADDR(&netmask, new_mask[0], new_mask[1], new_mask[2], new_mask[3]);
netif = netif_add(&NetIf, &ipaddr, &netmask, &gw, NULL, emacif_init,
ip_input);
netif_set_default(netif);
netif_set_up(netif);
firsttime = 0;
printf("P: Link detected 0x%X\n\r", errCount);
// Initialize http server application
if (ERR_OK != httpd_init()) {
return -1;
}
while(1) {
// Run periodic tasks
timers_update();
// Run polling tasks
emacif_poll(netif);
if (LWIP_DHCP_ON == dhcp_on){
if (firsttime == 0){
IP4_ADDR(&gw, 0, 0, 0, 0);
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
IP4_ADDR(&netmask, 0, 0, 0, 0);
netif_set_down(netif);
dhcp_stop(netif);
dhcp_state = DHCP_INIT;
netif_set_addr(netif, &ipaddr, &netmask, &gw);
dhcp_start(netif);
firsttime = 1;
}
// Dump DHCP addresses
if (netif->dhcp) {
u8_t tmp_state = netif->dhcp->state;
if (tmp_state != dhcp_state) {
if (tmp_state == DHCP_BOUND) {
u8_t * IP;
u8_t * Mask;
u8_t * GTW;
printf("\n\r");
printf("=== DHCP Configurations
===\n\r");
IP = (u8_t*)&netif->ip_addr;
Mask = (u8_t*)&netif->netmask;
GTW = (u8_t*)&netif->gw;
memcpy(current_ip, IP, 4);
printf("- DHCP IP:
%d.%d.%d.%d\n\r",
current_ip[0], current_ip[1],
current_ip[2], current_ip[3]);
memcpy(current_mask, Mask, 4);
printf("- DHCP Mask:
%d.%d.%d.%d\n\r",
current_mask[0],
current_mask[1], current_mask[2], current_mask[3]);
memcpy(current_gtw, GTW, 4);
printf("- DHCP Gateway:
%d.%d.%d.%d\n\r",
current_gtw[0], current_gtw[1],
current_gtw[2], current_gtw[3]);
printf("===========================\n\r\n");
LWIP_DHCP_ON = dhcp_wait;
status = dhcp_on;
firsttime = 0;
}
dhcp_state = tmp_state;
}
}
}
if(LWIP_DHCP_ON == dhcp_off){
u8_t tmp_state = netif->dhcp->state;
printf("DHCP: %d -> %d\n\r", dhcp_state, tmp_state);
if (dhcp_state != 0){
dhcp_release(netif);
dhcp_state = 0;
}
dhcp_stop(netif);
Read_NetConfig(&new_dhcp, new_ip, new_mask,
new_gateway, host);
memcpy(current_ip, new_ip, 4);
memcpy(current_mask, new_mask, 4);
memcpy(current_gtw, new_gateway, 4);
IP4_ADDR(&gw, current_gtw[0], current_gtw[1],
current_gtw[2],
current_gtw[3]);
IP4_ADDR(&ipaddr, current_ip[0], current_ip[1],
current_ip[2],
current_ip[3]);
IP4_ADDR(&netmask, current_mask[0], current_mask[1],
current_mask[2],
current_mask[3]);
netif_set_addr(netif, &ipaddr, &netmask, &gw);
netif_set_up(netif);
printf("\n\r");
printf("=== Static IP Configurations ===\n\r");
printf("-- New IP Address: %d.%d.%d.%d\n\r",
(int)current_ip[0],
(int)current_ip[1], (int)current_ip[2], (int)current_ip[3]);
printf("-- New NetMask Address: %d.%d.%d.%d\n\r",
(int)current_mask[0],
(int)current_mask[1], (int)current_mask[2], (int)current_mask[3]);
printf("-- New Gateway Address: %d.%d.%d.%d\n\r",
(int)current_gtw[0],
(int)current_gtw[1], (int)current_gtw[2], (int)current_gtw[3]);
printf("===========================\n\r\n");
status = dhcp_off;
LWIP_DHCP_ON = dhcp_wait;
}
}
return 0;
}
and my protocol.c
/* This is the callback function that is called
when a TCP segment has arrived in the connection. */
static err_t
httpd_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
// static u32_t reqcount;
//printf("CB recv %x, %x, %x, %x\n\r", arg, pcb, p, err);
if (err != ERR_OK) {
return err;
}
if (pcb->state != ESTABLISHED){
tcp_close(pcb);
return ERR_OK;
}
/* If we got a NULL pbuf in p, the remote end has closed
the connection. */
if(p == NULL) {
/* Close the connection. */
tcp_close(pcb);
return ERR_OK;
}
/* The payload pointer in the pbuf contains the data
in the TCP segment. */
int len = strlen(p->payload);
if (len <= 0)
return ERR_OK;
char* cmd = p->payload;
....
/* Free the pbuf. */
pbuf_free(p);
/* Close the connection. */
tcp_close(pcb);
return ERR_OK;
}
/* This is the callback function that is called when
a connection has been accepted. */
static err_t
httpd_accept(void *arg, struct tcp_pcb *pcb, err_t err){
if (err != ERR_OK) {
return err;
}
// send protocol identifier
tcp_write(pcb, "ready3.0#", 9, 0);
tcp_output(pcb);
printf("ready3.0# \n\r");
/* Set up the function httpd_recv() to be called when data arrives. */
tcp_recv(pcb, httpd_recv);
return ERR_OK;
}
/* The initialization function. */
err_t
httpd_init(void){
struct tcp_pcb *pcb;
err_t err;
/* Create a new TCP PCB. */
pcb = tcp_new();
if (pcb == NULL) {
printf("F: Fail to create PCB\n\r");
return ERR_BUF;
}
/* Bind the PCB to TCP port 23. */
err = tcp_bind(pcb, NULL, portnumber);
if (err != ERR_OK) {
printf("E: tcp_bind %x\n\r", err);
return err;
}
/* Change TCP state to LISTEN. */
pcb = tcp_listen(pcb);
if (pcb == NULL) {
printf("E: tcp_listen\n\r");
return ERR_BUF;
}
/* Set up httpd_accet() function to be called
when a new connection arrives. */
tcp_accept(pcb, httpd_accept);
return ERR_OK;
}
--
View this message in context:
http://old.nabble.com/Using-HostName-with-lwip-1.4.0-tp30643324p30646379.html
Sent from the lwip-users mailing list archive at Nabble.com.
- [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/11
- [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/11
- Re: [lwip-users] Using HostName with lwip 1.4.0, Simon Goldschmidt, 2011/01/11
- Re: [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/11
- Re: [lwip-users] Using HostName with lwip 1.4.0, Kieran Mansley, 2011/01/11
- Re: [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/11
- Re: [lwip-users] Using HostName with lwip 1.4.0, Kieran Mansley, 2011/01/11
- Re: [lwip-users] Using HostName with lwip 1.4.0,
Diecol <=
- Re: [lwip-users] Using HostName with lwip 1.4.0, Kieran Mansley, 2011/01/11
- Re: [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/13
- Re: [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/13
- Re: [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/13
- Re: [lwip-users] Using HostName with lwip 1.4.0, Simon Goldschmidt, 2011/01/13
- Re: [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/14
- Re: [lwip-users] Using HostName with lwip 1.4.0, Simon Goldschmidt, 2011/01/14
- Re: [lwip-users] Using HostName with lwip 1.4.0, Diecol, 2011/01/14
- Re: [lwip-users] Using HostName with lwip 1.4.0, Kieran Mansley, 2011/01/14
- RE: [lwip-users] Using HostName with lwip 1.4.0, Bill Auerbach, 2011/01/14