Timer

Timer service provides software timers and timer events for deferred execution, periodic processing and asynchronous task notification.

Timer Service

timer_service_t *timer_create(const uint8_t *timer_name, uint64_t period, timer_type_t type, void *message, pf_callback callback)

Timer service create a new timer.

The created timer will not start automatically, user application must call timer_start() to start the timer

Parameters:
  • timer_name – [in] pointer to the timer name string

  • period – [in] timer period in milliseconds

  • type – [in] timer type (TIMER_ONE_SHOT, TIMER_PERIODIC)

  • message – [in] pointer to the message to be sent when the timer expires

  • callback – [in] timer callback function pointer (MUST-BE not NULL)

Returns:

pointer to the created timer service control block

void timer_start(timer_service_t *timer)

Timer service start the specified timer.

Parameters:

timer – [in] pointer to the timer service control block

Returns:

none

timer_status_t timer_delete(timer_service_t *timer)

Timer service delete the specified timer.

Parameters:

timer – [in] pointer to the timer service control block

Returns:

  • TIMER_OK: timer delete success

  • TIMER_NG: timer remove fail

void timer_change_period(timer_service_t *timer, uint64_t period)

Timer service change the period of the specified timer.

Parameters:
  • timer – [in] pointer to the timer service control block

  • period – [in] new timer period in milliseconds

Returns:

none

Kernel Service

void timer_tick(uint32_t tick)

Timer service tick.

Parameters:

tick – [in] timer tick heart counter to decrement (unit: milliseconds)

Returns:

none

void timer_task()

Timer service task.

Parameters:

none – [in]

Returns:

none

Timer Event

timer_status_t timer_set(uint8_t task_id, uint8_t signal, uint64_t period, timer_type_t type)

Timer event set signal.

Parameters:
  • task_id – [in] destination task id

  • signal – [in] signal event

  • period – [in] timer period in milliseconds

  • type – [in] timer type (TIMER_ONE_SHOT, TIMER_PERIODIC)

Returns:

  • TIMER_OK: timer set success

  • TIMER_NG: timer set fail

timer_status_t timer_remove(uint8_t task_id, uint8_t signal)

Timer event remove signal.

Parameters:
  • task_id – [in] destination task id

  • signal – [in] signal event

Returns:

  • TIMER_OK: timer remove success

  • TIMER_NG: timer remove fail