Main Page | Directories | File List | Globals

itimers.c

Go to the documentation of this file.
00001 /*
00002  * kernel_super/timers/itimers.c
00003  *
00004  * Copyright (c) 2003-2004 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2004/08
00008  * Author:      Lukasz Dembinski
00009  * Info:        itimers.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/agnix.h>
00015 #include <agnix/tasks.h>
00016 #include <agnix/timer.h>
00017 #include <agnix/timers.h>
00018 #include <agnix/math64.h>
00019 #include <agnix/signals.h>
00020 #include <agnix/errno.h>
00021 #include <agnix/console.h>
00022 
00023 #define MOD_NAME                        "iTIMERS: "
00024 
00025 int timeval_to_jiffies(struct timeval_s *val, u32 *jiffies_buf)
00026 {
00027     u32 jiffies_usecs;
00028     
00029     mul_32_32(jiffies_buf, (u32)(val->tv_sec), TIMER_HZ);
00030     jiffies_usecs = (u32)(val->tv_usec) / TIMER_HZ;
00031     add_64_32(jiffies_buf, jiffies_buf, jiffies_usecs);
00032 
00033     return 0;
00034 }
00035 
00036 void itimer_expire(void *data)
00037 {
00038     struct task_s *task = (struct task_s *)data;
00039     struct timer_s *timer = &task->timer_real;
00040 
00041     signal_send(task->t_pid, SIGALRM, (siginfo_t *)1);
00042 
00043     if (task->timer_real_interval) {
00044         timer->timer_expire = task->timer_real_interval;
00045     }
00046 }
00047 
00048 int do_sys_setitimer(int which, struct itimerval_s *newval, struct itimerval_s *oldval)
00049 {
00050     struct timer_s *timer = &current_task->timer_real;
00051     u32 jiffies_interval[2];
00052     u32 jiffies_value[2];
00053 
00054     timeval_to_jiffies(&newval->it_value, jiffies_value);
00055     timeval_to_jiffies(&newval->it_interval, jiffies_interval);
00056 
00057     if (jiffies_value[1] || jiffies_interval[1])
00058         return -EINVAL;
00059 
00060     current_task->timer_real_expire   = jiffies_value[0];
00061     current_task->timer_real_interval = jiffies_interval[0];
00062     timer->timer_function       = itimer_expire;
00063     timer->timer_data           = (void *)current_task;
00064     timer->timer_expire         = jiffies_value[0];
00065     
00066     if (!current_task->timer_real_interval)
00067         timer->timer_flags      = TIMER_FLAG_ONESHOT;
00068     
00069     register_timer(timer);
00070     
00071     return 0;
00072 }
00073 
00074 int do_sys_getitimer(int which, struct itimerval_s *val)
00075 {
00076     return 0;
00077 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix