git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5300 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
48506ff348
commit
04385d42d4
|
@ -510,12 +510,16 @@ void can_lld_transmit(CANDriver *canp,
|
||||||
switch (mailbox) {
|
switch (mailbox) {
|
||||||
case CAN_ANY_TX_MAILBOX:
|
case CAN_ANY_TX_MAILBOX:
|
||||||
tmbp = &canp->can->sTxMailBox[(canp->can->TSR & CAN_TSR_CODE) >> 24];
|
tmbp = &canp->can->sTxMailBox[(canp->can->TSR & CAN_TSR_CODE) >> 24];
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
tmbp = &canp->can->sTxMailBox[0];
|
tmbp = &canp->can->sTxMailBox[0];
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
tmbp = &canp->can->sTxMailBox[1];
|
tmbp = &canp->can->sTxMailBox[1];
|
||||||
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
tmbp = &canp->can->sTxMailBox[2];
|
tmbp = &canp->can->sTxMailBox[2];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -546,8 +550,14 @@ void can_lld_transmit(CANDriver *canp,
|
||||||
*/
|
*/
|
||||||
bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
|
bool_t can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
|
||||||
|
|
||||||
return mailbox == 0 ? (canp->can->RF0R & CAN_RF0R_FMP0) > 0 :
|
switch (mailbox) {
|
||||||
(canp->can->RF1R & CAN_RF1R_FMP1) > 0;
|
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) {
|
CANRxFrame *crfp) {
|
||||||
uint32_t rir, rdtr;
|
uint32_t rir, rdtr;
|
||||||
|
|
||||||
if (mailbox == 0) {
|
switch (mailbox) {
|
||||||
|
case 1:
|
||||||
/* Fetches the message.*/
|
/* Fetches the message.*/
|
||||||
rir = canp->can->sFIFOMailBox[0].RIR;
|
rir = canp->can->sFIFOMailBox[0].RIR;
|
||||||
rdtr = canp->can->sFIFOMailBox[0].RDTR;
|
rdtr = canp->can->sFIFOMailBox[0].RDTR;
|
||||||
|
@ -578,8 +589,8 @@ void can_lld_receive(CANDriver *canp,
|
||||||
events again.*/
|
events again.*/
|
||||||
if ((canp->can->RF0R & CAN_RF0R_FMP0) == 0)
|
if ((canp->can->RF0R & CAN_RF0R_FMP0) == 0)
|
||||||
canp->can->IER |= CAN_IER_FMPIE0;
|
canp->can->IER |= CAN_IER_FMPIE0;
|
||||||
}
|
break;
|
||||||
else {
|
case 2:
|
||||||
/* Fetches the message.*/
|
/* Fetches the message.*/
|
||||||
rir = canp->can->sFIFOMailBox[1].RIR;
|
rir = canp->can->sFIFOMailBox[1].RIR;
|
||||||
rdtr = canp->can->sFIFOMailBox[1].RDTR;
|
rdtr = canp->can->sFIFOMailBox[1].RDTR;
|
||||||
|
@ -593,7 +604,12 @@ void can_lld_receive(CANDriver *canp,
|
||||||
events again.*/
|
events again.*/
|
||||||
if ((canp->can->RF1R & CAN_RF1R_FMP1) == 0)
|
if ((canp->can->RF1R & CAN_RF1R_FMP1) == 0)
|
||||||
canp->can->IER |= CAN_IER_FMPIE1;
|
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->RTR = (rir & CAN_RI0R_RTR) >> 1;
|
||||||
crfp->IDE = (rir & CAN_RI0R_IDE) >> 2;
|
crfp->IDE = (rir & CAN_RI0R_IDE) >> 2;
|
||||||
if (crfp->IDE)
|
if (crfp->IDE)
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
/**
|
/**
|
||||||
* @brief This implementation supports two receive mailboxes.
|
* @brief This implementation supports two receive mailboxes.
|
||||||
*/
|
*/
|
||||||
#define CAN_RX_MAILBOXES 3
|
#define CAN_RX_MAILBOXES 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name CAN registers helper macros
|
* @name CAN registers helper macros
|
||||||
|
|
|
@ -56,7 +56,7 @@ static msg_t can_rx(void *p) {
|
||||||
while(!chThdShouldTerminate()) {
|
while(!chThdShouldTerminate()) {
|
||||||
if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0)
|
if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0)
|
||||||
continue;
|
continue;
|
||||||
while (canReceive(cip->canp, &rxmsg, TIME_IMMEDIATE) == RDY_OK) {
|
while (canReceive(cip->canp, 1, &rxmsg, TIME_IMMEDIATE) == RDY_OK) {
|
||||||
/* Process message.*/
|
/* Process message.*/
|
||||||
palTogglePad(GPIOD, cip->led);
|
palTogglePad(GPIOD, cip->led);
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ static msg_t can_tx(void * p) {
|
||||||
txmsg.data32[1] = 0x00FF00FF;
|
txmsg.data32[1] = 0x00FF00FF;
|
||||||
|
|
||||||
while (!chThdShouldTerminate()) {
|
while (!chThdShouldTerminate()) {
|
||||||
canTransmit(&CAND1, &txmsg, MS2ST(100));
|
canTransmit(&CAND1, CAN_ANY_TX_MAILBOX, &txmsg, MS2ST(100));
|
||||||
canTransmit(&CAND2, &txmsg, MS2ST(100));
|
canTransmit(&CAND2, CAN_ANY_TX_MAILBOX, &txmsg, MS2ST(100));
|
||||||
chThdSleepMilliseconds(500);
|
chThdSleepMilliseconds(500);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue