Skip to content

seff34/Linux-Timer-API-In-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Embedded Linux Timer API

Library is a High-Level POSIX TIMER API.

API Functions

Define Timer Signal

#define TIMER_SIGNAL_1 SIGRTMIN + 1

Allocate Memory

timerValues_t *timer1 = (timerValues_t *)malloc(sizeof(timerValues_t));

Timer Initalize

timerInit(timer1,TIMER_SIGNAL_1,timerCallback_1);
Parameter Type Description
Name timer_t Timer Name
Signal uint16_t Timer Signal
Callback void * Timer Callback Functions

Timer Start

timerStart(timer1, 0 , 1000 );   -> 1second Periodic Timer
timerStart(timer1, 1000, 1000 ); -> 1second Periodic Timer
timerStart(timer1, 3000, 0 );    -> 3second One Shot Timer
Parameter Type Description
Name timer_t Timer Name
Time_Ms uint16_t One Shot Timer Value (ms)
Time_Ms uint16_t Periodic Timer Value (ms)

Timer Stop

timerStop(timer1);
Parameter Type Description
Name timer_t Timer Name

Timer Deinit

timerDeinit(timer1);
Parameter Type Description
Name timer_t Timer Name

Timer Callback Function

void timerCallback_1(int signal)
{
    //(void)signal;
    printf("Timer Interrupt %d ------------\n",signal);
}

Download Code

Clone Project

  git clone https://github.com/seff34/Linux-Timer-API

References:

https://man7.org/linux/

https://demirten.gitbooks.io/linux-sistem-programlama/content/timers/posix.html