Astra MCU SDK Peripheral Driver Library
Loading...
Searching...
No Matches

Topics

 Enumerated Types
 Enumerated types for CAN driver.
 Data Structures
 Data structures for CAN driver.
 Functions
 Functions for CAN driver.

Detailed Description

The CAN driver provides a complete software interface for operating the Synaptics CAN peripheral in Classical CAN and CAN FD modes.

The driver supports standard and extended identifiers, callback-driven transmit/receive operation, scheduled transmission, timestamp sampling, and runtime control of protocol and controller behavior.

Features:

  • Classical CAN and CAN FD transfer support
  • Standard (11-bit) and Extended (29-bit) identifier handling
  • RX filter subscription with callback dispatch
  • Blocking-style status tracking through callback completion state
  • Scheduled TX support using 64-bit controller timestamps
  • Timestamp capture callback support
  • Runtime configuration of bitrate, sample point, loopback, and watchdog
  • Interrupt mask management APIs for fine-grained event control

The driver is structured around:

  • Core lifecycle APIs for initialization, configuration, and enable flow
  • Transfer APIs for TX queueing and RX filter subscription
  • Runtime-control APIs for protocol and timing behavior
  • Interrupt/timestamp APIs for asynchronous status and timing events
Note
CAN APIs are divided into two categories:
  • High-level APIs: Provides structured lifecycle and transfer interfaces for most application-level use cases, including configuration, frame transmission, and RX filter subscription with callback dispatch.
  • Low-level APIs: Provides direct runtime control and event handling for advanced use cases, including timestamp sampling hooks and controller behavior tuning (ECC, retransmit, watchdog, and framing mode).
Warning
Reconfigure operating mode, bitrate, sampling, or ECC behavior only while the controller is disabled.

Configuration Considerations

To initialize and operate the CAN driver:

  1. Call can_init to initialize the peripheral instance and reset internal driver context.
  2. Fill a can_config_t, or pass NULL to use the driver defaults.
  3. Call can_configure to allocate driver-managed resources and apply the controller runtime state.
  4. Register optional timestamp callback using can_set_timestamp_sample_handler.
  5. Install receive filters using can_rx_subscribe.
  6. Call can_enable to start controller operation and bus participation.
  7. Submit frames using can_tx; pass a per-transfer callback when TX completion notification is required.

Using TX and RX Paths

Recommended transfer flow:

  1. Build a can_tx_frame_t descriptor with frame format, identifier, DLC, and payload.
  2. Submit the frame using can_tx (immediate or scheduled).
  3. Track completion through transfer callback status.
  4. Install one or more can_rx_filter_t entries using can_rx_subscribe to receive matching traffic.
  5. Remove filters when no longer needed using can_rx_unsubscribe.

can_init

Initializes the CAN peripheral and prepares hardware/software context.

if (can_init(id) != CAN_OK) {
return CAN_ERROR;
}

can_configure

Configures driver resources and default controller runtime behavior.

can_config_t cfg = {
.bitrate = CAN_BITRATE_500K,
.fd_mode = false,
.loopback_enable = true
};
if (can_configure(id, &cfg) != CAN_OK) {
return CAN_ERROR;
}

can_enable

Enables CAN controller operation.

return CAN_ERROR;
}

can_tx

Queues a frame for immediate or scheduled transmission.

can_tx_frame_t tx_frame = {0};
tx_frame.header.signal_desc.fields.id = 0x123;
tx_frame.header.signal_desc.fields.ide = 0;
tx_frame.header.signal_desc.fields.rtr = 0;
tx_frame.header.signal_desc.fields.frame_type = CAN_FRAME_CLASSIC;
tx_frame.header.signal_desc.fields.dlc = 8;
tx_frame.data[0] = 0x11;
tx_frame.data[1] = 0x22;
if (can_tx(CAN0, false, &tx_frame, NULL, NULL, NULL) != CAN_OK) {
return CAN_ERROR;
}

can_rx_subscribe

Installs an RX filter and callback subscription.

can_rx_filter_t filter = {
.id = 0x123,
.mask = 0x7FF,
.flags = CAN_FILTER_IDE
};
int subscription_id = -1;
if (can_rx_subscribe(CAN0, &filter, can_rx_callback, NULL, &subscription_id) != CAN_OK) {
return CAN_ERROR;
}

can_disable

Disables CAN controller operation.

return CAN_ERROR;
}

can_deinit

Deinitializes CAN instance resources.

return CAN_ERROR;
}