Browse Source

Unix port: fixed compilation after moving timeout handling to timers.c; fixed some threading- and other issues with initialization

master
goldsimon 17 years ago
parent
commit
2bb8f85116
  1. 1
      ports/unix/netif/unixif.c
  2. 29
      ports/unix/proj/lib/unixlib.c
  3. 7
      ports/unix/proj/minimal/Makefile
  4. 4
      ports/unix/proj/unixsim/Makefile
  5. 47
      ports/unix/proj/unixsim/simhost.c
  6. 54
      ports/unix/proj/unixsim/simnode.c
  7. 55
      ports/unix/proj/unixsim/simrouter.c
  8. 49
      ports/unix/sys_arch.c

1
ports/unix/netif/unixif.c

@ -53,6 +53,7 @@
#include "netif/list.h"
#include "netif/unixif.h"
#include "lwip/sys.h"
#include "lwip/timers.h"
#include "netif/tcpdump.h"

29
ports/unix/proj/lib/unixlib.c

@ -26,7 +26,7 @@
*
* Author: Kieran Mansley <kjm25@cam.ac.uk>
*
* $Id: unixlib.c,v 1.6 2008/01/15 13:10:51 kieranm Exp $
* $Id: unixlib.c,v 1.7 2010/01/07 10:21:13 goldsimon Exp $
*/
/*-----------------------------------------------------------------------------------*/
@ -54,34 +54,35 @@
#include "netif/tapif.h"
struct netif netif;
static void
tcpip_init_done(void *arg)
{
struct ip_addr ipaddr, netmask, gateway;
sys_sem_t *sem;
sem = arg;
/*
CHANGE THESE to suit your own network configuration:
*/
IP4_ADDR(&gateway, 192,168,1,1);
IP4_ADDR(&ipaddr, 192,168,1,2);
IP4_ADDR(&netmask, 255,255,255,0);
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, tapif_init,
tcpip_input));
sys_sem_signal(*sem);
}
struct netif netif;
void _init(void){
struct ip_addr ipaddr, netmask, gateway;
sys_sem_t sem;
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
/*
CHANGE THESE to suit your own network configuration:
*/
IP4_ADDR(&gateway, 192,168,1,1);
IP4_ADDR(&ipaddr, 192,168,1,2);
IP4_ADDR(&netmask, 255,255,255,0);
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, tapif_init,
tcpip_input));
}
void _fini(void){

7
ports/unix/proj/minimal/Makefile

@ -55,7 +55,7 @@ COREFILES=$(LWIPDIR)/core/mem.c $(LWIPDIR)/core/memp.c $(LWIPDIR)/core/netif.c \
$(LWIPDIR)/core/stats.c $(LWIPDIR)/core/sys.c \
$(LWIPDIR)/core/tcp.c $(LWIPDIR)/core/tcp_in.c \
$(LWIPDIR)/core/tcp_out.c $(LWIPDIR)/core/udp.c $(LWIPDIR)/core/dhcp.c \
$(LWIPDIR)/core/init.c
$(LWIPDIR)/core/init.c $(LWIPDIR)/core/timers.c
CORE4FILES=$(LWIPDIR)/core/ipv4/icmp.c $(LWIPDIR)/core/ipv4/ip.c \
$(LWIPDIR)/core/ipv4/inet.c $(LWIPDIR)/core/ipv4/ip_addr.c \
$(LWIPDIR)/core/ipv4/ip_frag.c $(LWIPDIR)/core/ipv4/inet_chksum.c
@ -68,8 +68,11 @@ SNMPFILES=$(LWIPDIR)/core/snmp/asn1_dec.c $(LWIPDIR)/core/snmp/asn1_enc.c \
# NETIFFILES: Files implementing various generic network interface functions.'
NETIFFILES=$(LWIPDIR)/netif/etharp.c mintapif.c
# ARCHFILES: Architecture specific files
ARCHFILES=$(LWIPARCH)/sys_arch.c
# LWIPFILES: All the above.
LWIPFILES=$(COREFILES) $(CORE4FILES) $(SNMPFILES) $(NETIFFILES)
LWIPFILES=$(COREFILES) $(CORE4FILES) $(SNMPFILES) $(NETIFFILES) $(ARCHFILES)
LWIPFILESW=$(wildcard $(LWIPFILES))
LWIPOBJS=$(notdir $(LWIPFILESW:.c=.o))

4
ports/unix/proj/unixsim/Makefile

@ -54,8 +54,8 @@ CFLAGS:=$(CFLAGS) \
COREFILES=$(LWIPDIR)/core/mem.c $(LWIPDIR)/core/memp.c $(LWIPDIR)/core/netif.c \
$(LWIPDIR)/core/pbuf.c $(LWIPDIR)/core/raw.c $(LWIPDIR)/core/stats.c \
$(LWIPDIR)/core/sys.c $(LWIPDIR)/core/tcp.c $(LWIPDIR)/core/tcp_in.c \
$(LWIPDIR)/core/tcp_out.c $(LWIPDIR)/core/udp.c $(LWIPDIR)/core/dhcp.c \
$(LWIPDIR)/core/init.c
$(LWIPDIR)/core/tcp_out.c $(LWIPDIR)/core/udp.c $(LWIPDIR)/core/dhcp.c \
$(LWIPDIR)/core/init.c $(LWIPDIR)/core/timers.c
CORE4FILES=$(wildcard $(LWIPDIR)/core/ipv4/*.c) $(LWIPDIR)/core/ipv4/inet.c \
$(LWIPDIR)/core/ipv4/inet_chksum.c

47
ports/unix/proj/unixsim/simhost.c

@ -108,6 +108,8 @@ static struct option longopts[] = {
};
#define NUM_OPTS ((sizeof(longopts) / sizeof(struct option)) - 1)
static void init_netifs(void);
void usage(void)
{
unsigned char i;
@ -132,6 +134,9 @@ tcpip_init_done(void *arg)
{
sys_sem_t *sem;
sem = arg;
init_netifs();
sys_sem_signal(*sem);
}
@ -199,7 +204,7 @@ pppLinkStatusCallback(void *ctx, int errCode, void *arg)
static int seq_num;
#if 0
/* Ping using the raw ip */
/* Ping using the raw api */
static int
ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *addr)
{
@ -248,7 +253,7 @@ ping_thread(void *arg)
raw_remove(raw);
}
#else
/* Ping using the socket ip */
/* Ping using the socket api */
static void
ping_send(int s, struct ip_addr *addr)
@ -311,22 +316,10 @@ struct netif netif;
#if LWIP_HAVE_LOOPIF
struct netif loopif;
#endif
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
init_netifs(void)
{
sys_sem_t sem;
#if PPP_SUPPORT
sio_fd_t ppp_sio;
#endif
netif_init();
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
printf("TCP/IP initialized.\n");
#if PPP_SUPPORT
pppInit();
#if PPP_PTY_TEST
@ -388,6 +381,25 @@ main_thread(void *arg)
#if LWIP_UDP
udpecho_init();
#endif
/* sys_timeout(5000, tcp_debug_timeout, NULL);*/
}
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
{
sys_sem_t sem;
#if PPP_SUPPORT
sio_fd_t ppp_sio;
#endif
netif_init();
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
printf("TCP/IP initialized.\n");
#if LWIP_RAW
/** @todo remove dependency on RAW PCB support */
@ -398,7 +410,6 @@ main_thread(void *arg)
printf("Applications started.\n");
/* sys_timeout(5000, tcp_debug_timeout, NULL);*/
#ifdef MEM_PERF
mem_perf_init("/tmp/memstats.client");
@ -476,8 +487,6 @@ main(int argc, char **argv)
perf_init("/tmp/simhost.perf");
#endif /* PERF */
lwip_init();
printf("System initialized.\n");
sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);

54
ports/unix/proj/unixsim/simnode.c

@ -38,6 +38,7 @@
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"
#include "lwip/tcp.h"
#include "lwip/stats.h"
@ -61,6 +62,9 @@
#include "tcpecho.h"
#include "shell.h"
/* nonstatic debug cmd option, exported in lwipopts.h */
unsigned char debug_flags;
/*-----------------------------------------------------------------------------------*/
static void
tcp_timeout(void *data)
@ -71,23 +75,15 @@ tcp_timeout(void *data)
sys_timeout(5000, tcp_timeout, NULL);
}
/*-----------------------------------------------------------------------------------*/
struct netif netif_unix;
/*-----------------------------------------------------------------------------------*/
static void
tcpip_init_done(void *arg)
{
struct ip_addr ipaddr, netmask, gw;
sys_sem_t *sem;
sem = arg;
sys_sem_signal(*sem);
}
/*-----------------------------------------------------------------------------------*/
struct netif netif_unix;
static void
main_thread(void *arg)
{
struct ip_addr ipaddr, netmask, gw;
sys_sem_t sem;
IP4_ADDR(&gw, 192,168,1,1);
IP4_ADDR(&ipaddr, 192,168,1,2);
IP4_ADDR(&netmask, 255,255,255,0);
@ -97,22 +93,30 @@ main_thread(void *arg)
/* netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1,
tcpip_input)); */
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
printf("TCP/IP initialized.\n");
tcpecho_init();
shell_init();
httpd_init();
udpecho_init();
printf("Applications started.\n");
sys_timeout(5000, tcp_timeout, NULL);
sys_sem_signal(*sem);
}
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
{
sys_sem_t sem;
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
printf("TCP/IP initialized.\n");
#ifdef MEM_PERF
mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
@ -128,20 +132,12 @@ main(int argc, char **argv)
#ifdef PERF
perf_init("/tmp/client.perf");
#endif /* PERF */
#if LWIP_STATS
stats_init();
#endif /* STATS */
sys_init();
mem_init();
memp_init();
pbuf_init();
tcpdump_init();
printf("System initialized.\n");
sys_thread_new("main_thread", (void *)(main_thread), NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
pause();
return 0;
}

55
ports/unix/proj/unixsim/simrouter.c

@ -38,6 +38,7 @@
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/sys.h"
#include "lwip/tcp.h"
#include "lwip/stats.h"
@ -63,6 +64,9 @@
#include "tcpecho.h"
#include "shell.h"
/* nonstatic debug cmd option, exported in lwipopts.h */
unsigned char debug_flags;
/*-----------------------------------------------------------------------------------*/
static void
tcp_timeout(void *data)
@ -73,23 +77,17 @@ tcp_timeout(void *data)
sys_timeout(5000, tcp_timeout, NULL);
}
/*-----------------------------------------------------------------------------------*/
static void
tcpip_init_done(void *arg)
{
sys_sem_t *sem;
sem = arg;
sys_sem_signal(*sem);
}
struct netif netif_tap, netif_unix;
/*-----------------------------------------------------------------------------------*/
static void
main_thread(void *arg)
tcpip_init_done(void *arg)
{
struct ip_addr ipaddr, netmask, gw;
sys_sem_t sem;
sys_sem_t *sem;
sem = arg;
IP4_ADDR(&gw, 192,168,0,1);
IP4_ADDR(&ipaddr, 192,168,0,2);
IP4_ADDR(&netmask, 255,255,255,0);
@ -106,26 +104,34 @@ main_thread(void *arg)
system("route add 192.168.1.1 192.168.0.2");
system("route add 192.168.1.2 192.168.0.2");
/*netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1,
tcpip_input)); */
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
printf("TCP/IP initialized.\n");
tcpecho_init();
shell_init();
httpd_init();
udpecho_init();
printf("Applications started.\n");
sys_timeout(5000, tcp_timeout, NULL);
sys_sem_signal(*sem);
}
static void
main_thread(void *arg)
{
sys_sem_t sem;
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
printf("TCP/IP initialized.\n");
#ifdef MEM_PERF
mem_perf_init("/tmp/memstats.client");
#endif /* MEM_PERF */
@ -139,20 +145,11 @@ main(int argc, char **argv)
#ifdef PERF
perf_init("/tmp/client.perf");
#endif /* PERF */
#if LWIP_STATS
stats_init();
#endif /* STATS */
sys_init();
mem_init();
memp_init();
pbuf_init();
tcpdump_init();
printf("System initialized.\n");
sys_thread_new("main_thread", (void *)(main_thread), NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
pause();
return 0;
}

49
ports/unix/sys_arch.c

@ -59,6 +59,10 @@
#define UMAX(a, b) ((a) > (b) ? (a) : (b))
static struct timeval starttime;
#if !NO_SYS
static struct sys_thread *threads = NULL;
static pthread_mutex_t threads_mutex = PTHREAD_MUTEX_INITIALIZER;
@ -86,13 +90,9 @@ struct sys_sem {
struct sys_thread {
struct sys_thread *next;
struct sys_timeouts timeouts;
pthread_t pthread;
};
static struct timeval starttime;
static pthread_mutex_t lwprot_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t lwprot_thread = (pthread_t) 0xDEAD;
static int lwprot_count = 0;
@ -114,7 +114,6 @@ introduce_thread(pthread_t id)
if (thread != NULL) {
pthread_mutex_lock(&threads_mutex);
thread->next = threads;
thread->timeouts.next = NULL;
thread->pthread = id;
threads = thread;
pthread_mutex_unlock(&threads_mutex);
@ -123,34 +122,6 @@ introduce_thread(pthread_t id)
return thread;
}
/*-----------------------------------------------------------------------------------*/
static struct sys_thread *
current_thread(void)
{
struct sys_thread *st;
pthread_t pt;
pt = pthread_self();
pthread_mutex_lock(&threads_mutex);
for(st = threads; st != NULL; st = st->next) {
if (pthread_equal(st->pthread, pt)) {
pthread_mutex_unlock(&threads_mutex);
return st;
}
}
pthread_mutex_unlock(&threads_mutex);
st = introduce_thread(pt);
if (!st) {
printf("current_thread???\n");
abort();
}
return st;
}
/*-----------------------------------------------------------------------------------*/
sys_thread_t
sys_thread_new(char *name, void (* function)(void *arg), void *arg, int stacksize, int prio)
{
@ -490,6 +461,7 @@ sys_sem_free(struct sys_sem *sem)
sys_sem_free_internal(sem);
}
}
#endif /* !NO_SYS */
/*-----------------------------------------------------------------------------------*/
u32_t
sys_now(void)
@ -513,15 +485,7 @@ sys_init()
gettimeofday(&starttime, &tz);
}
/*-----------------------------------------------------------------------------------*/
struct sys_timeouts *
sys_arch_timeouts(void)
{
struct sys_thread *thread;
thread = current_thread();
return &thread->timeouts;
}
/*-----------------------------------------------------------------------------------*/
#if SYS_LIGHTWEIGHT_PROT
/** sys_prot_t sys_arch_protect(void)
This optional function does a "fast" critical region protection and returns
@ -576,6 +540,7 @@ sys_arch_unprotect(sys_prot_t pval)
}
}
}
#endif /* SYS_LIGHTWEIGHT_PROT */
/*-----------------------------------------------------------------------------------*/

Loading…
Cancel
Save