CARME-M4 BSP
V1.5
|
CARME-M4 CAN Interface. More...
Modules | |
CARME_CAN_EXT_Ctrl | |
Files | |
file | can.h |
Drivers for the CAN interface. Uses the SJA1000 CAN controller on the CARME motherboard. | |
file | can.c |
Drivers for the CAN interface. Uses the SJA1000 CAN controller on the CARME motherboard. | |
Data Structures | |
struct | _CARME_CAN_MESSAGE |
This struct encapsulates a CAN message. More... | |
struct | _CARME_CAN_ACCEPTANCE_FILTER |
Information about the acceptance filter. More... | |
Typedefs | |
typedef struct _CARME_CAN_MESSAGE | CARME_CAN_MESSAGE |
This struct encapsulates a CAN message. | |
typedef struct _CARME_CAN_ACCEPTANCE_FILTER | CARME_CAN_ACCEPTANCE_FILTER |
Information about the acceptance filter. More... | |
typedef void(* | IRQ_CALLBACK) () |
Pointer to a function. | |
Enumerations | |
enum | CARME_CAN_IRQ_CALLBACKS { CARME_CAN_IRQID_RX_INTERRUPT = 0, CARME_CAN_IRQID_TX_INTERRUPT, CARME_CAN_IRQID_ERROR_INTERRUPT, CARME_CAN_IRQID_DATAOVERFLOW_INTERRUPT, CARME_CAN_IRQID_WAKEUP_INTERRUPT, CARME_CAN_IRQID_PASSIVE_INTERRUPT, CARME_CAN_IRQID_ARITRATION_LOST_INTERRUPT, CARME_CAN_IRQID_BUS_ERROR_INTERRUPT, CARME_CAN_IRQID_COUNT } |
Interrupt sources of the CAN-Controller. More... | |
enum | CARME_CAN_ACCEPTANCE_FILTER_MODE { MODE_SINGLE = 1, MODE_DUAL = 2 } |
Acceptance filter modes. More... | |
Functions | |
void | CARME_CAN_Init (uint32_t baud, uint8_t flags) |
Initialize GPIOs and the CAN-Controller. More... | |
void | CARME_CAN_InitI (uint32_t baud, uint8_t flags, uint32_t interrupts) |
Initialize GPIOs and the CAN-Controller. More... | |
ERROR_CODES | CARME_CAN_Write (CARME_CAN_MESSAGE *txMsg) |
Sends a CAN-Messsage over the CAN-Bus. More... | |
ERROR_CODES | CARME_CAN_Read (CARME_CAN_MESSAGE *rxMsg) |
Reads a CAN-Message from the Receive-Buffer. If no message is in the buffer, the function returns CARME_ERROR_CAN_ERROR_RXFIFO_EMPTY. More... | |
void | CARME_CAN_Interrupt_Handler (void) |
This function will be called from the Interrupt-Handler on a CAN-Interrupt. If it was not the EXTI Line from the CAN controller, then the functions MyEXTI9_5_IRQHandler is called. More... | |
void | CARME_CAN_RegisterIRQCallback (enum CARME_CAN_IRQ_CALLBACKS id, IRQ_CALLBACK pIRQCallback) |
Registers a callback function. Callback functions are called in Interruptmode. Use this function after CARME_CAN_init() or CARME_CAN_initI(). More... | |
void | CARME_CAN_UnregisterIRQCallback (enum CARME_CAN_IRQ_CALLBACKS id) |
Unregisters a callback function. Callback functions are called in Interruptmode. More... | |
ERROR_CODES | CARME_CAN_SetMode (uint8_t flags) |
Change operating mode from the CAN-Controller. More... | |
ERROR_CODES | CARME_CAN_SetBaudrate (uint32_t baud) |
Set the baudrate for the CAN-Communication. More... | |
ERROR_CODES | CARME_CAN_SetAcceptaceFilter (CARME_CAN_ACCEPTANCE_FILTER *af) |
ACCEPTANCE FILTER With the help of the acceptance filter the CAN controller is able to allow passing of received messages to the RXFIFO only when the identifier bits of the received message are equal to the predefined ones within the acceptance filter registers. The acceptance filter is defined by the Acceptance Code Registers (ACRn) and the Acceptance Mask Registers (AMRn). The bit patterns of messages to be received are defined within the acceptance code registers. The corresponding acceptance mask registers allow to define certain bit positions to be 'don't care'. Two different filter modes are selectable within the mode register: More... | |
ERROR_CODES | CARME_CAN_GetAcceptaceFilter (CARME_CAN_ACCEPTANCE_FILTER *af) |
Get the Acceptance Filter settings. More... | |
static void | CARME_CAN_Write_Register (uint8_t registerAddress, uint8_t val) |
Write a value in a SJA1000 register. More... | |
static uint8_t | CARME_CAN_Read_Register (uint8_t registerAddress) |
Reads a value from a SJA1000 register. More... | |
static uint8_t | CARME_CAN_IsBusOn (void) |
Returns 1 if the CAN Controller is involved in bus activities The Function checks the BS-bit in the status register of the SJA1000. More... | |
static uint8_t | CARME_CAN_IsDataOverrun (void) |
Returns 1 if an data overrun occurred The Function checks the DOS-bit in the status register of the SJA1000. More... | |
static uint8_t | CARME_CAN_IsError (void) |
Returns 1 if at least one of the error counters has reached or exceeded the value in the Error Warning Limit Register. The Function checks the ES-bit in the status register of the SJA1000. More... | |
static void | CARME_CAN_ClearDataOverrun (void) |
Clear Data-Overrun-Bit in the status register of the SJA1000. | |
static void | CARME_CAN_AbortTransmisssion (void) |
Cancel a pending transmission request. | |
static ERROR_CODES | CARME_CAN_SetErrorWarningLimit (uint8_t limit) |
Set the value of the Error Warning Limit Register. The content can only be changed in reset mode. More... | |
static void | CARME_CAN_GetErrorWarningLimit (uint8_t *limit) |
Get the value of the Error Warning Limit Register. More... | |
static void | CARME_CAN_GetRxErrCount (uint8_t *count) |
Get the value of the RX Error Count Register. More... | |
static void | CARME_CAN_GetTxErrCount (uint8_t *count) |
Get the value of the TX Error Count Register. More... | |
static void | CARME_CAN_GetArbitrationLostCapture (uint8_t *alc) |
Get the value of the TX Error Count Register. More... | |
static void | CARME_CAN_GetErrorCodeCapture (uint8_t *ecc) |
Get the value of the TX Error Count Register. More... | |
static void | CARME_CAN_InitSTM (void) |
Initialize the stm32f4xx GPIOs and the nCAN_INT. The CAN interrupt is on CARME_CAN_nCAN_IRQn_CH with NVIC_IRQChannelPreemptionPriority = 0x0F and NVIC_IRQChannelSubPriority = 0x0F. More... | |
static void | CARME_CAN_SetBusTiming (uint8_t btr0, uint8_t btr1) |
Set the Bus-Timing-Registers of the SJA1000 directly. More... | |
Variables | |
static __IO uint8_t * | SJA1000_CMD = (__IO uint8_t *) (FSMC_CAN_BASE) |
static __IO uint8_t * | SJA1000_DATA = (__IO uint8_t *) (FSMC_CAN_BASE + 8) |
static IRQ_CALLBACK | CARME_CAN_IRQCallbacks [CARME_CAN_IRQID_COUNT] |
CARME-M4 CAN Interface.
#define CARME_CAN_BAUD_250K 250000 |
#define CARME_CAN_DF_LISTEN_ONLY 0x02 |
#define CARME_CAN_DF_NORMAL 0x01 |
RM-Bit in MOD register cleared
#define CARME_CAN_DF_RESET 0x00 |
RM-Bit in MOD register set
#define CARME_CAN_INT_ARBIT_LOST (SJA1000_IER_ALIE) |
#define CARME_CAN_INT_BUSERR (SJA1000_IER_BEIE) |
#define CARME_CAN_INT_ERROR (SJA1000_IER_EIE) |
#define CARME_CAN_INT_OVERRUN (SJA1000_IER_DOIE) |
#define CARME_CAN_INT_PASSIVE (SJA1000_IER_EPIE) |
#define CARME_CAN_INT_RX (SJA1000_IER_RIE) |
#define CARME_CAN_INT_TX (SJA1000_IER_TIE) |
#define CARME_CAN_INT_WAKEUP (SJA1000_IER_WUIE) |
#define CARME_CAN_nCAN_INT_PIN GPIO_Pin_8 |
#define CARME_ERROR_CAN CARME_ERROR_CAN_BASE + 0 |
#define CARME_ERROR_CAN_ERROR_STATUS CARME_ERROR_CAN_BASE + 6 |
#define CARME_ERROR_CAN_INVALID_ACCEPTANCE_MODE CARME_ERROR_CAN_BASE + 5 |
#define CARME_ERROR_CAN_INVALID_BAUDRATE CARME_ERROR_CAN_BASE + 1 |
#define CARME_ERROR_CAN_INVALID_MODE CARME_ERROR_CAN_BASE + 3 |
#define CARME_ERROR_CAN_INVALID_OPMODE CARME_ERROR_CAN_BASE + 4 |
#define CARME_ERROR_CAN_RXFIFO_EMPTY CARME_ERROR_CAN_BASE + 2 |
typedef struct _CARME_CAN_ACCEPTANCE_FILTER CARME_CAN_ACCEPTANCE_FILTER |
Information about the acceptance filter.
Acceptance filter modes.
Enumerator | |
---|---|
MODE_SINGLE |
single acceptance filter option is enabled (one filter with the length of 32 bits) |
MODE_DUAL |
dual acceptance filter option is enabled (two filters with the length of 16 bits) |
Interrupt sources of the CAN-Controller.
ERROR_CODES CARME_CAN_GetAcceptaceFilter | ( | CARME_CAN_ACCEPTANCE_FILTER * | af | ) |
Get the Acceptance Filter settings.
[in] | af | acceptance filter information. Refer the struct CARME_CAN_ACCEPTANCE_FILTER for details. |
Definition at line 700 of file can.c.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
void CARME_CAN_Init | ( | uint32_t | baud, |
uint8_t | flags | ||
) |
Initialize GPIOs and the CAN-Controller.
Initializes the global variables from the driver, the baudrate and the acceptance-filter. This initialization function configures the CAN-Controller for communication without interrupts.
[in] | baud | Baud-rate. Refer CARME_CAN_setBaudrate() for valid arguments. |
[in] | flags | Driver Flags. The Flags can be OR-ed.
|
Definition at line 166 of file can.c.
void CARME_CAN_InitI | ( | uint32_t | baud, |
uint8_t | flags, | ||
uint32_t | interrupts | ||
) |
Initialize GPIOs and the CAN-Controller.
Initializes the global variables from the driver, the baudrate and the acceptance-filter. This initialization function configures the CAN-Controller for communication without interrupts.
[in] | baud | Baud-rate. Refer CARME_CAN_setBaudrate() for valid arguments. |
[in] | flags | Driver Flags. The Flags can be OR-ed.
|
[in] | interrupts | Enable specified Interrupts. The Flags can be OR-ed.
|
Definition at line 236 of file can.c.
|
static |
Initialize the stm32f4xx GPIOs and the nCAN_INT.
The CAN interrupt is on CARME_CAN_nCAN_IRQn_CH with NVIC_IRQChannelPreemptionPriority = 0x0F and NVIC_IRQChannelSubPriority = 0x0F.
Definition at line 116 of file can.c.
void CARME_CAN_Interrupt_Handler | ( | void | ) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
ERROR_CODES CARME_CAN_Read | ( | CARME_CAN_MESSAGE * | rxMsg | ) |
Reads a CAN-Message from the Receive-Buffer. If no message is in the buffer, the function returns CARME_ERROR_CAN_ERROR_RXFIFO_EMPTY.
[in] | rxMsg | Pointer to a CAN_MESSAGE struct for the received message. |
Definition at line 324 of file can.c.
|
static |
void CARME_CAN_RegisterIRQCallback | ( | enum CARME_CAN_IRQ_CALLBACKS | id, |
IRQ_CALLBACK | pIRQCallback | ||
) |
ERROR_CODES CARME_CAN_SetAcceptaceFilter | ( | CARME_CAN_ACCEPTANCE_FILTER * | af | ) |
ACCEPTANCE FILTER
With the help of the acceptance filter the CAN controller is able to allow passing of received messages to the RXFIFO only when the identifier bits of the received message are equal to the predefined ones within the acceptance filter registers.
The acceptance filter is defined by the Acceptance Code Registers (ACRn) and the Acceptance Mask Registers (AMRn). The bit patterns of messages to be received are defined within the acceptance code registers. The corresponding acceptance mask registers allow to define certain bit positions to be 'don't care'. Two different filter modes are selectable within the mode register:
Single filter configuration
In this filter configuration one long filter (4-bytes) could be defined. The bit correspondences between the filter bytes and the message bytes depend on the currently received frame format.
Standard frame: if a standard frame format message is received, the complete identifier including the RTR bit and the first two data bytes are used for acceptance filtering. Messages may also be accepted if there are no data bytes existing due to a set RTR bit or if there is none or only one data byte because of the corresponding data length code. For a successful reception of a message, all single bit comparisons have to signal acceptance.
Extended frame: if an extended frame format message is received, the complete identifier including the RTR bit is used for acceptance filtering.
For a successful reception of a message, all single bit comparisons have to signal acceptance.
Extended frame: if an extended frame message is received, the two defined filters are looking identically. Both filters are comparing the first two bytes of the extended identifier range only.
For a successful reception of a message, all single bit comparisons of at least one complete filter have to indicate acceptance.
[in] | af | acceptance filter information. Refer the struct CARME_CAN_ACCEPTANCE_FILTER for details. |
Definition at line 657 of file can.c.
ERROR_CODES CARME_CAN_SetBaudrate | ( | uint32_t | baud | ) |
Set the baudrate for the CAN-Communication.
The Bus-Timing is set as follows for the different baudrates:
[in] | baud | Baudrate. Can be one of the following constants:
|
Definition at line 469 of file can.c.
|
static |
|
inlinestatic |
ERROR_CODES CARME_CAN_SetMode | ( | uint8_t | flags | ) |
Change operating mode from the CAN-Controller.
This function is used to switch the controller in reset or normal mode for change settings like acceptance-filter, baud rate, bus timing,...
[in] | flags | Can be one of the following constants:
|
Definition at line 292 of file can.c.
void CARME_CAN_UnregisterIRQCallback | ( | enum CARME_CAN_IRQ_CALLBACKS | id | ) |
ERROR_CODES CARME_CAN_Write | ( | CARME_CAN_MESSAGE * | txMsg | ) |
Sends a CAN-Messsage over the CAN-Bus.
[in] | txMsg | CAN-ID |
Definition at line 501 of file can.c.