TIMER: Methods

TIMER

TIMER
Methods
DAVE_APP_VERSION_t TIMER_GetAppVersion (void)
 Get TIMER APP version.
TIMER_STATUS_t TIMER_Init (TIMER_t *const handle_ptr)
 Initializes a TIMER with generated configuration.
TIMER_STATUS_t TIMER_Start (TIMER_t *const handle_ptr)
 Starts the timer if the initialization of the APP is successful.
TIMER_STATUS_t TIMER_Stop (TIMER_t *const handle_ptr)
 Stops the TIMER, if it is running.
uint32_t TIMER_GetTime (TIMER_t *const handle_ptr)
 Returns the current time in micro seconds by scaling with 100.
TIMER_STATUS_t TIMER_Clear (TIMER_t *const handle_ptr)
 Clears the timer register.
bool TIMER_GetTimerStatus (TIMER_t *const handle_ptr)
 Returns the running state of the timer.
TIMER_STATUS_t TIMER_SetTimeInterval (TIMER_t *const handle_ptr, uint32_t time_interval)
 Set the new time interval for the event generation, by checking with the supported range.
bool TIMER_GetInterruptStatus (TIMER_t *const handle_ptr)
 Indicates the occurrence of time interval event.
void TIMER_ClearEvent (TIMER_t *const handle_ptr)
 Clears the period match interrupt status of the given timer.

Methods


Function Documentation

TIMER_STATUS_t TIMER_Clear ( TIMER_t *const  handle_ptr)

Clears the timer register.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
TIMER_STATUS_t
TIMER_STATUS_SUCCESS : if clear is successful
TIMER_STATUS_FAILURE : if timer is not initialized and clear is requested

Description:
TIMER_Clear() clears the timer register so that next cycle starts from reset value.

Example Usage:

 #include <DAVE.h>
 int main(void)
 {
  DAVE_STATUS_t init_status;
  TIMER_STATUS_t timer_status;
  init_status = DAVE_Init();    // TIMER_Init(&TIMER_0) will be called from DAVE_Init()

  if(init_status == DAVE_STATUS_SUCCESS)
  {
    timer_status = TIMER_Start(&TIMER_0);
  }

  if (TIMER_GetTimerStatus(&TIMER_0))
  {
    timer_status = TIMER_Stop(&TIMER_0);
  }

  timer_status = TIMER_Clear(&TIMER_0);

  while(1)
  {
  }
  return 1;
 }


Definition at line 415 of file TIMER.c.

References TIMER::timer_module, TIMER_MODULE_CCU4, TIMER_MODULE_CCU8, TIMER_STATUS_FAILURE, and TIMER_STATUS_SUCCESS.

void TIMER_ClearEvent ( TIMER_t *const  handle_ptr)

Clears the period match interrupt status of the given timer.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
None
Description:
For each occurrence of the time interval event, it has to be cleared through software only. So next event is considered as new.


Example Usage:

 #include <DAVE.h>
 int main(void)
 {
   DAVE_STATUS_t status;

   status = DAVE_Init();                // Initialization of DAVE APPs

   while(1U)
   {
   }
   return 1;
 }

 void Timetick_Handler(void)
 {
  TIMER_ClearEvent(&TIMER_0);
 }


Definition at line 350 of file TIMER.c.

References TIMER::timer_module, TIMER_MODULE_CCU4, and TIMER_MODULE_CCU8.

DAVE_APP_VERSION_t TIMER_GetAppVersion ( void  )

Get TIMER APP version.

Returns:
DAVE_APP_VERSION_t APP version information (major, minor and patch number)
Description:
The function can be used to check application software compatibility with a specific version of the APP.

Example Usage:

 #include <DAVE.h>
 int main(void)
 {
   DAVE_STATUS_t status;
   DAVE_APP_VERSION_t app_version;

   status = DAVE_Init();        // TIMER_Init() is called from DAVE_Init()

   app_version = TIMER_GetAppVersion();

   if (app_version.major != 4U)
   {
     // Probably, not the right version.
   }

   while(1U)
   {
   }
   return 1;
 }


Definition at line 97 of file TIMER.c.

bool TIMER_GetInterruptStatus ( TIMER_t *const  handle_ptr)

Indicates the occurrence of time interval event.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
bool
true : if event set
false : if event is not set
Description:
The status returned, can be utilized to generate the delay function.

Example Usage:

 #include <DAVE.h>
 #define TIMER_DELAY_MUL_FACTOR 100000U // Converts micro seconds to milli seconds with multiplication factor for
                                        // TIMER_GetInterruptStatus().
 void TIMER_Delay(uint32_t);
 int main(void)
 {
  DAVE_STATUS_t init_status;
  TIMER_STATUS_t status;
  uint32_t delay_val; // delay value in terms milli seconds

  init_status = DAVE_Init();    // TIMER_Init(&TIMER_0) will be called from DAVE_Init()

  TIMER_ClearEvent(&TIMER_0);

  if(init_status == DAVE_STATUS_SUCCESS)
  {
    delay_val = 1000; // 1000 milli seconds

    TIMER_Delay(delay_val);
  }

  while(1)
  {

  }
  return 1;
 }

 void TIMER_Delay(uint32_t delay_val)
 {
   uint32_t delay_cnt;

   delay_cnt = delay_val * TIMER_DELAY_MUL_FACTOR;

   TIMER_SetTimeInterval(&TIMER_0,delay_cnt);

   TIMER_Start(&TIMER_0);

   while(!TIMER_GetInterruptStatus(&TIMER_0));

   TIMER_Stop(&TIMER_0);
 }


Definition at line 324 of file TIMER.c.

References TIMER::timer_module, TIMER_MODULE_CCU4, and TIMER_MODULE_CCU8.

uint32_t TIMER_GetTime ( TIMER_t *const  handle_ptr)

Returns the current time in micro seconds by scaling with 100.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
uint32_t
time in microseconds
Description:
By using prescaler and frequency and timer register value, this API calculates the current time in micro seconds. Then the value is scaled with 100, before returning.

Example Usage:

 #include <DAVE.h>
 int main(void)
 {
  DAVE_STATUS_t init_status;
  TIMER_STATUS_t timer_status;
  uint32_t elapsed_time;
  init_status = DAVE_Init();    // TIMER_Init(&TIMER_0) will be called from DAVE_Init()

  if(init_status == DAVE_STATUS_SUCCESS)
  {
    timer_status = TIMER_Start(&TIMER_0);
  }

   timer_status = TIMER_Stop(&TIMER_0);

   elapsed_time = TIMER_GetTime(&TIMER_0);

  while(1)
  {
  }
  return 1;
 }


Definition at line 374 of file TIMER.c.

References TIMER::timer_module, TIMER_MODULE_CCU4, and TIMER_MODULE_CCU8.

bool TIMER_GetTimerStatus ( TIMER_t *const  handle_ptr)

Returns the running state of the timer.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
bool
true : if the timer is running
false : if the timer is not running

Description:
TIMER_GetTimerStatus() reads the run bit of the timer to indicate the actual state of the TIMER.

Example Usage:

 #include <DAVE.h>
 int main(void)
 {
  DAVE_STATUS_t init_status;
  TIMER_STATUS_t timer_status;
  init_status = DAVE_Init();    // TIMER_Init(&TIMER_0) will be called from DAVE_Init()

  if(init_status == DAVE_STATUS_SUCCESS)
  {
    timer_status = TIMER_Start(&TIMER_0);
  }

  if (TIMER_GetTimerStatus(&TIMER_0))
  {
    while(TIMER_GetTimerStatus(&TIMER_0));

    timer_status = TIMER_Stop(&TIMER_0);
  }
  while(1)
  {
  }
  return 1;
 }


Definition at line 219 of file TIMER.c.

References TIMER::timer_module, TIMER_MODULE_CCU4, and TIMER_MODULE_CCU8.

Referenced by TIMER_SetTimeInterval(), and TIMER_Stop().

TIMER_STATUS_t TIMER_Init ( TIMER_t *const  handle_ptr)

Initializes a TIMER with generated configuration.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
TIMER_STATUS_t
TIMER_STATUS_SUCCESS : if initialization is successful
TIMER_STATUS_FAILURE : if initialization is failed

Description:
  • Enable the clock for the slice and invoke the LLD API with generated configuration handle.
  • Load the Period, Compare and Prescaler shadow registers with the generated values and enable the shadow transfer request. This loads the values into the actual registers and start the TIMER based on the configuration.
  • If "Start after initialization" is not enabled, TIMER_Start() can be invoked to start the timer.

Example Usage:

 #include <DAVE.h>
 int main(void)
 {
  DAVE_STATUS_t init_status;
  init_status = DAVE_Init();    // TIMER_Init(&TIMER_0) will be called from DAVE_Init()

  while(1)
  {
  }
  return 1;
 }


Definition at line 112 of file TIMER.c.

References TIMER::timer_module, TIMER_MODULE_CCU4, TIMER_MODULE_CCU8, and TIMER_STATUS_SUCCESS.

TIMER_STATUS_t TIMER_SetTimeInterval ( TIMER_t *const  handle_ptr,
uint32_t  time_interval 
)

Set the new time interval for the event generation, by checking with the supported range.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
time_intervalnew time interval value in micro seconds.
Returns:
TIMER_STATUS_t
TIMER_STATUS_SUCCESS : Setting new time interval value is successful
TIMER_STATUS_FAILURE : New time value is not in range of supported time value
Timer is in running condition
Description:
Based on the timer interval, prescaler value is calculated for the CCU timer. By using this prescaler and time interval values Period value is calculated. The period value is updated into the shadow register and shadow transfer request is enabled. Timer has to be stopped before updating the time interval.

Note:
Input time interval value has to be scaled by 100 to the actual required value.
e.g. : required timer interval value = 30.45 micro seconds
Input value to the API = 30.45 * 100 = 3045

Example Usage:

 #include <DAVE.h>
 #include <xmc_gpio.h>                   // GPIO LLD header, this contains the interface for Port functionality
 #define TIMER_GPIO_PORT XMC_GPIO_PORT0  // PORT0 Address
 #define TIMER_GPIO_PIN  0U              // Pin number
 #define TIMER_500MS 500000*100U

 volatile uint32_t count = 0U;          // count variable to change the time tick interval
 uint32_t shadow_transfer_msk;          // This is to generate the slice specific shadow transfer mask

 const XMC_GPIO_CONFIG_t GPIO_0_config  =
 {
   .mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
   .output_level = XMC_GPIO_OUTPUT_LEVEL_LOW,
 };

 int main(void)
 {
   DAVE_STATUS_t status;

   XMC_GPIO_Init(TIMER_GPIO_PORT, TIMER_GPIO_PIN, &GPIO_0_config);

   status = DAVE_Init();                // Initialization of DAVE APPs

   while(1U)
   {
   }
   return 1;
 }

 void Timetick_Handler(void)
 {
  count++;

  TIMER_ClearEvent(&TIMER_0);

  XMC_GPIO_ToggleOutput(TIMER_GPIO_PORT, TIMER_GPIO_PIN);

  if(count > 10)
  {
    count = 0U;
    TIMER_Stop(&TIMER_0);
    status = TIMER_SetTimeInterval(&TIMER_0, TIMER_500MS);
    if (status == TIMER_STATUS_SUCCESS)
    {
      TIMER_Start(&TIMER_0);
    }
  }
 }


Definition at line 250 of file TIMER.c.

References TIMER::period_value, TIMER_GetTimerStatus(), TIMER::timer_max_value_us, TIMER::timer_min_value_us, TIMER::timer_module, TIMER_MODULE_CCU4, TIMER_MODULE_CCU8, TIMER_STATUS_FAILURE, and TIMER_STATUS_SUCCESS.

TIMER_STATUS_t TIMER_Start ( TIMER_t *const  handle_ptr)

Starts the timer if the initialization of the APP is successful.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
TIMER_STATUS_t
TIMER_STATUS_SUCCESS : if timer start is successful
TIMER_STATUS_FAILURE : if timer start is failed

Description:
If "Start after initialization" is not enabled, TIMER_Start() can be invoked to start the timer. TIMER_Stop() can be used to stop the Timer. No need to reconfigure the timer to start again.


Example Usage:

 #include <DAVE.h>
 int main(void)
 {
  DAVE_STATUS_t init_status;
  TIMER_STATUS_t timer_status;
  init_status = DAVE_Init();    // TIMER_Init(&TIMER_0) will be called from DAVE_Init()

  if(init_status == DAVE_STATUS_SUCCESS)
  {
    timer_status = TIMER_Start(&TIMER_0);
  }
  while(1)
  {
  }
  return 1;
 }


Definition at line 145 of file TIMER.c.

References TIMER::timer_module, TIMER_MODULE_CCU4, TIMER_MODULE_CCU8, TIMER_STATUS_FAILURE, and TIMER_STATUS_SUCCESS.

TIMER_STATUS_t TIMER_Stop ( TIMER_t *const  handle_ptr)

Stops the TIMER, if it is running.

Parameters:
handle_ptrpointer to the TIMER APP configuration.
Returns:
TIMER_STATUS_t
TIMER_STATUS_SUCCESS : if timer is running and stop is successful
TIMER_STATUS_FAILURE : if timer is in idle state, and stop is called

Description:
Clears the Timer run bit to stop. No further event is generated.

Example Usage:

 #include <DAVE.h>
 int main(void)
 {
  DAVE_STATUS_t init_status;
  TIMER_STATUS_t timer_status;
  init_status = DAVE_Init();    // TIMER_Init(&TIMER_0) will be called from DAVE_Init()

  if(init_status == DAVE_STATUS_SUCCESS)
  {
    timer_status = TIMER_Start(&TIMER_0);
  }

  if (timer_status == TIMER_STATUS_SUCCESS)
  {
    while(TIMER_GetInterruptStatus(&TIMER_0));

    timer_status = TIMER_Stop(&TIMER_0);
  }
  while(1)
  {
  }
  return 1;
 }


Definition at line 182 of file TIMER.c.

References TIMER_GetTimerStatus(), TIMER::timer_module, TIMER_MODULE_CCU4, TIMER_MODULE_CCU8, TIMER_STATUS_FAILURE, and TIMER_STATUS_SUCCESS.