2011-09-14 16:53:08 +00:00
|
|
|
/*
|
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2012-01-21 14:29:42 +00:00
|
|
|
2011,2012 Giovanni Di Sirio.
|
2011-09-14 16:53:08 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
2012-02-25 11:35:51 +00:00
|
|
|
#include "evtimer.h"
|
|
|
|
|
|
|
|
#define PERIODIC_TIMER_ID 1
|
|
|
|
#define FRAME_RECEIVED_ID 2
|
|
|
|
|
2012-02-23 20:50:27 +00:00
|
|
|
static const MACConfig mac_config = {NULL};
|
|
|
|
|
2012-02-25 11:35:51 +00:00
|
|
|
static uint8_t frame[STM32_MAC_BUFFERS_SIZE];
|
|
|
|
|
2011-09-14 16:53:08 +00:00
|
|
|
/*
|
|
|
|
* Application entry point.
|
|
|
|
*/
|
|
|
|
int main(void) {
|
2012-02-25 11:35:51 +00:00
|
|
|
EvTimer evt;
|
|
|
|
EventListener el0, el1;
|
2011-09-14 16:53:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* System initializations.
|
|
|
|
* - HAL initialization, this also initializes the configured device drivers
|
|
|
|
* and performs the board-specific initializations.
|
|
|
|
* - Kernel initialization, the main() function becomes a thread and the
|
|
|
|
* RTOS is active.
|
|
|
|
*/
|
|
|
|
halInit();
|
|
|
|
chSysInit();
|
|
|
|
|
|
|
|
/*
|
2012-01-09 19:37:58 +00:00
|
|
|
* Activates the MAC driver 1.
|
2011-09-14 16:53:08 +00:00
|
|
|
*/
|
2012-02-23 20:50:27 +00:00
|
|
|
macStart(ÐD1, &mac_config);
|
2011-09-14 16:53:08 +00:00
|
|
|
|
2012-02-25 11:35:51 +00:00
|
|
|
/* 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);
|
|
|
|
|
2011-09-14 16:53:08 +00:00
|
|
|
/*
|
|
|
|
* Normal main() thread activity, in this demo it enables and disables the
|
|
|
|
* button EXT channel using 5 seconds intervals.
|
|
|
|
*/
|
|
|
|
while (TRUE) {
|
2012-02-25 11:35:51 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2011-09-14 16:53:08 +00:00
|
|
|
}
|
|
|
|
}
|