From 27ab89ce98afa26410ef763190ba5b68e2981678 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 25 Feb 2012 11:35:51 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3976 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F1xx/MAC/main.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/testhal/STM32F1xx/MAC/main.c b/testhal/STM32F1xx/MAC/main.c index b1eac6fce..e563f779f 100644 --- a/testhal/STM32F1xx/MAC/main.c +++ b/testhal/STM32F1xx/MAC/main.c @@ -21,12 +21,21 @@ #include "ch.h" #include "hal.h" +#include "evtimer.h" + +#define PERIODIC_TIMER_ID 1 +#define FRAME_RECEIVED_ID 2 + static const MACConfig mac_config = {NULL}; +static uint8_t frame[STM32_MAC_BUFFERS_SIZE]; + /* * Application entry point. */ int main(void) { + EvTimer evt; + EventListener el0, el1; /* * System initializations. @@ -43,11 +52,28 @@ int main(void) { */ macStart(ÐD1, &mac_config); + /* Setup event sources.*/ + evtInit(&evt, S2ST(5)); + evtStart(&evt); + chEvtRegisterMask(&evt.et_es, &el0, PERIODIC_TIMER_ID); + chEvtRegisterMask(macGetReceiveEventSource(ÐD1), &el1, FRAME_RECEIVED_ID); + chEvtAddFlags(PERIODIC_TIMER_ID | FRAME_RECEIVED_ID); + /* * Normal main() thread activity, in this demo it enables and disables the * button EXT channel using 5 seconds intervals. */ while (TRUE) { - chThdSleepMilliseconds(500); + eventmask_t mask = chEvtWaitAny(ALL_EVENTS); + if (mask & PERIODIC_TIMER_ID) + (void)macPollLinkStatus(ÐD1); + if (mask & FRAME_RECEIVED_ID) { + MACReceiveDescriptor rd; + + if (macWaitReceiveDescriptor(ÐD1, &rd, TIME_IMMEDIATE) == RDY_OK) { + macReadReceiveDescriptor(&rd, frame, STM32_MAC_BUFFERS_SIZE); + macReleaseReceiveDescriptor(&rd); + } + } } }