Astra MCU SDK Peripheral Driver Library
 
Loading...
Searching...
No Matches

Functions for the SPWM driver. More...

Functions

spwm_status_en spwm_init (spwm_instance_en id)
 
spwm_status_en spwm_deinit (spwm_instance_en id)
 
spwm_status_en spwm_enable (spwm_instance_en id, uint8_t group_id)
 
spwm_status_en spwm_disable (spwm_instance_en id, uint8_t group_id)
 
spwm_status_en spwm_clkdiv_config (spwm_instance_en id, uint8_t clkdiv_id, uint32_t int_div, uint32_t fra_div)
 
spwm_status_en spwm_clkdiv_enable (spwm_instance_en id, uint8_t clkdiv_id, bool enable, uint8_t phase_align_sel)
 
spwm_status_en spwm_otrigclk_config (spwm_instance_en id, uint8_t clkdiv_id)
 
spwm_status_en spwm_configure (spwm_instance_en id, uint8_t group_id, const spwm_config_t *config)
 
spwm_status_en spwm_trigger (spwm_instance_en id, uint8_t group_id, spwm_trigger_en trig)
 
spwm_status_en spwm_group_trigger (spwm_instance_en id, uint8_t group_trigger_id)
 
spwm_status_en spwm_get_counter (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_cc0 (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_cc1 (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_period (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_line_sel (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_cc0_buff (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_cc1_buff (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_period_buff (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_get_line_sel_buff (spwm_instance_en id, uint8_t group_id, uint32_t *val)
 
spwm_status_en spwm_set_clkdiv (spwm_instance_en id, uint8_t group_id, uint8_t clkdiv_id)
 
spwm_status_en spwm_set_mode (spwm_instance_en id, uint8_t group_id, spwm_mode_en mode)
 
spwm_status_en spwm_set_count_mode (spwm_instance_en id, uint8_t group_id, spwm_count_mode_en count_mode)
 
spwm_status_en spwm_set_counter (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_one_shot (spwm_instance_en id, uint8_t group_id, bool one_shot)
 
spwm_status_en spwm_set_prescale (spwm_instance_en id, uint8_t group_id, spwm_prescale_en prescale)
 
spwm_status_en spwm_set_deadtime (spwm_instance_en id, uint8_t group_id, uint32_t deadtime, uint32_t compl_deadtime)
 
spwm_status_en spwm_set_cc0 (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_cc1 (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_period (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_line_sel (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_cc0_buff (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_cc1_buff (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_period_buff (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_line_sel_buff (spwm_instance_en id, uint8_t group_id, uint32_t val)
 
spwm_status_en spwm_set_trig_in_all (spwm_instance_en id, uint8_t group_id, const spwm_trigger_in_cfg_t *cfg)
 
spwm_status_en spwm_set_trig_in (spwm_instance_en id, uint8_t group_id, spwm_trigger_en trigger, const spwm_trigger_in_cfg_t *config)
 
spwm_status_en spwm_set_trig_out (spwm_instance_en id, uint8_t group_id, int out_id, spwm_trigger_out_en out)
 
spwm_status_en spwm_set_sema (spwm_instance_en id, uint8_t group_id, uint8_t sema_id, uint8_t val)
 
spwm_status_en spwm_set_sema_sel (spwm_instance_en id, uint8_t group_id, int sema_id, spwm_trigger_out_en out)
 
uint32_t spwm_make_line_sel (spwm_line_src_en out, spwm_line_src_en compl)
 
spwm_status_en spwm_get_interrupt_status (spwm_instance_en id, uint8_t group_id, uint32_t *irq_status)
 
spwm_status_en spwm_enable_interrupt (spwm_instance_en id, uint8_t group_id, spwm_intr_en intr)
 
spwm_status_en spwm_disable_interrupt (spwm_instance_en id, uint8_t group_id, spwm_intr_en intr)
 
spwm_status_en spwm_disable_all_interrupts (spwm_instance_en id, uint8_t group_id)
 
spwm_status_en spwm_clear_all_interrupts (spwm_instance_en id, uint8_t group_id)
 
spwm_status_en spwm_output_select (spwm_instance_en id, uint8_t group_id, spwm_io_pin_en pin, bool compl)
 
spwm_status_en spwm_clear_interrupt (spwm_instance_en id, uint8_t group_id, uint32_t mask)
 
spwm_status_en spwm_clear_desc_interrupt (spwm_instance_en id, uint8_t desc_id)
 
spwm_status_en spwm_enable_desc_interrupt (spwm_instance_en id, uint8_t desc_id)
 
spwm_status_en spwm_disable_desc_interrupt (spwm_instance_en id, uint8_t desc_id)
 
spwm_status_en spwm_register_callback (spwm_instance_en id, spwm_isr_cb_t cb, void *user_ctx)
 
spwm_status_en spwm_register_desc_callback (spwm_instance_en id, spwm_desc_isr_cb_t cb, void *param)
 
spwm_dsc_status_en spwm_dsc_mem_alloc (size_t size_bytes, uint16_t *handle)
 
void spwm_dsc_mem_free (uint16_t handle)
 
spwm_dsc_chain_tspwm_dsc_chain_create (void)
 
void spwm_dsc_chain_destroy (spwm_dsc_chain_t *chain)
 
spwm_dsc_status_en spwm_dsc_chain_init_for_handle (spwm_instance_en id, spwm_dsc_chain_t *chain, uint16_t handle)
 
spwm_dsc_status_en spwm_dsc_chain_init (spwm_instance_en id, spwm_dsc_chain_t *chain, uint32_t start_offset_bytes, uint32_t block_size_bytes)
 
spwm_dsc_status_en spwm_dsc_chain_add_cfg (spwm_dsc_chain_t *chain, uint8_t group_id, spwm_dsc_reg_id_en reg_id, const uint32_t *values, uint32_t num_values, bool last)
 
spwm_dsc_status_en spwm_dsc_chain_add_syn (spwm_dsc_chain_t *chain, spwm_dsc_syn_op_en opcode, uint8_t group, uint32_t counter_mask, bool last)
 
spwm_dsc_status_en spwm_dsc_chain_add_nxt (spwm_dsc_chain_t *chain, uint32_t target_offset_bytes)
 
spwm_dsc_status_en spwm_dsc_chain_start (spwm_instance_en id, const spwm_dsc_chain_t *chain, uint8_t desc_id, bool enable_interrupt)
 
spwm_dsc_status_en spwm_dsc_chain_get_status (spwm_instance_en id, const spwm_dsc_chain_t *chain, uint8_t instance, spwm_dsc_chain_status_t *status)
 

Detailed Description

Functions for the SPWM driver.

group_spwm_data_structures

Function Documentation

◆ spwm_init()

spwm_status_en spwm_init ( spwm_instance_en id)

Initializes the SPWM instance and low-level resources.

This function configures the hardware base address, resets registers to a known safe state, and prepares the instance for subsequent configuration.

Parameters
idSPWM instance identifier.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_deinit()

spwm_status_en spwm_deinit ( spwm_instance_en id)

Deinitializes the SPWM instance and releases resources.

Stops the counter, disables interrupts, and returns the block to reset state.

Parameters
idSPWM instance identifier.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_enable()

spwm_status_en spwm_enable ( spwm_instance_en id,
uint8_t group_id )

Enables the SPWM group.

This function enables the specified SPWM group within a given SPWM instance by setting the ENABLED bit in the group control register.

Parameters
idSPWM instance identifier.
group_idGroup index to enable.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_disable()

spwm_status_en spwm_disable ( spwm_instance_en id,
uint8_t group_id )

Disables the SPWM group.

This function disables the specified SPWM group by clearing the ENABLED bit in the group control register. Typically used when stopping output from a SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to disable.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_clkdiv_config()

spwm_status_en spwm_clkdiv_config ( spwm_instance_en id,
uint8_t clkdiv_id,
uint32_t int_div,
uint32_t fra_div )

Configures the integer and fractional dividers for an SPWM clock divider.

This function programs the INT_DIV and FRA_DIV fields of the selected SPWM clock divider. The divider must be disabled prior to calling this function.

Parameters
idSPWM instance identifier.
clkdiv_idClock divider index.
int_divInteger divider value (must be >= 1).
fra_divFractional divider value.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_clkdiv_enable()

spwm_status_en spwm_clkdiv_enable ( spwm_instance_en id,
uint8_t clkdiv_id,
bool enable,
uint8_t phase_align_sel )

Enables or disables a specific SPWM clock divider.

This function issues the DIV_CMD sequence to enable or disable the selected clock divider. When enabling, both divider selection and phase-alignment selection are written before asserting ENABLE.

Parameters
idSPWM instance identifier.
clkdiv_idClock divider index.
enabletrue to enable, false to disable.
phase_align_selDivider ID to phase-align with when enabling.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_otrigclk_config()

spwm_status_en spwm_otrigclk_config ( spwm_instance_en id,
uint8_t clkdiv_id )

Selects the output-trigger clock divider for the SPWM block.

This function configures the OTRIGCLK clock source by selecting which clock divider output is routed to the SPWM trigger-clock domain.

Parameters
idSPWM instance identifier.
clkdiv_idClock divider index to route as the trigger clock.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_configure()

spwm_status_en spwm_configure ( spwm_instance_en id,
uint8_t group_id,
const spwm_config_t * config )

Applies unified configuration to the SPWM instance for a specific group.

This function programs all configuration parameters for the selected SPWM group, including mode, clock divider, compare values, period, trigger routing, and mode-specific settings.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
configPointer to populated spwm_config_t structure.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_trigger()

spwm_status_en spwm_trigger ( spwm_instance_en id,
uint8_t group_id,
spwm_trigger_en trig )

Issues a single trigger pulse to a specific SPWM group.

This function generates a one-shot pulse on the selected trigger signal (START, STOP, RELOAD, CAPTURE0, or CAPTURE1).

Parameters
idSPWM instance identifier.
group_idGroup index to send the trigger to.
trigTrigger type to issue (see spwm_trigger_en).
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_group_trigger()

spwm_status_en spwm_group_trigger ( spwm_instance_en id,
uint8_t group_trigger_id )

Generates a trigger pulse on the global SPWM group-trigger bus.

This function asserts a single trigger line in the global TR_CMD register to activate the selected group trigger.

Parameters
idSPWM instance identifier.
group_trigger_idIndex of the group trigger to assert.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_get_counter()

spwm_status_en spwm_get_counter ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the current counter register value of a group.

This function retrieves the current register value of the counter register for the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the counter value.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_get_cc0()

spwm_status_en spwm_get_cc0 ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the CC0 compare value of a group.

This function retrieves the active CC0 register value from the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the CC0 value.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_get_cc1()

spwm_status_en spwm_get_cc1 ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the CC1 compare value of a group.

This function retrieves the active CC1 register value from the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the CC1 value.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_get_period()

spwm_status_en spwm_get_period ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the base period of a group.

This function retrieves the active period register value from the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the period value.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_get_line_sel()

spwm_status_en spwm_get_line_sel ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the line selection register of a group.

This function retrieves the current line selection configuration for the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the line selection value.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_get_cc0_buff()

spwm_status_en spwm_get_cc0_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the CC0 buffered compare value of a group.

This function retrieves the buffered CC0 value from the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the buffered CC0 value.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_get_cc1_buff()

spwm_status_en spwm_get_cc1_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the CC1 buffered compare value of a group.

This function retrieves the buffered CC1 value from the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the buffered CC1 value.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_get_period_buff()

spwm_status_en spwm_get_period_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the buffered period of a group.

This function retrieves the period buffer value from the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the buffered period value.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_get_line_sel_buff()

spwm_status_en spwm_get_line_sel_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t * val )

Reads the buffered line selection of a group.

This function retrieves the line selection buffer value from the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
val[out] Pointer to store the buffered line selection value.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_set_clkdiv()

spwm_status_en spwm_set_clkdiv ( spwm_instance_en id,
uint8_t group_id,
uint8_t clkdiv_id )

Selects the clock divider used by an SPWM group.

This function updates the CLKDIV_SEL field in the group clock control register to specify which clock divider output drives the selected SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index whose clock divider is being selected.
clkdiv_idClock divider index to assign to the group.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_mode()

spwm_status_en spwm_set_mode ( spwm_instance_en id,
uint8_t group_id,
spwm_mode_en mode )

Sets the operating mode of an SPWM group.

This function programs the MODE field in the group control register to select the functional mode of operation, such as timer, capture, PWM, PWM with dead-time, or pseudo-random PWM mode.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
modeSPWM operating mode to be applied.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_count_mode()

spwm_status_en spwm_set_count_mode ( spwm_instance_en id,
uint8_t group_id,
spwm_count_mode_en count_mode )

Sets the counter direction or counting mode of an SPWM group.

This function programs the UP_DOWN_MODE field in the group control register to control how the counter operates, such as counting up, down, or up-down.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
count_modeCounter mode selection.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_counter()

spwm_status_en spwm_set_counter ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the counter value of a group.

This function writes a new value to the active counter of the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to write.
valCounter value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_one_shot()

spwm_status_en spwm_set_one_shot ( spwm_instance_en id,
uint8_t group_id,
bool one_shot )

Configures the one-shot mode of a SPWM group.

This function enables or disables one-shot operation for the specified SPWM group. In one-shot mode, the counter stops automatically after reaching the terminal count.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
one_shottrue to enable one-shot mode, false to disable.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_prescale()

spwm_status_en spwm_set_prescale ( spwm_instance_en id,
uint8_t group_id,
spwm_prescale_en prescale )

Sets the prescaler for a SPWM group.

This function configures the clock prescaler that divides the input clock to the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
prescalePrescaler value (see spwm_prescale_en).
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_deadtime()

spwm_status_en spwm_set_deadtime ( spwm_instance_en id,
uint8_t group_id,
uint32_t deadtime,
uint32_t compl_deadtime )

Configures dead-time for PWM outputs of a SPWM group.

This function sets the line and complementary line dead-time values, which are inserted between high-side and low-side switches to prevent shoot-through.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
deadtimeDead-time for the main output line (in clock cycles).
compl_deadtimeDead-time for the complementary output line (in clock cycles).
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_cc0()

spwm_status_en spwm_set_cc0 ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the CC0 compare value of a SPWM group.

This function writes a new value to the CC0 register of the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to write.
valCC0 compare value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_cc1()

spwm_status_en spwm_set_cc1 ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the CC1 compare value of a SPWM group.

This function writes a new value to the CC1 register of the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to write.
valCC1 compare value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_period()

spwm_status_en spwm_set_period ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the base period of a SPWM group.

This function updates the active period register of the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to write.
valPeriod value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_line_sel()

spwm_status_en spwm_set_line_sel ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the line selection of a SPWM group.

This function configures the output line mapping for the SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
valLine selection value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_cc0_buff()

spwm_status_en spwm_set_cc0_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the CC0 buffer compare value of a SPWM group.

This function writes a value to the CC0 buffer register of the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to write.
valCC0 buffer value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_set_cc1_buff()

spwm_status_en spwm_set_cc1_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the CC1 buffer compare value of a SPWM group.

This function writes a value to the CC1 buffer register of the specified SPWM group.

Parameters
idSPWM instance identifier.
group_idGroup index to write.
valCC1 buffer value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_set_period_buff()

spwm_status_en spwm_set_period_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the buffered period value of a SPWM group.

This function writes a value to the period buffer register of the specified SPWM group. When auto-reload is enabled, the buffered value will be loaded into the active period register on the configured trigger event.

Parameters
idSPWM instance identifier.
group_idGroup index to write.
valPeriod buffer value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_set_line_sel_buff()

spwm_status_en spwm_set_line_sel_buff ( spwm_instance_en id,
uint8_t group_id,
uint32_t val )

Sets the buffered line selection of a SPWM group.

This function writes a value to the line selection buffer register of the specified SPWM group. When auto-reload is enabled, the buffered value will be loaded into the active line selection register on the configured trigger event.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
valLine selection buffer value to set.
Returns
spwm_status_en Status code indicating success or the reason for failure.
Note
Buffered values do not take effect immediately. The buffered value is transferred to the active register only when the configured reload condition occurs.

◆ spwm_set_trig_in_all()

spwm_status_en spwm_set_trig_in_all ( spwm_instance_en id,
uint8_t group_id,
const spwm_trigger_in_cfg_t * cfg )

Configures all input trigger lines for the SPWM group in a batch operation.

This function configures all SPWM_TRIG_IN_COUNT trigger inputs (CAP0, COUNT, RELOAD, STOP, START, CAP1) for the specified group in a single call, providing a more efficient alternative to multiple individual spwm_set_trig_in calls.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
cfgPointer to array of SPWM_TRIG_IN_COUNT trigger configuration structures. The array must contain configurations for all trigger inputs in order: [0]=CAP0, [1]=COUNT, [2]=RELOAD, [3]=STOP, [4]=START, [5]=CAP1.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_trig_in()

spwm_status_en spwm_set_trig_in ( spwm_instance_en id,
uint8_t group_id,
spwm_trigger_en trigger,
const spwm_trigger_in_cfg_t * config )

Configures a single input trigger line for the SPWM group.

This function programs the source, edge detection mode, and inversion setting for a specified trigger input (CAP0, COUNT, RELOAD, STOP, START, or CAP1).

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
triggerInput trigger selection (see spwm_trigger_en).
configPointer to input trigger configuration structure containing source, edge detection, and inversion settings.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_trig_out()

spwm_status_en spwm_set_trig_out ( spwm_instance_en id,
uint8_t group_id,
int out_id,
spwm_trigger_out_en out )

Configures an output trigger event source for the SPWM group.

This function selects which internal counter event (overflow, underflow, terminal count, CC0/CC1 match, or line output) generates a pulse on the specified trigger output (TR_OUT0 or TR_OUT1).

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
out_idOutput trigger index (0 for TR_OUT0, 1 for TR_OUT1).
outOutput event selection (see spwm_trigger_out_en).
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_sema()

spwm_status_en spwm_set_sema ( spwm_instance_en id,
uint8_t group_id,
uint8_t sema_id,
uint8_t val )

Sets a semaphore value for a specified channel in the SPWM group.

This function writes to a semaphore register, which can be used for synchronization between SPWM groups or with descriptor chains. Semaphores are typically set by hardware events and polled or cleared by software or descriptor operations.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
sema_idSemaphore channel index (0 for SEMA0, 1 for SEMA1).
valValue to write to the semaphore register.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_set_sema_sel()

spwm_status_en spwm_set_sema_sel ( spwm_instance_en id,
uint8_t group_id,
int sema_id,
spwm_trigger_out_en out )

Selects the trigger-out source for a semaphore channel.

This function configures which internal counter event automatically sets the specified semaphore. This allows hardware events to signal descriptor chains or other SPWM groups without software intervention.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
sema_idSemaphore channel index (0 for SEMA0, 1 for SEMA1).
outOutput event selection that will set the semaphore (see spwm_trigger_out_en).
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_make_line_sel()

uint32_t spwm_make_line_sel ( spwm_line_src_en out,
spwm_line_src_en compl )

Creates a line selection value for SPWM output routing.

This utility function encodes the source selections for both normal and complementary PWM outputs into a single 32-bit value that can be written to the line selection register. Each output can be configured independently to drive low, high, PWM signal, inverted PWM, or high-impedance.

Parameters
outSource selection for the normal output (see spwm_line_src_en).
complSource selection for the complementary output (see spwm_line_src_en).
Returns
uint32_t Combined line selection value to be used with spwm_set_line_sel or spwm_set_line_sel_buff.

◆ spwm_get_interrupt_status()

spwm_status_en spwm_get_interrupt_status ( spwm_instance_en id,
uint8_t group_id,
uint32_t * irq_status )

Reads the interrupt status for the specified SPWM group.

This function retrieves the current state of all interrupt sources for the group, including terminal count, CC0 match, and CC1 match interrupts. The status reflects which interrupts have been latched regardless of whether they are enabled.

Parameters
idSPWM instance identifier.
group_idGroup index to read.
irq_status[out] Pointer to store the interrupt status bitmask.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_enable_interrupt()

spwm_status_en spwm_enable_interrupt ( spwm_instance_en id,
uint8_t group_id,
spwm_intr_en intr )

Enables a specific interrupt source for the SPWM group.

This function unmasks the specified interrupt type (terminal count, CC0 match, or CC1 match) for the given group, allowing it to trigger the group's interrupt handler when the corresponding event occurs.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
intrInterrupt type to enable (see spwm_intr_en).
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_disable_interrupt()

spwm_status_en spwm_disable_interrupt ( spwm_instance_en id,
uint8_t group_id,
spwm_intr_en intr )

Disables a specific interrupt source for the SPWM group.

This function masks the specified interrupt type (terminal count, CC0 match, or CC1 match) for the given group, preventing it from triggering the group's interrupt handler even if the corresponding event occurs.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
intrInterrupt type to disable (see spwm_intr_en).
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_disable_all_interrupts()

spwm_status_en spwm_disable_all_interrupts ( spwm_instance_en id,
uint8_t group_id )

Disables all interrupt sources for the specified SPWM group.

This function masks all interrupt types (terminal count, CC0 match, and CC1 match) for the given group, ensuring no interrupts from this group will be triggered.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_clear_all_interrupts()

spwm_status_en spwm_clear_all_interrupts ( spwm_instance_en id,
uint8_t group_id )

Clears all pending interrupts for the specified SPWM group.

This function clears the latched state of all interrupt sources (terminal count, CC0 match, and CC1 match) for the given group. This is typically called from the interrupt service routine to acknowledge handled interrupts.

Parameters
idSPWM instance identifier.
group_idGroup index to clear.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_output_select()

spwm_status_en spwm_output_select ( spwm_instance_en id,
uint8_t group_id,
spwm_io_pin_en pin,
bool compl )

Selects the output pin and polarity for the specified SPWM group.

This function configures which physical SPWM output pin is driven by the specified group and whether the normal or complementary output is used. This allows flexible routing of SPWM signals to different output pins.

Parameters
idSPWM instance identifier.
group_idGroup index to configure.
pinOutput pin to select (see spwm_io_pin_en).
compltrue to route the complementary output to the pin, false for normal output.
Returns
spwm_status_en Status code indicating success or the reason for failure.

◆ spwm_clear_interrupt()

spwm_status_en spwm_clear_interrupt ( spwm_instance_en id,
uint8_t group_id,
uint32_t mask )

Clears selected interrupt sources for a given SPWM group.

This function clears specific interrupt flags for the group based on the provided bitmask, allowing selective acknowledgment of interrupt sources.

Parameters
idSPWM instance identifier.
group_idSPWM group index.
maskBitmask specifying which interrupt sources to clear.
Returns
spwm_status_en Status code indicating success or failure.

◆ spwm_clear_desc_interrupt()

spwm_status_en spwm_clear_desc_interrupt ( spwm_instance_en id,
uint8_t desc_id )

Clears the descriptor interrupt for an SPWM instance.

This function clears the descriptor-related interrupt status for the specified descriptor instance, acknowledging completion or error conditions generated by the descriptor engine.

Parameters
idSPWM instance identifier.
desc_idDescriptor instance index.
Returns
spwm_status_en Status code indicating success or failure.

◆ spwm_enable_desc_interrupt()

spwm_status_en spwm_enable_desc_interrupt ( spwm_instance_en id,
uint8_t desc_id )

Enables interrupt for a specific descriptor instance.

This function unmasks the interrupt for the specified descriptor instance. Descriptor interrupt callbacks must be registered separately using spwm_register_desc_callback.

Parameters
idSPWM instance identifier.
desc_idDescriptor instance index to enable.
Returns
spwm_status_en Status code indicating success or failure.

◆ spwm_disable_desc_interrupt()

spwm_status_en spwm_disable_desc_interrupt ( spwm_instance_en id,
uint8_t desc_id )

Disables interrupt for a specific descriptor instance.

This function masks the interrupt for the specified descriptor instance, preventing it from triggering interrupt handlers even if descriptor events occur.

Parameters
idSPWM instance identifier.
desc_idDescriptor instance index to disable.
Returns
spwm_status_en Status code indicating success or failure.

◆ spwm_register_callback()

spwm_status_en spwm_register_callback ( spwm_instance_en id,
spwm_isr_cb_t cb,
void * user_ctx )

Registers an ISR callback for the SPWM instance.

This function registers a callback function that will be invoked from the SPWM ISR context when enabled interrupt sources are latched. The callback receives a bitmask indicating which interrupt sources fired.

Parameters
idSPWM instance identifier.
cbCallback function pointer (see spwm_isr_cb_t).
user_ctxOpaque pointer passed back to the callback function.
Returns
spwm_status_en Status code indicating success or failure.

◆ spwm_register_desc_callback()

spwm_status_en spwm_register_desc_callback ( spwm_instance_en id,
spwm_desc_isr_cb_t cb,
void * param )

Registers a descriptor ISR callback for the SPWM instance.

This function registers a callback function that will be invoked when any descriptor instance on the SPWM instance completes or encounters an error. The callback receives the descriptor instance ID that triggered the event.

Parameters
idSPWM instance identifier.
cbCallback function pointer (see spwm_desc_isr_cb_t).
paramUser-defined context pointer passed to the callback function.
Returns
spwm_status_en Status code indicating success or failure.

◆ spwm_dsc_mem_alloc()

spwm_dsc_status_en spwm_dsc_mem_alloc ( size_t size_bytes,
uint16_t * handle )

Allocates memory from the SPWM descriptor memory pool.

This function allocates a contiguous block of descriptor SRAM and returns a handle that can be used to reference the allocated memory. The handle can be converted to an offset for use with descriptor chain initialization.

Parameters
size_bytesNumber of bytes to allocate from the descriptor memory pool.
handle[out] Pointer to a variable where the allocated descriptor handle will be stored.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.

◆ spwm_dsc_mem_free()

void spwm_dsc_mem_free ( uint16_t handle)

Frees previously allocated SPWM descriptor memory.

This function releases descriptor SRAM identified by the provided handle, making it available for future allocations. The handle becomes invalid after this call.

Parameters
handleHandle of the allocated descriptor memory to be freed.
Returns
void

◆ spwm_dsc_chain_create()

spwm_dsc_chain_t * spwm_dsc_chain_create ( void )

Allocates and initializes a new SPWM descriptor chain object.

This function dynamically allocates a descriptor chain structure and initializes it to an empty state. The chain can then be populated with descriptors and executed on a descriptor instance.

Returns
spwm_dsc_chain_t* Pointer to the newly created descriptor chain, or NULL if allocation fails.

◆ spwm_dsc_chain_destroy()

void spwm_dsc_chain_destroy ( spwm_dsc_chain_t * chain)

Frees resources associated with a SPWM descriptor chain.

This function deallocates the descriptor chain structure and releases any associated resources. The chain pointer becomes invalid after this call.

Parameters
chainPointer to the descriptor chain to destroy.
Returns
void

◆ spwm_dsc_chain_init_for_handle()

spwm_dsc_status_en spwm_dsc_chain_init_for_handle ( spwm_instance_en id,
spwm_dsc_chain_t * chain,
uint16_t handle )

Initializes a descriptor chain using a memory handle.

This function associates a descriptor chain with descriptor SRAM previously allocated via spwm_dsc_mem_alloc. The handle is automatically converted to the appropriate offset within the descriptor memory space.

Parameters
idSPWM instance identifier.
chain[out] Pointer to a descriptor chain structure to initialize.
handleDescriptor memory handle obtained from spwm_dsc_mem_alloc.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.

◆ spwm_dsc_chain_init()

spwm_dsc_status_en spwm_dsc_chain_init ( spwm_instance_en id,
spwm_dsc_chain_t * chain,
uint32_t start_offset_bytes,
uint32_t block_size_bytes )

Initializes a descriptor chain at a specified offset in descriptor SRAM.

This function associates a descriptor chain with a given SPWM instance and initializes it to start at the specified byte offset within the descriptor SRAM. This allows manual control over descriptor memory placement.

Parameters
idSPWM instance identifier.
chain[out] Pointer to a descriptor chain structure to initialize.
start_offset_bytesByte offset from the descriptor SRAM base address where this chain begins. Must be within the descriptor SRAM window and aligned to a 4-byte boundary.
block_size_bytesSize of the descriptor memory block allocated for this chain, in bytes.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.

◆ spwm_dsc_chain_add_cfg()

spwm_dsc_status_en spwm_dsc_chain_add_cfg ( spwm_dsc_chain_t * chain,
uint8_t group_id,
spwm_dsc_reg_id_en reg_id,
const uint32_t * values,
uint32_t num_values,
bool last )

Appends a CFG descriptor to a descriptor chain.

A CFG descriptor performs a burst write of multiple 32-bit values to consecutive SPWM group registers starting at the specified register address. This enables efficient batch configuration of SPWM parameters.

Parameters
chain[in,out] Pointer to an initialized descriptor chain.
group_idSPWM group index whose registers will be written.
reg_idStarting register identifier for the burst write (see spwm_dsc_reg_id_en).
valuesPointer to an array of 32-bit values to be written. The first value is written to the starting register, and subsequent values to consecutive registers.
num_valuesNumber of 32-bit values in the array. Must be greater than zero and within the maximum supported by a single CFG descriptor.
lastIf true, marks this as the last descriptor in the chain (LC bit set), stopping execution. If false, execution continues with the next descriptor.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.

◆ spwm_dsc_chain_add_syn()

spwm_dsc_status_en spwm_dsc_chain_add_syn ( spwm_dsc_chain_t * chain,
spwm_dsc_syn_op_en opcode,
uint8_t group,
uint32_t counter_mask,
bool last )

Appends a SYN descriptor to a descriptor chain.

A SYN descriptor synchronizes descriptor execution with SPWM counter semaphores. It can wait for semaphores to be set, set semaphores, or clear semaphores, enabling coordination between descriptor chains and hardware events.

Parameters
chain[in,out] Pointer to an initialized descriptor chain.
opcodeSynchronization operation to perform (see spwm_dsc_syn_op_en):
  • SPWM_DSC_SYN_WAIT_ALL: Wait until all selected semaphores are set
  • SPWM_DSC_SYN_WAIT_ANY: Wait until any selected semaphore is set
  • SPWM_DSC_SYN_SET: Set all selected semaphores
  • SPWM_DSC_SYN_CLEAR: Wait for all selected semaphores, then clear them
groupSemaphore group index (typically 0 or 1) selecting which semaphore per counter is targeted.
counter_maskBitmask selecting which counters participate in the operation. Bit n corresponds to counter index n within the chosen group. Must be non-zero.
lastIf true, marks this as the last descriptor in the chain (LC bit set), stopping execution. If false, execution continues with the next descriptor.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.

◆ spwm_dsc_chain_add_nxt()

spwm_dsc_status_en spwm_dsc_chain_add_nxt ( spwm_dsc_chain_t * chain,
uint32_t target_offset_bytes )

Appends a NXT descriptor to a descriptor chain.

A NXT descriptor performs an unconditional jump to another descriptor offset in descriptor SRAM, enabling loops and multi-stage execution flows within a chain.

Parameters
chainPointer to an initialized descriptor chain.
target_offset_bytesTarget descriptor offset in bytes from the descriptor SRAM base address. Must be 4-byte aligned and within the descriptor SRAM range.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.

◆ spwm_dsc_chain_start()

spwm_dsc_status_en spwm_dsc_chain_start ( spwm_instance_en id,
const spwm_dsc_chain_t * chain,
uint8_t desc_id,
bool enable_interrupt )

Starts execution of a descriptor chain on a descriptor instance.

Programs the descriptor instance with the chain start offset and issues a start command. Optionally enables instance-level interrupts.

Parameters
idSPWM instance identifier.
chainPointer to the descriptor chain to execute.
desc_idDescriptor instance index on which to run the chain.
enable_interruptEnables or disables descriptor instance interrupts.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.

◆ spwm_dsc_chain_get_status()

spwm_dsc_status_en spwm_dsc_chain_get_status ( spwm_instance_en id,
const spwm_dsc_chain_t * chain,
uint8_t instance,
spwm_dsc_chain_status_t * status )

Retrieves the execution status of a descriptor instance.

Reads hardware execution and interrupt state and reports decoded status information for the specified descriptor instance.

Parameters
idSPWM instance identifier.
chainPointer to the descriptor chain associated with the instance.
instanceDescriptor instance index to query.
statusPointer to a structure receiving the execution status.
Returns
spwm_dsc_status_en Status code indicating success or the reason for failure.