libyggdrasil  v1.0.0
timer.h File Reference

Timer abstraction implementation for Midgard. More...

#include <c/common/types.h>
#include <stm32f7xx_hal.h>
Include dependency graph for timer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tim_t
 Timer handle type. More...
 
struct  tim_channel_t
 Timer channel handle type. More...
 

Enumerations

enum  EncoderDirection { EncoderDirection_Clockwise, EncoderDirection_CounterClockwise }
 Last known turning direction of the encoder. More...
 
enum  EncoderMode { EncoderMode_48StepsPerTurn, EncoderMode_96StepsPerTurn }
 Modes for the encoder, 48 odr 96 steps per turn are possible. More...
 

Functions

C_LINKAGE bool yggdrasil_TIM_Init (tim_t tim)
 Timer initialization. More...
 
C_LINKAGE bool yggdrasil_TIM_Deinit (tim_t tim)
 Timer deinitialization. More...
 
C_LINKAGE void yggdrasil_TIM_Enable (tim_t tim)
 Timer enable. More...
 
C_LINKAGE void yggdrasil_TIM_Disable (tim_t tim)
 Timer disable. More...
 
C_LINKAGE u32 yggdrasil_TIM_GetCount (tim_t tim)
 Get the counter value. More...
 
C_LINKAGE void yggdrasil_TIM_SetCount (tim_t tim, u32 cnt)
 Set the counter value. More...
 
C_LINKAGE void yggdrasil_TIM_ResetCount (tim_t tim)
 Reset the counter value. More...
 
C_LINKAGE u32 yggdrasil_TIM_GetPwmFrequency (tim_t tim)
 Get the pwm frequency. More...
 
C_LINKAGE bool yggdrasil_TIM_SetPwmFrequency (tim_t tim, u32 f_hz, u32 resolution)
 Set the pwm frequency and (optional) the maximal ticks within on cycle for all channels. More...
 
C_LINKAGE bool yggdrasil_TIM_Channel_StartPwm (tim_channel_t channel)
 Start PWM generation for the channel. More...
 
C_LINKAGE bool yggdrasil_TIM_Channel_StopPwm (tim_channel_t channel)
 Stop PWM generation for the channel. More...
 
C_LINKAGE bool yggdrasil_TIM_Channel_SetPolarityHigh (tim_channel_t channel, bool highActive)
 Start set pwm polarity. More...
 
C_LINKAGE bool yggdrasil_TIM_Channel_SetDutyCycle (tim_channel_t channel, float dutyCycle)
 Set the duty cycle as a float value. More...
 
C_LINKAGE void yggdrasil_ProfileCounter_Start (tim_t tim)
 Start the counter. More...
 
C_LINKAGE void yggdrasil_ProfileCounter_Stop (tim_t tim)
 Stop the counter. More...
 
C_LINKAGE void yggdrasil_ProfileCounter_Reset (tim_t tim)
 Reset the counter to 0. More...
 
C_LINKAGE u64 yggdrasil_ProfileCounter_GetTimeToOverflow (tim_t tim)
 Get the time to an overflow. More...
 
C_LINKAGE void yggdrasil_ProfileCounter_GetFormattedTimeToOverflow (tim_t tim, char *buffer, size_t size)
 Get the time to an overflow formatted as a string. More...
 
C_LINKAGE u64 yggdrasil_ProfileCounter_GetPassedTime (tim_t tim)
 Get the time passed time since the start. More...
 
C_LINKAGE void yggdrasil_ProfileCounter_GetFormattedPassedTime (tim_t tim, char *buffer, size_t size)
 Get the time passed time since the start. More...
 
C_LINKAGE bool yggdrasil_Encoder_Init (tim_t tim)
 Initialization function for the encoder. More...
 
C_LINKAGE bool yggdrasil_Encoder_Enable (tim_t tim)
 Enable the encoder mode. More...
 
C_LINKAGE bool yggdrasil_Encoder_Disable (tim_t tim)
 Disable the encoder mode. More...
 
C_LINKAGE u32 yggdrasil_Encoder_GetCount (tim_t tim)
 Get the counter value. More...
 
C_LINKAGE void yggdrasil_Encoder_SetCount (tim_t tim, u32 cnt)
 Set the encoder counter value. More...
 
C_LINKAGE enum EncoderDirection yggdrasil_Encoder_GetDirection (tim_t tim)
 Get the direction of the last rotation. More...
 
C_LINKAGE void yggdrasil_Encoder_SetMode (tim_t tim, enum EncoderMode mode)
 Set the mode of the encoder (48 or 96 counts per turn) More...
 

Detailed Description

Timer abstraction implementation for Midgard.

Author
Fabian Weber, Nikolaij Saegesser

Enumeration Type Documentation

◆ EncoderDirection

Last known turning direction of the encoder.

Enumerator
EncoderDirection_Clockwise 
EncoderDirection_CounterClockwise 

◆ EncoderMode

Modes for the encoder, 48 odr 96 steps per turn are possible.

Enumerator
EncoderMode_48StepsPerTurn 
EncoderMode_96StepsPerTurn 

Function Documentation

◆ yggdrasil_Encoder_Disable()

C_LINKAGE bool yggdrasil_Encoder_Disable ( tim_t  tim)

Disable the encoder mode.

Note
This does only work for timer with a encoder modul
Parameters
timTimer handle
Returns
Success

◆ yggdrasil_Encoder_Enable()

C_LINKAGE bool yggdrasil_Encoder_Enable ( tim_t  tim)

Enable the encoder mode.

Note
This does only work for timer with a encoder modul
Parameters
timTimer handle
Returns
Success

◆ yggdrasil_Encoder_GetCount()

C_LINKAGE u32 yggdrasil_Encoder_GetCount ( tim_t  tim)

Get the counter value.

Note
This does only work for timer with a encoder modul
Parameters
timTimer handle
Returns
Actual timer count

◆ yggdrasil_Encoder_GetDirection()

C_LINKAGE enum EncoderDirection yggdrasil_Encoder_GetDirection ( tim_t  tim)

Get the direction of the last rotation.

Note
This bit might not be accurate while turning the encoder
Parameters
timTimer handle
Returns
Direction

◆ yggdrasil_Encoder_Init()

C_LINKAGE bool yggdrasil_Encoder_Init ( tim_t  tim)

Initialization function for the encoder.

Note
Default encoder mode is 96 steps per turn
Parameters
timTimer handle
Returns
Success

◆ yggdrasil_Encoder_SetCount()

C_LINKAGE void yggdrasil_Encoder_SetCount ( tim_t  tim,
u32  cnt 
)

Set the encoder counter value.

Parameters
timTimer handle
cntNew counter value

◆ yggdrasil_Encoder_SetMode()

C_LINKAGE void yggdrasil_Encoder_SetMode ( tim_t  tim,
enum EncoderMode  mode 
)

Set the mode of the encoder (48 or 96 counts per turn)

Parameters
timTimer handle
modeMode selection

◆ yggdrasil_ProfileCounter_GetFormattedPassedTime()

C_LINKAGE void yggdrasil_ProfileCounter_GetFormattedPassedTime ( tim_t  tim,
char *  buffer,
size_t  size 
)

Get the time passed time since the start.

Parameters
timTimer handle
bufferString buffer
sizeBuffer size
Returns
Passed time formatted as a string

◆ yggdrasil_ProfileCounter_GetFormattedTimeToOverflow()

C_LINKAGE void yggdrasil_ProfileCounter_GetFormattedTimeToOverflow ( tim_t  tim,
char *  buffer,
size_t  size 
)

Get the time to an overflow formatted as a string.

Parameters
timTimer handle
bufferString buffer
sizeBuffer size
Returns
Time to an overflow formatted as a string

◆ yggdrasil_ProfileCounter_GetPassedTime()

C_LINKAGE u64 yggdrasil_ProfileCounter_GetPassedTime ( tim_t  tim)

Get the time passed time since the start.

Parameters
timTimer handle
Returns
Passed time in a u64

◆ yggdrasil_ProfileCounter_GetTimeToOverflow()

C_LINKAGE u64 yggdrasil_ProfileCounter_GetTimeToOverflow ( tim_t  tim)

Get the time to an overflow.

Parameters
timTimer handle
Returns
Time to an overflow in a u64

◆ yggdrasil_ProfileCounter_Reset()

C_LINKAGE void yggdrasil_ProfileCounter_Reset ( tim_t  tim)

Reset the counter to 0.

Parameters
timTimer handle

◆ yggdrasil_ProfileCounter_Start()

C_LINKAGE void yggdrasil_ProfileCounter_Start ( tim_t  tim)

Start the counter.

Parameters
timTimer handle

◆ yggdrasil_ProfileCounter_Stop()

C_LINKAGE void yggdrasil_ProfileCounter_Stop ( tim_t  tim)

Stop the counter.

Parameters
timTimer handle

◆ yggdrasil_TIM_Channel_SetDutyCycle()

C_LINKAGE bool yggdrasil_TIM_Channel_SetDutyCycle ( tim_channel_t  channel,
float  dutyCycle 
)

Set the duty cycle as a float value.

Parameters
channelTimer channel handle
dutyCycleDuty cycle in % [0 100]
Returns
Success

◆ yggdrasil_TIM_Channel_SetPolarityHigh()

C_LINKAGE bool yggdrasil_TIM_Channel_SetPolarityHigh ( tim_channel_t  channel,
bool  highActive 
)

Start set pwm polarity.

Parameters
channelTimer channel handle
highActiveSet channel to high active when true
Returns
Success

◆ yggdrasil_TIM_Channel_StartPwm()

C_LINKAGE bool yggdrasil_TIM_Channel_StartPwm ( tim_channel_t  channel)

Start PWM generation for the channel.

Note
A duty cycle should be set with setDuty()
Parameters
channelTimer channel handle
Returns
Success

◆ yggdrasil_TIM_Channel_StopPwm()

C_LINKAGE bool yggdrasil_TIM_Channel_StopPwm ( tim_channel_t  channel)

Stop PWM generation for the channel.

Note
This function disables the counter when no PWM channel is active
Parameters
channelTimer channel handle
Returns
Success

◆ yggdrasil_TIM_Deinit()

C_LINKAGE bool yggdrasil_TIM_Deinit ( tim_t  tim)

Timer deinitialization.

Parameters
timTimer handle
Returns
Success

◆ yggdrasil_TIM_Disable()

C_LINKAGE void yggdrasil_TIM_Disable ( tim_t  tim)

Timer disable.

Parameters
timTimer handle

◆ yggdrasil_TIM_Enable()

C_LINKAGE void yggdrasil_TIM_Enable ( tim_t  tim)

Timer enable.

Parameters
timTimer handle

◆ yggdrasil_TIM_GetCount()

C_LINKAGE u32 yggdrasil_TIM_GetCount ( tim_t  tim)

Get the counter value.

Parameters
timTimer handle
Returns
Actual timer count

◆ yggdrasil_TIM_GetPwmFrequency()

C_LINKAGE u32 yggdrasil_TIM_GetPwmFrequency ( tim_t  tim)

Get the pwm frequency.

Note
The frequency is for all channels the same
Parameters
timTimer handle
Returns
Frequency in Hz

◆ yggdrasil_TIM_Init()

C_LINKAGE bool yggdrasil_TIM_Init ( tim_t  tim)

Timer initialization.

Parameters
timTimer handle
Returns
Success

◆ yggdrasil_TIM_ResetCount()

C_LINKAGE void yggdrasil_TIM_ResetCount ( tim_t  tim)

Reset the counter value.

Parameters
timTimer handle

◆ yggdrasil_TIM_SetCount()

C_LINKAGE void yggdrasil_TIM_SetCount ( tim_t  tim,
u32  cnt 
)

Set the counter value.

Parameters
timTimer handle
cntNew timer value

◆ yggdrasil_TIM_SetPwmFrequency()

C_LINKAGE bool yggdrasil_TIM_SetPwmFrequency ( tim_t  tim,
u32  f_hz,
u32  resolution 
)

Set the pwm frequency and (optional) the maximal ticks within on cycle for all channels.

Note
The actual duty cycle for all channels will be restored after the changes
Implement a proper error handling, the function does not guarantee to be successful
Parameters
timTimer handle
f_hznew frequency in hz
resolutionof the pwm, for 0 the actual value will be used
Returns
True when the adjustment was possible, false when the parameter did not match