can_status_get()

can_status_get()

Description

Reads the current run-time status of a CAN interface into a can_status structure (controller state, error counters, active bit rates, and frame count).

Syntax

can_status_get(can_interface, can_status);

Parameters

Parameter

Array structure

Description

can_interface

 

CAN interface to query – CAN1 or CAN2.

can_status

.state

Current controller state:

  • CAN_STATE_ERROR_ACTIVE - RX/TX error count < 96

  • CAN_STATE_ERROR_WARNING - RX/TX error count < 128

  • CAN_STATE_ERROR_PASSIVE - RX/TX error count < 256

  • CAN_STATE_BUS_OFF - RX/TX error count >= 256

  • CAN_STATE_STOPPED - Device is stopped

.error

Bitwise error code flags, or 0 when no error is pending:

  • CAN_PROTOCOL_NO_ERROR

  • CAN_PROTOCOL_STUFF_ERROR

  • CAN_PROTOCOL_FORM_ERROR

  • CAN_PROTOCOL_ACK_ERROR

  • CAN_PROTOCOL_RECESSIVE_ERROR

  • CAN_PROTOCOL_DOMINANT_ERROR

  • CAN_PROTOCOL_CRC_ERROR

  • CAN_PROTOCOL_SOFTWARE_ERROR

.tx_error_count

CAN controller transmit error counter.

.rx_error_count

CAN controller receive error counter.

.frame_count

Number of frames processed since the interface was initialized.

.bit_rate

Nominal (arbitration phase) bit rate currently configured, in bit/s.

.data_bit_rate

FD data-phase bit rate currently configured, in bit/s (0 when FD/BRS is not enabled).

.status_flags

Last CAN bus status change reason:

  • CAN_STATUS_NO_CHANGE - No change in status detected

  • CAN_STATUS_NEW_STATE - .state state value changed

  • CAN_STATUS_NEW_RX_ARB_ERR - Protocol error in arbitration phase detected

  • CAN_STATUS_NEW_RX_DATA_ERR - Protocol error in data phase detected

  • CAN_STATUS_NEW_RX_ERR - Protocol error in received frame detected

  • CAN_STATUS_NEW_TX_ERR - .tx_error_countincremented

  • CAN_STATUS_NEW_FRAME - new frame received

  • CAN_STATUS_NEW_BIT_RATE - .bit_rate value changed

Returns

Return value

Return explanation

SCRIPT_OPERATION_SUCCESS

The operation completed successfully.

SCRIPT_OPERATION_FAILED

The operation could not be completed (invalid state, hardware error, etc.).

SCRIPT_NO_ACCESS

The CAN interface has not been initialized (call can_fd_init first).

SCRIPT_PARAM_INVALID

One or more passed parameters are invalid.

Function call example

#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> #include <can> #define CAN_BUS CAN1 new can_status[.state, .error, .tx_error_count, .rx_error_count, .frame_count, .bit_rate, .data_bit_rate, .status_flags]; new can_rx_buffer{4096}; main() { can_fd_init(CAN_BUS, CAN_CTRL_MODE_NORMAL | CAN_CTRL_MODE_ONE_SHOT | CAN_CTRL_MODE_FD_BRS, 2000, 500000, can_rx_buffer); for(;;) { can_status_get(CAN_BUS, can_status); Delay(1000); } }