|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
PWM Delay Generation Circuit (PDG) driver implementation. More...
#include "ra8_pdg.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_gpt_regs.h"#include "ra8_hw_intrinsics.h"#include "ra8_log.h"#include "ra8_mstp.h"#include "ra8_pdg_regs.h"Go to the source code of this file.
Enumerations | |
| enum | ra8_pdg_internal_t : uint16_t { k_ra8_pdg_channel_mask_all = 0x000FU , k_ra8_pdg_dll_lock_us = 20U , k_ra8_pdg_busy_loops_per_us = 1000U , k_ra8_pdg_post_reset_loops = 32U , k_ra8_pdg_ns_per_sec_kilo = 1000U } |
| Driver-internal magic values (no magic numbers in functions). More... | |
| enum | ra8_pdg_gtwp_key_t : uint32_t { k_ra8_pdg_gtwp_unlock = 0xA500U , k_ra8_pdg_gtwp_lock = 0xA501U } |
| GPT GTWP write-protect key values (mirrors FSP). More... | |
| enum | ra8_pdg_constraint_t : uint32_t { k_ra8_pdg_constraint_low_thresh = 2U , k_ra8_pdg_constraint_high_pad = 2U } |
| Numeric thresholds in HUM Ch 23.4.2 Table 23.4. More... | |
| enum | ra8_pdg_write_interval_t : uint32_t { k_ra8_pdg_pclka_mult = 6U , k_ra8_pdg_gptclk_mult = 4U } |
| Multipliers in the HUM Ch 23.4.3 (p 1163) interval formula. More... | |
| enum | ra8_pdg_unit_t : uint32_t { k_ra8_pdg_ns_per_sec = 1000000000UL } |
| Units used by internal_freq_to_period_ns. More... | |
Functions | |
| static bool | internal_pdg_is_initialized (void) |
| Probe live PDG registers to decide whether ra8_pdg_init has run successfully. | |
| static void | internal_busy_wait_us (uint16_t usec) |
| Coarse software busy-wait used during init. | |
| static void | internal_wait_5_gtclk (void) |
| Spin >= 5 GTCLK cycles after releasing DLYRST (HUM Fig 23.2). | |
| static bool | internal_frange_ok (ra8_pdg_frange_t f) |
| Validate the FRANGE encoding. | |
| static ra8_err_t | internal_validate_cfg (const ra8_pdg_config_t *cfg) |
| Validate a user-supplied PDG configuration. | |
| static volatile uint16_t * | internal_dly_cell (uint8_t channel, ra8_pdg_pin_t pin, ra8_pdg_edge_t edge) |
| Compute a pointer to the right delay register cell. | |
| static ra8_err_t | internal_validate_slot (uint8_t channel, ra8_pdg_pin_t pin, ra8_pdg_edge_t edge, uint8_t code) |
| Validate a (channel, pin, edge, code) tuple. | |
| static uint32_t | internal_freq_to_period_ns (uint32_t hz) |
| Convert a frequency in Hz to a period in nanoseconds. | |
| static void | internal_program_dll (const ra8_pdg_config_t *cfg, ra8_pdg_frange_t frange_use) |
| Run the six-step DLL bring-up sequence from HUM Fig 23.2. | |
| ra8_err_t | ra8_pdg_init (const ra8_pdg_config_t *cfg) |
| Initialise the PDG block per HUM Figure 23.2 (p 1160). | |
| ra8_err_t | ra8_pdg_deinit (void) |
| Tear down the PDG block (reset + module-stop). | |
| ra8_err_t | ra8_pdg_set_delay (uint8_t channel, ra8_pdg_pin_t pin, ra8_pdg_edge_t edge, uint8_t code) |
| Set the per-edge fine delay for one PDG channel/pin/edge. | |
| ra8_err_t | ra8_pdg_get_delay (uint8_t channel, ra8_pdg_pin_t pin, ra8_pdg_edge_t edge, uint8_t *out_code) |
| Read back the last-programmed delay code. | |
| ra8_err_t | ra8_pdg_set_delay_batch (const ra8_pdg_delay_entry_t *entries, uint8_t count) |
| Atomically program a batch of (channel, pin, edge, code) delay updates. | |
| ra8_err_t | ra8_pdg_delay_ns_to_code (uint32_t delay_ns, uint32_t gptclk_hz, ra8_pdg_frange_t frange, uint8_t *out_code) |
| Convert a desired pin-to-pin delay (in nanoseconds) to a DLY[6:0] code given a measured GPTCLK frequency. | |
| ra8_err_t | ra8_pdg_exit_stop (uint8_t channel) |
| Power up one PDG channel (clear the GTDLYCR2.DLYENn bit). | |
| ra8_err_t | ra8_pdg_enter_stop (uint8_t channel) |
| Power down one PDG channel (set GTDLYCR2.DLYENn). | |
| ra8_err_t | ra8_pdg_channel_bypass_set (uint8_t channel, uint8_t bypass) |
| Set or clear the bypass bit for a channel. | |
| ra8_err_t | ra8_pdg_pin_disable (uint8_t channel, ra8_pdg_pin_t pin) |
| Force a single A or B pin's delay to zero (per-pin disable) without touching the channel-level bypass / power bits. | |
| ra8_err_t | ra8_pdg_get_status (uint16_t *out) |
| Read GTDLYCR packed into a status mask. | |
| ra8_err_t | ra8_pdg_get_status_full (ra8_pdg_status_full_t *out) |
| Read a fully-decoded snapshot of GTDLYCR + GTDLYCR2. | |
| ra8_err_t | ra8_pdg_clear_status (uint16_t mask) |
| Clear the soft-reset bit (DLYRST -> 0) and re-enable the DLL. | |
| ra8_err_t | ra8_pdg_attach_handler (ra8_pdg_event_fn_t fn, void *ctx) |
| Attach an asynchronous PDG event callback. | |
| void | ra8_pdg_dispatch (void) |
| Fire the registered handler. | |
| ra8_err_t | ra8_pdg_capture_start (const ra8_pdg_delay_entry_t *buf, uint8_t len) |
| Stage a buffer of ra8_pdg_delay_entry_t records and arm them. | |
| ra8_err_t | ra8_pdg_capture_stop (void) |
| Cancel any pending buffered apply and clear the completion latch. | |
| ra8_err_t | ra8_pdg_pick_frange (uint32_t gptclk_hz, ra8_pdg_frange_t *out) |
| Auto-pick a FRANGE value from a measured GPTCLK frequency. | |
| ra8_err_t | ra8_pdg_set_frange (ra8_pdg_frange_t new_frange) |
| Switch FRANGE at runtime, re-running the DLL re-lock sequence with the new band. | |
| ra8_err_t | ra8_pdg_bind_gpt_channel (uint8_t channel) |
| Bind PDG channel n to its host GPT32n channel. | |
| ra8_err_t | ra8_pdg_unbind_gpt_channel (uint8_t channel) |
| Reverse ra8_pdg_bind_gpt_channel, restoring write-protect. | |
| ra8_err_t | ra8_pdg_check_constraints (ra8_pdg_wave_mode_t mode, ra8_pdg_count_dir_t dir, uint32_t compare_match, uint32_t gtpr) |
| Check Table 23.4 constraints before writing a delay register. | |
| ra8_err_t | ra8_pdg_required_write_ns (uint32_t pclka_hz, uint32_t gptclk_hz, uint32_t *out_ns) |
| Compute the minimum register-write interval (HUM 23.4.3 p 1163). | |
Variables | |
| static const char * | s_tag = "PDG" |
| static ra8_pdg_event_fn_t | s_pdg_event_fn |
| Most recent callback registered by ra8_pdg_attach_handler. | |
| static void * | s_pdg_event_ctx |
| Opaque pointer forwarded to s_pdg_event_fn. | |
| static bool | s_pdg_capture_in_flight |
| Set true between ra8_pdg_capture_start and the callback fire. | |
PWM Delay Generation Circuit (PDG) driver implementation.
Drives the PDG block per HUM Ch 23 (p 1152-1163). The driver exposes init/deinit, per-edge delay programming, batch programming, per-channel + per-pin power transition, status snapshot, runtime FRANGE switch with proper DLL re-lock, GPT0/1/2/3 binding helpers, compare-match-window constraint validation (HUM Ch 23.4.2 p 1162), register-write-interval helpers (HUM Ch 23.4.3 p 1163), and an event-callback hook.
The PDG sits between GPT320..GPT323 and the GTIOC0..GTIOC3 pads (HUM Figure 23.1 p 1153). Higher GPT channels (4..9) bypass the PDG entirely and the driver therefore caps the channel index at k_ra8_pdg_channel_count = 4.
Definition in file ra8_pdg.c.
| enum ra8_pdg_constraint_t : uint32_t |
| enum ra8_pdg_gtwp_key_t : uint32_t |
| enum ra8_pdg_internal_t : uint16_t |
Driver-internal magic values (no magic numbers in functions).
| enum ra8_pdg_unit_t : uint32_t |
| enum ra8_pdg_write_interval_t : uint32_t |
|
static |
Coarse software busy-wait used during init.
The HAL does not expose a microsecond busy-wait helper; the loop pads each iteration with ra8_hw_nop, which is a real nop on the target and a host no-op through the ra8_hw_intrinsics seam (the host has no timing requirement to meet).
| [in] | usec | Microseconds to spin. |
Definition at line 201 of file ra8_pdg.c.
References k_ra8_pdg_busy_loops_per_us, ra8_hw_nop(), and RA8_INTERNAL.
Referenced by internal_program_dll(), and ra8_pdg_set_frange().
|
inlinestatic |
Compute a pointer to the right delay register cell.
Centralises the (channel, pin, edge) -> register pointer math so the various write/read entry points share one decoder. Callers MUST have already validated the indices.
Definition at line 308 of file ra8_pdg.c.
References r_pdg_dly_pair_t::A, r_pdg_dly_pair_t::B, r_pdg_regs_t::GTDLYF, r_pdg_regs_t::GTDLYR, k_ra8_pdg_edge_rising, k_ra8_pdg_pin_a, pin, and ra8_pdg().
Referenced by ra8_pdg_get_delay(), ra8_pdg_pin_disable(), ra8_pdg_set_delay(), and ra8_pdg_set_delay_batch().
|
static |
Validate the FRANGE encoding.
See implementation.
| [in] | f | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 247 of file ra8_pdg.c.
References k_ra8_pdg_frange_155_300_mhz, k_ra8_pdg_frange_80_160_mhz, and RA8_INTERNAL.
Referenced by internal_validate_cfg(), ra8_pdg_delay_ns_to_code(), and ra8_pdg_set_frange().
|
static |
Convert a frequency in Hz to a period in nanoseconds.
| [in] | hz | Frequency in Hz, must be > 0. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 368 of file ra8_pdg.c.
References k_ra8_pdg_ns_per_sec, and RA8_INTERNAL.
Referenced by ra8_pdg_required_write_ns().
|
static |
Probe live PDG registers to decide whether ra8_pdg_init has run successfully.
The PDG block is "initialized" when ra8_pdg_init has driven the DLL into the locked / running state, i.e. GTDLYCR.DLLEN == 1 and GTDLYCR.DLYRST == 0 (HUM Ch 23.2.1 p 1154). Reading the register directly avoids stale-static-flag bugs across host-test resets that wipe the fake MMIO without touching driver-side TU statics.
| k_ra8_ok | Operation succeeded. |
Definition at line 153 of file ra8_pdg.c.
References r_pdg_regs_t::GTDLYCR, k_ra8_pdg_gtdlycr_mask_dllen, k_ra8_pdg_gtdlycr_mask_dlyrst, RA8_INTERNAL, and ra8_pdg().
Referenced by ra8_pdg_bind_gpt_channel(), ra8_pdg_channel_bypass_set(), ra8_pdg_pin_disable(), ra8_pdg_set_delay(), ra8_pdg_set_delay_batch(), and ra8_pdg_set_frange().
|
static |
Run the six-step DLL bring-up sequence from HUM Fig 23.2.
HUM Ch 23.3.1 "Adjustments to the Timing of Rising and Falling Edges" p 1159 describes the exact sequence: latch FRANGE, enable DLL, wait >= 20 us for lock, release DLYRST, wait >= 5 GTCLK cycles, then turn off bypass for the channels selected by cfg->channel_mask.
| [in] | cfg | Validated config. |
| [in] | frange_use | Final FRANGE band (post auto-tune resolution). |
Definition at line 400 of file ra8_pdg.c.
References ra8_pdg_config_t::channel_mask, r_pdg_regs_t::GTDLYCR, r_pdg_regs_t::GTDLYCR2, internal_busy_wait_us(), internal_wait_5_gtclk(), k_ra8_pdg_dll_lock_us, k_ra8_pdg_gtdlycr2_shift_dlybs, k_ra8_pdg_gtdlycr_mask_dllen, k_ra8_pdg_gtdlycr_mask_dlyrst, k_ra8_pdg_gtdlycr_shift_frange, RA8_INTERNAL, and ra8_pdg().
Referenced by ra8_pdg_init().
|
static |
Validate a user-supplied PDG configuration.
| [in] | cfg | Caller-supplied descriptor (must be non-null). |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 277 of file ra8_pdg.c.
References ra8_pdg_config_t::auto_tune, ra8_pdg_config_t::channel_mask, ra8_pdg_config_t::frange, ra8_pdg_config_t::gptclk_hz, internal_frange_ok(), k_ra8_err_invalid_arg, k_ra8_err_out_of_range, k_ra8_ok, k_ra8_pdg_channel_mask_all, k_ra8_pdg_freq_high_max_hz, k_ra8_pdg_freq_low_min_hz, and RA8_INTERNAL.
Referenced by ra8_pdg_init().
|
static |
Validate a (channel, pin, edge, code) tuple.
See implementation.
| [in] | channel | See implementation. |
| [in] | pin | See implementation. |
| [in] | edge | See implementation. |
| [in] | code | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 336 of file ra8_pdg.c.
References k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_dly_max, k_ra8_pdg_edge_falling, k_ra8_pdg_edge_rising, k_ra8_pdg_pin_a, k_ra8_pdg_pin_b, and pin.
Referenced by ra8_pdg_get_delay(), ra8_pdg_set_delay(), and ra8_pdg_set_delay_batch().
|
static |
Spin >= 5 GTCLK cycles after releasing DLYRST (HUM Fig 23.2).
See implementation.
Definition at line 222 of file ra8_pdg.c.
References k_ra8_pdg_post_reset_loops, ra8_hw_nop(), and RA8_INTERNAL.
Referenced by internal_program_dll(), and ra8_pdg_set_frange().
|
nodiscard |
Attach an asynchronous PDG event callback.
The PDG itself does not raise an NVIC vector – this hook is available for higher-level code that wants to forward GPT compare-match events (e.g. "delay updated") through a single registration point.
| [in] | fn | Callback invoked from ra8_pdg_dispatch. |
| [in] | ctx | Forwarded to fn. |
Definition at line 707 of file ra8_pdg.c.
References k_ra8_ok, s_pdg_event_ctx, and s_pdg_event_fn.
|
nodiscard |
Bind PDG channel n to its host GPT32n channel.
HUM Ch 23.2.3 (p 1156) requires that GTWP write-protect is cleared on the matching GPT channel before the PDG delay registers can be written. This helper performs that GTWP unlock (and stores the prior value so the caller can re-arm protection later via ra8_pdg_unbind_gpt_channel).
| [in] | channel | 0..3 (GPT320..GPT323). |
| k_ra8_ok | GTWP cleared, binding active. |
| k_ra8_err_invalid_arg | channel out of range. |
Definition at line 839 of file ra8_pdg.c.
References r_gpt_channel_regs_t::GTWP, internal_pdg_is_initialized(), k_ra8_err_hw_unmapped, k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_gtwp_unlock, and ra8_gpt().
|
nodiscard |
Stage a buffer of ra8_pdg_delay_entry_t records and arm them.
The PDG itself does not "capture" data – this entry-point exists so the camera/data-capture orchestrator can stream a buffer of fine-delay updates through the same *_capture_start(buf, len) shape that the VIN / CEU drivers expose. Each ra8_pdg_delay_entry_t in buf is forwarded to ra8_pdg_set_delay_batch after a NULL / range check, and the registered completion callback (see ra8_pdg_attach_handler) fires via ra8_pdg_dispatch once all entries land.
| [in] | buf | Pointer to an array of ra8_pdg_delay_entry_t records. |
| [in] | len | Element count (must be > 0 and <= k_ra8_pdg_slot_count). |
| k_ra8_ok | Entries staged + dispatch fired. |
| k_ra8_err_null_ptr | buf was NULL. |
| k_ra8_err_invalid_arg | len out of range or bad entry. |
| k_ra8_err_not_initialized | PDG init has not run. |
Definition at line 738 of file ra8_pdg.c.
References k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_pdg_dispatch(), ra8_pdg_set_delay_batch(), s_pdg_capture_in_flight, and s_tag.
|
nodiscard |
Cancel any pending buffered apply and clear the completion latch.
Mirrors the VIN / CEU *_capture_stop shape. Implementation simply clears the internal "in flight" flag so a subsequent ra8_pdg_dispatch does not double-fire the callback.
| k_ra8_ok | Always. |
Definition at line 754 of file ra8_pdg.c.
References k_ra8_ok, and s_pdg_capture_in_flight.
|
nodiscard |
Set or clear the bypass bit for a channel.
HUM Ch 23.2.2 (p 1155) describes the DLYBSn bit: 1 = delay applied, 0 = bypass. ra8_pdg_init already sets the bit for every channel in cfg->channel_mask; this helper exists so a caller can flip the bypass on the fly without a full re-init.
| [in] | channel | 0..3. |
| [in] | bypass | Non-zero sets bypass-off (delay applied); zero sets bypass-on (delay skipped). |
Definition at line 616 of file ra8_pdg.c.
References r_pdg_regs_t::GTDLYCR2, internal_pdg_is_initialized(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_gtdlycr2_shift_dlybs, and ra8_pdg().
|
nodiscard |
Check Table 23.4 constraints before writing a delay register.
HUM Ch 23.4.2 Table 23.4 (p 1162) forbids changing a delay register while the host GPT is in a "no write" window:
| mode | direction | compare-match value forbidden |
|---|---|---|
| Saw | Up | >= GTPR - 2 |
| Saw | Down | <= 2 |
| Triangle | Down | <= 2 |
| [in] | mode | Saw vs triangle. |
| [in] | dir | Counter direction. |
| [in] | compare_match | Current GTCCRx (= compare match value). |
| [in] | gtpr | GPT period register value. |
| k_ra8_ok | Safe to write the delay register. |
| k_ra8_err_invalid_state | Inside the forbidden window. |
Definition at line 881 of file ra8_pdg.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, k_ra8_pdg_constraint_high_pad, k_ra8_pdg_constraint_low_thresh, k_ra8_pdg_dir_down, k_ra8_pdg_dir_up, k_ra8_pdg_wave_saw, and k_ra8_pdg_wave_triangle.
|
nodiscard |
Clear the soft-reset bit (DLYRST -> 0) and re-enable the DLL.
Used to re-arm the block after a controlled park via ra8_pdg_enter_stop. The "status mask" is in fact the GTDLYCR register so this call only writes back the bit that the caller provided – DLYRST is forced low.
| [in] | mask | Caller-supplied bits to clear in GTDLYCR. Only k_ra8_pdg_status_in_reset is meaningful today. |
Definition at line 696 of file ra8_pdg.c.
References r_pdg_regs_t::GTDLYCR, k_ra8_ok, k_ra8_pdg_gtdlycr_mask_dlyrst, k_ra8_pdg_status_in_reset, and ra8_pdg().
|
nodiscard |
Tear down the PDG block (reset + module-stop).
| k_ra8_ok | Block parked back in module-stop with all channels disabled. |
Definition at line 464 of file ra8_pdg.c.
References r_pdg_dly_pair_t::A, r_pdg_dly_pair_t::B, r_pdg_regs_t::GTDLYCR, r_pdg_regs_t::GTDLYCR2, r_pdg_regs_t::GTDLYF, r_pdg_regs_t::GTDLYR, k_ra8_mstp_pdg, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_gtdlycr_mask_dlyrst, ra8_mstp_disable(), and ra8_pdg().
|
nodiscard |
Convert a desired pin-to-pin delay (in nanoseconds) to a DLY[6:0] code given a measured GPTCLK frequency.
Uses the divider table from HUM Ch 23.2.3..23.2.6 (p 1156-1158): 1/128 step at k_ra8_pdg_frange_80_160_mhz, 1/64 step at k_ra8_pdg_frange_155_300_mhz. The result is rounded to the nearest representable code and clamped to [0, 0x7F].
| [in] | delay_ns | Desired delay in nanoseconds. |
| [in] | gptclk_hz | GPTCLK frequency in Hz (must be > 0). |
| [in] | frange | The FRANGE band currently programmed. |
| [out] | out_code | Receives the closest DLY[6:0] code. |
| k_ra8_ok | Code computed. |
| k_ra8_err_null_ptr | out_code is NULL. |
| k_ra8_err_invalid_arg | gptclk_hz is zero or frange out of range. |
Definition at line 554 of file ra8_pdg.c.
References internal_frange_ok(), k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_pdg_dly_div_high, k_ra8_pdg_dly_div_low, k_ra8_pdg_dly_max, k_ra8_pdg_frange_80_160_mhz, k_ra8_pdg_ns_per_sec, RA8_CHECK_NULL_PTR, and s_tag.
| void ra8_pdg_dispatch | ( | void | ) |
Fire the registered handler.
Test / ELC entry point.
See implementation.
Definition at line 715 of file ra8_pdg.c.
References s_pdg_event_ctx, and s_pdg_event_fn.
Referenced by ra8_pdg_capture_start().
|
nodiscard |
Power down one PDG channel (set GTDLYCR2.DLYENn).
| [in] | channel | 0..3. |
Definition at line 603 of file ra8_pdg.c.
References r_pdg_regs_t::GTDLYCR2, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_gtdlycr2_shift_dlyen, and ra8_pdg().
|
nodiscard |
Power up one PDG channel (clear the GTDLYCR2.DLYENn bit).
| [in] | channel | 0..3. |
Definition at line 589 of file ra8_pdg.c.
References r_pdg_regs_t::GTDLYCR2, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_gtdlycr2_shift_dlyen, and ra8_pdg().
|
nodiscard |
Read back the last-programmed delay code.
| [in] | channel | PDG channel (0..3). |
| [in] | pin | k_ra8_pdg_pin_a / k_ra8_pdg_pin_b. |
| [in] | edge | k_ra8_pdg_edge_rising / k_ra8_pdg_edge_falling. |
| [out] | out_code | Receives the DLY[6:0] code last written. |
Definition at line 512 of file ra8_pdg.c.
References internal_dly_cell(), internal_validate_slot(), k_ra8_ok, k_ra8_pdg_dly_mask, pin, RA8_CHECK_NULL_PTR, RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_pdg_demo_sample().
|
nodiscard |
Read GTDLYCR packed into a status mask.
| [out] | out | Receives a bitmask of ra8_pdg_status_t bits. |
Definition at line 663 of file ra8_pdg.c.
References r_pdg_regs_t::GTDLYCR, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_pdg(), and s_tag.
|
nodiscard |
Read a fully-decoded snapshot of GTDLYCR + GTDLYCR2.
| [out] | out | Non-null structure to fill in. |
| k_ra8_ok | Snapshot stored. |
| k_ra8_err_null_ptr | out is NULL. |
Definition at line 672 of file ra8_pdg.c.
References ra8_pdg_status_full_t::dll_enabled, ra8_pdg_status_full_t::frange, r_pdg_regs_t::GTDLYCR, r_pdg_regs_t::GTDLYCR2, ra8_pdg_status_full_t::in_reset, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_gtdlycr2_shift_dlybs, k_ra8_pdg_gtdlycr2_shift_dlyen, k_ra8_pdg_gtdlycr_mask_dllen, k_ra8_pdg_gtdlycr_mask_dlyrst, k_ra8_pdg_gtdlycr_mask_frange, k_ra8_pdg_gtdlycr_shift_frange, ra8_pdg_status_full_t::per_channel_bypass_off, ra8_pdg_status_full_t::per_channel_powered, RA8_CHECK_NULL_PTR, ra8_pdg(), ra8_pdg_status_full_t::raw_gtdlycr, ra8_pdg_status_full_t::raw_gtdlycr2, and s_tag.
Referenced by internal_pdg_demo_sample().
|
nodiscard |
Initialise the PDG block per HUM Figure 23.2 (p 1160).
Clears the PDG module-stop bit (MSTPD6 per HUM Ch 23.4.1 p 1162), holds the circuit in reset, programs FRANGE (or auto-derives it from cfg->gptclk_hz when cfg->auto_tune == 1), enables the DLL, waits for lock, releases reset, and turns off bypass for the channels listed in cfg->channel_mask.
| [in] | cfg | Non-NULL driver descriptor. |
| k_ra8_ok | Init complete. |
| k_ra8_err_null_ptr | cfg was NULL. |
| k_ra8_err_invalid_arg | cfg->frange out of range or cfg->channel_mask selects bits outside [0..3] or auto-tune saw gptclk_hz == 0. |
| k_ra8_err_out_of_range | Auto-tune saw gptclk_hz outside the 80..300 MHz range allowed by HUM Ch 23.2.1 p 1154. |
| k_ra8_err_hw_init_failed | MSTP failed to release the block. |
Definition at line 438 of file ra8_pdg.c.
References ra8_pdg_config_t::auto_tune, ra8_pdg_config_t::frange, ra8_pdg_config_t::gptclk_hz, internal_program_dll(), internal_validate_cfg(), k_ra8_mstp_pdg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info, ra8_mstp_enable(), ra8_pdg_pick_frange(), RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_pdg_demo_configure().
|
nodiscard |
Auto-pick a FRANGE value from a measured GPTCLK frequency.
Implements the band-selection table of HUM Ch 23.2.1 (p 1154):
The two ranges overlap between 155 and 160 MHz; this helper picks the lower band when the input falls in the overlap because that gives the finer 1/128 step.
| [in] | gptclk_hz | GPTCLK in Hz (>0). 80..300 MHz inclusive. |
| [out] | out | Receives the chosen ra8_pdg_frange_t. |
| k_ra8_ok | Band selected. |
| k_ra8_err_null_ptr | out is NULL. |
| k_ra8_err_invalid_arg | gptclk_hz is 0. |
| k_ra8_err_out_of_range | gptclk_hz outside [80 MHz, 300 MHz]. |
Definition at line 765 of file ra8_pdg.c.
References k_ra8_err_invalid_arg, k_ra8_err_out_of_range, k_ra8_ok, k_ra8_pdg_frange_155_300_mhz, k_ra8_pdg_frange_80_160_mhz, k_ra8_pdg_freq_high_max_hz, k_ra8_pdg_freq_low_min_hz, k_ra8_pdg_freq_overlap_top, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by ra8_pdg_init().
|
nodiscard |
Force a single A or B pin's delay to zero (per-pin disable) without touching the channel-level bypass / power bits.
The HUM lets DLYBSn / DLYENn be flipped per channel; per-pin disable is achieved by writing 0x00 into the pin's two delay cells (rising + falling). ra8_pdg_pin_disable does that, and ra8_pdg_pin_enable restores caller-supplied codes.
| [in] | channel | 0..3. |
| [in] | pin | k_ra8_pdg_pin_a or k_ra8_pdg_pin_b. |
Definition at line 637 of file ra8_pdg.c.
References internal_dly_cell(), internal_pdg_is_initialized(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_edge_falling, k_ra8_pdg_edge_rising, k_ra8_pdg_pin_a, k_ra8_pdg_pin_b, and pin.
|
nodiscard |
Compute the minimum register-write interval (HUM 23.4.3 p 1163).
Write_Interval [ns] = Period_of_PCLKA [ns] x 6
Used by callers that issue back-to-back writes to the same delay register to size their software pacing.
| [in] | pclka_hz | PCLKA frequency in Hz (>0). |
| [in] | gptclk_hz | GPTCLK frequency in Hz (>0). |
| [out] | out_ns | Receives the required interval, in ns. |
Definition at line 921 of file ra8_pdg.c.
References internal_freq_to_period_ns(), k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_pdg_gptclk_mult, k_ra8_pdg_pclka_mult, RA8_CHECK_NULL_PTR, and s_tag.
|
nodiscard |
Set the per-edge fine delay for one PDG channel/pin/edge.
| [in] | channel | PDG channel (0..3, mapped to GPT320..GPT323). |
| [in] | pin | k_ra8_pdg_pin_a (GTIOCnA) or k_ra8_pdg_pin_b (GTIOCnB). |
| [in] | edge | k_ra8_pdg_edge_rising or k_ra8_pdg_edge_falling. |
| [in] | code | DLY[6:0] code, 0..0x7F. 0 disables the delay on this edge; the meaning of non-zero codes depends on the FRANGE bit currently programmed in GTDLYCR (HUM Ch 23.2.3..23.2.6 p 1156-1158). |
| k_ra8_ok | Code written. |
| k_ra8_err_invalid_arg | Channel >= 4, pin/edge invalid, or code > 0x7F. |
| k_ra8_err_not_initialized | PDG init has not run. |
Definition at line 494 of file ra8_pdg.c.
References internal_dly_cell(), internal_pdg_is_initialized(), internal_validate_slot(), k_ra8_err_not_initialized, k_ra8_ok, k_ra8_pdg_dly_mask, pin, RA8_RETURN_ON_ERROR, and s_tag.
Referenced by internal_pdg_demo_configure().
|
nodiscard |
Atomically program a batch of (channel, pin, edge, code) delay updates.
Walks entries and applies each one with IRQs nominally masked (host-test build is single-threaded). All writes land in the PDG temporary registers in the same critical section, so the next GPT overflow / underflow / trough applies them as one coherent set. This is the multi-edge atomic batch entry-point called for in HUM Ch 23.3.2 (p 1161).
| [in] | entries | Pointer to count entries. |
| [in] | count | Number of entries (must be > 0 and <= k_ra8_pdg_slot_count). |
| k_ra8_ok | All entries written. |
| k_ra8_err_null_ptr | entries is NULL. |
| k_ra8_err_invalid_arg | Count out of range or any entry contains a bad channel / pin / edge / code. |
| k_ra8_err_not_initialized | PDG init has not run. |
Definition at line 525 of file ra8_pdg.c.
References internal_dly_cell(), internal_pdg_is_initialized(), internal_validate_slot(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, k_ra8_pdg_dly_mask, k_ra8_pdg_slot_count, pin, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by ra8_pdg_capture_start().
|
nodiscard |
Switch FRANGE at runtime, re-running the DLL re-lock sequence with the new band.
HUM Ch 23.2.1 (p 1154): "Set the FRANGE[1:0] bits only when the DLLEN bit is 0." This routine therefore performs:
| [in] | new_frange | The new FRANGE encoding. |
| k_ra8_ok | Switch complete. |
| k_ra8_err_invalid_arg | new_frange not a legal band. |
| k_ra8_err_not_initialized | PDG init has not run. |
Definition at line 787 of file ra8_pdg.c.
References r_pdg_regs_t::GTDLYCR, r_pdg_regs_t::GTDLYCR2, internal_busy_wait_us(), internal_frange_ok(), internal_pdg_is_initialized(), internal_wait_5_gtclk(), k_ra8_err_invalid_arg, k_ra8_err_not_initialized, k_ra8_ok, k_ra8_pdg_dll_lock_us, k_ra8_pdg_gtdlycr_mask_dllen, k_ra8_pdg_gtdlycr_mask_dlyrst, k_ra8_pdg_gtdlycr_shift_frange, and ra8_pdg().
|
nodiscard |
Reverse ra8_pdg_bind_gpt_channel, restoring write-protect.
| [in] | channel | 0..3. |
Definition at line 860 of file ra8_pdg.c.
References r_gpt_channel_regs_t::GTWP, k_ra8_err_hw_unmapped, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_pdg_channel_count, k_ra8_pdg_gtwp_lock, and ra8_gpt().
|
static |
Set true between ra8_pdg_capture_start and the callback fire.
Definition at line 736 of file ra8_pdg.c.
Referenced by ra8_pdg_capture_start(), and ra8_pdg_capture_stop().
|
static |
Opaque pointer forwarded to s_pdg_event_fn.
Definition at line 179 of file ra8_pdg.c.
Referenced by ra8_pdg_attach_handler(), and ra8_pdg_dispatch().
|
static |
Most recent callback registered by ra8_pdg_attach_handler.
Definition at line 173 of file ra8_pdg.c.
Referenced by ra8_pdg_attach_handler(), and ra8_pdg_dispatch().