Last active
October 13, 2017 02:40
-
-
Save energee/816f6c8882e8566389c0abb6dbb1d8eb to your computer and use it in GitHub Desktop.
Can message forwarding for panda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// added this at the end of CAN_RX() | |
// make a copy | |
CAN_FIFOMailBox_TypeDef tx_to_push; | |
tx_to_push.RDHR = to_push.RDHR; | |
tx_to_push.RDLR = to_push.RDLR; | |
tx_to_push.RDTR = to_push.RDTR; | |
tx_to_push.RIR = to_push.RIR; | |
int flags = (tx_to_push.RDTR >> 4) & 0xF; | |
CAN_TypeDef *CANTX; | |
can_ring *can_q; | |
int can_number; | |
set_led(LED_GREEN, 1); | |
if (flags == can_numbering[0] && (((tx_to_push.RIR >> 21) & 0x7FF) == 0x33d)) { | |
set_led(LED_GREEN,1); | |
CANTX = CAN2; | |
can_q = &can_tx2_q; | |
tx_to_push.RIR = 0; | |
tx_to_push.RIR |= ((unsigned int)(0x400000 << 3)) | ((uint32_t)0x00000004); | |
// add CAN packet to send queue | |
// bus number isn't passed through | |
tx_to_push.RDTR &= 0xF; | |
push(can_q, &tx_to_push); | |
// flags = can_number | |
process_can(CANTX, can_q, flags); | |
} | |
// changed this portion in process_can() | |
// check for empty mailbox | |
CAN_FIFOMailBox_TypeDef to_send; | |
if ((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) { | |
if (pop(can_q, &to_send)) { | |
// only send if we have received a packet | |
CAN->sTxMailBox[0].TDLR = to_send.RDLR; | |
CAN->sTxMailBox[0].TDHR = to_send.RDHR; | |
CAN->sTxMailBox[0].TDTR = to_send.RDTR; | |
CAN->sTxMailBox[0].TIR = to_send.RIR; | |
CAN->IER |= CAN_IER_TMEIE; // enable TME interrupt | |
CAN->sTxMailBox[0].TIR |= ((unsigned long)0x00000001); // transmit message | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment