diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-06 09:33:47 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-06 09:33:47 +0000 |
commit | ed8a14e6880b1ec6f065c6267d4ee86ae1cdb745 (patch) | |
tree | 325331c343a5e0c3c9d59161fe3cdc18afb45493 /demos/ARM7-AT91SAM7X-LWIP-GCC/lwip | |
parent | 079f323649c9adcbb49791903f357fb90681628e (diff) | |
download | ChibiOS-ed8a14e6880b1ec6f065c6267d4ee86ae1cdb745.tar.gz ChibiOS-ed8a14e6880b1ec6f065c6267d4ee86ae1cdb745.tar.bz2 ChibiOS-ed8a14e6880b1ec6f065c6267d4ee86ae1cdb745.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3031 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'demos/ARM7-AT91SAM7X-LWIP-GCC/lwip')
-rw-r--r-- | demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/cc.h | 9 | ||||
-rw-r--r-- | demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.c | 88 | ||||
-rw-r--r-- | demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.h | 25 | ||||
-rw-r--r-- | demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/lwip.mk | 71 |
4 files changed, 107 insertions, 86 deletions
diff --git a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/cc.h b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/cc.h index b90b447e2..ecac81e09 100644 --- a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/cc.h +++ b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/cc.h @@ -71,5 +71,14 @@ typedef uint32_t mem_ptr_t; }
#define BYTE_ORDER LITTLE_ENDIAN
+#define LWIP_PROVIDE_ERRNO
+
+#define PACK_STRUCT_BEGIN
+#ifdef PACK_STRUCT_STRUCT
+#undef PACK_STRUCT_STRUCT
+#endif
+#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
+#define PACK_STRUCT_END
+#define PACK_STRUCT_FIELD(x) x
#endif /* __CC_H__ */
diff --git a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.c b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.c index 082f2db4d..7e0212df7 100644 --- a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.c +++ b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.c @@ -52,6 +52,8 @@ *
*/
+// see http://lwip.wikia.com/wiki/Porting_for_an_OS for instructions
+
#include "ch.h"
#include "lwip/opt.h"
@@ -66,37 +68,39 @@ void sys_init(void) { }
-sys_sem_t sys_sem_new(u8_t count) {
+err_t sys_sem_new(sys_sem_t *sem, u8_t count) {
- sys_sem_t sem = chHeapAlloc(NULL, sizeof(Semaphore));
- if (sem == 0) {
+ *sem = chHeapAlloc(NULL, sizeof(Semaphore));
+ if (*sem == 0) {
SYS_STATS_INC(sem.err);
+ return ERR_MEM;
}
else {
- chSemInit(sem, (cnt_t)count);
+ chSemInit(*sem, (cnt_t)count);
SYS_STATS_INC(sem.used);
+ return ERR_OK;
}
- return sem;
}
-void sys_sem_free(sys_sem_t sem) {
+void sys_sem_free(sys_sem_t *sem) {
- chHeapFree(sem);
+ chHeapFree(*sem);
+ *sem = SYS_SEM_NULL;
SYS_STATS_DEC(sem.used);
}
-void sys_sem_signal(sys_sem_t sem) {
+void sys_sem_signal(sys_sem_t *sem) {
- chSemSignal(sem);
+ chSemSignal(*sem);
}
-u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout) {
+u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) {
systime_t time, tmo;
chSysLock();
tmo = timeout > 0 ? (systime_t)timeout : TIME_INFINITE;
time = chTimeNow();
- if (chSemWaitTimeoutS(sem, tmo) != RDY_OK)
+ if (chSemWaitTimeoutS(*sem, tmo) != RDY_OK)
time = SYS_ARCH_TIMEOUT;
else
time = chTimeNow() - time;
@@ -104,44 +108,65 @@ u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout) { return time;
}
-sys_mbox_t sys_mbox_new(int size) {
+int sys_sem_valid(sys_sem_t *sem) {
+ return *sem != SYS_SEM_NULL;
+}
+
+// typically called within lwIP after freeing a semaphore
+// to make sure the pointer is not left pointing to invalid data
+void sys_sem_set_invalid(sys_sem_t *sem) {
+ *sem = SYS_SEM_NULL;
+}
+
+err_t sys_mbox_new(sys_mbox_t *mbox, int size) {
- sys_mbox_t mbox = chHeapAlloc(NULL, sizeof(Mailbox) + sizeof(msg_t) * size);
- if (mbox == 0) {
+ *mbox = chHeapAlloc(NULL, sizeof(Mailbox) + sizeof(msg_t) * size);
+ if (*mbox == 0) {
SYS_STATS_INC(mbox.err);
+ return ERR_MEM;
}
else {
- chMBInit(mbox, (void *)(((uint8_t *)mbox) + sizeof(Mailbox)), size);
+ chMBInit(*mbox, (void *)(((uint8_t *)*mbox) + sizeof(Mailbox)), size);
SYS_STATS_INC(mbox.used);
+ return ERR_OK;
}
- return mbox;
}
-void sys_mbox_free(sys_mbox_t mbox) {
+void sys_mbox_free(sys_mbox_t *mbox) {
- chHeapFree(mbox);
+ if (chMBGetUsedCountI(*mbox) != 0) {
+ // If there are messages still present in the mailbox when the mailbox
+ // is deallocated, it is an indication of a programming error in lwIP
+ // and the developer should be notified.
+ SYS_STATS_INC(mbox.err);
+ chMBReset(*mbox);
+ }
+ chHeapFree(*mbox);
+ *mbox = SYS_MBOX_NULL;
SYS_STATS_DEC(mbox.used);
}
-void sys_mbox_post(sys_mbox_t mbox, void *msg) {
+void sys_mbox_post(sys_mbox_t *mbox, void *msg) {
- chMBPost(mbox, (msg_t)msg, TIME_INFINITE);
+ chMBPost(*mbox, (msg_t)msg, TIME_INFINITE);
}
-err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg) {
+err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) {
- if (chMBPost(mbox, (msg_t)msg, TIME_IMMEDIATE) == RDY_TIMEOUT)
+ if (chMBPost(*mbox, (msg_t)msg, TIME_IMMEDIATE) == RDY_TIMEOUT) {
+ SYS_STATS_INC(mbox.err);
return ERR_MEM;
+ }
return ERR_OK;
}
-u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout) {
+u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) {
systime_t time, tmo;
chSysLock();
tmo = timeout > 0 ? (systime_t)timeout : TIME_INFINITE;
time = chTimeNow();
- if (chMBFetchS(mbox, (msg_t *)msg, tmo) != RDY_OK)
+ if (chMBFetchS(*mbox, (msg_t *)msg, tmo) != RDY_OK)
time = SYS_ARCH_TIMEOUT;
else
time = chTimeNow() - time;
@@ -149,19 +174,24 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout) { return time;
}
-u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg) {
+u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) {
- if (chMBFetch(mbox, (msg_t *)msg, TIME_IMMEDIATE) == RDY_TIMEOUT)
+ if (chMBFetch(*mbox, (msg_t *)msg, TIME_IMMEDIATE) == RDY_TIMEOUT)
return SYS_MBOX_EMPTY;
return 0;
}
-struct sys_timeouts *sys_arch_timeouts(void) {
+int sys_mbox_valid(sys_mbox_t *mbox) {
+ return *mbox != SYS_MBOX_NULL;
+}
- return (struct sys_timeouts *)currp->p_lwipspace;
+// typically called within lwIP after freeing an mbox
+// to make sure the pointer is not left pointing to invalid data
+void sys_mbox_set_invalid(sys_mbox_t *mbox) {
+ *mbox = SYS_MBOX_NULL;
}
-sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg),
+sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread,
void *arg, int stacksize, int prio) {
(void)name;
size_t wsz = THD_WA_SIZE(stacksize);
diff --git a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.h b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.h index 229ff6638..5c287b243 100644 --- a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.h +++ b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/arch/sys_arch.h @@ -66,28 +66,7 @@ typedef int sys_prot_t; #define SYS_THREAD_NULL (Thread *)0
#define SYS_SEM_NULL (Semaphore *)0
-void sys_init(void);
-sys_sem_t sys_sem_new(u8_t count);
-void sys_sem_free(sys_sem_t sem);
-void sys_sem_signal(sys_sem_t sem);
-u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout);
-
-sys_mbox_t sys_mbox_new(int size);
-void sys_mbox_free(sys_mbox_t mbox);
-void sys_mbox_post(sys_mbox_t mbox, void *msg);
-err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg);
-u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout);
-u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg);
-
-struct sys_timeouts *sys_arch_timeouts(void);
-
-sys_thread_t sys_thread_new(char *name,
- void (* thread)(void *arg),
- void *arg,
- int stacksize,
- int prio);
-
-sys_prot_t sys_arch_protect(void);
-void sys_arch_unprotect(sys_prot_t pval);
+/* let sys.h use binary semaphores for mutexes */
+#define LWIP_COMPAT_MUTEX 1
#endif /* __SYS_ARCH_H__ */
diff --git a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/lwip.mk b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/lwip.mk index 99a046b9d..55a9bf7f4 100644 --- a/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/lwip.mk +++ b/demos/ARM7-AT91SAM7X-LWIP-GCC/lwip/lwip.mk @@ -1,44 +1,47 @@ # List of the required lwIP files.
+LWIP = ${CHIBIOS}/ext/lwip-1.4.0
+
LWNETIFSRC = \
- ${CHIBIOS}/ext/lwip/src/netif/etharp.c \
- ${CHIBIOS}/ext/lwip/src/netif/loopif.c
+ ${LWIP}/src/netif/etharp.c
LWCORESRC = \
- ${CHIBIOS}/ext/lwip/src/core/dhcp.c \
- ${CHIBIOS}/ext/lwip/src/core/dns.c \
- ${CHIBIOS}/ext/lwip/src/core/init.c \
- ${CHIBIOS}/ext/lwip/src/core/mem.c \
- ${CHIBIOS}/ext/lwip/src/core/memp.c \
- ${CHIBIOS}/ext/lwip/src/core/netif.c \
- ${CHIBIOS}/ext/lwip/src/core/pbuf.c \
- ${CHIBIOS}/ext/lwip/src/core/raw.c \
- ${CHIBIOS}/ext/lwip/src/core/stats.c \
- ${CHIBIOS}/ext/lwip/src/core/sys.c \
- ${CHIBIOS}/ext/lwip/src/core/tcp.c \
- ${CHIBIOS}/ext/lwip/src/core/tcp_in.c \
- ${CHIBIOS}/ext/lwip/src/core/tcp_out.c \
- ${CHIBIOS}/ext/lwip/src/core/udp.c
+ ${LWIP}/src/core/dhcp.c \
+ ${LWIP}/src/core/dns.c \
+ ${LWIP}/src/core/init.c \
+ ${LWIP}/src/core/mem.c \
+ ${LWIP}/src/core/memp.c \
+ ${LWIP}/src/core/netif.c \
+ ${LWIP}/src/core/pbuf.c \
+ ${LWIP}/src/core/raw.c \
+ ${LWIP}/src/core/stats.c \
+ ${LWIP}/src/core/sys.c \
+ ${LWIP}/src/core/tcp.c \
+ ${LWIP}/src/core/tcp_in.c \
+ ${LWIP}/src/core/tcp_out.c \
+ ${LWIP}/src/core/udp.c
LWIPV4SRC = \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/autoip.c \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/icmp.c \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/igmp.c \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/inet.c \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/inet_chksum.c \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/ip.c \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/ip_addr.c \
- ${CHIBIOS}/ext/lwip/src/core/ipv4/ip_frag.c
+ ${LWIP}/src/core/ipv4/autoip.c \
+ ${LWIP}/src/core/ipv4/icmp.c \
+ ${LWIP}/src/core/ipv4/igmp.c \
+ ${LWIP}/src/core/ipv4/inet.c \
+ ${LWIP}/src/core/ipv4/inet_chksum.c \
+ ${LWIP}/src/core/ipv4/ip.c \
+ ${LWIP}/src/core/ipv4/ip_addr.c \
+ ${LWIP}/src/core/ipv4/ip_frag.c \
+ ${LWIP}/src/core/def.c \
+ ${LWIP}/src/core/timers.c
LWAPISRC = \
- ${CHIBIOS}/ext/lwip/src/api/api_lib.c \
- ${CHIBIOS}/ext/lwip/src/api/api_msg.c \
- ${CHIBIOS}/ext/lwip/src/api/err.c \
- ${CHIBIOS}/ext/lwip/src/api/netbuf.c \
- ${CHIBIOS}/ext/lwip/src/api/netdb.c \
- ${CHIBIOS}/ext/lwip/src/api/netifapi.c \
- ${CHIBIOS}/ext/lwip/src/api/sockets.c \
- ${CHIBIOS}/ext/lwip/src/api/tcpip.c
+ ${LWIP}/src/api/api_lib.c \
+ ${LWIP}/src/api/api_msg.c \
+ ${LWIP}/src/api/err.c \
+ ${LWIP}/src/api/netbuf.c \
+ ${LWIP}/src/api/netdb.c \
+ ${LWIP}/src/api/netifapi.c \
+ ${LWIP}/src/api/sockets.c \
+ ${LWIP}/src/api/tcpip.c
LWINC = \
- ${CHIBIOS}/ext/lwip/src/include \
- ${CHIBIOS}/ext/lwip/src/include/ipv4
+ ${LWIP}/src/include \
+ ${LWIP}/src/include/ipv4
|