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.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
* - lwIP subsystem initialization using the default configuration.
*/
halInit();
chSysInit();
lwipInit(NULL);
/*
* Initializes a serial-over-USB CDC driver.
@ -660,12 +662,6 @@ int main(void) {
*/
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).
*/

View File

@ -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(&ETHD1), &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();
}
/** @} */

View File

@ -26,102 +26,132 @@
#include <lwip/opt.h>
/** @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

View File

@ -74,6 +74,9 @@
*****************************************************************************
*** 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
(bug #610).