timer_posix.c
Go to the documentation of this file.00001
00037
00038 #include <os/hptime.h>
00039 #include <kern/irq.h>
00040
00041 #if !CONFIG_KERN_IRQ
00042 #include <signal.h>
00043 #include <string.h>
00044 #endif
00045 #include <sys/time.h>
00046
00047
00048
00049 void timer_isr(int);
00050
00052 static void timer_hw_init(void)
00053 {
00054 #if CONFIG_KERN_IRQ
00055 irq_register(SIGALRM, (void (*)(void))timer_isr);
00056 #else // ! CONFIG_KERN_IRQ
00057 struct sigaction sa;
00058 memset(&sa, 0, sizeof(sa));
00059
00060
00061 sa.sa_handler = timer_isr;
00062 sigemptyset(&sa.sa_mask);
00063 sigaddset(&sa.sa_mask, SIGALRM);
00064 sa.sa_flags = SA_RESTART;
00065 sigaction(SIGALRM, &sa, NULL);
00066 #endif // CONFIG_KERN_IRQ
00067
00068
00069 static const struct itimerval itv =
00070 {
00071 { 0, 1000000 / TIMER_TICKS_PER_SEC },
00072 { 0, 1000000 / TIMER_TICKS_PER_SEC }
00073 };
00074 setitimer(ITIMER_REAL, &itv, NULL);
00075 }
00076
00077 static void timer_hw_cleanup(void)
00078 {
00079 static const struct itimerval itv =
00080 {
00081 { 0, 0 },
00082 { 0, 0 }
00083 };
00084 setitimer(ITIMER_REAL, &itv, NULL);
00085 signal(SIGALRM, SIG_DFL);
00086 }
00087
00088 INLINE hptime_t timer_hw_hpread(void)
00089 {
00090 return hptime_get();
00091 }
00092
00093 #define timer_hw_triggered() (true)