git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@311 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
d8e1d5a103
commit
16e097d23e
|
@ -74,7 +74,6 @@ KSRC = ../../src/chinit.c ../../src/chdebug.c \
|
|||
# List of the required uIP source files.
|
||||
USRC = ../../ext/uip-1.0/uip/uip_arp.c \
|
||||
../../ext/uip-1.0/uip/psock.c \
|
||||
../../ext/uip-1.0/uip/timer.c \
|
||||
../../ext/uip-1.0/uip/uip.c \
|
||||
../../ext/uip-1.0/apps/webserver/httpd.c \
|
||||
../../ext/uip-1.0/apps/webserver/http-strings.c \
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <uip.h>
|
||||
#include <uip_arp.h>
|
||||
#include <httpd.h>
|
||||
#include <timer.h>
|
||||
#include <clock-arch.h>
|
||||
|
||||
//#define IPADDR0 192
|
||||
|
@ -45,9 +44,6 @@ static const struct uip_eth_addr macaddr = {
|
|||
{0xC2, 0xAF, 0x51, 0x03, 0xCF, 0x46}
|
||||
};
|
||||
|
||||
static EvTimer evt;
|
||||
struct EventListener el0, el1;
|
||||
|
||||
#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
|
||||
|
||||
/*
|
||||
|
@ -95,45 +91,35 @@ clock_time_t clock_time( void )
|
|||
}
|
||||
|
||||
/*
|
||||
* Ethernet link status monitor.
|
||||
* TCP/IP periodic timer.
|
||||
*/
|
||||
static void TimerHandler(eventid_t id) {
|
||||
static void PeriodicTimerHandler(eventid_t id) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < UIP_CONNS; i++) {
|
||||
uip_periodic(i);
|
||||
if (uip_len > 0) {
|
||||
uip_arp_out();
|
||||
network_device_send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ARP periodic timer.
|
||||
*/
|
||||
static void ARPTimerHandler(eventid_t id) {
|
||||
|
||||
uip_arp_timer();
|
||||
(void)EMACGetLinkStatus();
|
||||
}
|
||||
|
||||
msg_t WebThread(void *p) {
|
||||
static const evhandler_t evhndl[] = {
|
||||
TimerHandler,
|
||||
NULL
|
||||
};
|
||||
uip_ipaddr_t ipaddr;
|
||||
struct timer periodic_timer, arp_timer;
|
||||
|
||||
EMACSetAddress(&macaddr.addr[0]);
|
||||
|
||||
/*
|
||||
* Event sources setup.
|
||||
/*
|
||||
* Ethernet frame received.
|
||||
*/
|
||||
evtInit(&evt, 1000); /* Initializes an event timer object. */
|
||||
evtStart(&evt); /* Starts the event timer. */
|
||||
chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */
|
||||
chEvtRegister(&EMACFrameReceived, &el1, 1);
|
||||
static void FrameReceivedHandler(eventid_t id) {
|
||||
|
||||
/*
|
||||
* uIP initialization.
|
||||
*/
|
||||
timer_set(&periodic_timer, CLOCK_SECOND / 2);
|
||||
timer_set(&arp_timer, CLOCK_SECOND * 10);
|
||||
uip_init();
|
||||
uip_setethaddr(macaddr);
|
||||
uip_ipaddr(ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3);
|
||||
uip_sethostaddr(ipaddr);
|
||||
httpd_init();
|
||||
|
||||
while (TRUE) {
|
||||
uip_len = network_device_read();
|
||||
if (uip_len > 0) {
|
||||
while ((uip_len = network_device_read()) > 0) {
|
||||
if (BUF->type == HTONS(UIP_ETHTYPE_IP)) {
|
||||
uip_arp_ipin();
|
||||
uip_input();
|
||||
|
@ -148,26 +134,49 @@ msg_t WebThread(void *p) {
|
|||
network_device_send();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (timer_expired(&periodic_timer)) {
|
||||
int i;
|
||||
timer_reset(&periodic_timer);
|
||||
for (i = 0; i < UIP_CONNS; i++) {
|
||||
uip_periodic(i);
|
||||
if (uip_len > 0) {
|
||||
uip_arp_out();
|
||||
network_device_send();
|
||||
}
|
||||
}
|
||||
if (timer_expired(&arp_timer)) {
|
||||
timer_reset(&arp_timer);
|
||||
uip_arp_timer();
|
||||
}
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
#define FRAME_RECEIVED_ID 0
|
||||
#define PERIODIC_TIMER_ID 1
|
||||
#define ARP_TIMER_ID 2
|
||||
|
||||
static const evhandler_t evhndl[] = {
|
||||
FrameReceivedHandler,
|
||||
PeriodicTimerHandler,
|
||||
ARPTimerHandler
|
||||
};
|
||||
|
||||
msg_t WebThread(void *p) {
|
||||
EvTimer evt1, evt2;
|
||||
EventListener el0, el1, el2;
|
||||
uip_ipaddr_t ipaddr;
|
||||
|
||||
EMACSetAddress(&macaddr.addr[0]);
|
||||
(void)EMACGetLinkStatus();
|
||||
|
||||
/*
|
||||
* Event sources setup.
|
||||
*/
|
||||
chEvtRegister(&EMACFrameReceived, &el0, FRAME_RECEIVED_ID);
|
||||
|
||||
evtInit(&evt1, CH_FREQUENCY / 2);
|
||||
evtStart(&evt1);
|
||||
chEvtRegister(&evt1.et_es, &el1, PERIODIC_TIMER_ID);
|
||||
|
||||
evtInit(&evt2, CH_FREQUENCY * 10);
|
||||
evtStart(&evt2);
|
||||
chEvtRegister(&evt2.et_es, &el2, ARP_TIMER_ID);
|
||||
|
||||
/*
|
||||
* uIP initialization.
|
||||
*/
|
||||
uip_init();
|
||||
uip_setethaddr(macaddr);
|
||||
uip_ipaddr(ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3);
|
||||
uip_sethostaddr(ipaddr);
|
||||
httpd_init();
|
||||
|
||||
while (TRUE)
|
||||
chEvtWait(ALL_EVENTS, evhndl);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue