|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Full-featured General PWM Timer (GPT) driver. More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_gpt_cfg_t |
| Configuration descriptor for ra8_gpt_init. More... | |
| struct | ra8_gpt_pwm_pin_cfg_t |
| Configuration descriptor for ra8_gpt_pwm_pin_configure. More... | |
| struct | ra8_gpt_three_phase_cfg_t |
| Configuration descriptor for ra8_gpt_three_phase_open. More... | |
Typedefs | |
| typedef void(* | ra8_gpt_event_fn_t) (void *ctx, uint32_t status_mask) |
| GPT IRQ event callback signature. | |
Functions | |
| ra8_err_t | ra8_gpt_init (uint8_t channel, const ra8_gpt_cfg_t *cfg) |
| Initialise a GPT channel with a full config descriptor. | |
| ra8_err_t | ra8_gpt_deinit (uint8_t channel) |
| Tear down a channel (stop + MSTP release). | |
| ra8_err_t | ra8_gpt_start_free_run (uint8_t channel, uint32_t period) |
| Configure a GPT channel as a free-running up-counter. | |
| ra8_err_t | ra8_gpt_stop (uint8_t channel) |
| Stop a GPT channel. | |
| ra8_err_t | ra8_gpt_read (uint8_t channel, uint32_t *out) |
| Read the current counter value. | |
| ra8_err_t | ra8_gpt_set_period (uint8_t channel, uint32_t period) |
| Change the GPT period (GTPR / GTPBR) at runtime. | |
| ra8_err_t | ra8_gpt_set_duty (uint8_t channel, ra8_gpt_ccr_sel_t which, uint32_t value) |
| Change one compare register (GTCCRA / GTCCRB) at runtime. | |
| ra8_err_t | ra8_gpt_period_set (uint8_t channel, uint32_t period_counts) |
| Update the GPT period via the shadow buffer (GTPBR). | |
| ra8_err_t | ra8_gpt_duty_cycle_set (uint8_t channel, ra8_gpt_pwm_pin_t pin, uint32_t compare_counts) |
| Update one PWM compare value via the shadow buffer. | |
| ra8_err_t | ra8_gpt_counter_set (uint8_t channel, uint32_t value) |
| Force GTCNT to value (timer must be stopped). | |
| ra8_err_t | ra8_gpt_pwm_pin_configure (uint8_t channel, ra8_gpt_pwm_pin_t pin, const ra8_gpt_pwm_pin_cfg_t *cfg) |
| Configure GTIOR for one PWM output pin. | |
| ra8_err_t | ra8_gpt_dead_time_set (uint8_t channel, uint32_t rising_dt, uint32_t falling_dt) |
| Programme the dead-time value pair for complementary PWM. | |
| ra8_err_t | ra8_gpt_three_phase_open (const ra8_gpt_three_phase_cfg_t *cfg) |
| Open three GPT channels as a phase-synchronized U/V/W triple. | |
| ra8_err_t | ra8_gpt_three_phase_set_duty (uint32_t u_duty, uint32_t v_duty, uint32_t w_duty) |
| Atomically update U/V/W compare values via the shadow buffer. | |
| ra8_err_t | ra8_gpt_three_phase_close (void) |
| Stop and tear down the three U/V/W channels. | |
| ra8_err_t | ra8_gpt_get_status (uint8_t channel, uint32_t *out_mask) |
| Read GTST overflow / underflow / compare flags. | |
| ra8_err_t | ra8_gpt_clear_status (uint8_t channel, uint32_t mask) |
| Clear GTST flag bits (write-0 to clear). | |
| ra8_err_t | ra8_gpt_attach_handler (uint8_t channel, ra8_gpt_event_fn_t fn, void *ctx) |
| Attach a GPT event callback for a channel. | |
| ra8_err_t | ra8_gpt_enter_stop (uint8_t channel) |
| Put a channel into MSTP-gated stop. | |
| ra8_err_t | ra8_gpt_exit_stop (uint8_t channel) |
| Exit MSTP-gated stop. | |
| ra8_err_t | ra8_gpt_write_dma (uint8_t channel, const uint32_t *periods, uint16_t count, ra8_dma_complete_fn_t on_complete, void *ctx, uint8_t *out_dma_channel) |
| Stream a buffer of period values into GPT GTPR via DMA. | |
| ra8_err_t | ra8_gpt_read_dma (uint8_t channel, uint32_t *out_counts, uint16_t count, ra8_dma_complete_fn_t on_complete, void *ctx, uint8_t *out_dma_channel) |
| Capture a stream of GTCNT values into a buffer via DMA. | |
| void | ra8_gpt_dispatch_ovf (uint8_t channel) |
| Dispatch GPT overflow (GTCIV) – clear + fire callback. | |
| void | ra8_gpt_dispatch_und (uint8_t channel) |
| Dispatch GPT underflow (GTCIU) – clear + fire callback. | |
| void | ra8_gpt_dispatch_ccra (uint8_t channel) |
| Dispatch GPT compare-match A (GTCIA) – clear + fire callback. | |
| void | ra8_gpt_dispatch_ccrb (uint8_t channel) |
| Dispatch GPT compare-match B (GTCIB) – clear + fire callback. | |
Full-featured General PWM Timer (GPT) driver.
full build-out of the RA8D2 GPT peripheral. Extends the free-run stub with: descriptor-based init, deinit, runtime period / duty reconfigure, status flags, interrupt attach / dispatch, power transition.
API surface:
Definition in file ra8_gpt.h.
| typedef void(* ra8_gpt_event_fn_t) (void *ctx, uint32_t status_mask) |
| enum ra8_gpt_ccr_sel_t : uint8_t |
Selector for ra8_gpt_set_duty.
| Enumerator | |
|---|---|
| k_ra8_gpt_ccr_a | GTCCRA. |
| k_ra8_gpt_ccr_b | GTCCRB. |
| enum ra8_gpt_mode_t : uint8_t |
GPT counter-mode selection (GTCR.MD field).
| enum ra8_gpt_prescaler_t : uint8_t |
| enum ra8_gpt_pwm_disable_t : uint8_t |
Output-disable-on-POEG-fault behaviour (GTIOR.OADF / OBDF).
HUM Ch 22.2.13 "GTIOR" Table 22.18, p 944..946.
| enum ra8_gpt_pwm_pin_t : uint8_t |
Selector for the GTIOCnA / GTIOCnB PWM output pins.
Used by ra8_gpt_duty_cycle_set and ra8_gpt_pwm_pin_configure. Mirrors FSP gpt_io_pin_t::GPT_IO_PIN_GTIOCA / GPT_IO_PIN_GTIOCB from fsp/ra/fsp/src/r_gpt/r_gpt.c.
HUM Ch 22.2.13 "GTIOR : General PWM Timer I/O Control Register" p 942..946 – bit 8 is OAE (output enable A), bit 24 is OBE.
| Enumerator | |
|---|---|
| k_ra8_gpt_pin_a | GTIOCnA – compare register A path. |
| k_ra8_gpt_pin_b | GTIOCnB – compare register B path. |
| enum ra8_gpt_pwm_polarity_t : uint8_t |
Output polarity for ra8_gpt_pwm_pin_configure.
Active-high writes the GTIOR.GTIOA / GTIOR.GTIOB sub-field with "low at compare match, high at cycle end" (0x9 per HUM Table 22.18, p 944). Active-low writes the inverted pattern (0x6).
| Enumerator | |
|---|---|
| k_ra8_gpt_pol_active_high | Output is high while duty < count. |
| k_ra8_gpt_pol_active_low | Output is low while duty < count. |
| enum ra8_gpt_pwm_stop_level_t : uint8_t |
| enum ra8_gpt_status_mask_t : uint32_t |
Bit mask of GPT status flags (GTST register subset).
Bit positions match the GTST register in HUM Ch 22.2.16 "GTST : General PWM Timer Status Register", p 962..964: TCFA = bit 0, TCFB = bit 1, TCFPO = bit 6, TCFPU = bit 7.
| enum ra8_gpt_three_phase_idx_t : uint8_t |
Index into ra8_gpt_three_phase_cfg_t::channels for U/V/W.
| Enumerator | |
|---|---|
| k_ra8_gpt_three_phase_u | U-phase channel slot. |
| k_ra8_gpt_three_phase_v | V-phase channel slot. |
| k_ra8_gpt_three_phase_w | W-phase channel slot. |
| k_ra8_gpt_three_phase_count | Number of phases. |
|
nodiscard |
Attach a GPT event callback for a channel.
| [in] | channel | GPT channel. |
| [in] | fn | Callback fired on ISR dispatch. |
| [in] | ctx | Context passed to the callback. |
Definition at line 429 of file ra8_gpt.c.
References k_ra8_err_invalid_arg, k_ra8_gpt_channel_count, k_ra8_ok, and s_gpt_state.
|
nodiscard |
Clear GTST flag bits (write-0 to clear).
Definition at line 418 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTST, k_ra8_gpt_gtst_mask, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
Referenced by gpt_ecc_service_capture(), and internal_wait_ovf().
|
nodiscard |
Force GTCNT to value (timer must be stopped).
Mirrors FSP R_GPT_CounterSet – the underlying register is not safe to write while the counter is running, so the call rejects any channel whose GTCR.CST bit is set.
| [in] | channel | GPT channel 0..13. |
| [in] | value | New GTCNT value. |
| k_ra8_ok | Counter updated. |
| k_ra8_err_null_ptr | channel out of range. |
| k_ra8_err_invalid_state | Counter is currently running. |
Definition at line 637 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTCNT, r_gpt_channel_regs_t::GTCR, r_gpt_channel_regs_t::GTWP, k_ra8_err_invalid_state, k_ra8_gpt_gtcr_cst_mask, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
|
nodiscard |
Programme the dead-time value pair for complementary PWM.
Writes GTDVU (rising-edge dead-time) and GTDVD (falling-edge dead-time) and asserts GTDTCR.TDE (dead-time enable) iff at least one of the two values is non-zero. Mirrors the dead-time branch of FSP gpt_hardware_initialize.
| [in] | channel | GPT channel 0..13. |
| [in] | rising_dt | Dead-time count for the rising edge (GTDVU). |
| [in] | falling_dt | Dead-time count for the falling edge (GTDVD). |
| k_ra8_ok | Dead-time programmed. |
| k_ra8_err_null_ptr | channel out of range. |
Definition at line 716 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTDTCR, r_gpt_channel_regs_t::GTDVD, r_gpt_channel_regs_t::GTDVU, r_gpt_channel_regs_t::GTWP, k_ra8_gpt_gtdtcr_tde, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
Referenced by internal_motor_3phase_pin_configure_all().
|
nodiscard |
Tear down a channel (stop + MSTP release).
Definition at line 365 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTCR, r_gpt_channel_regs_t::GTSTP, r_gpt_channel_regs_t::GTWP, k_ra8_gpt_gtstp_stop, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), ra8_mstp_disable(), s_gpt_mstp_table, s_gpt_state, and s_tag.
Referenced by internal_three_phase_init_subs(), and ra8_gpt_three_phase_close().
| void ra8_gpt_dispatch_ccra | ( | uint8_t | channel | ) |
Dispatch GPT compare-match A (GTCIA) – clear + fire callback.
| [in] | channel | GPT channel. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 913 of file ra8_gpt.c.
References internal_dispatch(), and k_ra8_gpt_status_ccra.
| void ra8_gpt_dispatch_ccrb | ( | uint8_t | channel | ) |
Dispatch GPT compare-match B (GTCIB) – clear + fire callback.
| [in] | channel | GPT channel. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 919 of file ra8_gpt.c.
References internal_dispatch(), and k_ra8_gpt_status_ccrb.
| void ra8_gpt_dispatch_ovf | ( | uint8_t | channel | ) |
Dispatch GPT overflow (GTCIV) – clear + fire callback.
| [in] | channel | GPT channel. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 901 of file ra8_gpt.c.
References internal_dispatch(), and k_ra8_gpt_status_overflow.
| void ra8_gpt_dispatch_und | ( | uint8_t | channel | ) |
Dispatch GPT underflow (GTCIU) – clear + fire callback.
| [in] | channel | GPT channel. |
See the matching header declaration for the full contract; this site adds no behaviour beyond what the public API documents.
Definition at line 907 of file ra8_gpt.c.
References internal_dispatch(), and k_ra8_gpt_status_underflow.
|
nodiscard |
Update one PWM compare value via the shadow buffer.
Writes compare_counts into GTCCRC (for k_ra8_gpt_pin_a) or GTCCRE (for k_ra8_gpt_pin_b). Per FSP R_GPT_DutyCycleSet the buffer registers are swapped into GTCCRA/GTCCRB at the next cycle end, so PWM transitions are glitch-free. The GTBER.CCRA / GTBER.CCRB single-buffer enable bits are also asserted so the swap actually happens.
| [in] | channel | GPT channel 0..13. |
| [in] | pin | Which output pin – A or B. |
| [in] | compare_counts | New compare value (must be <= period). |
| k_ra8_ok | Compare buffer programmed. |
| k_ra8_err_invalid_arg | pin not in ra8_gpt_pwm_pin_t. |
| k_ra8_err_null_ptr | channel out of range. |
Definition at line 613 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTBER, r_gpt_channel_regs_t::GTCCR, r_gpt_channel_regs_t::GTWP, k_ra8_err_invalid_arg, k_ra8_gpt_ccr_idx_c, k_ra8_gpt_ccr_idx_e, k_ra8_gpt_gtber_ccra_single, k_ra8_gpt_gtber_ccrb_single, k_ra8_gpt_pin_a, k_ra8_gpt_pin_b, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, pin, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
|
nodiscard |
Put a channel into MSTP-gated stop.
Definition at line 439 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTSTP, r_gpt_channel_regs_t::GTWP, k_ra8_err_invalid_arg, k_ra8_gpt_channel_count, k_ra8_gpt_gtstp_stop, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, ra8_gpt(), ra8_mstp_disable(), and s_gpt_mstp_table.
|
nodiscard |
Exit MSTP-gated stop.
Definition at line 453 of file ra8_gpt.c.
References k_ra8_err_invalid_arg, k_ra8_gpt_channel_count, ra8_mstp_enable(), and s_gpt_mstp_table.
|
nodiscard |
Read GTST overflow / underflow / compare flags.
| [in] | channel | GPT channel. |
| [out] | out_mask | OR of k_ra8_gpt_status_*. |
Definition at line 408 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTST, k_ra8_gpt_gtst_mask, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
Referenced by gpt_ecc_service_capture(), and internal_wait_ovf().
|
nodiscard |
Initialise a GPT channel with a full config descriptor.
| [in] | channel | GPT channel (0..13). |
| [in] | cfg | Non-NULL configuration descriptor. |
Definition at line 329 of file ra8_gpt.c.
References ra8_gpt_cfg_t::auto_start, ra8_gpt_cfg_t::duty_a, ra8_gpt_cfg_t::duty_b, r_gpt_channel_regs_t::GTCCR, r_gpt_channel_regs_t::GTCNT, r_gpt_channel_regs_t::GTCR, r_gpt_channel_regs_t::GTPBR, r_gpt_channel_regs_t::GTPR, r_gpt_channel_regs_t::GTSTP, r_gpt_channel_regs_t::GTSTR, r_gpt_channel_regs_t::GTWP, internal_gpt_clock_block_init(), internal_gtcr(), k_ra8_gpt_gtcr_cst_set, k_ra8_gpt_gtstp_stop, k_ra8_gpt_gtstr_start, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, ra8_gpt_cfg_t::mode, ra8_gpt_cfg_t::period, ra8_gpt_cfg_t::prescaler, RA8_CHECK_NULL_PTR, ra8_gpt(), ra8_log_info_val, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_gpt_mstp_table, s_gpt_state, and s_tag.
Referenced by gpt_ecc_timers_or_halt(), internal_arm(), internal_arm_channel(), internal_gpt_irq_demo_arm(), internal_gpt_pwm_demo_arm(), internal_poeg_demo_arm_gpt(), internal_setup_or_halt(), internal_three_phase_init_subs(), ra8_board_camera_xclk_start(), and ra8_nsc_gpt_init().
|
nodiscard |
Update the GPT period via the shadow buffer (GTPBR).
Writes period_counts to GTPBR; on the next overflow the timer loads GTPBR into GTPR. If the counter is currently stopped the value is also written into GTPR immediately and the counter is cleared so the next ra8_gpt_set_period style call has the same starting point as a fresh ra8_gpt_init. Mirrors FSP R_GPT_PeriodSet from fsp/ra/fsp/src/r_gpt/r_gpt.c.
| [in] | channel | GPT channel 0..13. |
| [in] | period_counts | New period in counter ticks. |
| k_ra8_ok | Period buffer programmed. |
| k_ra8_err_null_ptr | channel out of range. |
Definition at line 595 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTCNT, r_gpt_channel_regs_t::GTCR, r_gpt_channel_regs_t::GTPBR, r_gpt_channel_regs_t::GTPR, r_gpt_channel_regs_t::GTWP, k_ra8_gpt_gtcr_cst_mask, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
|
nodiscard |
Configure GTIOR for one PWM output pin.
Programmes the polarity, output-enable, stop level, and output-disable-on-POEG-fault behaviour for either GTIOCnA or GTIOCnB. Mirrors the GTIOR-write portion of FSP R_GPT_OutputEnable / R_GPT_OutputDisable and the PWM setup logic in gpt_hardware_initialize.
| [in] | channel | GPT channel 0..13. |
| [in] | pin | Which output pin – A or B. |
| [in] | cfg | Non-NULL configuration descriptor. |
| k_ra8_ok | Pin configured. |
| k_ra8_err_null_ptr | channel out of range or cfg NULL. |
| k_ra8_err_invalid_arg | pin not in ra8_gpt_pwm_pin_t. |
Definition at line 678 of file ra8_gpt.c.
References ra8_gpt_pwm_pin_cfg_t::disable_on_fault, r_gpt_channel_regs_t::GTIOR, r_gpt_channel_regs_t::GTWP, internal_gtio_pattern(), k_ra8_err_invalid_arg, k_ra8_gpt_gtioa_mask, k_ra8_gpt_gtioa_shift, k_ra8_gpt_gtiob_mask, k_ra8_gpt_gtiob_shift, k_ra8_gpt_oadf_mask, k_ra8_gpt_oadf_shift, k_ra8_gpt_oadflt_mask, k_ra8_gpt_oadflt_shift, k_ra8_gpt_oae_mask, k_ra8_gpt_obdf_mask, k_ra8_gpt_obdf_shift, k_ra8_gpt_obdflt_mask, k_ra8_gpt_obdflt_shift, k_ra8_gpt_obe_mask, k_ra8_gpt_pin_a, k_ra8_gpt_pin_b, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, ra8_gpt_pwm_pin_cfg_t::output_enable, pin, ra8_gpt_pwm_pin_cfg_t::polarity, RA8_CHECK_NULL_PTR, ra8_gpt(), s_tag, and ra8_gpt_pwm_pin_cfg_t::stop_level.
Referenced by internal_motor_3phase_pin_configure_all(), and ra8_board_camera_xclk_start().
|
nodiscard |
Read the current counter value.
| [in] | channel | GPT channel (0..13). |
| [out] | out | Receive counter value. |
Definition at line 314 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTCNT, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
Referenced by cam_run(), internal_poeg_demo_cycle(), internal_read(), main(), ra8_nsc_gpt_read(), and timer_demo_one_capture().
|
nodiscard |
Capture a stream of GTCNT values into a buffer via DMA.
Programmes the ra8_dma substrate to copy count 32-bit counter snapshots from the channel's GTCNT register into out_counts[]. This is the "capture streaming" DMA RX path from the roadmap note – the driver samples GTCNT on each ELC trigger and stores the value, so the host sees the full capture sequence without ISR overhead.
| [in] | channel | GPT channel 0..13. |
| [out] | out_counts | Destination counter buffer. Must outlive the transfer. |
| [in] | count | Number of samples; non-zero. |
| [in] | on_complete | Completion callback. May be NULL. |
| [in] | ctx | Context passed to on_complete. |
| [out] | out_dma_channel | Allocated DMAC channel on success. |
| k_ra8_ok | Transfer armed. |
| k_ra8_err_null_ptr | out_counts / out_dma_channel NULL. |
| k_ra8_err_invalid_arg | Channel or count invalid. |
| k_ra8_err_no_mem | All DMAC channels in use. |
| k_ra8_err_hw_error | ra8_dma_request failed. |
Definition at line 493 of file ra8_gpt.c.
References ra8_dma_request_t::count, ra8_dma_request_t::ctx, ra8_dma_request_t::dst_addr, ra8_dma_request_t::dst_inc, r_gpt_channel_regs_t::GTCNT, k_ra8_dmac_width_word, k_ra8_err_invalid_arg, k_ra8_gpt_channel_count, ra8_dma_request_t::on_complete, RA8_CHECK_NULL_PTR, ra8_dma_request(), ra8_gpt(), s_tag, ra8_dma_request_t::src_addr, ra8_dma_request_t::src_inc, ra8_dma_request_t::trigger, and ra8_dma_request_t::width.
|
nodiscard |
Change one compare register (GTCCRA / GTCCRB) at runtime.
| [in] | channel | GPT channel. |
| [in] | which | Which compare register. |
| [in] | value | New compare value. |
Definition at line 394 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTCCR, r_gpt_channel_regs_t::GTWP, k_ra8_err_invalid_arg, k_ra8_gpt_ccr_b, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
Referenced by main().
|
nodiscard |
Change the GPT period (GTPR / GTPBR) at runtime.
| [in] | channel | GPT channel. |
| [in] | period | New GTPR value. |
Definition at line 382 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTPBR, r_gpt_channel_regs_t::GTPR, r_gpt_channel_regs_t::GTWP, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
|
nodiscard |
Configure a GPT channel as a free-running up-counter.
| [in] | channel | GPT channel (0..13). |
| [in] | period | Period in timer ticks (write to GTPR). |
Definition at line 274 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTCNT, r_gpt_channel_regs_t::GTCR, r_gpt_channel_regs_t::GTPR, r_gpt_channel_regs_t::GTSTP, r_gpt_channel_regs_t::GTSTR, r_gpt_channel_regs_t::GTWP, internal_gpt_clock_block_init(), k_ra8_err_invalid_arg, k_ra8_gpt_channel_count, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), ra8_log_info_val, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_gpt_mstp_table, and s_tag.
Referenced by internal_gpt_irq_demo_arm(), main(), and timer_demo_setup_or_halt().
|
nodiscard |
Stop a GPT channel.
| [in] | channel | GPT channel (0..13). |
Definition at line 303 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTSTP, r_gpt_channel_regs_t::GTWP, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), and s_tag.
|
nodiscard |
Stop and tear down the three U/V/W channels.
Stops the three channels via a single GTSTP write and calls ra8_gpt_deinit on each. Mirrors FSP R_GPT_THREE_PHASE_Stop + R_GPT_THREE_PHASE_Close.
| k_ra8_ok | All three channels closed. |
| k_ra8_err_invalid_state | ra8_gpt_three_phase_open not called. |
Definition at line 860 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTSTP, r_gpt_channel_regs_t::GTWP, k_ra8_err_invalid_state, k_ra8_gpt_three_phase_count, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, ra8_gpt(), ra8_gpt_deinit(), and s_three_phase.
|
nodiscard |
Open three GPT channels as a phase-synchronized U/V/W triple.
Calls ra8_gpt_init on each of the three channels in cfg->channels with the same mode, prescaler, and period. After all three are configured, the U-channel's GTSTR is written with a bitmask covering all three channel positions so they start on the same PCLKD edge. Mirrors FSP R_GPT_THREE_PHASE_Open + R_GPT_THREE_PHASE_Start.
| [in] | cfg | Non-NULL three-phase configuration descriptor. |
| k_ra8_ok | All three channels opened and started. |
| k_ra8_err_null_ptr | cfg NULL. |
| k_ra8_err_invalid_arg | Any channel id out of range or already open. |
Definition at line 799 of file ra8_gpt.c.
References ra8_gpt_three_phase_cfg_t::channels, r_gpt_channel_regs_t::GTSTR, r_gpt_channel_regs_t::GTWP, internal_three_phase_init_subs(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_gpt_channel_count, k_ra8_gpt_three_phase_count, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_gpt(), ra8_log_info_val, s_tag, and s_three_phase.
Referenced by internal_gpt_3p_demo_arm(), and internal_motor_3phase_init_pwm().
|
nodiscard |
Atomically update U/V/W compare values via the shadow buffer.
Writes u_duty / v_duty / w_duty into the GTCCRC and GTCCRE shadow buffers of the three channels recorded by ra8_gpt_three_phase_open. The GTBER buffer-enable bit makes the swap into GTCCRA/B happen at the next cycle end, so all three phases update on the same overflow. Mirrors FSP R_GPT_THREE_PHASE_DutyCycleSet.
| [in] | u_duty | New U-phase compare value. |
| [in] | v_duty | New V-phase compare value. |
| [in] | w_duty | New W-phase compare value. |
| k_ra8_ok | Compare values queued for swap. |
| k_ra8_err_invalid_state | ra8_gpt_three_phase_open not called. |
| k_ra8_err_invalid_arg | Any duty value > GTPR. |
Definition at line 833 of file ra8_gpt.c.
References r_gpt_channel_regs_t::GTBER, r_gpt_channel_regs_t::GTCCR, r_gpt_channel_regs_t::GTPR, r_gpt_channel_regs_t::GTWP, k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_gpt_ccr_idx_c, k_ra8_gpt_ccr_idx_e, k_ra8_gpt_gtber_ccra_single, k_ra8_gpt_gtber_ccrb_single, k_ra8_gpt_three_phase_count, k_ra8_gtwp_key_lock, k_ra8_gtwp_key_unlock, k_ra8_ok, ra8_gpt(), and s_three_phase.
Referenced by internal_motor_3phase_init_pwm(), and main().
|
nodiscard |
Stream a buffer of period values into GPT GTPR via DMA.
Programmes the ra8_dma substrate to copy count 32-bit period values from periods[] into the channel's GTPR register. This is the "sample streaming" DMA TX path from the roadmap note – the driver pumps a preloaded period sequence into the timer without the CPU touching GTPR each tick.
| [in] | channel | GPT channel 0..13. |
| [in] | periods | Source array of 32-bit period values. Must outlive the transfer. |
| [in] | count | Number of periods; non-zero. |
| [in] | on_complete | Completion callback. May be NULL. |
| [in] | ctx | Context passed to on_complete. |
| [out] | out_dma_channel | Allocated DMAC channel on success. |
| k_ra8_ok | Transfer armed. |
| k_ra8_err_null_ptr | periods / out_dma_channel NULL. |
| k_ra8_err_invalid_arg | Channel or count invalid. |
| k_ra8_err_no_mem | All DMAC channels in use. |
| k_ra8_err_hw_error | ra8_dma_request failed. |
Definition at line 463 of file ra8_gpt.c.
References ra8_dma_request_t::count, ra8_dma_request_t::ctx, ra8_dma_request_t::dst_addr, ra8_dma_request_t::dst_inc, r_gpt_channel_regs_t::GTPR, k_ra8_dmac_width_word, k_ra8_err_invalid_arg, k_ra8_gpt_channel_count, ra8_dma_request_t::on_complete, RA8_CHECK_NULL_PTR, ra8_dma_request(), ra8_gpt(), s_tag, ra8_dma_request_t::src_addr, ra8_dma_request_t::src_inc, ra8_dma_request_t::trigger, and ra8_dma_request_t::width.
Referenced by internal_run_one().