Subversion Repositories shark

Compare Revisions

Regard whitespace Rev 1387 → Rev 1386

/demos/trunk/base/initfile.c
37,12 → 37,6
#define INTDRIVE_T 10000
#define INTDRIVE_FLAG 0
 
void call_shutdown_task(void *arg);
int device_drivers_init();
int device_drivers_close();
void set_shutdown_task();
TASK shutdown_task_body(void *arg);
 
PID shutdown_task_PID = 1;
 
TIME __kernel_register_levels__(void *arg)
60,44 → 54,16
return TICK;
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
int device_drivers_close() {
 
HARTPORT_init();
KEYB26_close();
 
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
INPUT26_close();
 
/* Init the drivers */
device_drivers_init();
return 0;
 
/* Set the shutdown task activation */
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}
 
void set_shutdown_task() {
 
/* WARNING: the shutdown task is a background thread. It cannot execute
if the system is overloaded */
NRT_TASK_MODEL nrt;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
 
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
sys_end();
}
 
}
 
int device_drivers_init() {
 
KEYB_PARMS kparms = BASE_KEYB;
114,39 → 80,53
 
}
 
int device_drivers_close() {
TASK shutdown_task_body(void *arg) {
KEYB26_close();
device_drivers_close();
INPUT26_close();
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
return 0;
sys_end();
return NULL;
}
 
#define SHUTDOWN_TIMEOUT_SEC 3
void set_shutdown_task() {
 
void call_shutdown_task(void *arg)
{
struct timespec t;
NRT_TASK_MODEL nrt;
 
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
nrt_task_def_nokill(nrt);
 
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
if (shutdown_task_PID == NIL) {
sys_shutdown_message("Error: Cannot create shutdown task\n");
sys_end();
}
 
}
 
void call_shutdown_task(void *arg) {
 
task_activate(shutdown_task_PID);
 
}
 
TASK shutdown_task_body(void *arg) {
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
 
device_drivers_close();
HARTPORT_init();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
set_shutdown_task();
 
sys_abort_shutdown(0);
device_drivers_init();
 
return NULL;
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
 
__call_main__(mb);
 
return (void *)0;
}