Rev 2 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (c) 1996 The University of Utah and
* the Computer Systems Laboratory at the University of Utah (CSL).
* All rights reserved.
*
* Permission to use, copy, modify and distribute this software is hereby
* granted provided that (1) source code retains these copyright, permission,
* and disclaimer notices, and (2) redistributions including binaries
* reproduce the notices in supporting documentation, and (3) all advertising
* materials mentioning features or use of this software display the following
* acknowledgement: ``This product includes software developed by the
* Computer Systems Laboratory at the University of Utah.''
*
* THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
* IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
* ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* CSL requests users of this software to return to csl-dist@cs.utah.edu any
* improvements that they make and grant CSL redistribution rights.
*/
/*
* Linux timer support.
*/
#include<hartik.h>
#include<linux/timer.h>
#define N_MAX_TIMER 50
struct timer_entry {
unsigned long data;
void (*function)(unsigned long);
PID pid;
char Signat;
};
struct timer_entry timer_table[N_MAX_TIMER];
TASK timer_task(int i)
{
void (*fn)(unsigned long) = timer_table[i].function;
unsigned long data = timer_table[i].data;
if (timer_table[i].Signat != 'L') {
sys_abort(200);
}
cprintf("Delay 1\n");
task_endcycle(); /* 1st of all, sleep!!! */
cprintf("Delay 2\n");
/* Ok, now the timer is expired... */
fn(data);
/* The timer task now can die... */
cprintf("Delay 3\n");
task_abort();
}
int add_timer(struct timer_list *timer)
{
SYS_FLAGS flags;
PID p;
MODEL m = BASE_MODEL;
int done = 0;
int i = 0;
flags = kern_fsave();
while (!done) {
done = ((i = N_MAX_TIMER) || (timer_table[i].Signat != 'L'));
if (!done) {
i++;
} else {
timer_table[i].Signat = 'L';
}
}
kern_frestore(flags);
if (i == N_MAX_TIMER) {
return -1;
}
timer_table[i].function = timer->function;
timer_table[i].data = timer->data;
task_set_arg(m,i);
task_set_wcet(m, 2000);
p = task_create("Timer", timer_task, SOFT, PERIODIC, timer->expires,&m);
if (p != -1) {
timer_table[i].pid = p;
task_activate(p);
return 1;
} else {
timer_table[i].Signat = ' ';
return -1;
}
}
void del_timer(struct timer_list *timer)
{
int done = 0;
int i = 0;
while (!done) {
done = ((i = N_MAX_TIMER) || (timer_table[i].function = timer->function));
if (!done) {
i++;
} else {
timer_table[i].Signat = ' ';
task_kill(timer_table[i].pid);
}
}
}