From 151e9e60ec4af4a599ac98ea27c8642eed1e75e0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 4 Jul 2015 09:24:09 +0000 Subject: lwip-related improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8066 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/various/lwip_bindings/lwipthread.c | 35 +++++++++++++++-- os/various/lwip_bindings/lwipthread.h | 74 ++++++++++++++++++++++++----------- 2 files changed, 83 insertions(+), 26 deletions(-) (limited to 'os/various/lwip_bindings') diff --git a/os/various/lwip_bindings/lwipthread.c b/os/various/lwip_bindings/lwipthread.c index aab55b233..6a918afa0 100644 --- a/os/various/lwip_bindings/lwipthread.c +++ b/os/various/lwip_bindings/lwipthread.c @@ -79,10 +79,15 @@ #define PERIODIC_TIMER_ID 1 #define FRAME_RECEIVED_ID 2 -/** +/* + * Suspension point for initialization procedure. + */ +thread_reference_t lwip_trp = NULL; + +/* * Stack area for the LWIP-MAC thread. */ -THD_WORKING_AREA(wa_lwip_thread, LWIP_THREAD_STACK_SIZE); +static THD_WORKING_AREA(wa_lwip_thread, LWIP_THREAD_STACK_SIZE); /* * Initialization. @@ -214,7 +219,7 @@ static err_t ethernetif_init(struct netif *netif) { * @param[in] p pointer to a @p lwipthread_opts structure or @p NULL * @return The function does not return. */ -THD_FUNCTION(lwip_thread, p) { +static THD_FUNCTION(lwip_thread, p) { event_timer_t evt; event_listener_t el0, el1; struct ip_addr ip, gateway, netmask; @@ -261,7 +266,8 @@ THD_FUNCTION(lwip_thread, p) { chEvtRegisterMask(macGetReceiveEventSource(ÐD1), &el1, FRAME_RECEIVED_ID); chEvtAddEvents(PERIODIC_TIMER_ID | FRAME_RECEIVED_ID); - /* Goes to the final priority after initialization.*/ + /* Resumes the caller and goes to the final priority.*/ + chThdResume(&lwip_trp, MSG_OK); chThdSetPriority(LWIP_THREAD_PRIORITY); while (true) { @@ -310,4 +316,25 @@ THD_FUNCTION(lwip_thread, p) { } } +/** + * @brief Initializes the lwIP subsystem. + * @note The function exits after the initialization is finished. + * + * @param[in] opts pointer to the configuration structure, if @p NULL + * then the static configuration is used. + */ +void lwipInit(const lwipthread_opts_t *opts) { + + /* Creating the lwIP thread (it changes priority internally).*/ + chThdCreateStatic(wa_lwip_thread, LWIP_THREAD_STACK_SIZE, + chThdGetPriorityX() - 1, lwip_thread, (void *)opts); + + /* Waiting for the lwIP thread complete initialization. Note, + this thread reaches the thread reference object first because + the relative priorities.*/ + chSysLock(); + chThdSuspendS(&lwip_trp); + chSysUnlock(); +} + /** @} */ diff --git a/os/various/lwip_bindings/lwipthread.h b/os/various/lwip_bindings/lwipthread.h index e9b7367a0..8b76eb67e 100644 --- a/os/various/lwip_bindings/lwipthread.h +++ b/os/various/lwip_bindings/lwipthread.h @@ -26,102 +26,132 @@ #include -/** @brief MAC thread priority.*/ +/** + * @brief lwIP thread priority. + */ #ifndef LWIP_THREAD_PRIORITY #define LWIP_THREAD_PRIORITY LOWPRIO #endif -/** @brief MAC thread stack size. */ +/** + * @brief lwIP thread stack size. + */ #if !defined(LWIP_THREAD_STACK_SIZE) || defined(__DOXYGEN__) #define LWIP_THREAD_STACK_SIZE 576 #endif -/** @brief Link poll interval. */ +/** + * @brief Link poll interval. + */ #if !defined(LWIP_LINK_POLL_INTERVAL) || defined(__DOXYGEN__) #define LWIP_LINK_POLL_INTERVAL S2ST(5) #endif -/** @brief IP Address. */ +/** + * @brief IP Address. + */ #if !defined(LWIP_IPADDR) || defined(__DOXYGEN__) #define LWIP_IPADDR(p) IP4_ADDR(p, 192, 168, 1, 10) #endif -/** @brief IP Gateway. */ +/** + * @brief IP Gateway. + */ #if !defined(LWIP_GATEWAY) || defined(__DOXYGEN__) #define LWIP_GATEWAY(p) IP4_ADDR(p, 192, 168, 1, 1) #endif -/** @brief IP netmask. */ +/** + * @brief IP netmask. + */ #if !defined(LWIP_NETMASK) || defined(__DOXYGEN__) #define LWIP_NETMASK(p) IP4_ADDR(p, 255, 255, 255, 0) #endif -/** @brief Transmission timeout. */ +/** + * @brief Transmission timeout. + */ #if !defined(LWIP_SEND_TIMEOUT) || defined(__DOXYGEN__) #define LWIP_SEND_TIMEOUT 50 #endif -/** @brief Link speed. */ +/** + * @brief Link speed. + */ #if !defined(LWIP_LINK_SPEED) || defined(__DOXYGEN__) #define LWIP_LINK_SPEED 100000000 #endif -/** @brief MAC Address byte 0. */ +/** + * @brief MAC Address byte 0. + */ #if !defined(LWIP_ETHADDR_0) || defined(__DOXYGEN__) #define LWIP_ETHADDR_0 0xC2 #endif -/** @brief MAC Address byte 1. */ +/** + * @brief MAC Address byte 1. + */ #if !defined(LWIP_ETHADDR_1) || defined(__DOXYGEN__) #define LWIP_ETHADDR_1 0xAF #endif -/** @brief MAC Address byte 2. */ +/** + * @brief MAC Address byte 2. + */ #if !defined(LWIP_ETHADDR_2) || defined(__DOXYGEN__) #define LWIP_ETHADDR_2 0x51 #endif -/** @brief MAC Address byte 3. */ +/** + * @brief MAC Address byte 3. + */ #if !defined(LWIP_ETHADDR_3) || defined(__DOXYGEN__) #define LWIP_ETHADDR_3 0x03 #endif -/** @brief MAC Address byte 4. */ +/** + * @brief MAC Address byte 4. + */ #if !defined(LWIP_ETHADDR_4) || defined(__DOXYGEN__) #define LWIP_ETHADDR_4 0xCF #endif -/** @brief MAC Address byte 5. */ +/** + * @brief MAC Address byte 5. + */ #if !defined(LWIP_ETHADDR_5) || defined(__DOXYGEN__) #define LWIP_ETHADDR_5 0x46 #endif -/** @brief Interface name byte 0. */ +/** + * @brief Interface name byte 0. + */ #if !defined(LWIP_IFNAME0) || defined(__DOXYGEN__) #define LWIP_IFNAME0 'm' #endif -/** @brief Interface name byte 1. */ +/** + * @brief Interface name byte 1. + */ #if !defined(LWIP_IFNAME1) || defined(__DOXYGEN__) #define LWIP_IFNAME1 's' #endif /** - * @brief Runtime TCP/IP settings. + * @brief Runtime TCP/IP settings. */ -struct lwipthread_opts { +typedef struct lwipthread_opts { uint8_t *macaddress; uint32_t address; uint32_t netmask; uint32_t gateway; -}; - -extern THD_WORKING_AREA(wa_lwip_thread, LWIP_THREAD_STACK_SIZE); +} lwipthread_opts_t; #ifdef __cplusplus extern "C" { #endif - THD_FUNCTION(lwip_thread, p); + void lwipInit(const lwipthread_opts_t *opts); #ifdef __cplusplus } #endif -- cgit v1.2.3