34#ifndef LIBOPENCM3_CAN_H
35#define LIBOPENCM3_CAN_H
50#define CAN1 BX_CAN1_BASE
51#define CAN2 BX_CAN2_BASE
57#define CAN_MCR(can_base) MMIO32((can_base) + 0x000)
59#define CAN_MSR(can_base) MMIO32((can_base) + 0x004)
61#define CAN_TSR(can_base) MMIO32((can_base) + 0x008)
64#define CAN_RF0R(can_base) MMIO32((can_base) + 0x00C)
66#define CAN_RF1R(can_base) MMIO32((can_base) + 0x010)
69#define CAN_IER(can_base) MMIO32((can_base) + 0x014)
71#define CAN_ESR(can_base) MMIO32((can_base) + 0x018)
73#define CAN_BTR(can_base) MMIO32((can_base) + 0x01C)
80#define CAN_MBOX0 0x180
81#define CAN_MBOX1 0x190
82#define CAN_MBOX2 0x1A0
83#define CAN_FIFO0 0x1B0
84#define CAN_FIFO1 0x1C0
87#define CAN_TIxR(can_base, mbox) MMIO32((can_base) + (mbox) + 0x0)
88#define CAN_TI0R(can_base) CAN_TIxR(can_base, CAN_MBOX0)
89#define CAN_TI1R(can_base) CAN_TIxR(can_base, CAN_MBOX1)
90#define CAN_TI2R(can_base) CAN_TIxR(can_base, CAN_MBOX2)
93#define CAN_TDTxR(can_base, mbox) MMIO32((can_base) + (mbox) + 0x4)
94#define CAN_TDT0R(can_base) CAN_TDTxR((can_base), CAN_MBOX0)
95#define CAN_TDT1R(can_base) CAN_TDTxR((can_base), CAN_MBOX1)
96#define CAN_TDT2R(can_base) CAN_TDTxR((can_base), CAN_MBOX2)
99#define CAN_TDLxR(can_base, mbox) MMIO32((can_base) + (mbox) + 0x8)
100#define CAN_TDL0R(can_base) CAN_TDLxR((can_base), CAN_MBOX0)
101#define CAN_TDL1R(can_base) CAN_TDLxR((can_base), CAN_MBOX1)
102#define CAN_TDL2R(can_base) CAN_TDLxR((can_base), CAN_MBOX2)
105#define CAN_TDHxR(can_base, mbox) MMIO32((can_base) + (mbox) + 0xC)
106#define CAN_TDH0R(can_base) CAN_TDHxR((can_base), CAN_MBOX0)
107#define CAN_TDH1R(can_base) CAN_TDHxR((can_base), CAN_MBOX1)
108#define CAN_TDH2R(can_base) CAN_TDHxR((can_base), CAN_MBOX2)
111#define CAN_RIxR(can_base, fifo) MMIO32((can_base) + (fifo) + 0x0)
112#define CAN_RI0R(can_base) CAN_RIxR((can_base), CAN_FIFO0)
113#define CAN_RI1R(can_base) CAN_RIxR((can_base), CAN_FIFO1)
116#define CAN_RDTxR(can_base, fifo) MMIO32((can_base) + (fifo) + 0x4)
117#define CAN_RDT0R(can_base) CAN_RDTxR((can_base), CAN_FIFO0)
118#define CAN_RDT1R(can_base) CAN_RDTxR((can_base), CAN_FIFO1)
121#define CAN_RDLxR(can_base, fifo) MMIO32((can_base) + (fifo) + 0x8)
122#define CAN_RDL0R(can_base) CAN_RDLxR((can_base), CAN_FIFO0)
123#define CAN_RDL1R(can_base) CAN_RDLxR((can_base), CAN_FIFO1)
126#define CAN_RDHxR(can_base, fifo) MMIO32((can_base) + (fifo) + 0xC)
127#define CAN_RDH0R(can_base) CAN_RDHxR((can_base), CAN_FIFO0)
128#define CAN_RDH1R(can_base) CAN_RDHxR((can_base), CAN_FIFO1)
133#define CAN_FMR(can_base) MMIO32((can_base) + 0x200)
136#define CAN_FM1R(can_base) MMIO32((can_base) + 0x204)
141#define CAN_FS1R(can_base) MMIO32((can_base) + 0x20C)
146#define CAN_FFA1R(can_base) MMIO32((can_base) + 0x214)
151#define CAN_FA1R(can_base) MMIO32((can_base) + 0x21C)
162#define CAN_FiR1(can_base, bank) MMIO32((can_base) + 0x240 + \
163 ((bank) * 0x8) + 0x0)
164#define CAN_FiR2(can_base, bank) MMIO32((can_base) + 0x240 + \
165 ((bank) * 0x8) + 0x4)
172#define CAN_MCR_DBF (1 << 16)
175#define CAN_MCR_RESET (1 << 15)
180#define CAN_MCR_TTCM (1 << 7)
183#define CAN_MCR_ABOM (1 << 6)
186#define CAN_MCR_AWUM (1 << 5)
189#define CAN_MCR_NART (1 << 4)
192#define CAN_MCR_RFLM (1 << 3)
195#define CAN_MCR_TXFP (1 << 2)
198#define CAN_MCR_SLEEP (1 << 1)
201#define CAN_MCR_INRQ (1 << 0)
208#define CAN_MSR_RX (1 << 11)
211#define CAN_MSR_SAMP (1 << 10)
214#define CAN_MSR_RXM (1 << 9)
217#define CAN_MSR_TXM (1 << 8)
222#define CAN_MSR_SLAKI (1 << 4)
225#define CAN_MSR_WKUI (1 << 3)
228#define CAN_MSR_ERRI (1 << 2)
231#define CAN_MSR_SLAK (1 << 1)
234#define CAN_MSR_INAK (1 << 0)
239#define CAN_TSR_LOW2 (1 << 31)
242#define CAN_TSR_LOW1 (1 << 30)
245#define CAN_TSR_LOW0 (1 << 29)
248#define CAN_TSR_TME2 (1 << 28)
251#define CAN_TSR_TME1 (1 << 27)
254#define CAN_TSR_TME0 (1 << 26)
257#define CAN_TSR_CODE_MASK (0x3 << 24)
260#define CAN_TSR_ABRQ2 (1 << 23)
265#define CAN_TSR_TERR2 (1 << 19)
268#define CAN_TSR_ALST2 (1 << 18)
271#define CAN_TSR_TXOK2 (1 << 17)
274#define CAN_TSR_RQCP2 (1 << 16)
277#define CAN_TSR_ABRQ1 (1 << 15)
282#define CAN_TSR_TERR1 (1 << 11)
285#define CAN_TSR_ALST1 (1 << 10)
288#define CAN_TSR_TXOK1 (1 << 9)
291#define CAN_TSR_RQCP1 (1 << 8)
294#define CAN_TSR_ABRQ0 (1 << 7)
299#define CAN_TSR_TERR0 (1 << 3)
302#define CAN_TSR_ALST0 (1 << 2)
305#define CAN_TSR_TXOK0 (1 << 1)
308#define CAN_TSR_RQCP0 (1 << 0)
315#define CAN_RF0R_RFOM0 (1 << 5)
318#define CAN_RF0R_FOVR0 (1 << 4)
321#define CAN_RF0R_FULL0 (1 << 3)
326#define CAN_RF0R_FMP0_MASK (0x3 << 0)
333#define CAN_RF1R_RFOM1 (1 << 5)
336#define CAN_RF1R_FOVR1 (1 << 4)
339#define CAN_RF1R_FULL1 (1 << 3)
344#define CAN_RF1R_FMP1_MASK (0x3 << 0)
351#define CAN_IER_SLKIE (1 << 17)
354#define CAN_IER_WKUIE (1 << 16)
357#define CAN_IER_ERRIE (1 << 15)
362#define CAN_IER_LECIE (1 << 11)
365#define CAN_IER_BOFIE (1 << 10)
368#define CAN_IER_EPVIE (1 << 9)
371#define CAN_IER_EWGIE (1 << 8)
376#define CAN_IER_FOVIE1 (1 << 6)
379#define CAN_IER_FFIE1 (1 << 5)
382#define CAN_IER_FMPIE1 (1 << 4)
385#define CAN_IER_FOVIE0 (1 << 3)
388#define CAN_IER_FFIE0 (1 << 2)
391#define CAN_IER_FMPIE0 (1 << 1)
394#define CAN_IER_TMEIE (1 << 0)
399#define CAN_ESR_REC_MASK (0xF << 24)
402#define CAN_ESR_TEC_MASK (0xF << 16)
407#define CAN_ESR_LEC_NO_ERROR (0x0 << 4)
408#define CAN_ESR_LEC_STUFF_ERROR (0x1 << 4)
409#define CAN_ESR_LEC_FORM_ERROR (0x2 << 4)
410#define CAN_ESR_LEC_ACK_ERROR (0x3 << 4)
411#define CAN_ESR_LEC_REC_ERROR (0x4 << 4)
412#define CAN_ESR_LEC_DOM_ERROR (0x5 << 4)
413#define CAN_ESR_LEC_CRC_ERROR (0x6 << 4)
414#define CAN_ESR_LEC_SOFT_ERROR (0x7 << 4)
415#define CAN_ESR_LEC_MASK (0x7 << 4)
420#define CAN_ESR_BOFF (1 << 2)
423#define CAN_ESR_EPVF (1 << 1)
426#define CAN_ESR_EWGF (1 << 0)
431#define CAN_BTR_SILM (1 << 31)
434#define CAN_BTR_LBKM (1 << 30)
439#define CAN_BTR_SJW_1TQ (0x0 << 24)
440#define CAN_BTR_SJW_2TQ (0x1 << 24)
441#define CAN_BTR_SJW_3TQ (0x2 << 24)
442#define CAN_BTR_SJW_4TQ (0x3 << 24)
443#define CAN_BTR_SJW_MASK (0x3 << 24)
444#define CAN_BTR_SJW_SHIFT 24
449#define CAN_BTR_TS2_1TQ (0x0 << 20)
450#define CAN_BTR_TS2_2TQ (0x1 << 20)
451#define CAN_BTR_TS2_3TQ (0x2 << 20)
452#define CAN_BTR_TS2_4TQ (0x3 << 20)
453#define CAN_BTR_TS2_5TQ (0x4 << 20)
454#define CAN_BTR_TS2_6TQ (0x5 << 20)
455#define CAN_BTR_TS2_7TQ (0x6 << 20)
456#define CAN_BTR_TS2_8TQ (0x7 << 20)
457#define CAN_BTR_TS2_MASK (0x7 << 20)
458#define CAN_BTR_TS2_SHIFT 20
461#define CAN_BTR_TS1_1TQ (0x0 << 16)
462#define CAN_BTR_TS1_2TQ (0x1 << 16)
463#define CAN_BTR_TS1_3TQ (0x2 << 16)
464#define CAN_BTR_TS1_4TQ (0x3 << 16)
465#define CAN_BTR_TS1_5TQ (0x4 << 16)
466#define CAN_BTR_TS1_6TQ (0x5 << 16)
467#define CAN_BTR_TS1_7TQ (0x6 << 16)
468#define CAN_BTR_TS1_8TQ (0x7 << 16)
469#define CAN_BTR_TS1_9TQ (0x8 << 16)
470#define CAN_BTR_TS1_10TQ (0x9 << 16)
471#define CAN_BTR_TS1_11TQ (0xA << 16)
472#define CAN_BTR_TS1_12TQ (0xB << 16)
473#define CAN_BTR_TS1_13TQ (0xC << 16)
474#define CAN_BTR_TS1_14TQ (0xD << 16)
475#define CAN_BTR_TS1_15TQ (0xE << 16)
476#define CAN_BTR_TS1_16TQ (0xF << 16)
477#define CAN_BTR_TS1_MASK (0xF << 16)
478#define CAN_BTR_TS1_SHIFT 16
483#define CAN_BTR_BRP_MASK (0x3FFUL << 0)
488#define CAN_TIxR_STID_MASK (0x7FF << 21)
489#define CAN_TIxR_STID_SHIFT 21
492#define CAN_TIxR_EXID_MASK (0x1FFFFFF << 3)
493#define CAN_TIxR_EXID_SHIFT 3
496#define CAN_TIxR_IDE (1 << 2)
499#define CAN_TIxR_RTR (1 << 1)
502#define CAN_TIxR_TXRQ (1 << 0)
507#define CAN_TDTxR_TIME_MASK (0xFFFF << 15)
508#define CAN_TDTxR_TIME_SHIFT 15
513#define CAN_TDTxR_TGT (1 << 5)
518#define CAN_TDTxR_DLC_MASK (0xF << 0)
519#define CAN_TDTxR_DLC_SHIFT 0
538#define CAN_RIxR_STID_MASK (0x7FF)
539#define CAN_RIxR_STID_SHIFT 21
542#define CAN_RIxR_EXID_MASK (0x1FFFFFFF)
543#define CAN_RIxR_EXID_SHIFT 3
546#define CAN_RIxR_IDE (1 << 2)
549#define CAN_RIxR_RTR (1 << 1)
556#define CAN_RDTxR_TIME_MASK (0xFFFF << 16)
557#define CAN_RDTxR_TIME_SHIFT 16
560#define CAN_RDTxR_FMI_MASK (0xFF << 8)
561#define CAN_RDTxR_FMI_SHIFT 8
566#define CAN_RDTxR_DLC_MASK (0xF << 0)
567#define CAN_RDTxR_DLC_SHIFT 0
591#define CAN_FMR_CAN2SB_SHIFT 8
592#define CAN_FMR_CAN2SB_MASK (0x3F << CAN_FMR_CAN2SB_SHIFT)
597#define CAN_FMR_FINIT (1 << 0)
648int can_init(uint32_t canport,
bool ttcm,
bool abom,
bool awum,
bool nart,
649 bool rflm,
bool txfp, uint32_t sjw, uint32_t ts1, uint32_t ts2,
650 uint32_t brp,
bool loopback,
bool silent);
653 bool id_list_mode, uint32_t fr1, uint32_t fr2,
654 uint32_t fifo,
bool enable);
656 uint16_t mask1, uint16_t id2,
657 uint16_t mask2, uint32_t fifo,
bool enable);
659 uint32_t mask, uint32_t fifo,
bool enable);
661 uint16_t id2, uint16_t id3, uint16_t id4,
662 uint32_t fifo,
bool enable);
664 uint32_t id2, uint32_t fifo,
bool enable);
669int can_transmit(uint32_t canport, uint32_t
id,
bool ext,
bool rtr,
670 uint8_t length, uint8_t *data);
671void can_receive(uint32_t canport, uint8_t fifo,
bool release, uint32_t *
id,
672 bool *ext,
bool *rtr, uint8_t *fmi, uint8_t *length,
673 uint8_t *data, uint16_t *timestamp);
bool can_available_mailbox(uint32_t canport)
void can_filter_init(uint32_t nr, bool scale_32bit, bool id_list_mode, uint32_t fr1, uint32_t fr2, uint32_t fifo, bool enable)
CAN Filter Init.
void can_receive(uint32_t canport, uint8_t fifo, bool release, uint32_t *id, bool *ext, bool *rtr, uint8_t *fmi, uint8_t *length, uint8_t *data, uint16_t *timestamp)
CAN Receive Message.
void can_filter_id_list_32bit_init(uint32_t nr, uint32_t id1, uint32_t id2, uint32_t fifo, bool enable)
CAN Initialize a 32bit Message ID List Filter.
void can_filter_id_list_16bit_init(uint32_t nr, uint16_t id1, uint16_t id2, uint16_t id3, uint16_t id4, uint32_t fifo, bool enable)
CAN Initialize a 16bit Message ID List Filter.
int can_init(uint32_t canport, bool ttcm, bool abom, bool awum, bool nart, bool rflm, bool txfp, uint32_t sjw, uint32_t ts1, uint32_t ts2, uint32_t brp, bool loopback, bool silent)
CAN Init.
int can_transmit(uint32_t canport, uint32_t id, bool ext, bool rtr, uint8_t length, uint8_t *data)
CAN Transmit Message.
void can_disable_irq(uint32_t canport, uint32_t irq)
CAN Disable IRQ.
void can_reset(uint32_t canport)
CAN Reset.
void can_enable_irq(uint32_t canport, uint32_t irq)
CAN Enable IRQ.
void can_filter_id_mask_16bit_init(uint32_t nr, uint16_t id1, uint16_t mask1, uint16_t id2, uint16_t mask2, uint32_t fifo, bool enable)
CAN Initialize a 16bit Message ID Mask Filter.
void can_fifo_release(uint32_t canport, uint8_t fifo)
CAN Release FIFO.
void can_filter_id_mask_32bit_init(uint32_t nr, uint32_t id, uint32_t mask, uint32_t fifo, bool enable)
CAN Initialize a 32bit Message ID Mask Filter.