Choco OS  V.0.16.9.0
Join to the chocolate world
(TIMER-LLD) Timers Low Level Driver

Managing timers operations. More...

The driver is for managing timers of the machine. Timers are divided for channels that can work independently of the others. The channel variable is stored in the #oC_TIMER_LLD_Channel_t type, that is generated using definitions from the Machine module. General rule of timer work is that it automatically increment or decrement special counter with the frequency that is selected during configuration. It is counting to the configured value, and then it starts from the beginning. There are some predefined interrupts, that can occurs, when the timer value achieve some specified value, or when some other event occur. Moreover most of timers are equipped with additional special functionality, like generation PWM signal, counting edges from an input pin, or measuring time between 2 edges of input pin. This module is for supporting most popular features, that timers modules are equipped. It includes:
  • periodic interrupts
  • time measurement
  • input edge counting
  • input edge time measurement
  • PWM signal generation

Example of PWM configuration:

oC_ErrorCode_t errorCode = oC_ErrorCode_None;
if ( oC_AssignErrorCode(&errorCode , oC_TIMER_LLD_TurnOnDriver()) )
{
oC_TIMER_LLD_PeripheralPin_t RedPwmPin;
oC_TIMER_LLD_Channel_t RedPwmChannel;
oC_TIMER_LLD_SubTimer_t RedPwmSubTimer;
if(
oC_AssignErrorCode(&errorCode , oC_TIMER_LLD_ReadPeripheralPinsOfPin( RedPin , &RedPwmPin , &RedArraySize)) &&
oC_AssignErrorCode(&errorCode , oC_TIMER_LLD_ReadSubTimerOfPeripheralPin(RedPwmPin, &RedPwmSubTimer))
)
{
RedPwmChannel = oC_TIMER_LLD_GetChannelOfPeripheralPin(RedPwmPin);
if(
oC_AssignErrorCodeIfFalse(&errorCode ,!oC_TIMER_LLD_IsChannelUsed(RedPwmChannel,RedPwmSubTimer) , oC_ErrorCode_ChannelIsUsed ) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_SetChannelUsed(RedPwmChannel , RedPwmSubTimer )) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_SetPower(RedPwmChannel , oC_Power_On)) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_TimerStop(RedPwmChannel , RedPwmSubTimer)) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_ChangeMode(RedPwmChannel , RedPwmSubTimer, oC_TIMER_LLD_Mode_PWM )) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_ChangeFrequency(RedPwmChannel , RedPwmSubTimer, oC_MHz(80) , oC_MHz(10))) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_ChangeMaximumValue(RedPwmChannel , RedPwmSubTimer, 255)) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_ChangeMatchValue(RedPwmChannel , RedPwmSubTimer, 0)) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_ConnectPeripheralPin(RedPwmPin) ) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_ChangeStartPwmState(RedPwmChannel, RedPwmSubTimer , oC_TIMER_LLD_PwmState_Low)) &&
oC_AssignErrorCode( &errorCode , oC_TIMER_LLD_TimerStart(RedPwmChannel , RedPwmSubTimer))
)
{
errorCode = oC_ErrorCode_None;
}
}
}