git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5300 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2013-02-22 14:45:58 +00:00
parent 48506ff348
commit 04385d42d4
3 changed files with 25 additions and 9 deletions

View File

@ -510,12 +510,16 @@ void can_lld_transmit(CANDriver *canp,
switch (mailbox) {
case CAN_ANY_TX_MAILBOX:
tmbp = &canp->can->sTxMailBox[(canp->can->TSR & CAN_TSR_CODE) >> 24];
break;
case 1:
tmbp = &canp->can->sTxMailBox[0];
break;
case 2:
tmbp = &canp->can->sTxMailBox[1];
break;
case 3:
tmbp = &canp->can->sTxMailBox[2];
break;
default:
return;
}
@ -546,8 +550,14 @@ void can_lld_transmit(CANDriver *canp,
*/
bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
return mailbox == 0 ? (canp->can->RF0R & CAN_RF0R_FMP0) > 0 :
(canp->can->RF1R & CAN_RF1R_FMP1) > 0;
switch (mailbox) {
case 1:
return (canp->can->RF0R & CAN_RF0R_FMP0) > 0;
case 2:
return (canp->can->RF1R & CAN_RF1R_FMP1) > 0;
default:
return FALSE;
}
}
/**
@ -564,7 +574,8 @@ void can_lld_receive(CANDriver *canp,
CANRxFrame *crfp) {
uint32_t rir, rdtr;
if (mailbox == 0) {
switch (mailbox) {
case 1:
/* Fetches the message.*/
rir = canp->can->sFIFOMailBox[0].RIR;
rdtr = canp->can->sFIFOMailBox[0].RDTR;
@ -578,8 +589,8 @@ void can_lld_receive(CANDriver *canp,
events again.*/
if ((canp->can->RF0R & CAN_RF0R_FMP0) == 0)
canp->can->IER |= CAN_IER_FMPIE0;
}
else {
break;
case 2:
/* Fetches the message.*/
rir = canp->can->sFIFOMailBox[1].RIR;
rdtr = canp->can->sFIFOMailBox[1].RDTR;
@ -593,7 +604,12 @@ void can_lld_receive(CANDriver *canp,
events again.*/
if ((canp->can->RF1R & CAN_RF1R_FMP1) == 0)
canp->can->IER |= CAN_IER_FMPIE1;
break;
default:
return;
}
/* Decodes the various fields in the RX frame.*/
crfp->RTR = (rir & CAN_RI0R_RTR) >> 1;
crfp->IDE = (rir & CAN_RI0R_IDE) >> 2;
if (crfp->IDE)

View File

@ -58,7 +58,7 @@
/**
* @brief This implementation supports two receive mailboxes.
*/
#define CAN_RX_MAILBOXES 3
#define CAN_RX_MAILBOXES 2
/**
* @name CAN registers helper macros

View File

@ -56,7 +56,7 @@ static msg_t can_rx(void *p) {
while(!chThdShouldTerminate()) {
if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0)
continue;
while (canReceive(cip->canp, &rxmsg, TIME_IMMEDIATE) == RDY_OK) {
while (canReceive(cip->canp, 1, &rxmsg, TIME_IMMEDIATE) == RDY_OK) {
/* Process message.*/
palTogglePad(GPIOD, cip->led);
}
@ -82,8 +82,8 @@ static msg_t can_tx(void * p) {
txmsg.data32[1] = 0x00FF00FF;
while (!chThdShouldTerminate()) {
canTransmit(&CAND1, &txmsg, MS2ST(100));
canTransmit(&CAND2, &txmsg, MS2ST(100));
canTransmit(&CAND1, CAN_ANY_TX_MAILBOX, &txmsg, MS2ST(100));
canTransmit(&CAND2, CAN_ANY_TX_MAILBOX, &txmsg, MS2ST(100));
chThdSleepMilliseconds(500);
}
return 0;