diff options
Diffstat (limited to 'demos/ARM7-AT91SAM7X-WEB-GCC')
-rw-r--r-- | demos/ARM7-AT91SAM7X-WEB-GCC/Makefile | 1 | ||||
-rw-r--r-- | demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c | 121 |
2 files changed, 65 insertions, 57 deletions
diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/Makefile b/demos/ARM7-AT91SAM7X-WEB-GCC/Makefile index 0f9806151..a1ebaba71 100644 --- a/demos/ARM7-AT91SAM7X-WEB-GCC/Makefile +++ b/demos/ARM7-AT91SAM7X-WEB-GCC/Makefile @@ -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 \
diff --git a/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c b/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c index 425a6366d..825ff1eff 100644 --- a/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.c +++ b/demos/ARM7-AT91SAM7X-WEB-GCC/web/webthread.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,79 +91,92 @@ clock_time_t clock_time( void ) }
/*
- * Ethernet link status monitor.
+ * TCP/IP periodic timer.
+ */
+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 TimerHandler(eventid_t id) {
+static void ARPTimerHandler(eventid_t id) {
+ uip_arp_timer();
(void)EMACGetLinkStatus();
}
+/*
+ * Ethernet frame received.
+ */
+static void FrameReceivedHandler(eventid_t id) {
+
+ while ((uip_len = network_device_read()) > 0) {
+ if (BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+ uip_arp_ipin();
+ uip_input();
+ if (uip_len > 0) {
+ uip_arp_out();
+ network_device_send();
+ }
+ }
+ else if (BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin();
+ if (uip_len > 0)
+ network_device_send();
+ }
+ }
+}
+
+#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) {
- static const evhandler_t evhndl[] = {
- TimerHandler,
- NULL
- };
+ EvTimer evt1, evt2;
+ EventListener el0, el1, el2;
uip_ipaddr_t ipaddr;
- struct timer periodic_timer, arp_timer;
EMACSetAddress(&macaddr.addr[0]);
+ (void)EMACGetLinkStatus();
/*
* Event sources setup.
*/
- 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);
+ 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.
*/
- 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) {
- if (BUF->type == HTONS(UIP_ETHTYPE_IP)) {
- uip_arp_ipin();
- uip_input();
- if (uip_len > 0) {
- uip_arp_out();
- network_device_send();
- }
- }
- else if (BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
- uip_arp_arpin();
- if (uip_len > 0)
- 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 {
- chEvtWait(ALL_EVENTS, evhndl);
- }
- }
- }
+ while (TRUE)
+ chEvtWait(ALL_EVENTS, evhndl);
return 0;
}
|