|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
PWM Delay Generation Circuit (PDG) driver public API. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_pdg_config_t |
| Driver configuration descriptor for ra8_pdg_init. More... | |
| struct | ra8_pdg_status_full_t |
| Decoded snapshot of GTDLYCR / GTDLYCR2 returned by ra8_pdg_get_status_full. More... | |
| struct | ra8_pdg_delay_entry_t |
| Single-edge descriptor for the batch update API. More... | |
Typedefs | |
| typedef void(* | ra8_pdg_event_fn_t) (void *ctx) |
| PDG event callback (DLL lock event, etc.). | |
Enumerations | |
| enum | ra8_pdg_edge_t : uint8_t { k_ra8_pdg_edge_rising = 0U , k_ra8_pdg_edge_falling = 1U } |
| Selects which delay register family is targeted. More... | |
| enum | ra8_pdg_pin_t : uint8_t { k_ra8_pdg_pin_a = 0U , k_ra8_pdg_pin_b = 1U } |
| Picks the A or B pin within a PDG channel. More... | |
| enum | ra8_pdg_status_t : uint16_t { k_ra8_pdg_status_dll_locked = 0x0001U , k_ra8_pdg_status_in_reset = 0x0002U , k_ra8_pdg_status_frange_msk = 0x0300U } |
| Bits surfaced by ra8_pdg_get_status (legacy compact form). More... | |
| enum | ra8_pdg_count_dir_t : uint8_t { k_ra8_pdg_dir_up = 0U , k_ra8_pdg_dir_down = 1U } |
| Counter direction passed to ra8_pdg_check_constraints. More... | |
| enum | ra8_pdg_wave_mode_t : uint8_t { k_ra8_pdg_wave_saw = 0U , k_ra8_pdg_wave_triangle = 1U } |
| PWM waveform shape – selects which Table 23.4 row applies. More... | |
Functions | |
| 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_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). | |
| 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. | |
PWM Delay Generation Circuit (PDG) driver public API.
The PDG (HUM Ch 23 "PWM Delay Generation Circuit (PDG)", p 1152-1163) is a per-edge fine-delay sub-block that sits in line with the GPT320..GPT323 PWM outputs and shifts each rising or falling edge by an integer fraction of the GPT core clock period (1/128 in the 80..160 MHz range, 1/64 in the 155..300 MHz range).
Hardware binding:
GPT324..GPT329 are not delayed – they bypass the PDG entirely (HUM Figure 23.1 p 1153). The driver therefore caps the channel argument at 4.
Initialization sequence implemented by ra8_pdg_init follows Figure 23.2 (p 1160):
Note: PDG is bound to GPT0/1/2/3 channels; you must also configure the matching GPT timer through the GPT driver. Use this driver solely for the per-edge fine delay overlay.
Round-3 additions (full Ch 23 coverage):
Definition in file ra8_pdg.h.
| typedef void(* ra8_pdg_event_fn_t) (void *ctx) |
PDG event callback (DLL lock event, etc.).
| [in] | ctx | Caller context forwarded from ra8_pdg_attach_handler. |
The PDG itself does not raise its own NVIC vector – delay transfers happen on GPT timer overflow / underflow / trough (HUM Ch 23.3.2 p 1161). The callback hook is exposed so a host test (or a future "DLL lost lock" watchdog wired through ELC) has a single entry point to deliver async notifications.
| enum ra8_pdg_count_dir_t : uint8_t |
Counter direction passed to ra8_pdg_check_constraints.
HUM Ch 23.4.2 Table 23.4 (p 1162) restricts when a delay register may be updated, depending on whether the host GPT counter is counting up or down. The two values match the GPT GTST.TUCF bit semantics so callers can pass GTST.TUCF directly.
| Enumerator | |
|---|---|
| k_ra8_pdg_dir_up | Counter is up-counting (TUCF == 0). |
| k_ra8_pdg_dir_down | Counter is down-counting (TUCF == 1). |
| enum ra8_pdg_edge_t : uint8_t |
Selects which delay register family is targeted.
Maps directly to the HUM split between GTDLYRn (rising) and GTDLYFn (falling) registers. Used by ra8_pdg_set_delay / ra8_pdg_get_delay.
| Enumerator | |
|---|---|
| k_ra8_pdg_edge_rising | GTDLYRnA / GTDLYRnB. |
| k_ra8_pdg_edge_falling | GTDLYFnA / GTDLYFnB. |
| enum ra8_pdg_pin_t : uint8_t |
| enum ra8_pdg_status_t : uint16_t |
Bits surfaced by ra8_pdg_get_status (legacy compact form).
The PDG has no dedicated status register – "status" here is a snapshot of GTDLYCR (DLLEN / DLYRST / FRANGE) packed into a caller-friendly mask. ra8_pdg_get_status reads GTDLYCR directly per HUM Ch 23.2.1 p 1154.
| Enumerator | |
|---|---|
| k_ra8_pdg_status_dll_locked | DLLEN = 1 (DLL running). |
| k_ra8_pdg_status_in_reset | DLYRST = 1 (held in reset). |
| k_ra8_pdg_status_frange_msk | Live FRANGE[1:0] bits. |
| enum ra8_pdg_wave_mode_t : uint8_t |
PWM waveform shape – selects which Table 23.4 row applies.
The constraint table in HUM Ch 23.4.2 (p 1162) lists two rows: saw-wave mode and triangle-wave mode. Triangle mode is identified here so that ra8_pdg_check_constraints selects the right row.
| Enumerator | |
|---|---|
| k_ra8_pdg_wave_saw | Saw-wave PWM (count up or down). |
| k_ra8_pdg_wave_triangle | Triangle-wave PWM. |
|
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().