lwip-related improvements.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8066 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
gdisirio 2015-07-04 09:24:09 +00:00
parent ff637e456f
commit 151e9e60ec
4 changed files with 88 additions and 32 deletions

View File

@ -618,9 +618,11 @@ int main(void) {
* and performs the board-specific initializations. * and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the * - Kernel initialization, the main() function becomes a thread and the
* RTOS is active. * RTOS is active.
* - lwIP subsystem initialization using the default configuration.
*/ */
halInit(); halInit();
chSysInit(); chSysInit();
lwipInit(NULL);
/* /*
* Initializes a serial-over-USB CDC driver. * Initializes a serial-over-USB CDC driver.
@ -660,12 +662,6 @@ int main(void) {
*/ */
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
* Creates the LWIP threads (it changes priority internally).
*/
chThdCreateStatic(wa_lwip_thread, LWIP_THREAD_STACK_SIZE, NORMALPRIO + 2,
lwip_thread, NULL);
/* /*
* Creates the HTTP thread (it changes priority internally). * Creates the HTTP thread (it changes priority internally).
*/ */

View File

@ -79,10 +79,15 @@
#define PERIODIC_TIMER_ID 1 #define PERIODIC_TIMER_ID 1
#define FRAME_RECEIVED_ID 2 #define FRAME_RECEIVED_ID 2
/** /*
* Suspension point for initialization procedure.
*/
thread_reference_t lwip_trp = NULL;
/*
* Stack area for the LWIP-MAC thread. * 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. * 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 * @param[in] p pointer to a @p lwipthread_opts structure or @p NULL
* @return The function does not return. * @return The function does not return.
*/ */
THD_FUNCTION(lwip_thread, p) { static THD_FUNCTION(lwip_thread, p) {
event_timer_t evt; event_timer_t evt;
event_listener_t el0, el1; event_listener_t el0, el1;
struct ip_addr ip, gateway, netmask; struct ip_addr ip, gateway, netmask;
@ -261,7 +266,8 @@ THD_FUNCTION(lwip_thread, p) {
chEvtRegisterMask(macGetReceiveEventSource(&ETHD1), &el1, FRAME_RECEIVED_ID); chEvtRegisterMask(macGetReceiveEventSource(&ETHD1), &el1, FRAME_RECEIVED_ID);
chEvtAddEvents(PERIODIC_TIMER_ID | 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); chThdSetPriority(LWIP_THREAD_PRIORITY);
while (true) { 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();
}
/** @} */ /** @} */

View File

@ -26,102 +26,132 @@
#include <lwip/opt.h> #include <lwip/opt.h>
/** @brief MAC thread priority.*/ /**
* @brief lwIP thread priority.
*/
#ifndef LWIP_THREAD_PRIORITY #ifndef LWIP_THREAD_PRIORITY
#define LWIP_THREAD_PRIORITY LOWPRIO #define LWIP_THREAD_PRIORITY LOWPRIO
#endif #endif
/** @brief MAC thread stack size. */ /**
* @brief lwIP thread stack size.
*/
#if !defined(LWIP_THREAD_STACK_SIZE) || defined(__DOXYGEN__) #if !defined(LWIP_THREAD_STACK_SIZE) || defined(__DOXYGEN__)
#define LWIP_THREAD_STACK_SIZE 576 #define LWIP_THREAD_STACK_SIZE 576
#endif #endif
/** @brief Link poll interval. */ /**
* @brief Link poll interval.
*/
#if !defined(LWIP_LINK_POLL_INTERVAL) || defined(__DOXYGEN__) #if !defined(LWIP_LINK_POLL_INTERVAL) || defined(__DOXYGEN__)
#define LWIP_LINK_POLL_INTERVAL S2ST(5) #define LWIP_LINK_POLL_INTERVAL S2ST(5)
#endif #endif
/** @brief IP Address. */ /**
* @brief IP Address.
*/
#if !defined(LWIP_IPADDR) || defined(__DOXYGEN__) #if !defined(LWIP_IPADDR) || defined(__DOXYGEN__)
#define LWIP_IPADDR(p) IP4_ADDR(p, 192, 168, 1, 10) #define LWIP_IPADDR(p) IP4_ADDR(p, 192, 168, 1, 10)
#endif #endif
/** @brief IP Gateway. */ /**
* @brief IP Gateway.
*/
#if !defined(LWIP_GATEWAY) || defined(__DOXYGEN__) #if !defined(LWIP_GATEWAY) || defined(__DOXYGEN__)
#define LWIP_GATEWAY(p) IP4_ADDR(p, 192, 168, 1, 1) #define LWIP_GATEWAY(p) IP4_ADDR(p, 192, 168, 1, 1)
#endif #endif
/** @brief IP netmask. */ /**
* @brief IP netmask.
*/
#if !defined(LWIP_NETMASK) || defined(__DOXYGEN__) #if !defined(LWIP_NETMASK) || defined(__DOXYGEN__)
#define LWIP_NETMASK(p) IP4_ADDR(p, 255, 255, 255, 0) #define LWIP_NETMASK(p) IP4_ADDR(p, 255, 255, 255, 0)
#endif #endif
/** @brief Transmission timeout. */ /**
* @brief Transmission timeout.
*/
#if !defined(LWIP_SEND_TIMEOUT) || defined(__DOXYGEN__) #if !defined(LWIP_SEND_TIMEOUT) || defined(__DOXYGEN__)
#define LWIP_SEND_TIMEOUT 50 #define LWIP_SEND_TIMEOUT 50
#endif #endif
/** @brief Link speed. */ /**
* @brief Link speed.
*/
#if !defined(LWIP_LINK_SPEED) || defined(__DOXYGEN__) #if !defined(LWIP_LINK_SPEED) || defined(__DOXYGEN__)
#define LWIP_LINK_SPEED 100000000 #define LWIP_LINK_SPEED 100000000
#endif #endif
/** @brief MAC Address byte 0. */ /**
* @brief MAC Address byte 0.
*/
#if !defined(LWIP_ETHADDR_0) || defined(__DOXYGEN__) #if !defined(LWIP_ETHADDR_0) || defined(__DOXYGEN__)
#define LWIP_ETHADDR_0 0xC2 #define LWIP_ETHADDR_0 0xC2
#endif #endif
/** @brief MAC Address byte 1. */ /**
* @brief MAC Address byte 1.
*/
#if !defined(LWIP_ETHADDR_1) || defined(__DOXYGEN__) #if !defined(LWIP_ETHADDR_1) || defined(__DOXYGEN__)
#define LWIP_ETHADDR_1 0xAF #define LWIP_ETHADDR_1 0xAF
#endif #endif
/** @brief MAC Address byte 2. */ /**
* @brief MAC Address byte 2.
*/
#if !defined(LWIP_ETHADDR_2) || defined(__DOXYGEN__) #if !defined(LWIP_ETHADDR_2) || defined(__DOXYGEN__)
#define LWIP_ETHADDR_2 0x51 #define LWIP_ETHADDR_2 0x51
#endif #endif
/** @brief MAC Address byte 3. */ /**
* @brief MAC Address byte 3.
*/
#if !defined(LWIP_ETHADDR_3) || defined(__DOXYGEN__) #if !defined(LWIP_ETHADDR_3) || defined(__DOXYGEN__)
#define LWIP_ETHADDR_3 0x03 #define LWIP_ETHADDR_3 0x03
#endif #endif
/** @brief MAC Address byte 4. */ /**
* @brief MAC Address byte 4.
*/
#if !defined(LWIP_ETHADDR_4) || defined(__DOXYGEN__) #if !defined(LWIP_ETHADDR_4) || defined(__DOXYGEN__)
#define LWIP_ETHADDR_4 0xCF #define LWIP_ETHADDR_4 0xCF
#endif #endif
/** @brief MAC Address byte 5. */ /**
* @brief MAC Address byte 5.
*/
#if !defined(LWIP_ETHADDR_5) || defined(__DOXYGEN__) #if !defined(LWIP_ETHADDR_5) || defined(__DOXYGEN__)
#define LWIP_ETHADDR_5 0x46 #define LWIP_ETHADDR_5 0x46
#endif #endif
/** @brief Interface name byte 0. */ /**
* @brief Interface name byte 0.
*/
#if !defined(LWIP_IFNAME0) || defined(__DOXYGEN__) #if !defined(LWIP_IFNAME0) || defined(__DOXYGEN__)
#define LWIP_IFNAME0 'm' #define LWIP_IFNAME0 'm'
#endif #endif
/** @brief Interface name byte 1. */ /**
* @brief Interface name byte 1.
*/
#if !defined(LWIP_IFNAME1) || defined(__DOXYGEN__) #if !defined(LWIP_IFNAME1) || defined(__DOXYGEN__)
#define LWIP_IFNAME1 's' #define LWIP_IFNAME1 's'
#endif #endif
/** /**
* @brief Runtime TCP/IP settings. * @brief Runtime TCP/IP settings.
*/ */
struct lwipthread_opts { typedef struct lwipthread_opts {
uint8_t *macaddress; uint8_t *macaddress;
uint32_t address; uint32_t address;
uint32_t netmask; uint32_t netmask;
uint32_t gateway; uint32_t gateway;
}; } lwipthread_opts_t;
extern THD_WORKING_AREA(wa_lwip_thread, LWIP_THREAD_STACK_SIZE);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
THD_FUNCTION(lwip_thread, p); void lwipInit(const lwipthread_opts_t *opts);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -74,6 +74,9 @@
***************************************************************************** *****************************************************************************
*** 3.0.0 *** *** 3.0.0 ***
- NEW: Added an initialization function to the lwIP bindings, now it is
sufficient to call lwipInit(NULL); in order to start the subsystem.
Demo updated.
- HAL: Fixed TIM2 wrongly classified as 32bits in STM32F1xx devices - HAL: Fixed TIM2 wrongly classified as 32bits in STM32F1xx devices
(bug #610). (bug #610).