libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
CAN Peripheral API

CAN Application Programming Interface. More...

Collaboration diagram for CAN Peripheral API:

Functions

void can_enable (uint32_t canport)
 CAN Enable Enable the CAN peripheral and its associated FIFOs/counters/interrupts. More...
 
void can_disable (uint32_t canport)
 CAN Disable Disable the CAN peripheral and all associated FIFOs/counters/interrupts. More...
 
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. More...
 
void can_filter_clear (uint32_t canport)
 CAN Filter Clear Clear the message filters to receive all messages. More...
 
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: More...
 
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: More...
 
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: More...
 
void can_filter_single_ext (uint32_t canport, uint32_t id, uint32_t id_mask)
 CAN Filter Single Extended Frame Notes: More...
 
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: More...
 
void can_enable_irq (uint32_t canport, uint8_t imr)
 CAN Enable IRQ. More...
 
void can_disable_irq (uint32_t canport, uint8_t imr)
 CAN Disable IRQ. More...
 
bool can_transmit_std (uint32_t canport, uint32_t id, bool rtr, uint8_t length, const uint8_t *data)
 CAN Transmit Standard Frame. More...
 
bool can_transmit_ext (uint32_t canport, uint32_t id, bool rtr, uint8_t length, const uint8_t *data)
 CAN Transmit Extended Frame. More...
 
void can_abort_transmit (uint32_t canport)
 CAN Abort Transmit Aborts the current transmission. More...
 
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. More...
 

Detailed Description

CAN Application Programming Interface.

PAC55xxxx CAN Driver

Author
© 2020 Kevin Stefanik kevin.nosp@m.@all.nosp@m.ocor..nosp@m.tech
Date
February 13, 2020

This library supports the CAN module in the PAC55xx SoC from Qorvo.

Note: Acceptance Code Mask Register values of 1 indicate the filter is to ignore the bit. However, standard CAN driver APIs use a positive logic for the mask. The implementations in this file inverts masks as appropriate to the mask to make this more portable/intuitive.

LGPL License Terms libopencm3 License

Function Documentation

◆ can_abort_transmit()

void can_abort_transmit ( uint32_t  canport)

CAN Abort Transmit Aborts the current transmission.

Parameters
[in]canportUnsigned int32. CAN block register base address.

Definition at line 369 of file can.c.

References CAN_CMR_AT, and CAN_ISR_SR_CMR_MR_SET.

◆ can_disable()

void can_disable ( uint32_t  canport)

CAN Disable Disable the CAN peripheral and all associated FIFOs/counters/interrupts.

Parameters
[in]canportUnsigned int32. CAN block register base address.

Definition at line 50 of file can.c.

References CAN_ISR_SR_CMR_MR_SET, and CAN_MR_RM.

◆ can_disable_irq()

void can_disable_irq ( uint32_t  canport,
uint8_t  irq 
)

CAN Disable IRQ.

Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]irqUnsigned int8. IRQ bit(s).

Definition at line 278 of file can.c.

References CAN_BTR1_BTR0_RMC_IMR.

◆ can_enable()

void can_enable ( uint32_t  canport)

CAN Enable Enable the CAN peripheral and its associated FIFOs/counters/interrupts.

Parameters
[in]canportUnsigned int32. CAN block register base address.

Definition at line 41 of file can.c.

References CAN_ISR_SR_CMR_MR_CLEAR, and CAN_MR_RM.

◆ can_enable_irq()

void can_enable_irq ( uint32_t  canport,
uint8_t  irq 
)

CAN Enable IRQ.

Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]irqUnsigned int8. IRQ bit(s).

Definition at line 268 of file can.c.

References CAN_BTR1_BTR0_RMC_IMR.

◆ can_filter_clear()

void can_filter_clear ( uint32_t  canport)

CAN Filter Clear Clear the message filters to receive all messages.

Parameters
[in]canportUnsigned int32. CAN block register base address.

Definition at line 96 of file can.c.

References CAN_ACR, CAN_AMR, CAN_ISR_SR_CMR_MR_SET, and CAN_MR_AFM.

◆ can_filter_dual()

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:

  • Acceptance Code Mask Register values of 1 indicate the filter is to ignore the bit. However standard CAN driver APIs use a positive logic for the mask. So this function inverts the mask to make this more portable/intuitive.
  • Register definition byte order is opposite what is shown in Rev 1.23 of the PAC55XX Family User Guide. Since both data and ID values cross byte boundaries, the bswap32 function is used to correct for the discrepancy.
Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]id1Unsigned int32. CAN ID 1. Only bits 10:0 are used.
[in]id1_maskUnsigned int32. CAN ID 1 mask. Only bits 10:0 are used.
[in]id2Unsigned int32. CAN ID 2. Only bits 10:0 are used.
[in]id2_maskUnsigned int32. CAN ID 2 mask. Only bits 10:0 are used.
[in]dbbool. CAN first data byte value.
[in]db_maskbool. CAN first data byte mask.

Definition at line 123 of file can.c.

References CAN_ACR, CAN_ACR_DUAL_DB_LOWER, CAN_ACR_DUAL_DB_UPPER, CAN_ACR_DUAL_ID1, CAN_ACR_DUAL_ID2, CAN_ACR_DUAL_RTR1, CAN_ACR_DUAL_RTR2, CAN_AMR, CAN_ISR_SR_CMR_MR_CLEAR, and CAN_MR_AFM.

◆ can_filter_single_ext()

void can_filter_single_ext ( uint32_t  canport,
uint32_t  id,
uint32_t  id_mask 
)

CAN Filter Single Extended Frame Notes:

  • Acceptance Code Mask Register values of 1 indicate the filter is to ignore the bit. However standard CAN driver APIs use a positive logic for the mask. So this function inverts the mask to make this more portable/intuitive.
  • Register definition byte order is opposite what is shown in Rev 1.23 of the PAC55XX Family User Guide. Since both data and ID values cross byte boundaries, the bswap32 function is used to correct for the discrepancy.
Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]idUnsigned int32. CAN ID. Only bits 28:0 are used.
[in]id_maskUnsigned int32. CAN ID mask. Only bits 28:0 are used.

Definition at line 227 of file can.c.

References CAN_ACR, CAN_ACR_SINGLE_EXT_ID, CAN_ACR_SINGLE_EXT_RTR, CAN_AMR, CAN_ISR_SR_CMR_MR_SET, and CAN_MR_AFM.

◆ can_filter_single_ext_rtr()

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:

  • Acceptance Code Mask Register values of 1 indicate the filter is to ignore the bit. However standard CAN driver APIs use a positive logic for the mask. So this function inverts the mask to make this more portable/intuitive.
  • Register definition byte order is opposite what is shown in Rev 1.23 of the PAC55XX Family User Guide. Since both data and ID values cross byte boundaries, the bswap32 function is used to correct for the discrepancy.
Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]idUnsigned int32. CAN ID. Only bits 28:0 are used.
[in]id_maskUnsigned int32. CAN ID mask. Only bits 28:0 are used.

Definition at line 252 of file can.c.

References CAN_ACR, CAN_ACR_SINGLE_EXT_ID, CAN_ACR_SINGLE_EXT_RTR, CAN_AMR, CAN_ISR_SR_CMR_MR_SET, and CAN_MR_AFM.

◆ can_filter_single_std()

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:

  • Acceptance Code Mask Register values of 1 indicate the filter is to ignore the bit. However standard CAN driver APIs use a positive logic for the mask. So this function inverts the mask to make this more portable/intuitive.
  • Register definition byte order is opposite what is shown in Rev 1.23 of the PAC55XX Family User Guide. Since both data and ID values cross byte boundaries, the bswap32 function is used to correct for the discrepancy.
Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]idUnsigned int32. CAN ID. Only bits 10:0 are used.
[in]id_maskUnsigned int32. CAN ID mask. Only bits 10:0 are used.
[in]db1bool. CAN first data byte value.
[in]db1_maskbool. CAN first data byte mask.
[in]db2bool. CAN second data byte value.
[in]db2_maskbool. CAN second data byte mask.

Definition at line 160 of file can.c.

References CAN_ACR, CAN_ACR_DUAL_DB_UPPER, CAN_ACR_SINGLE_STD_DB1, CAN_ACR_SINGLE_STD_DB2, CAN_ACR_SINGLE_STD_ID, CAN_ACR_SINGLE_STD_RTR, CAN_AMR, CAN_ISR_SR_CMR_MR_SET, and CAN_MR_AFM.

◆ can_filter_single_std_rtr()

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:

  • Acceptance Code Mask Register values of 1 indicate the filter is to ignore the bit. However standard CAN driver APIs use a positive logic for the mask. So this function inverts the mask to make this more portable/intuitive.
  • Register definition byte order is opposite what is shown in Rev 1.23 of the PAC55XX Family User Guide. Since both data and ID values cross byte boundaries, the bswap32 function is used to correct for the discrepancy.
Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]idUnsigned int32. CAN ID. Only bits 10:0 are used.
[in]id_maskUnsigned int32. CAN ID mask. Only bits 10:0 are used.
[in]db1bool. CAN first data byte value.
[in]db1_maskbool. CAN first data byte mask.
[in]db2bool. CAN second data byte value.
[in]db2_maskbool. CAN second data byte mask.

Definition at line 196 of file can.c.

References CAN_ACR, CAN_ACR_SINGLE_STD_DB1, CAN_ACR_SINGLE_STD_DB2, CAN_ACR_SINGLE_STD_ID, CAN_ACR_SINGLE_STD_RTR, CAN_AMR, CAN_ISR_SR_CMR_MR_SET, and CAN_MR_AFM.

◆ can_init()

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.

Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]listen_onlybool. Enable listen only mode.
[in]sjwUnsigned int32. Resynchronization time quanta jump width.
[in]tseg1Unsigned int32. Time segment 1 time quanta width.
[in]tseg2Unsigned int32. Time segment 2 time quanta width.
[in]sam3bool. Use best 2 out of 3 samples.
[in]brpUnsigned int32. Baud rate prescaler.

Definition at line 65 of file can.c.

References CAN_ACR, CAN_AMR, CAN_BTR0_BRP, CAN_BTR0_SJW, CAN_BTR1_BTR0_RMC_IMR, CAN_BTR1_SAM, CAN_BTR1_TSEG1, CAN_BTR1_TSEG2, CAN_ISR_SR_CMR_MR, CAN_ISR_SR_CMR_MR_SET, CAN_MR_AFM, CAN_MR_LOM, and CAN_MR_RM.

◆ can_receive()

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.

Parameters
[in]canportUnsigned int32. CAN block register base address.
[out]idUnsigned int32 pointer. Message ID.
[out]extbool pointer. The message ID is extended.
[out]rtrbool pointer. Remote Request bit value.
[out]lengthUnsigned int8 pointer. Length of message payload.
[out]dataUnsigned int8[]. Message payload data, min length 8.

Definition at line 384 of file can.c.

References BIT6, BIT7, CAN_BITS_15_8, CAN_BITS_23_16, CAN_BITS_23_21, CAN_BITS_31_24, CAN_BITS_3_0, CAN_BITS_7_3, CAN_ISR_ACKNOWLEDGE, CAN_ISR_RI, CAN_ISR_SR_CMR_MR, CAN_RMC, and CAN_RXBUF.

◆ can_transmit_ext()

bool can_transmit_ext ( uint32_t  canport,
uint32_t  id,
bool  rtr,
uint8_t  length,
const uint8_t *  data 
)

CAN Transmit Extended Frame.

Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]idUnsigned int32. Message ID bits 28:0 used.
[in]rtrbool. Remote Request bit value.
[in]lengthUnsigned int8. Message payload length, 0-8.
[in]dataUnsigned int8[]. Message payload data.
Returns
true if able to transmit, false otherwise.

Definition at line 330 of file can.c.

References BIT6, BIT7, CAN_BITS_12_5, CAN_BITS_20_13, CAN_BITS_28_21, CAN_BITS_3_0, CAN_BITS_4_0, CAN_CMR_TR, CAN_ISR_SR_CMR_MR, CAN_ISR_SR_CMR_MR_SET, CAN_SR_TBS, and CAN_TXBUF.

◆ can_transmit_std()

bool can_transmit_std ( uint32_t  canport,
uint32_t  id,
bool  rtr,
uint8_t  length,
const uint8_t *  data 
)

CAN Transmit Standard Frame.

Parameters
[in]canportUnsigned int32. CAN block register base address.
[in]idUnsigned int32. Message ID bits 10:0 used.
[in]rtrbool. Remote Request bit value.
[in]lengthUnsigned int8. Message payload length.
[in]dataUnsigned int8[]. Message payload data.
Returns
true if able to transmit, false otherwise.

Definition at line 292 of file can.c.

References BIT6, CAN_BITS_10_3, CAN_BITS_2_0, CAN_BITS_3_0, CAN_CMR_TR, CAN_ISR_SR_CMR_MR, CAN_ISR_SR_CMR_MR_SET, CAN_SR_TBS, and CAN_TXBUF.