ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches

CANFD Lite driver (bit-timing, TX, RX, error state). More...

#include <stdint.h>
#include "ra8_canfd_regs.h"
#include "ra8_err.h"
Include dependency graph for ra8_canfd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_canfd_frame_t
 A single CAN / CAN-FD frame as seen by the driver public API. More...
struct  ra8_canfd_afl_rule_t
 One Acceptance-Filter-List (AFL) rule: hardware ID/mask match plus an RX-FIFO routing target. More...
struct  ra8_canfd_tdc_cfg_t
 Transmitter Delay Compensation (TDC) configuration for one CANFD channel. More...

Typedefs

typedef void(* ra8_canfd_event_fn_t) (void *ctx, uint8_t channel, uint32_t status_mask)
 CANFD event callback.

Enumerations

enum  ra8_canfd_afl_capacity_t : uint8_t { k_ra8_canfd_afl_rule_capacity = 16U }
 Per-channel Acceptance-Filter-List capacity used by ra8_canfd_set_accept_filter. More...

Functions

ra8_err_t ra8_canfd_init (uint8_t channel)
 Take a CANFD channel out of reset into operation mode.
ra8_err_t ra8_canfd_deinit (uint8_t channel)
 Put the CANFD channel back into reset.
ra8_err_t ra8_canfd_set_bitrate (uint8_t channel, uint32_t bitrate_bps, uint32_t data_bitrate_bps)
 Programme nominal (and optional data) bit-timing registers.
ra8_err_t ra8_canfd_transmit (uint8_t channel, const ra8_canfd_frame_t *frame)
 Queue a frame into the TX message buffer and trigger transmission.
ra8_err_t ra8_canfd_receive (uint8_t channel, ra8_canfd_frame_t *out_frame)
 Poll the RX FIFO for the next available frame.
ra8_err_t ra8_canfd_get_error_state (uint8_t channel, uint8_t *tx_err, uint8_t *rx_err)
 Read the TX and RX error counters.
ra8_err_t ra8_canfd_get_status (uint8_t channel, uint32_t *out_mask)
 Read the channel status register (CFDCnSTS).
ra8_err_t ra8_canfd_clear_status (uint8_t channel, uint32_t mask)
 Clear error flags in CFDCnERFL.
ra8_err_t ra8_canfd_attach_handler (ra8_canfd_event_fn_t fn, void *ctx)
 Attach a callback for CANFD events (shared across channels).
void ra8_canfd_dispatch (uint8_t channel)
 Dispatch a CANFD event for a channel – snapshot + fire callback.
ra8_err_t ra8_canfd_filter_set (uint16_t filter_id, uint32_t accept_id, uint32_t mask, uint8_t dlc)
 Programme one Global Acceptance-Filter-List (GAFL) entry.
ra8_err_t ra8_canfd_set_accept_filter (uint8_t channel, const ra8_canfd_afl_rule_t *rules, uint8_t count)
 Program the channel Acceptance-Filter-List from a rule array.
ra8_err_t ra8_canfd_set_brs (uint8_t channel, uint32_t fast_bitrate)
 Configure the CAN-FD bit-rate-switch (BRS) data-phase rate.
ra8_err_t ra8_canfd_set_tdc (uint8_t channel, const ra8_canfd_tdc_cfg_t *cfg)
 Configure Transmitter Delay Compensation on a CANFD channel.
ra8_err_t ra8_canfd_set_iso_mode (bool enable)
 Select ISO 11898-1 vs non-ISO CAN-FD framing.
ra8_err_t ra8_canfd_set_test_mode (uint8_t channel, ra8_ctms_mode_t mode)
 Enable a CFDC[0].CTR test mode (basic / listen-only / loopback).
ra8_err_t ra8_canfd_enter_stop (uint8_t channel)
 Put the CANFD channel into MSTP-gated stop.
ra8_err_t ra8_canfd_exit_stop (uint8_t channel)
 Exit MSTP-gated stop.

Detailed Description

CANFD Lite driver (bit-timing, TX, RX, error state).

Minimal driver surface over the RA8D2 CANFD Lite controller – enough to bring a channel up at a chosen nominal bit rate, queue a CAN 2.0B / CAN-FD frame into the TX message buffer, poll the RX FIFO for inbound frames, and read the TX/RX error counters.

DMA hooks, interrupt delivery, and the full acceptance-filter bank are deferred until there is a real consumer that needs them.

Definition in file ra8_canfd.h.

Typedef Documentation

◆ ra8_canfd_event_fn_t

typedef void(* ra8_canfd_event_fn_t) (void *ctx, uint8_t channel, uint32_t status_mask)

CANFD event callback.

Definition at line 155 of file ra8_canfd.h.

Enumeration Type Documentation

◆ ra8_canfd_afl_capacity_t

enum ra8_canfd_afl_capacity_t : uint8_t

Per-channel Acceptance-Filter-List capacity used by ra8_canfd_set_accept_filter.

ra8_canfd_set_accept_filter installs its rules into a single 16-entry AFL page (page 0). The CFDGAFLECTR.AFLPN page selector is 4 bits and each page exposes k_ra8_canfd_afl_page_size entries; one page is the working set the list-config API supports, so the rule count is capped here. HUM Ch 41.2.18 "CFDGAFLCFG0 : Global AFL Configuration Register 0" p 2735 (RNC field) and Ch 41.2.17 "CFDGAFLECTR" p 2734.

Enumerator
k_ra8_canfd_afl_rule_capacity 

One 16-entry AFL page (page 0).

Definition at line 237 of file ra8_canfd.h.

Function Documentation

◆ ra8_canfd_attach_handler()

ra8_err_t ra8_canfd_attach_handler ( ra8_canfd_event_fn_t fn,
void * ctx )
nodiscard

Attach a callback for CANFD events (shared across channels).

Since
0.1.0

Definition at line 585 of file ra8_canfd.c.

References k_ra8_ok, s_canfd_ctx, and s_canfd_fn.

◆ ra8_canfd_clear_status()

ra8_err_t ra8_canfd_clear_status ( uint8_t channel,
uint32_t mask )
nodiscard

Clear error flags in CFDCnERFL.

Since
0.1.0

Definition at line 574 of file ra8_canfd.c.

References r_canfd_t::CFDC, r_canfd_cfdc_t::ERFL, k_ra8_ok, ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_canfd_deinit()

ra8_err_t ra8_canfd_deinit ( uint8_t channel)
nodiscard

Put the CANFD channel back into reset.

Parameters
[in]channelChannel index (0..1).
Returns
k_ra8_ok on success, k_ra8_err_null_ptr if channel out of range.
Since
0.1.0

Definition at line 546 of file ra8_canfd.c.

References k_ra8_chmdc_reset, k_ra8_ok, priv_ra8_canfd_internal_set_channel_mode(), ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_canfd_dispatch()

void ra8_canfd_dispatch ( uint8_t channel)

Dispatch a CANFD event for a channel – snapshot + fire callback.

Since
0.1.0

See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.

Parameters
[in]channelSee header declaration for direction and constraints.
Precondition
Driver state has been initialized by the matching *_init.
Caller has validated all pointer parameters.
Postcondition
Side effects are limited to those documented in the header.
No global state is modified on the error path.
Note
Thread safety: see the header declaration.

Definition at line 593 of file ra8_canfd.c.

References r_canfd_t::CFDC, r_canfd_cfdc_t::ERFL, ra8_canfd(), s_canfd_ctx, and s_canfd_fn.

◆ ra8_canfd_enter_stop()

ra8_err_t ra8_canfd_enter_stop ( uint8_t channel)
nodiscard

Put the CANFD channel into MSTP-gated stop.

Since
0.1.0

Definition at line 777 of file ra8_canfd.c.

References k_ra8_canfd_instance_count, k_ra8_err_invalid_arg, ra8_mstp_disable(), and s_canfd_mstp_table.

◆ ra8_canfd_exit_stop()

ra8_err_t ra8_canfd_exit_stop ( uint8_t channel)
nodiscard

Exit MSTP-gated stop.

Since
0.1.0

Definition at line 786 of file ra8_canfd.c.

References k_ra8_canfd_instance_count, k_ra8_err_invalid_arg, ra8_mstp_enable(), and s_canfd_mstp_table.

◆ ra8_canfd_filter_set()

ra8_err_t ra8_canfd_filter_set ( uint16_t filter_id,
uint32_t accept_id,
uint32_t mask,
uint8_t dlc )
nodiscard

Programme one Global Acceptance-Filter-List (GAFL) entry.

Selects the AFL page that contains filter_id (each page holds 16 entries) by writing CFDGAFLECTR.AFLPN with the page index and unlocking the data window with CFDGAFLECTR.AFLDAE. Then writes CFDGAFL[idx].ID with the accept ID, CFDGAFL[idx].M with the bit mask, and CFDGAFL[idx].P1 with the DLC field used to gate fast RX-FIFO routing. See HUM Ch 41 "CFDGAFLECTR / CFDGAFL" pp 2702-2867.

Parameters
[in]filter_idFilter index (0..k_ra8_canfd_afl_total - 1).
[in]accept_idRaw arbitration ID to accept (11- or 29-bit).
[in]maskBit mask – bits clear are "don't care".
[in]dlcDLC code packed into CFDGAFL.P1 (0..15).
Returns
ra8_err_t outcome.
Return values
k_ra8_okFilter slot programmed.
k_ra8_err_invalid_argfilter_id, accept_id, or dlc out of range.
Precondition
Channel is initialized; controller is in global-reset mode.
Caller is single-threaded init context.
Postcondition
CFDGAFL[entry].ID/M/P1 reflect the requested rule.
CFDGAFLECTR.AFLDAE re-locked when the call returns.
Note
Not thread-safe.
Since
0.1.0

Definition at line 689 of file ra8_canfd.c.

References r_canfd_t::CFDGAFLECTR, internal_bump_rnc0_locked(), internal_enable_rx_fifo0(), internal_set_global_mode(), internal_write_afl_slot(), k_ra8_canfd_afl_per_page, k_ra8_canfd_afl_total, k_ra8_canfd_dlc_max, k_ra8_canfd_id_ext_mask, k_ra8_err_invalid_arg, k_ra8_gaflectr_bit_afldae, k_ra8_gaflectr_mask_aflpn, k_ra8_gctr_value_operation, k_ra8_gctr_value_reset, k_ra8_ok, ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_canfd_filter_program_slots().

◆ ra8_canfd_get_error_state()

ra8_err_t ra8_canfd_get_error_state ( uint8_t channel,
uint8_t * tx_err,
uint8_t * rx_err )
nodiscard

Read the TX and RX error counters.

Parameters
[in]channelChannel index (0..1).
[out]tx_errTEC counter value. Must not be NULL.
[out]rx_errREC counter value. Must not be NULL.
Returns
k_ra8_err_null_ptr if any pointer is NULL or channel out of range.
k_ra8_ok on success.
Since
0.1.0

Definition at line 350 of file ra8_canfd_frame.c.

References r_canfd_t::CFDC, k_ra8_cnsts_bit_rec, k_ra8_cnsts_bit_tec, k_ra8_cnsts_mask_rec, k_ra8_cnsts_mask_tec, k_ra8_ok, ra8_canfd(), RA8_CHECK_NULL_PTR, s_tag, and r_canfd_cfdc_t::STS.

◆ ra8_canfd_get_status()

ra8_err_t ra8_canfd_get_status ( uint8_t channel,
uint32_t * out_mask )
nodiscard

Read the channel status register (CFDCnSTS).

Since
0.1.0

Definition at line 564 of file ra8_canfd.c.

References r_canfd_t::CFDC, k_ra8_ok, ra8_canfd(), RA8_CHECK_NULL_PTR, s_tag, and r_canfd_cfdc_t::STS.

◆ ra8_canfd_init()

ra8_err_t ra8_canfd_init ( uint8_t channel)
nodiscard

◆ ra8_canfd_receive()

ra8_err_t ra8_canfd_receive ( uint8_t channel,
ra8_canfd_frame_t * out_frame )
nodiscard

Poll the RX FIFO for the next available frame.

Non-blocking: on an empty FIFO the call returns k_ra8_err_no_data immediately. On success the frame is popped (by writing the pointer control register) before returning.

Parameters
[in]channelChannel index (0..1).
[out]out_frameDestination frame. Must not be NULL.
Returns
k_ra8_err_null_ptr if channel out of range or out_frame == NULL.
k_ra8_err_no_data if the RX FIFO is empty.
k_ra8_ok on success.
Since
0.1.0

Definition at line 326 of file ra8_canfd_frame.c.

References r_canfd_t::CFDRF, r_canfd_t::CFDRFPCTR, r_canfd_t::CFDRFSTS, r_canfd_cfdrf_t::FDSTS, r_canfd_cfdrf_t::ID, internal_decode_rx_header(), internal_read_rx_data(), k_ra8_canfd_rx_fifo_default, k_ra8_err_no_data, k_ra8_ok, k_ra8_rfpctr_value_ack, k_ra8_rfsts_bit_empty, r_canfd_cfdrf_t::PTR, ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_can_demo_one_round_trip(), internal_canfd_demo_one_round_trip(), internal_canfd_filter_one_round(), internal_thread_rx_entry(), and main().

◆ ra8_canfd_set_accept_filter()

ra8_err_t ra8_canfd_set_accept_filter ( uint8_t channel,
const ra8_canfd_afl_rule_t * rules,
uint8_t count )
nodiscard

Program the channel Acceptance-Filter-List from a rule array.

Installs count hardware acceptance rules into AFL page 0 for channel, replacing the single pass-all rule that ra8_canfd_init installs. The routine follows the documented AFL edit transaction exactly:

  1. Unlock the AFL data window and select page 0 by writing CFDGAFLECTR.AFLPN + CFDGAFLECTR.AFLDAE.
  2. Set the page-0 rule count in CFDGAFLCFG0.RNC0.
  3. Write each rule's CFDGAFLID / CFDGAFLM / CFDGAFLP0 / CFDGAFLP1.
  4. Re-lock the window by clearing CFDGAFLECTR.

For a rule, IDE and RTR are added to the match (CFDGAFLM.GAFLIDEM / GAFLRTRM) so extended and rtr are honoured, and CFDGAFLP1 routes the match into RX FIFO rule.target_rx.

Parameters
[in]channelCANFD channel index (0..1).
[in]rulesArray of count rules. Must not be NULL.
[in]countNumber of rules, 1..k_ra8_canfd_afl_rule_capacity.
Returns
ra8_err_t outcome.
Return values
k_ra8_okAll count rules programmed and re-locked.
k_ra8_err_null_ptrchannel out of range or rules NULL.
k_ra8_err_invalid_argcount is zero or above capacity, a rule's id/mask overflows the std/ext range, or a rule's target_rx is out of range.
Precondition
rules points to at least count valid rule descriptors.
The global block is in GL_RESET: RNC0 and the CFDGAFL entries are RESET-only, and the AFL lookup engine only resamples the list on the next GL_RESET -> GL_OPERATION transition (HUM Ch 41.2.18 p 2735, Ch 41.2.17 p 2734).
Postcondition
On success CFDGAFLCFG0.RNC0 == count and the first count CFDGAFL slots reflect the supplied rules.
CFDGAFLECTR.AFLDAE is cleared (window re-locked) on every return that reaches the write stage.
Note
Not thread-safe; single-threaded init / reconfigure context only.
See also
ra8_canfd_filter_set() Single-rule variant that wraps the GL_RESET transition itself.
Since
0.1.0

Definition at line 302 of file ra8_canfd_afl.c.

References r_canfd_t::CFDGAFLECTR, internal_afl_set_rule_count(), internal_afl_validate_all(), internal_afl_write_slot(), k_ra8_canfd_afl_page0, k_ra8_canfd_afl_rule_capacity, k_ra8_err_invalid_arg, k_ra8_gaflectr_bit_afldae, k_ra8_gaflectr_mask_aflpn, k_ra8_ok, ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_canfd_set_bitrate()

ra8_err_t ra8_canfd_set_bitrate ( uint8_t channel,
uint32_t bitrate_bps,
uint32_t data_bitrate_bps )
nodiscard

Programme nominal (and optional data) bit-timing registers.

Uses PCLKA as the CAN source clock (HUM default). Targets a 75% sample point (TSEG1=15, TSEG2=4, SJW=min(4,TSEG2)) and rejects any bit rate that does not resolve to an integer prescaler in 1..256.

Parameters
[in]channelChannel index (0..1).
[in]bitrate_bpsNominal-phase bit rate in bits per second.
[in]data_bitrate_bpsData-phase bit rate (for CAN-FD). Set to bitrate_bps (or 0) for classic-only.
Returns
k_ra8_err_null_ptr if channel out of range.
k_ra8_err_invalid_arg if either bit rate is zero or does not resolve to a valid prescaler / timing triple.
k_ra8_ok on success.
Since
0.1.0

Definition at line 196 of file ra8_canfd_timing.c.

References r_canfd_t::CFDC, r_canfd_t::CFDC2, r_canfd_cfdc2_t::DCFG, internal_pack_dcfg(), internal_pack_ncfg(), internal_solve_timing(), k_ra8_canfd_data_prescaler_max, k_ra8_canfd_prescaler_max, k_ra8_chmdc_operation, k_ra8_chmdc_reset, k_ra8_clock_id_pclka, k_ra8_ok, r_canfd_cfdc_t::NCFG, priv_ra8_canfd_internal_set_channel_mode(), ra8_canfd(), ra8_cgc_get_clock_hz(), RA8_CHECK_NULL_PTR, ra8_log_info_val, and s_tag.

Referenced by internal_can_demo_setup_or_halt(), internal_canfd_demo_setup_or_halt(), internal_canfd_filter_setup_or_halt(), and main().

◆ ra8_canfd_set_brs()

ra8_err_t ra8_canfd_set_brs ( uint8_t channel,
uint32_t fast_bitrate )
nodiscard

Configure the CAN-FD bit-rate-switch (BRS) data-phase rate.

Re-runs the data-phase timing solver against PCLKA and updates CFDC2[0].DCFG so that subsequent BRS frames sent on channel use fast_bitrate during the payload phase. See HUM Ch 41 "CFDCnDCFG" pp 2702-2867.

Parameters
[in]channelChannel index (0..1).
[in]fast_bitrateData-phase bit rate in bits per second.
Returns
ra8_err_t outcome.
Return values
k_ra8_okDCFG updated.
k_ra8_err_null_ptrchannel out of range.
k_ra8_err_invalid_argfast_bitrate is zero or unsolvable.
Precondition
ra8_canfd_init succeeded for channel.
PCLKA frequency is reachable via ra8_cgc_get_clock_hz.
Postcondition
CFDC2[0].DCFG reflects the new fast-phase timing triple.
Subsequent BRS frames switch to fast_bitrate after BRS bit.
Note
Not thread-safe.
Since
0.1.0

Definition at line 296 of file ra8_canfd_timing.c.

References internal_program_data_phase(), ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_canfd_set_iso_mode()

ra8_err_t ra8_canfd_set_iso_mode ( bool enable)
nodiscard

Select ISO 11898-1 vs non-ISO CAN-FD framing.

Writes CFDGFDCFG.NISO – when the bit is clear the controller uses the ISO 11898-1 stuff-count + CRC; when set it falls back to the original Bosch non-ISO framing. See HUM Ch 41 "CFDGFDCFG" pp 2702-2867.

Parameters
[in]enabletrue -> ISO mode, false -> non-ISO mode.
Returns
ra8_err_t outcome.
Return values
k_ra8_okMode bit updated.
Precondition
At least one CANFD channel is initialized.
Controller is in global-reset before flipping the bit.
Postcondition
CFDGFDCFG.NISO reflects enable.
Subsequent CAN-FD frames use the selected framing.
Note
Not thread-safe.
Since
0.1.0

Definition at line 761 of file ra8_canfd.c.

References r_canfd_t::CFDGFDCFG, k_ra8_gfdcfg_bit_niso, k_ra8_ok, ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

◆ ra8_canfd_set_tdc()

ra8_err_t ra8_canfd_set_tdc ( uint8_t channel,
const ra8_canfd_tdc_cfg_t * cfg )
nodiscard

Configure Transmitter Delay Compensation on a CANFD channel.

Writes the TDE, TDCOC, and TDCO fields in CFDCnFDCFG to enable or disable the transmitter delay compensation block, select the offset source (hardware-measured vs. manual), and program the TDCO offset value. All non-TDC bits (FDOE, REFE, CLOE, ESIC, EOCCFG) are preserved by a read-modify-write.

The write is bracketed by a CH_RESET / CH_OPERATION mode transition (mirrors the ra8_canfd_set_bitrate contract: FDCFG is only writable in CH_RESET or CH_HALT mode, per HUM Ch 41 "CFDCnFDCFG" p 2788). On a transition timeout the function returns the timeout error and the channel is left in the failing mode; the caller must call ra8_canfd_deinit before attempting recovery.

Parameters
[in]channelCANFD channel index (0..1).
[in]cfgTDC configuration descriptor. Must not be NULL. cfg->offset must be <= k_ra8_canfd_tdc_offset_max.
Returns
ra8_err_t outcome.
Return values
k_ra8_okCFDCnFDCFG updated; channel back in CH_OPERATION.
k_ra8_err_null_ptrchannel is out of range or cfg is NULL.
k_ra8_err_invalid_argcfg->offset exceeds the 7-bit TDCO cap (127).
k_ra8_err_hw_timeoutChannel mode transition stalled.
Precondition
ra8_canfd_init returned k_ra8_ok for channel.
PCLKA / CANFDCLK is stable (block-clock guard in ra8_canfd_init).
Postcondition
On k_ra8_ok: FDCFG.TDE / TDCOC / TDCO reflect cfg.
On k_ra8_ok: channel is back in CH_OPERATION; TX/RX may resume.
Non-TDC FDCFG bits (FDOE, REFE, CLOE, ESIC, EOCCFG) are unchanged.
On error: the channel may be stuck in CH_RESET; caller must deinit.
Note
Not thread-safe; serialize with TX/RX operations.
Since
0.1.0

Configure Transmitter Delay Compensation on a CANFD channel.

Definition at line 37 of file ra8_canfd_tdc.c.

References r_canfd_t::CFDC2, ra8_canfd_tdc_cfg_t::enable, r_canfd_cfdc2_t::FDCFG, k_ra8_canfd_tdc_offset_max, k_ra8_chmdc_operation, k_ra8_chmdc_reset, k_ra8_err_invalid_arg, k_ra8_fdcfg_mask_tdco, k_ra8_fdcfg_mask_tdcoc, k_ra8_fdcfg_mask_tde, k_ra8_fdcfg_shift_tdco, k_ra8_ok, ra8_canfd_tdc_cfg_t::manual, ra8_canfd_tdc_cfg_t::offset, priv_ra8_canfd_internal_set_channel_mode(), ra8_canfd(), RA8_CHECK_NULL_PTR, ra8_log_info, and s_tag.

◆ ra8_canfd_set_test_mode()

ra8_err_t ra8_canfd_set_test_mode ( uint8_t channel,
ra8_ctms_mode_t mode )
nodiscard

Enable a CFDC[0].CTR test mode (basic / listen-only / loopback).

Stamps CTME (bit 24) and CTMS[1:0] (bits [26:25]) in CFDC[0].CTR. Per HUM Ch 41 "CFDCnCTR" p 2710 these bits are only writable while the channel is in CH_HALT mode, so the helper:

  1. Drives the channel from CH_OPERATION (the post-init steady state) into CH_HALT via CHMDC = 10b and waits for CHLTSTS.
  2. Writes CTME=1 with the requested CTMS value.
  3. Returns the channel to CH_OPERATION via CHMDC = 00b.

The internal-loopback mode (k_ra8_ctms_self_test_1, 11b) is the documented way to validate the CANFD IP without a transceiver – the controller routes every TX frame straight to its own RX acceptance filter (HUM Ch 41 "Self-test mode 1 (Internal Loopback mode)" p 2710).

Parameters
[in]channelChannel index (0..1).
[in]modeDesired CTMS selector (ra8_ctms_mode_t).
Returns
ra8_err_t outcome.
Return values
k_ra8_okTest mode latched, channel back in operation.
k_ra8_err_invalid_argchannel or mode out of range.
k_ra8_err_hw_timeoutHalt/operation status bit never asserted.
Precondition
ra8_canfd_init has returned k_ra8_ok for channel.
No outstanding TX/RX is in flight on channel.
Postcondition
CFDC[0].CTR.CTME=1 and CTMS=mode.
Channel is back in CH_OPERATION ready to TX/RX.
Note
Not thread-safe; caller must serialize with TX/RX.
Since
0.1.0

Definition at line 731 of file ra8_canfd.c.

References r_canfd_t::CFDC, r_canfd_cfdc_t::CTR, k_ra8_chmdc_halt, k_ra8_chmdc_operation, k_ra8_cnctr_bit_ctms, k_ra8_cnctr_mask_ctme, k_ra8_cnctr_mask_ctms, k_ra8_ctms_self_test_1, k_ra8_err_invalid_arg, k_ra8_ok, priv_ra8_canfd_internal_set_channel_mode(), ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_can_demo_enable_internal_loopback(), internal_canfd_demo_enable_internal_loopback(), internal_canfd_filter_loopback(), and main().

◆ ra8_canfd_transmit()

ra8_err_t ra8_canfd_transmit ( uint8_t channel,
const ra8_canfd_frame_t * frame )
nodiscard

Queue a frame into the TX message buffer and trigger transmission.

Fire-and-forget: the routine validates every field, writes the ID / DLC / FD-status / payload into the TX message-buffer registers, then asserts TMTR in CFDTMC. No completion callback is raised.

Parameters
[in]channelChannel index (0..1).
[in]frameFrame descriptor. Must not be NULL.
Returns
k_ra8_err_null_ptr if channel out of range or frame == NULL.
k_ra8_err_invalid_arg on bad DLC, oversized ID, or inconsistent flags.
k_ra8_ok on success.
Since
0.1.0

Definition at line 235 of file ra8_canfd_frame.c.

References r_canfd_t::CFDTM, r_canfd_t::CFDTMC, r_canfd_t::CFDTMSTS, ra8_canfd_frame_t::dlc, r_canfd_cfdtm_t::FDCTR, r_canfd_cfdtm_t::ID, internal_tx_fdctr(), internal_tx_id(), internal_validate_frame(), internal_wait_tx_complete(), internal_write_tx_data(), k_ra8_canfd_ptr_mask_dlc, k_ra8_canfd_ptr_shift_dlc, k_ra8_canfd_tmc_txreq, k_ra8_canfd_tx_mb_default, k_ra8_ok, r_canfd_cfdtm_t::PTR, ra8_canfd(), RA8_CHECK_NULL_PTR, and s_tag.

Referenced by internal_can_demo_one_round_trip(), internal_canfd_demo_one_round_trip(), internal_canfd_filter_one_round(), and internal_thread_tx_entry().