InES Hardware Abstraction Layer
Data Structures | Enumerations | Functions
hal_timer.h File Reference

Interface of module hal_timer. More...

#include "reg_stm32f4xx.h"
#include "hal_common.h"

Go to the source code of this file.

Data Structures

struct  hal_timer_base_init_t
 Initialization structure for basic timer functionality. More...
 
struct  hal_timer_filter_init_t
 Initialization structure for input filter. More...
 
struct  hal_timer_clock_init_t
 Initialization structure for basic timer functionality. More...
 
struct  hal_timer_input_init_t
 
struct  hal_timer_output_init_t
 Initialization structure for output functionality. More...
 

Enumerations

enum  hal_timer_channel_t {
  HAL_TIMER_CH1 = 0u, HAL_TIMER_CH2 = 1u, HAL_TIMER_CH3 = 2u, HAL_TIMER_CH4 = 3u,
  HAL_TIMER_CH1N = 16u, HAL_TIMER_CH2N = 17u, HAL_TIMER_CH3N = 18u
}
 Defines the capture / compare channel of a timer. More...
 
enum  hal_timer_mode_t {
  HAL_TIMER_MODE_UP = 0x0, HAL_TIMER_MODE_DOWN = 0x1, HAL_TIMER_MODE_CENTER1 = 0x2, HAL_TIMER_MODE_CENTER2 = 0x4,
  HAL_TIMER_MODE_CENTER3 = 0x6
}
 Defines counting mode of timer. More...
 
enum  hal_timer_run_t { HAL_TIMER_RUN_CONTINOUS = 0x0, HAL_TIMER_RUN_ONCE = 0x1 }
 Defines run mode of timer. More...
 
enum  hal_timer_irq_t {
  HAL_TIMER_IRQ_UE = 0x01, HAL_TIMER_IRQ_CC1 = 0x02, HAL_TIMER_IRQ_CC2 = 0x04, HAL_TIMER_IRQ_CC3 = 0x08,
  HAL_TIMER_IRQ_CC4 = 0x10, HAL_TIMER_IRQ_TRIGGER = 0x40
}
 Defines the different interrupts used by the timer. More...
 
enum  hal_timer_dmasrc_t {
  HAL_TIMER_DMA_UDE = 0x0100, HAL_TIMER_DMA_CC1 = 0x0200, HAL_TIMER_DMA_CC2 = 0x0400, HAL_TIMER_DMA_CC3 = 0x0800,
  HAL_TIMER_DMA_CC4 = 0x1000, HAL_TIMER_DMA_TRG = 0x4000
}
 
enum  hal_timer_mastermode_t {
  HAL_TIMER_MASTER_RESET = 0u, HAL_TIMER_MASTER_ENABLE = 1u, HAL_TIMER_MASTER_UPDATE = 2u, HAL_TIMER_MASTER_COMPARE = 3u,
  HAL_TIMER_MASTER_COMPOC1 = 4u, HAL_TIMER_MASTER_COMPOC2 = 5u, HAL_TIMER_MASTER_COMPOC3 = 6u, HAL_TIMER_MASTER_COMPOC4 = 7u
}
 
enum  hal_timer_polarity_t { HAL_TIMER_POLARITY_HIGH = 0x0, HAL_TIMER_POLARITY_LOW = 0x1, HAL_TIMER_POLARITY_BOTH = 0x5 }
 Defines polarity. More...
 
enum  hal_timer_psc_t { HAL_TIMER_PSC_OFF = 0x0, HAL_TIMER_PSC_DIV2 = 0x1, HAL_TIMER_PSC_DIV4 = 0x2, HAL_TIMER_PSC_DIV8 = 0x3 }
 Defines the filter prescaler. More...
 
enum  hal_timer_filter_t {
  HAL_TIMER_FILTER_OFF = 0u, HAL_TIMER_FILTER_INT_N2 = 1u, HAL_TIMER_FILTER_INT_N4 = 2u, HAL_TIMER_FILTER_INT_N8 = 3u,
  HAL_TIMER_FILTER_DTS2_N6 = 4u, HAL_TIMER_FILTER_DTS2_N8 = 5u, HAL_TIMER_FILTER_DTS4_N6 = 6u, HAL_TIMER_FILTER_DTS4_N8 = 7u,
  HAL_TIMER_FILTER_DTS8_N6 = 8u, HAL_TIMER_FILTER_DTS8_N8 = 9u, HAL_TIMER_FILTER_DTS16_N5 = 10u, HAL_TIMER_FILTER_DTS16_N6 = 11u,
  HAL_TIMER_FILTER_DTS16_N8 = 12u, HAL_TIMER_FILTER_DTS32_N5 = 13u, HAL_TIMER_FILTER_DTS32_N6 = 14u, HAL_TIMER_FILTER_DTS32_N8 = 15u
}
 
enum  hal_timer_oc_mode_t {
  HAL_TIMER_OCMODE_NONE = 0x0, HAL_TIMER_OCMODE_ACTIVE = 0x1, HAL_TIMER_OCMODE_INACTIVE = 0x2, HAL_TIMER_OCMODE_TOGGLE = 0x3,
  HAL_TIMER_OCMODE_PWM1 = 0x6, HAL_TIMER_OCMODE_PWM2 = 0x7
}
 Defines mode of the output capture unit. More...
 
enum  hal_timer_ic_sel_t { HAL_TIMER_IC_SEL_DIRECT = 0x1, HAL_TIMER_IC_SEL_INDIRECT = 0x2, HAL_TIMER_IC_SEL_TRC = 0x3 }
 Defines the route for trigger input. More...
 
enum  hal_timer_source_t { HAL_TIMER_CLKSRC_INT, HAL_TIMER_CLKSRC_ETRF, HAL_TIMER_CLKSRC_TRGI }
 Defines the source for the counter source. More...
 
enum  hal_timer_clk_dts_t { HAL_TIMER_CLK_OFF = 0x00, HAL_TIMER_CLK_DIV2 = 0x01, HAL_TIMER_CLK_DIV4 = 0x02 }
 Divider used for generating sampling clock for digital filters. More...
 
enum  hal_timer_trgsrc_t {
  HAL_TIMER_TRGSRC_ITR0 = 0u, HAL_TIMER_TRGSRC_ITR1 = 1u, HAL_TIMER_TRGSRC_ITR2 = 2u, HAL_TIMER_TRGSRC_ITR3 = 3u,
  HAL_TIMER_TRGSRC_TI1F_ED = 4u, HAL_TIMER_TRGSRC_TI1FP = 5u, HAL_TIMER_TRGSRC_TI2FP = 6u, HAL_TIMER_TRGSRC_ETRF = 7u
}
 Defines the source for TRG. More...
 
enum  hal_timer_slavemode_t {
  HAL_TIMER_SLAVE_OFF = 0u, HAL_TIMER_SLAVE_ENC1 = 1u, HAL_TIMER_SLAVE_ENC2 = 2u, HAL_TIMER_SLAVE_ENC3 = 3u,
  HAL_TIMER_SLAVE_RESET = 4u, HAL_TIMER_SLAVE_GATED = 5u, HAL_TIMER_SLAVE_TRIGGER = 6u, HAL_TIMER_SLAVE_EXT = 7u
}
 

Functions

void hal_timer_reset (reg_tim_t *timer) __attribute__((deprecated("Please use ATIMx_RESET().")))
 Resets the specified timer to its default values. More...
 
void hal_timer_init_base (reg_tim_t *timer, hal_timer_base_init_t init)
 Initializes the basic timer according to the specified parameters. More...
 
void hal_timer_init_clock (reg_tim_t *timer, hal_timer_clock_init_t init)
 Initializes the clock source to be used by timer. More...
 
void hal_timer_init_input (reg_tim_t *timer, hal_timer_channel_t channel, hal_timer_input_init_t init)
 Configures the specified channel and timer input capture mode. More...
 
void hal_timer_init_output (reg_tim_t *timer, hal_timer_channel_t channel, hal_timer_output_init_t init)
 Configures the specified channel and timer output compare mode. More...
 
void hal_timer_start (reg_tim_t *timer)
 Start specified timer. More...
 
void hal_timer_stop (reg_tim_t *timer)
 Stops specified timer. More...
 
void hal_timer_channel_set (reg_tim_t *timer, hal_timer_channel_t channel, hal_bool_t status)
 Enables channel on specified timer. More...
 
void hal_timer_irq_set (reg_tim_t *timer, hal_timer_irq_t irq, hal_bool_t status)
 Enables interrupt on specified timer. More...
 
hal_bool_t hal_timer_irq_status (reg_tim_t *timer, hal_timer_irq_t irq)
 Return status of specified timers interrupt. More...
 
void hal_timer_irq_clear (reg_tim_t *timer, hal_timer_irq_t irq)
 Clear specified timers interrupt. More...
 
void hal_timer_dma_set (reg_tim_t *timer, hal_timer_dmasrc_t dma, hal_bool_t status)
 Enable DMA for specific timer. More...
 
uint32_t hal_timer_counter_read (reg_tim_t *timer)
 Return value of specified timers counter register. More...
 
void hal_timer_reload_write (reg_tim_t *timer, uint32_t value)
 Set reload value of specified timer. More...
 
void hal_timer_prescaler_write (reg_tim_t *timer, uint32_t value)
 Set prescaler value of specified timer. More...
 
uint32_t hal_timer_compare_read (reg_tim_t *timer, hal_timer_channel_t channel)
 Return compare register value of specified timer and channel. More...
 
int8_t hal_timer_compare_write (reg_tim_t *timer, hal_timer_channel_t channel, uint32_t value)
 Set value of compare register of specified timer and channel. More...
 

Detailed Description

Interface of module hal_timer.

Example of programming a basic timer:

Additional pwm channel:

Additional output compare (oc) mode:

Additional Input capture (ic) mode:

Only for external capture trigger

$Id$

Enumeration Type Documentation

◆ hal_timer_channel_t

Defines the capture / compare channel of a timer.

Enumerator
HAL_TIMER_CH1 

Capture/compare channel 1.

HAL_TIMER_CH2 

Capture/compare channel 2.

HAL_TIMER_CH3 

Capture/compare channel 3.

HAL_TIMER_CH4 

Capture/compare channel 4.

HAL_TIMER_CH1N 

Capture/compare channel 1N.

HAL_TIMER_CH2N 

Capture/compare channel 2N.

HAL_TIMER_CH3N 

Capture/compare channel 3N.

◆ hal_timer_clk_dts_t

Divider used for generating sampling clock for digital filters.

Enumerator
HAL_TIMER_CLK_OFF 

No divider.

HAL_TIMER_CLK_DIV2 

CK_INT / 2.

HAL_TIMER_CLK_DIV4 

CK_INT / 4.

◆ hal_timer_dmasrc_t

Enumerator
HAL_TIMER_DMA_UDE 

Update request.

HAL_TIMER_DMA_CC1 

Capture/compare channel 1.

HAL_TIMER_DMA_CC2 

Capture/compare channel 2.

HAL_TIMER_DMA_CC3 

Capture/compare channel 3.

HAL_TIMER_DMA_CC4 

Capture/compare channel 4.

HAL_TIMER_DMA_TRG 

Trigger request.

◆ hal_timer_ic_sel_t

Defines the route for trigger input.

Enumerator
HAL_TIMER_IC_SEL_DIRECT 

Straight: 1->IC1

HAL_TIMER_IC_SEL_INDIRECT 

Crossed: 1->IC2

HAL_TIMER_IC_SEL_TRC 

All pins to TRC.

◆ hal_timer_irq_t

Defines the different interrupts used by the timer.

Enumerator
HAL_TIMER_IRQ_UE 

Timer update event.

HAL_TIMER_IRQ_CC1 

Capture/compare channel 1.

HAL_TIMER_IRQ_CC2 

Capture/compare channel 2.

HAL_TIMER_IRQ_CC3 

Capture/compare channel 3.

HAL_TIMER_IRQ_CC4 

Capture/compare channel 4.

HAL_TIMER_IRQ_TRIGGER 

Trigger event.

◆ hal_timer_mastermode_t

Enumerator
HAL_TIMER_MASTER_RESET 

UG bit (in EGR) triggers TRGO.

HAL_TIMER_MASTER_ENABLE 

EN bit (in CR1) triggers TRGO.

HAL_TIMER_MASTER_UPDATE 

Update event triggers TRGO.

HAL_TIMER_MASTER_COMPARE 

Pulse on TRGO when CC1F is set.

HAL_TIMER_MASTER_COMPOC1 

OC1REF used as TRGO.

HAL_TIMER_MASTER_COMPOC2 

OC2REF used as TRGO.

HAL_TIMER_MASTER_COMPOC3 

OC3REF used as TRGO.

HAL_TIMER_MASTER_COMPOC4 

OC4REF used as TRGO.

◆ hal_timer_mode_t

Defines counting mode of timer.

Enumerator
HAL_TIMER_MODE_UP 

CR1: CMS[6..5] = 00, DIR[4] = 0.

HAL_TIMER_MODE_DOWN 

CR1: CMS[6..5] = 00, DIR[4] = 1.

HAL_TIMER_MODE_CENTER1 

CR1: CMS[6..5] = 01.

HAL_TIMER_MODE_CENTER2 

CR1: CMS[6..5] = 10.

HAL_TIMER_MODE_CENTER3 

CR1: CMS[6..5] = 11.

◆ hal_timer_oc_mode_t

Defines mode of the output capture unit.

Enumerator
HAL_TIMER_OCMODE_NONE 

Not configured.

HAL_TIMER_OCMODE_ACTIVE 

Active if CNT = CCRx.

HAL_TIMER_OCMODE_INACTIVE 

Inctive if CNT = CCRx.

HAL_TIMER_OCMODE_TOGGLE 

Toggle if CNT = CCRx.

HAL_TIMER_OCMODE_PWM1 

PWM 1, active if CNT < CCRx.

HAL_TIMER_OCMODE_PWM2 

PWM 2, active if CNT > CCRx.

◆ hal_timer_polarity_t

Defines polarity.

Enumerator
HAL_TIMER_POLARITY_HIGH 

Positive polarity, active-high.

HAL_TIMER_POLARITY_LOW 

Negative polarity, active-low.

HAL_TIMER_POLARITY_BOTH 

Trigger on both edges.

◆ hal_timer_psc_t

Defines the filter prescaler.

Enumerator
HAL_TIMER_PSC_OFF 

Prescaler off.

HAL_TIMER_PSC_DIV2 

Divided by 2.

HAL_TIMER_PSC_DIV4 

Divided by 4.

HAL_TIMER_PSC_DIV8 

Divided by 8.

◆ hal_timer_run_t

Defines run mode of timer.

Enumerator
HAL_TIMER_RUN_CONTINOUS 

Restart timer after update event.

HAL_TIMER_RUN_ONCE 

Stop timer after update event.

◆ hal_timer_slavemode_t

Enumerator
HAL_TIMER_SLAVE_OFF 

Slave mode disabled.

HAL_TIMER_SLAVE_ENC1 

Counts on edge of TI2FP1.

HAL_TIMER_SLAVE_ENC2 

Counts on edge of TI1FP2.

HAL_TIMER_SLAVE_ENC3 

Counts on edge of TIxFPx.

HAL_TIMER_SLAVE_RESET 

Clock reset if TRGI high.

HAL_TIMER_SLAVE_GATED 

Clock enabled, if TRGI high.

HAL_TIMER_SLAVE_TRIGGER 

Start clock if TRGI high.

HAL_TIMER_SLAVE_EXT 

Clock enabled, if TRGI high.

◆ hal_timer_source_t

Defines the source for the counter source.

Enumerator
HAL_TIMER_CLKSRC_INT 

Internal clock source (TCLK).

HAL_TIMER_CLKSRC_ETRF 

External clock source (ETRF).

HAL_TIMER_CLKSRC_TRGI 

Trigger clock source (TRGI).

◆ hal_timer_trgsrc_t

Defines the source for TRG.

Enumerator
HAL_TIMER_TRGSRC_ITR0 

Internal trigger 0.

HAL_TIMER_TRGSRC_ITR1 

Internal trigger 1.

HAL_TIMER_TRGSRC_ITR2 

Internal trigger 2.

HAL_TIMER_TRGSRC_ITR3 

Internal trigger 3.

HAL_TIMER_TRGSRC_TI1F_ED 

TI1 edge detector.

HAL_TIMER_TRGSRC_TI1FP 

Filtered timer input 1.

HAL_TIMER_TRGSRC_TI2FP 

Filtered timer input 2.

HAL_TIMER_TRGSRC_ETRF 

External trigger input.

Function Documentation

◆ hal_timer_channel_set()

void hal_timer_channel_set ( reg_tim_t timer,
hal_timer_channel_t  channel,
hal_bool_t  status 
)

Enables channel on specified timer.

Parameters
timer: Defines timer to interact with.
channel: Specifies channel.
status: ENABLE/DISABLE specified channel.

◆ hal_timer_compare_read()

uint32_t hal_timer_compare_read ( reg_tim_t timer,
hal_timer_channel_t  channel 
)

Return compare register value of specified timer and channel.

Parameters
timer: Defines timer to interact with.
channel: Defines capture / compare channel to read.
Returns
Actual value of the capture / compare channel.

◆ hal_timer_compare_write()

int8_t hal_timer_compare_write ( reg_tim_t timer,
hal_timer_channel_t  channel,
uint32_t  value 
)

Set value of compare register of specified timer and channel.

Parameters
timer: Defines timer to interact with.
channel: Defines capture / compare channel to write.
value: New value of the capture / compare channel.
Returns
(-1) if array index out of bounds, else 0

◆ hal_timer_counter_read()

uint32_t hal_timer_counter_read ( reg_tim_t timer)

Return value of specified timers counter register.

Parameters
timer: Defines timer to interact with.
Returns
Actual value of the CNT register.

◆ hal_timer_dma_set()

void hal_timer_dma_set ( reg_tim_t timer,
hal_timer_dmasrc_t  dma,
hal_bool_t  status 
)

Enable DMA for specific timer.

Parameters
timer: Defines timer to interact with.
dma: Trigger source for DMA.
status: ENABLE/DISABLE specified DMA source.

◆ hal_timer_init_base()

void hal_timer_init_base ( reg_tim_t timer,
hal_timer_base_init_t  init 
)

Initializes the basic timer according to the specified parameters.

Parameters
timer: Defines timer to interact with.
init: Basic initialisation structure for timer.

◆ hal_timer_init_clock()

void hal_timer_init_clock ( reg_tim_t timer,
hal_timer_clock_init_t  init 
)

Initializes the clock source to be used by timer.

Parameters
timer: Defines timer to interact with.
init: Initialisation structure for clock source.

◆ hal_timer_init_input()

void hal_timer_init_input ( reg_tim_t timer,
hal_timer_channel_t  channel,
hal_timer_input_init_t  init 
)

Configures the specified channel and timer input capture mode.

Parameters
timer: Defines timer to interact with.
channel: Defines capture / compare channel to initialize.
init: Initialisation structure for ic channel.

◆ hal_timer_init_output()

void hal_timer_init_output ( reg_tim_t timer,
hal_timer_channel_t  channel,
hal_timer_output_init_t  init 
)

Configures the specified channel and timer output compare mode.

Parameters
timer: Defines timer to interact with.
channel: Defines capture / compare channel to initialize.
init: Initialisation structure for oc channel.

◆ hal_timer_irq_clear()

void hal_timer_irq_clear ( reg_tim_t timer,
hal_timer_irq_t  irq 
)

Clear specified timers interrupt.

Parameters
timer: Defines timer to interact with.
irq: Interrupt to clear.

◆ hal_timer_irq_set()

void hal_timer_irq_set ( reg_tim_t timer,
hal_timer_irq_t  irq,
hal_bool_t  status 
)

Enables interrupt on specified timer.

Parameters
timer: Defines timer to interact with.
irq: Specifies interrupt.
status: ENABLE/DISABLE specified interrupt.

◆ hal_timer_irq_status()

hal_bool_t hal_timer_irq_status ( reg_tim_t timer,
hal_timer_irq_t  irq 
)

Return status of specified timers interrupt.

Parameters
timer: Defines timer to interact with.
irq: Interrupt to read.
Returns
Actual status of specified interrupt.

◆ hal_timer_prescaler_write()

void hal_timer_prescaler_write ( reg_tim_t timer,
uint32_t  value 
)

Set prescaler value of specified timer.

Parameters
timer: Defines timer to interact with.
value: New prescaler value for the timer.

◆ hal_timer_reload_write()

void hal_timer_reload_write ( reg_tim_t timer,
uint32_t  value 
)

Set reload value of specified timer.

Parameters
timer: Defines timer to interact with.
value: New reload value for the timer.

◆ hal_timer_reset()

void hal_timer_reset ( reg_tim_t timer)

Resets the specified timer to its default values.

Parameters
timer: Defines timer to reset.

◆ hal_timer_start()

void hal_timer_start ( reg_tim_t timer)

Start specified timer.

Parameters
timer: Defines timer to start.

◆ hal_timer_stop()

void hal_timer_stop ( reg_tim_t timer)

Stops specified timer.

Parameters
timer: Defines timer to stop.