FD32M0P Microcontroller SDK
Loading...
Searching...
No Matches
timer.h File Reference
#include "TIMER_REGS.h"
#include "TIMER_RW_API.h"
#include <stdbool.h>
Include dependency graph for timer.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  timer_clk_cfg_t
 Clock configuration. More...
struct  timer_ctr_cfg_t
struct  timer_input_chan_cfg_t
struct  timer_output_chan_cfg_t
struct  timer_pwm_output_channel_action_cfg_t
struct  timer_capture_channel_ctrl_t
struct  timer_pwm_cfg_t

Macros

#define TIMER_CLK_CFG_DEFAULT
#define TIMER_CTR_CFG_DEFAULT
#define TIMER_INPUT_CHAN_CFG_DEFAULT
#define TIMER_OUTPUT_CHAN_CFG_DEFAULT
#define TIMER_PWM_OUTPUT_CHANNEL_ACTION_CFG_DEFAULT
#define TIMER_CAPTURE_CHANNEL_CTRL_CFG_DEFAULT
#define TIMER_PWM_CFG_DEFAULT

Functions

void timer_set_clk_cfg (TIMER_REGS_s *TIMER_REGS, timer_clk_cfg_t *clk_cfg)
 This function sets the clock configuration.
void timer_clk_enable (TIMER_REGS_s *TIMER_REGS)
 This function enables the timer clock.
void timer_clk_disable (TIMER_REGS_s *TIMER_REGS)
 This function disables the timer clock.
void timer_set_load_val (TIMER_REGS_s *TIMER_REGS, uint16_t load_val)
 This function sets the LOAD value of the timer counter.
void timer_set_counter_val (TIMER_REGS_s *TIMER_REGS, uint16_t ctr_val)
 This function sets the counter value of the timer counter.
void timer_set_counter_ctrl (TIMER_REGS_s *TIMER_REGS, timer_ctr_cfg_t *ctr_cfg)
 This function sets the configuration of the timer counter.
void timer_set_repeat_counter_val (TIMER_REGS_s *TIMER_REGS, uint16_t rctr_val)
 This function sets the REPEAT COUNTER value of the timer.
void timer_start (TIMER_REGS_s *TIMER_REGS)
 This function starts the timer counter.
void timer_stop (TIMER_REGS_s *TIMER_REGS)
 This function stops the timer counter.
void timer_set_input_channel_cfg (TIMER_REGS_s *TIMER_REGS, timer_input_chan_cfg_t *in_chan_cfg, uint8_t chan_num)
 This function sets the input channel configuration of the desired timer channel.
void timer_set_output_channel_cfg (TIMER_REGS_s *TIMER_REGS, timer_output_chan_cfg_t *out_chan_cfg, uint8_t chan_num)
 This function sets the output channel configuration of the desired timer channel.
void timer_set_init_cfg (TIMER_REGS_s *TIMER_REGS, timer_clk_cfg_t *clk_cfg, timer_ctr_cfg_t *ctr_cfg)
 This function sets the initial timer configuration. It generates periodic interrupts.
void timer_delay_in_us (TIMER_REGS_s *TIMER_REGS, uint16_t delay_in_us)
 This function generates an interrupt after a ceratin time period mentioned in us.
void timer_delay_in_ms (TIMER_REGS_s *TIMER_REGS, uint16_t delay_in_ms)
 This function generates an interrupt after a ceratin time period mentioned in ms.
void timer_set_compare_val (TIMER_REGS_s *TIMER_REGS, uint8_t comp_val, uint8_t chan_num)
void timer_set_pwm_cfg (TIMER_REGS_s *TIMER_REGS, timer_clk_cfg_t *clk_cfg, timer_pwm_cfg_t *pwm_cfg)
void timer_set_pwm_output_channel_action_cfg (TIMER_REGS_s *TIMER_REGS, timer_pwm_output_channel_action_cfg_t *pwm_act_cfg, uint8_t chan_num)
void timer_set_capture_channel_ctrl (TIMER_REGS_s *TIMER_REGS, timer_capture_channel_ctrl_t *cap_chan_ctrl, uint8_t chan_num)

Data Structure Documentation

◆ timer_clk_cfg_t

struct timer_clk_cfg_t

Clock configuration.

Data Fields
TIMER_CLK_CONFIG_CLK_SEL_E clk_sel
uint16_t clk_div

◆ timer_ctr_cfg_t

struct timer_ctr_cfg_t
Data Fields
TIMER_CTR_CTL_COUNT_MODE_E ctr_mode
bool repeat
TIMER_CTR_CTL_CTR_ZERO_CTRL_E ctr_zero_cond
TIMER_CTR_CTL_CTR_LOAD_CTRL_E ctr_load_cond
TIMER_CTR_CTL_CTR_ADV_CTRL_E ctr_adv_cond

◆ timer_input_chan_cfg_t

struct timer_input_chan_cfg_t
Data Fields
TIMER_INPUT_CC_0_INPUT_SEL_0_E in_sel
bool in_inv
bool in_filter_en
TIMER_INPUT_FILTER_CC_0_FILTER_PERIOD_0_E in_filter_prd

◆ timer_output_chan_cfg_t

struct timer_output_chan_cfg_t
Data Fields
TIMER_CC0_OUTPUT_CTL_CC_OUT_SEL_0_E out_sel
bool out_inv
bool out_init_val

◆ timer_pwm_output_channel_action_cfg_t

◆ timer_capture_channel_ctrl_t

◆ timer_pwm_cfg_t

struct timer_pwm_cfg_t
Data Fields
timer_ctr_cfg_t ctr_cfg
uint16_t pwm_period
uint8_t chan_num
uint16_t pwm_high_period
timer_output_chan_cfg_t out_chan_cfg
timer_capture_channel_ctrl_t cap_chan_ctrl

Macro Definition Documentation

◆ TIMER_CLK_CFG_DEFAULT

#define TIMER_CLK_CFG_DEFAULT
Value:
{ \
.clk_div = 0 \
}
@ TIMER_CLK_CONFIG_CLK_SEL_CLK_BUS
0x2
Definition TIMER_REGS.h:1612

Referenced by timer_delay_in_ms(), and timer_delay_in_us().

◆ TIMER_CTR_CFG_DEFAULT

#define TIMER_CTR_CFG_DEFAULT
Value:
{ \
.repeat = 1 ,\
}
@ TIMER_CTR_CTL_CTR_ADV_CTRL_CHANNEL_0_ADV_COND
0x0
Definition TIMER_REGS.h:2637
@ TIMER_CTR_CTL_CTR_ZERO_CTRL_CHANNEL_0_ZERO_COND
0x0
Definition TIMER_REGS.h:2613
@ TIMER_CTR_CTL_COUNT_MODE_UP
0x0
Definition TIMER_REGS.h:2603
@ TIMER_CTR_CTL_CTR_LOAD_CTRL_CHANNEL_0_LOAD_COND
0x0
Definition TIMER_REGS.h:2625

Referenced by timer_delay_in_ms(), and timer_delay_in_us().

◆ TIMER_INPUT_CHAN_CFG_DEFAULT

#define TIMER_INPUT_CHAN_CFG_DEFAULT
Value:
{ \
.in_inv = 0 ,\
.in_filter_en = 1 ,\
}
@ TIMER_INPUT_CC_0_INPUT_SEL_0_CCPIN_X
0x0
Definition TIMER_REGS.h:1686
@ TIMER_INPUT_FILTER_CC_0_FILTER_PERIOD_0_WIDTH_3
0x0
Definition TIMER_REGS.h:1650

◆ TIMER_OUTPUT_CHAN_CFG_DEFAULT

#define TIMER_OUTPUT_CHAN_CFG_DEFAULT
Value:
{ \
.out_inv = 0 ,\
.out_init_val = 0 \
}
@ TIMER_CC0_OUTPUT_CTL_CC_OUT_SEL_0_PWM_OUTPUT
0x0
Definition TIMER_REGS.h:2452

◆ TIMER_PWM_OUTPUT_CHANNEL_ACTION_CFG_DEFAULT

#define TIMER_PWM_OUTPUT_CHANNEL_ACTION_CFG_DEFAULT
Value:
{ \
}
@ TIMER_CC0_CC_PWM_CFG_CC_OUT_ZERO_0_DISABLE
0x5
Definition TIMER_REGS.h:2174
@ TIMER_CC0_CC_PWM_CFG_CC_OUT_CC2D_0_DISABLE
0x0
Definition TIMER_REGS.h:2124
@ TIMER_CC0_CC_PWM_CFG_CC_OUT_CC2U_0_DISABLE
0x1
Definition TIMER_REGS.h:2134
@ TIMER_CC0_CC_PWM_CFG_CC_OUT_LOAD_0_DISABLE
0x4
Definition TIMER_REGS.h:2164
@ TIMER_CC0_CC_PWM_CFG_CC_OUT_CCU_0_DISABLE
0x3
Definition TIMER_REGS.h:2154
@ TIMER_CC0_CC_PWM_CFG_CC_OUT_CCD_0_DISABLE
0x2
Definition TIMER_REGS.h:2144

Referenced by timer_set_pwm_cfg().

◆ TIMER_CAPTURE_CHANNEL_CTRL_CFG_DEFAULT

#define TIMER_CAPTURE_CHANNEL_CTRL_CFG_DEFAULT
Value:
{ \
}
@ TIMER_CC0_CAPTURE_CTRL_ADV_COND_0_EACH_CLK
0x0
Definition TIMER_REGS.h:1796
@ TIMER_CC0_CAPTURE_CTRL_CAP_COND_0_DISABLE
0x0
Definition TIMER_REGS.h:1766
@ TIMER_CC0_CAPTURE_CTRL_LOAD_COND_0_DISABLE
0x0
Definition TIMER_REGS.h:1776
@ TIMER_CC0_CAPTURE_CTRL_ZERO_COND_0_DISABLE
0x0
Definition TIMER_REGS.h:1786

◆ TIMER_PWM_CFG_DEFAULT

#define TIMER_PWM_CFG_DEFAULT
Value:
{ \
.ctr_cfg = TIMER_CTR_CFG_DEFAULT ,\
.pwm_period = 100 ,\
.chan_num = 0x0 ,\
.pwm_high_period = 40 ,\
.out_chan_cfg = TIMER_OUTPUT_CHAN_CFG_DEFAULT ,\
}
#define TIMER_OUTPUT_CHAN_CFG_DEFAULT
Definition timer.h:62
#define TIMER_CAPTURE_CHANNEL_CTRL_CFG_DEFAULT
Definition timer.h:93
#define TIMER_CTR_CFG_DEFAULT
Definition timer.h:32

Function Documentation

◆ timer_set_clk_cfg()

void timer_set_clk_cfg ( TIMER_REGS_s * TIMER_REGS,
timer_clk_cfg_t * clk_cfg )

This function sets the clock configuration.

Parameters
TIMER_REGS: pointer to the timer register space
clk_cfg: pointer to the struct containing the clock configurations
Return values
void

timer_set_clk_cfg

References TIMER_REGS_s::CLK_CONFIG, timer_clk_cfg_t::clk_div, and timer_clk_cfg_t::clk_sel.

Referenced by timer_delay_in_ms(), timer_delay_in_us(), timer_set_init_cfg(), and timer_set_pwm_cfg().

Here is the caller graph for this function:

◆ timer_clk_enable()

void timer_clk_enable ( TIMER_REGS_s * TIMER_REGS)

This function enables the timer clock.

Parameters
TIMER_REGS: pointer to the timer register space
Return values
void

timer_clk_enable

References TIMER_REGS_s::CLK_CTRL.

Referenced by timer_delay_in_ms(), timer_delay_in_us(), and timer_set_init_cfg().

Here is the caller graph for this function:

◆ timer_clk_disable()

void timer_clk_disable ( TIMER_REGS_s * TIMER_REGS)

This function disables the timer clock.

Parameters
TIMER_REGS: pointer to the timer register space
Return values
void

timer_clk_disable

References TIMER_REGS_s::CLK_CTRL.

Referenced by timer_delay_in_ms().

Here is the caller graph for this function:

◆ timer_set_load_val()

void timer_set_load_val ( TIMER_REGS_s * TIMER_REGS,
uint16_t load_val )

This function sets the LOAD value of the timer counter.

Parameters
TIMER_REGS: pointer to the timer register space
load_val: LOAD value for the counter
Return values
void

timer_set_load_val

References TIMER_REGS_s::CTR_LOAD_VAL.

Referenced by timer_delay_in_ms(), timer_delay_in_us(), timer_set_init_cfg(), and timer_set_pwm_cfg().

Here is the caller graph for this function:

◆ timer_set_counter_val()

void timer_set_counter_val ( TIMER_REGS_s * TIMER_REGS,
uint16_t ctr_val )

This function sets the counter value of the timer counter.

Parameters
TIMER_REGS: pointer to the timer register space
ctr_val: counter value for the counter

Note: Setting the counter value directly while the timer's counter is running can lead to unpredictable behavior. This function should only be used when the timer's counter isn't running.

Return values
void

timer_set_counter_val

References TIMER_REGS_s::CTR_VAL.

◆ timer_set_counter_ctrl()

void timer_set_counter_ctrl ( TIMER_REGS_s * TIMER_REGS,
timer_ctr_cfg_t * ctr_cfg )

This function sets the configuration of the timer counter.

Parameters
TIMER_REGS: pointer to the timer register space
ctr_cfg: pointer to the structure containing the timer counter configuration
Return values
void

timer_set_counter_ctrl

References timer_ctr_cfg_t::ctr_adv_cond, TIMER_REGS_s::CTR_CTL, timer_ctr_cfg_t::ctr_load_cond, timer_ctr_cfg_t::ctr_mode, timer_ctr_cfg_t::ctr_zero_cond, and timer_ctr_cfg_t::repeat.

Referenced by timer_delay_in_ms(), timer_delay_in_us(), timer_set_init_cfg(), and timer_set_pwm_cfg().

Here is the caller graph for this function:

◆ timer_set_repeat_counter_val()

void timer_set_repeat_counter_val ( TIMER_REGS_s * TIMER_REGS,
uint16_t rctr_val )

This function sets the REPEAT COUNTER value of the timer.

Parameters
TIMER_REGS: pointer to the timer register space
rctr_val: repeat counter value for the timer
Return values
void

timer_set_repeat_counter_val

References TIMER_REGS_s::RCTR_VAL.

◆ timer_start()

void timer_start ( TIMER_REGS_s * TIMER_REGS)

This function starts the timer counter.

Parameters
TIMER_REGS: pointer to the timer register space
Return values
void

timer_start

References TIMER_REGS_s::CTR_CTL.

Referenced by timer_delay_in_ms(), timer_delay_in_us(), and timer_set_init_cfg().

Here is the caller graph for this function:

◆ timer_stop()

void timer_stop ( TIMER_REGS_s * TIMER_REGS)

This function stops the timer counter.

Parameters
TIMER_REGS: pointer to the timer register space
Return values
void

timer_stop

References TIMER_REGS_s::CTR_CTL.

◆ timer_set_input_channel_cfg()

void timer_set_input_channel_cfg ( TIMER_REGS_s * TIMER_REGS,
timer_input_chan_cfg_t * in_chan_cfg,
uint8_t chan_num )

This function sets the input channel configuration of the desired timer channel.

Parameters
TIMER_REGS: pointer to the timer register space
in_chan_cfg: pointer to the structure containing the input channel configuration
chan_num: input channel number
Return values
void

timer_set_input_channel_cfg

References timer_input_chan_cfg_t::in_filter_en, timer_input_chan_cfg_t::in_filter_prd, timer_input_chan_cfg_t::in_inv, timer_input_chan_cfg_t::in_sel, TIMER_REGS_s::INPUT_CC_0, TIMER_REGS_s::INPUT_CC_1, TIMER_REGS_s::INPUT_CC_2, TIMER_REGS_s::INPUT_CC_3, TIMER_REGS_s::INPUT_FILTER_CC_0, TIMER_REGS_s::INPUT_FILTER_CC_1, TIMER_REGS_s::INPUT_FILTER_CC_2, and TIMER_REGS_s::INPUT_FILTER_CC_3.

◆ timer_set_output_channel_cfg()

void timer_set_output_channel_cfg ( TIMER_REGS_s * TIMER_REGS,
timer_output_chan_cfg_t * out_chan_cfg,
uint8_t chan_num )

This function sets the output channel configuration of the desired timer channel.

Parameters
TIMER_REGS: pointer to the timer register space
in_chan_cfg: pointer to the structure containing the output channel configuration
chan_num: output channel number
Return values
void

timer_set_output_channel_cfg

References TIMER_REGS_s::CC0_OUTPUT_CTL, TIMER_REGS_s::CC1_OUTPUT_CTL, TIMER_REGS_s::CC2_OUTPUT_CTL, TIMER_REGS_s::CC3_OUTPUT_CTL, timer_output_chan_cfg_t::out_init_val, timer_output_chan_cfg_t::out_inv, and timer_output_chan_cfg_t::out_sel.

Referenced by timer_set_pwm_cfg().

Here is the caller graph for this function:

◆ timer_set_init_cfg()

void timer_set_init_cfg ( TIMER_REGS_s * TIMER_REGS,
timer_clk_cfg_t * clk_cfg,
timer_ctr_cfg_t * ctr_cfg )

This function sets the initial timer configuration. It generates periodic interrupts.

Parameters
TIMER_REGS: pointer to the timer register space
clk_cfg: pointer to the struct containing the clock configurations
ctr_cfg: pointer to the structure containing the timer counter configuration
Return values
void

timer_set_init_cfg generates periodic interrupts

References timer_clk_enable(), timer_set_clk_cfg(), timer_set_counter_ctrl(), timer_set_load_val(), and timer_start().

Here is the call graph for this function:

◆ timer_delay_in_us()

void timer_delay_in_us ( TIMER_REGS_s * TIMER_REGS,
uint16_t delay_in_us )

This function generates an interrupt after a ceratin time period mentioned in us.

Parameters
TIMER_REGS: pointer to the timer register space
delay_in_us: time period in us after which interrupt should be generated
Return values
void

timer_delay_in_us generates an interrupt after a certain time period mentioned in us

References timer_ctr_cfg_t::repeat, TIMER_CLK_CFG_DEFAULT, timer_clk_enable(), TIMER_CTR_CFG_DEFAULT, timer_set_clk_cfg(), timer_set_counter_ctrl(), timer_set_load_val(), and timer_start().

Here is the call graph for this function:

◆ timer_delay_in_ms()

void timer_delay_in_ms ( TIMER_REGS_s * TIMER_REGS,
uint16_t delay_in_ms )

This function generates an interrupt after a ceratin time period mentioned in ms.

Parameters
TIMER_REGS: pointer to the timer register space
delay_in_ms: time period in ms after which interrupt should be generated
Return values
void

timer_delay_in_ms generates an interrupt after a certain time period mentioned in ms

References timer_clk_cfg_t::clk_div, timer_ctr_cfg_t::repeat, TIMER_CLK_CFG_DEFAULT, timer_clk_disable(), timer_clk_enable(), TIMER_CTR_CFG_DEFAULT, timer_set_clk_cfg(), timer_set_compare_val(), timer_set_counter_ctrl(), timer_set_load_val(), and timer_start().

Here is the call graph for this function:

◆ timer_set_compare_val()

void timer_set_compare_val ( TIMER_REGS_s * TIMER_REGS,
uint8_t comp_val,
uint8_t chan_num )

timer_set_compare_val Sets the compare value for a particular channel

References TIMER_REGS_s::CC0_COMPARE_CTRL, TIMER_REGS_s::CC1_COMPARE_CTRL, TIMER_REGS_s::CC2_COMPARE_CTRL, and TIMER_REGS_s::CC3_COMPARE_CTRL.

Referenced by timer_delay_in_ms(), and timer_set_pwm_cfg().

Here is the caller graph for this function:

◆ timer_set_pwm_cfg()

◆ timer_set_pwm_output_channel_action_cfg()

◆ timer_set_capture_channel_ctrl()

void timer_set_capture_channel_ctrl ( TIMER_REGS_s * TIMER_REGS,
timer_capture_channel_ctrl_t * cap_chan_ctrl,
uint8_t chan_num )