timer_posix.c

Go to the documentation of this file.
00001 
00039 #include <cfg/compiler.h> // hptime.t
00040 #include <os/hptime.h>
00041 
00042 #include <signal.h>       // sigaction()
00043 #include <sys/time.h>     // setitimer()
00044 #include <string.h>       // memset()
00045 
00046 
00047 // Forward declaration for the user interrupt server routine.
00048 void timer_isr(int);
00049 
00051 static void timer_hw_init(void)
00052 {
00053     struct sigaction sa;
00054     memset(&sa, 0, sizeof(sa));
00055 
00056     // Setup interrupt callback
00057     sa.sa_handler = timer_isr;
00058     sigemptyset(&sa.sa_mask);
00059     sigaddset(&sa.sa_mask, SIGALRM);
00060     sa.sa_flags = SA_RESTART;
00061     sigaction(SIGALRM, &sa, NULL);
00062 
00063     // Setup POSIX realtime timer to interrupt every 1/TIMER_TICKS_PER_SEC.
00064     static struct itimerval itv =
00065     {
00066         { 0, 1000000 / TIMER_TICKS_PER_SEC }, /* it_interval */
00067         { 0, 1000000 / TIMER_TICKS_PER_SEC }  /* it_value */
00068     };
00069     setitimer(ITIMER_REAL, &itv, NULL);
00070 }
00071 
00072 INLINE hptime_t timer_hw_hpread(void)
00073 {
00074     return hptime_get();
00075 }