From 88b8b3eea1cf7c073e8312ca592ea1e5813e0338 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 20 Jan 2013 09:07:35 +0000 Subject: [PATCH] git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5084 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F4xx/CAN/main.c | 26 ++++++++++++++++++++------ testhal/STM32F4xx/CAN/mcuconf.h | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/testhal/STM32F4xx/CAN/main.c b/testhal/STM32F4xx/CAN/main.c index 6992facb7..a5db154ed 100644 --- a/testhal/STM32F4xx/CAN/main.c +++ b/testhal/STM32F4xx/CAN/main.c @@ -21,6 +21,14 @@ #include "ch.h" #include "hal.h" +struct can_instance { + CANDriver *canp; + uint32_t led; +}; + +static const struct can_instance can1 = {&CAND1, GPIOD_LED5}; +//static const struct can_instance can2 = {&CAND2, GPIOD_LED3}; + /* * Internal loopback mode, 500KBaud, automatic wakeup, automatic recover * from abort mode. @@ -37,20 +45,22 @@ static const CANConfig cancfg = { /* * Receiver thread. */ -static WORKING_AREA(can_rx_wa, 256); +static WORKING_AREA(can_rx1_wa, 256); +//static WORKING_AREA(can_rx2_wa, 256); static msg_t can_rx(void *p) { + struct can_instance *cip = p; EventListener el; CANRxFrame rxmsg; (void)p; chRegSetThreadName("receiver"); - chEvtRegister(&CAND1.rxfull_event, &el, 0); + chEvtRegister(&cip->canp->rxfull_event, &el, 0); while(!chThdShouldTerminate()) { if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0) continue; - while (canReceive(&CAND1, &rxmsg, TIME_IMMEDIATE) == RDY_OK) { + while (canReceive(cip->canp, &rxmsg, TIME_IMMEDIATE) == RDY_OK) { /* Process message.*/ - palTogglePad(GPIOD, GPIOD_LED5); + palTogglePad(GPIOD, cip->led); } } chEvtUnregister(&CAND1.rxfull_event, &el); @@ -103,8 +113,12 @@ int main(void) { /* * Starting the transmitter and receiver threads. */ - chThdCreateStatic(can_rx_wa, sizeof(can_rx_wa), NORMALPRIO + 7, can_rx, NULL); - chThdCreateStatic(can_tx_wa, sizeof(can_tx_wa), NORMALPRIO + 7, can_tx, NULL); + chThdCreateStatic(can_rx1_wa, sizeof(can_rx1_wa), NORMALPRIO + 7, + can_rx, (void *)&can1); +// chThdCreateStatic(can_rx2_wa, sizeof(can_rx2_wa), NORMALPRIO + 7, +// can_rx, (void *)&can2); + chThdCreateStatic(can_tx_wa, sizeof(can_tx_wa), NORMALPRIO + 7, + can_tx, NULL); /* * Normal main() thread activity, in this demo it does nothing. diff --git a/testhal/STM32F4xx/CAN/mcuconf.h b/testhal/STM32F4xx/CAN/mcuconf.h index 0b732c558..c3b1a182a 100644 --- a/testhal/STM32F4xx/CAN/mcuconf.h +++ b/testhal/STM32F4xx/CAN/mcuconf.h @@ -87,7 +87,7 @@ * CAN driver system settings. */ #define STM32_CAN_USE_CAN1 TRUE -#define STM32_CAN_USE_CAN2 FALSE +#define STM32_CAN_USE_CAN2 TRUE #define STM32_CAN_CAN1_IRQ_PRIORITY 11 #define STM32_CAN_CAN2_IRQ_PRIORITY 11