Task Timer API

Application Example

waybyte/example-timer

API Reference

Header File

Source: include/task_timer.h

#include <task_timer.h>

Functions

int task_timer_register(timer_callback_f cb, void *arg)

Register a task timer. Task timers can only be created/controlled from parent task.

Note

Task timer will stop running if task is waiting on a semaphore or mutex or any blocking function call. Please use system timer APIs in that case.

Parameters:
  • cb – [in] timer callback function of type timer_callback_f

  • arg – [in] User data pointer passed to callback function

Returns:

On success, returns timer ID registered. On error a negative value is returned

int task_timer_start(int tid, unsigned int ms, int cyclic)

Start Task timer

Parameters:
  • tid – [in] Timer ID returned by task_timer_register()

  • ms – [in] Timeout in ms

  • cyclic – [in] TRUE if cyclic or periodic timer, FALSE for one-shot timer

Returns:

0 on Success, On error negative value is returned

int task_timer_stop(int tid)

Stop task timer

Parameters:

tid – [in] Timer ID returned by task_timer_register()

Returns:

0 on Success, On error negative value is returned

Type Definitions

typedef void (*timer_callback_f)(int id, void *arg)

Timer callback function type

Param id:

Timer ID

Param arg:

User data argument supplied during registration