34#ifndef LIBOPENCM3_PAC55XX_CAN_H_
35#define LIBOPENCM3_PAC55XX_CAN_H_
54#define CAN_ISR_SR_CMR_MR(can_base) MMIO32((can_base) + 0x0000)
55#define CAN_ISR_SR_CMR_MR_SET(can_base, bits) (CAN_ISR_SR_CMR_MR(can_base) = \
56 (CAN_ISR_SR_CMR_MR(can_base) & 0x00FFFFFF) | (bits))
57#define CAN_ISR_SR_CMR_MR_CLEAR(can_base, bits) (CAN_ISR_SR_CMR_MR(can_base) = \
58 (CAN_ISR_SR_CMR_MR(can_base) & 0x00FFFFFF) & ~(bits))
70#define CAN_BTR1_BTR0_RMC_IMR(can_base) MMIO32((can_base) + 0x0004)
74#define CAN_TXBUF(can_base) MMIO32((can_base) + 0x0008)
76#define CAN_RXBUF(can_base) MMIO32((can_base) + 0x000C)
78#define CAN_ACR(can_base) MMIO32((can_base) + 0x0010)
80#define CAN_AMR(can_base) MMIO32((can_base) + 0x0014)
85#define CAN_ALC_TXERR_RXERR_ECC(can_base) MMIO32((can_base) + 0x0018)
87#define CAN_ECC(can_base) (CAN_ALC_TXERR_RXERR_ECC(can_base) & 0xFF)
89#define CAN_RXERR(can_base) ((CAN_ALC_TXERR_RXERR_ECC(can_base) >> 8) & 0xFF)
91#define CAN_TXERR(can_base) ((CAN_ALC_TXERR_RXERR_ECC(can_base) >> 16) & 0xFF)
93#define CAN_ALC(can_base) ((CAN_ALC_TXERR_RXERR_ECC(can_base) >> 24) & 0xFF)
100#define CAN_MR_AFM BIT0
102#define CAN_MR_LOM BIT1
104#define CAN_MR_RM BIT2
111#define CAN_CMR_AT BIT9
113#define CAN_CMR_TR BIT10
120#define CAN_SR_BS BIT16
122#define CAN_SR_ES BIT17
124#define CAN_SR_TS BIT18
126#define CAN_SR_RS BIT19
128#define CAN_SR_TBS BIT21
130#define CAN_SR_DSO BIT22
132#define CAN_SR_RBS BIT23
142#define CAN_ISR_DOI BIT24
144#define CAN_ISR_BEI BIT25
146#define CAN_ISR_TI BIT26
148#define CAN_ISR_RI BIT27
150#define CAN_ISR_EPI BIT28
152#define CAN_ISR_EWI BIT29
154#define CAN_ISR_ALI BIT30
156#define CAN_ISR_ACKNOWLEDGE(can_base, isr) CAN_ISR_SR_CMR_MR_SET(can_base, ((isr) & 0x7F000000))
165#define CAN_IMR_DOIM BIT0
167#define CAN_IMR_BEIM BIT1
169#define CAN_IMR_TIM BIT2
171#define CAN_IMR_RIM BIT3
173#define CAN_IMR_EPIM BIT4
175#define CAN_IMR_EWIM BIT5
177#define CAN_IMR_ALIM BIT6
183#define CAN_RMC(can_base) ((CAN_BTR1_BTR0_RMC_IMR(can_base) >> 8) & 0x1F)
189#define CAN_BTR0_BRP_MASK (0x3F)
190#define CAN_BTR0_BRP_SHIFT 16
191#define CAN_BTR0_BRP(val) (((val) & CAN_BTR0_BRP_MASK) << CAN_BTR0_BRP_SHIFT)
192#define CAN_BTR0_SJW_MASK (0x03)
193#define CAN_BTR0_SJW_SHIFT 22
194#define CAN_BTR0_SJW(val) (((val) & CAN_BTR0_SJW_MASK) << CAN_BTR0_SJW_SHIFT)
200#define CAN_BTR1_TSEG1_MASK (0x0F)
201#define CAN_BTR1_TSEG1_SHIFT 24
202#define CAN_BTR1_TSEG1(val) (((val) & CAN_BTR1_TSEG1_MASK) << CAN_BTR1_TSEG1_SHIFT)
204#define CAN_BTR1_TSEG2_MASK (0x07)
205#define CAN_BTR1_TSEG2_SHIFT 28
206#define CAN_BTR1_TSEG2(val) (((val) & CAN_BTR1_TSEG2_MASK) << CAN_BTR1_TSEG2_SHIFT)
207#define CAN_BTR1_SAM BIT31
214#define CAN_ECC_BER BIT0
216#define CAN_ECC_STFER BIT1
218#define CAN_ECC_CRCER BIT2
220#define CAN_ECC_FRMER BIT3
222#define CAN_ECC_ACKER BIT4
224#define CAN_ECC_EDIR BIT5
226#define CAN_ECC_TXWRN BIT6
228#define CAN_ECC_RXWRN BIT7
235#define CAN_ACR_DUAL_DB_UPPER 0x000F0000U
236#define CAN_ACR_DUAL_DB_LOWER 0x0000000FU
237#define CAN_ACR_DUAL_ID1 0xFFE00000U
238#define CAN_ACR_DUAL_ID2 0x0000FFE0U
239#define CAN_ACR_DUAL_RTR1 0x00100000U
240#define CAN_ACR_DUAL_RTR2 0x00000010U
242#define CAN_ACR_SINGLE_STD_ID 0xFFE00000U
243#define CAN_ACR_SINGLE_STD_RTR 0x00100000U
244#define CAN_ACR_SINGLE_STD_DB1 0x0000FF00U
245#define CAN_ACR_SINGLE_STD_DB2 0x000000FFU
247#define CAN_ACR_SINGLE_EXT_ID 0xFFFFFFF8U
248#define CAN_ACR_SINGLE_EXT_RTR 0x00000004U
254#define CAN_BITS_2_0 (0x07)
255#define CAN_BITS_3_0 (0x0F)
256#define CAN_BITS_4_0 (0x1F)
257#define CAN_BITS_7_3 (0xF8)
258#define CAN_BITS_10_3 (0x07F8)
259#define CAN_BITS_12_5 (0x00001FE0U)
260#define CAN_BITS_20_13 (0x001FE000U)
261#define CAN_BITS_28_21 (0x1FE00000U)
262#define CAN_BITS_15_8 (0x0000FF00U)
263#define CAN_BITS_23_16 (0x00FF0000U)
264#define CAN_BITS_31_24 (0xFF000000U)
265#define CAN_BITS_23_21 (0x00E00000U)
277void can_init(uint32_t canport,
bool listen_only, uint32_t sjw,
278 uint32_t tseg1, uint32_t tseg2,
279 bool sam3, uint32_t brp);
282 uint32_t id2, uint32_t id2_mask,
283 uint8_t db, uint8_t db_mask);
285 uint8_t db1, uint8_t db1_mask,
286 uint8_t db2, uint8_t db2_mask);
288 uint8_t db1, uint8_t db1_mask,
289 uint8_t db2, uint8_t db2_mask);
295bool can_transmit_std(uint32_t canport, uint32_t
id,
bool rtr, uint8_t length,
296 const uint8_t *data);
297bool can_transmit_ext(uint32_t canport, uint32_t
id,
bool rtr, uint8_t length,
298 const uint8_t *data);
301void can_receive(uint32_t canport, uint32_t *
id,
bool *ext,
bool *rtr, uint8_t *length,
void can_filter_single_std(uint32_t canport, uint32_t id, uint32_t id_mask, uint8_t db1, uint8_t db1_mask, uint8_t db2, uint8_t db2_mask)
CAN Filter Single Standard Frame Notes:
void can_enable(uint32_t canport)
CAN Enable Enable the CAN peripheral and its associated FIFOs/counters/interrupts.
void can_filter_single_std_rtr(uint32_t canport, uint32_t id, uint32_t id_mask, uint8_t db1, uint8_t db1_mask, uint8_t db2, uint8_t db2_mask)
CAN Filter Single Standard Frame w/RTR set Notes:
void can_filter_single_ext(uint32_t canport, uint32_t id, uint32_t id_mask)
CAN Filter Single Extended Frame Notes:
void can_abort_transmit(uint32_t canport)
CAN Abort Transmit Aborts the current transmission.
void can_filter_single_ext_rtr(uint32_t canport, uint32_t id, uint32_t id_mask)
CAN Filter Single Extended Frame w/RTR set Notes:
void can_disable(uint32_t canport)
CAN Disable Disable the CAN peripheral and all associated FIFOs/counters/interrupts.
void can_filter_clear(uint32_t canport)
CAN Filter Clear Clear the message filters to receive all messages.
void can_filter_dual(uint32_t canport, uint32_t id1, uint32_t id1_mask, uint32_t id2, uint32_t id2_mask, uint8_t db, uint8_t db_mask)
CAN Dual Filter Standard Frame Notes:
void can_init(uint32_t canport, bool listen_only, uint32_t sjw, uint32_t tseg1, uint32_t tseg2, bool sam3, uint32_t brp)
CAN Init Initialize the selected CAN peripheral block.
void can_receive(uint32_t canport, uint32_t *id, bool *ext, bool *rtr, uint8_t *length, uint8_t *data)
CAN Receive Message If no data is in the RX buffer, id and length are set to 0.
void can_enable_irq(uint32_t canport, uint8_t imr)
CAN Enable IRQ.
void can_disable_irq(uint32_t canport, uint8_t imr)
CAN Disable IRQ.
bool can_transmit_ext(uint32_t canport, uint32_t id, bool rtr, uint8_t length, const uint8_t *data)
CAN Transmit Extended Frame.
bool can_transmit_std(uint32_t canport, uint32_t id, bool rtr, uint8_t length, const uint8_t *data)
CAN Transmit Standard Frame.