31static const char*
s_tag =
"AGT";
43typedef enum : uint8_t {
295 *out_mask = reg->
AGTCR;
353 if (
ra8_agt(channel) ==
nullptr) {
425 if (
ra8_agt(channel) ==
nullptr) {
770typedef enum : uint32_t {
843 const uint8_t tmr1_hi =
static ra8_err_t internal_agt_cascade_resolve_halves(volatile r_agt_regs_t **out_lo, volatile r_agt_regs_t **out_hi)
Fetch and validate both AGT register windows for cascade.
ra8_agt_cascade_split_t
Shift / mask used to split the cascade 32-bit reload.
@ k_ra8_agt_cascade_lo_mask
RA8 AGT cascade lo mask.
@ k_ra8_agt_cascade_hi_shift
RA8 AGT cascade hi shift.
static void internal_agt_cascade_install_callback(const ra8_agt_cascade_cfg_t *cfg)
Install the optional cascade-completion callback.
static ra8_err_t internal_agt_cascade_clock_to_tck(ra8_agt_cascade_clk_t clock, uint8_t *out_tck)
Translate the cascade clock enum into an AGTMR1.TCK encoding.
ra8_err_t ra8_agt_set_reload(uint8_t channel, uint16_t reload)
Change the AGT reload value at runtime.
static void internal_agt_pulse_program_registers(volatile r_agt_regs_t *reg, const ra8_agt_pulse_cfg_t *cfg)
Write the AGT mode / I/O / compare-match registers for pulse output.
static void internal_agt_cascade_program_and_start(volatile r_agt_regs_t *lo, volatile r_agt_regs_t *hi, uint32_t reload32, uint8_t tck_lo)
Programme both AGT halves and start them in cascade order.
ra8_err_t ra8_agt_exit_stop(uint8_t channel)
Exit MSTP-gated stop for one AGT channel.
ra8_err_t ra8_agt_attach_handler(ra8_agt_event_fn_t fn, void *ctx)
Attach an AGT event callback (shared across channels).
ra8_err_t ra8_agt_start_free_run(uint8_t channel, uint16_t reload)
Start an AGT channel in free-running mode.
static void internal_agt_pulse_program_compare(volatile r_agt_regs_t *reg, ra8_agt_pulse_compare_t compare, uint16_t duty)
Programme the AGTCMA / AGTCMB compare register for pulse mode.
ra8_agt_mstp_limit_t
Number of AGT channels that have dedicated MSTPD bits.
@ k_ra8_agt_mstp_id_count
RA8 AGT mstp ID count.
static const ra8_mstp_t s_agt_mstp_table[k_ra8_agt_mstp_id_count]
Channel-index -> MSTP id lookup for AGT0 / AGT1.
static ra8_err_t internal_agt_mstp_acquire(uint8_t channel)
Acquire the per-channel AGT MSTP reference exactly once (issue #68).
static void internal_agt_cascade_arm_half(volatile r_agt_regs_t *reg, uint8_t tmr1, uint16_t reload)
Reset and arm one cascade half in plain timer mode.
static uint8_t internal_agt_pulse_agtcmsr_value(ra8_agt_pulse_compare_t compare)
Build the AGTCMSR mask for a chosen compare-match output.
static ra8_agt_event_fn_t s_agt_fn
static ra8_err_t internal_agt_cascade_mstp_enable_both(void)
Power on both halves of the cascade pair.
ra8_err_t ra8_agt_deinit(uint8_t channel)
Tear down one AGT channel.
ra8_err_t ra8_agt_start_cascade(const ra8_agt_cascade_cfg_t *cfg)
Cascade AGT0 and AGT1 into a 32-bit virtual down-counter.
ra8_err_t ra8_agt_get_status(uint8_t channel, uint8_t *out_mask)
Read the AGTCR status register.
static ra8_err_t internal_agt_mstp_release(uint8_t channel)
Release the per-channel AGT MSTP reference if held (issue #68).
static ra8_err_t internal_agt_pulse_validate_cfg(const ra8_agt_pulse_cfg_t *cfg)
Validate the enum members of a pulse-output config block.
static uint8_t internal_agt_pulse_agtioc_value(ra8_agt_output_polarity_t polarity)
Translate the pulse-mode polarity enum into an AGTIOC mask.
ra8_err_t ra8_agt_start_pulse_output(uint8_t channel, const ra8_agt_pulse_cfg_t *cfg)
Arm one AGT channel in pulse-output / output-compare mode.
ra8_err_t ra8_agt_enter_stop(uint8_t channel)
Put one AGT channel into MSTP-gated stop.
ra8_err_t ra8_agt_stop(uint8_t channel)
Stop an AGT channel.
void ra8_agt_dispatch(uint8_t channel)
Dispatch an AGT event to the registered shared callback.
static bool s_agt_mstp_held[k_ra8_agt_mstp_id_count]
Per-channel "this driver holds the MSTP reference" latch (AGT0/AGT1).
Asynchronous General-Purpose Timer (AGT) driver header.
ra8_agt_pulse_compare_t
Compare-match output channel selection for pulse mode.
@ k_ra8_agt_pulse_compare_b
AGTCMB + AGTOBn toggle armed.
@ k_ra8_agt_pulse_compare_a
AGTCMA + AGTOAn toggle armed.
@ k_ra8_agt_pulse_compare_none
No compare-match output.
void(* ra8_agt_event_fn_t)(void *ctx, uint8_t channel)
AGT event callback.
@ k_ra8_agt_cascade_clk_pclkb
TCK = 000b.
@ k_ra8_agt_cascade_clk_pclkb_div2
TCK = 011b.
@ k_ra8_agt_cascade_clk_pclkb_div8
TCK = 001b.
ra8_agt_output_polarity_t
Initial level of the AGTOn pulse output.
@ k_ra8_agt_output_polarity_active_low
TEDGSEL = 0, start-high pin.
@ k_ra8_agt_output_polarity_active_high
TEDGSEL = 1, start-low pin.
Asynchronous General-Purpose Timer (AGT) register layout for RA8D2.
static volatile r_agt_regs_t * ra8_agt(uint8_t channel)
Get pointer to AGT channel N.
@ k_ra8_agt_cascade_lo_channel
Low 16 bits live in AGT0.
@ k_ra8_agt_cascade_hi_channel
High 16 bits live in AGT1.
@ k_ra8_agt_agtmr1_tmod_timer
TMOD = 000b.
@ k_ra8_agt_agtmr1_tmod_pulse_output
TMOD = 001b.
@ k_ra8_agt_agtmr1_tck_pclkb
TCK = 000b @ bit 4.
@ k_ra8_agt_agtmr1_tck_pclkb_div2
TCK = 011b @ bit 4.
@ k_ra8_agt_agtmr1_tck_pclkb_div8
TCK = 001b @ bit 4.
@ k_ra8_agt_agtmr1_tck_agt0_underflow
TCK = 101b (AGT1 only).
@ k_ra8_agt_agtcr_tstart_msk
RA8 AGT agtcr tstart msk.
@ k_ra8_agt_compare_parked_value
RA8 AGT compare parked value.
@ k_ra8_agt_agtioc_tedgsel_msk
Output polarity bit 0.
@ k_ra8_agt_agtioc_toe_msk
AGTOn pin output enable.
@ k_ra8_agt_agtcmsr_tcmea_msk
Compare match A enable.
@ k_ra8_agt_agtcmsr_toeb_msk
AGTOBn output enable.
@ k_ra8_agt_agtcmsr_tcmeb_msk
Compare match B enable.
@ k_ra8_agt_agtcmsr_toea_msk
AGTOAn output enable.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_ISR_SAFE
The function is callable from interrupt context.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
ra8_mstp_t
Packed (reg << 8) | bit module-stop identifier.
@ k_ra8_mstp_agt0
MSTPD5 AGT0.
@ k_ra8_mstp_agt1
MSTPD4 AGT1.
AGT (16-bit view) register layout, one per channel.
volatile uint8_t AGTMR2
+0x0A Mode 2.
volatile uint8_t AGTCR
+0x08 Control.
volatile uint16_t AGTCMA
+0x02 Compare Match A.
volatile uint8_t AGTIOC
+0x0C I/O Control.
volatile uint16_t AGT
+0x00 16-bit counter.
volatile uint8_t AGTCMSR
+0x0E Compare Match Function.
volatile uint8_t AGTMR1
+0x09 Mode 1.
volatile uint16_t AGTCMB
+0x04 Compare Match B.
Configuration for ra8_agt_start_cascade.
void * ctx
Opaque ctx forwarded to callback.
ra8_agt_event_fn_t on_underflow
Optional: fires on AGT1 underflow.
uint32_t reload32
32-bit virtual reload value.
ra8_agt_cascade_clk_t clock
Count source for the AGT0 half.
Configuration for ra8_agt_start_pulse_output.
ra8_agt_pulse_compare_t compare
Which compare-match pin is armed.
uint16_t period
16-bit reload (AGT register).
uint16_t duty
Compare-match A/B value.
ra8_agt_pulse_mode_t mode
continuous or one-shot.
ra8_agt_output_polarity_t polarity
Start-level of AGTOn.