Subversion Repositories shark

Compare Revisions

Regard whitespace Rev 1386 → Rev 1387

/demos/trunk/base/initfile.c
37,6 → 37,12
#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)
54,16 → 60,44
return TICK;
}
 
int device_drivers_close() {
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
KEYB26_close();
HARTPORT_init();
INPUT26_close();
/* Create the shutdown task. It will be activated at RUNLEVEL
SHUTDOWN */
set_shutdown_task();
return 0;
/* Init the drivers */
device_drivers_init();
/* 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;
80,53 → 114,39
 
}
 
TASK shutdown_task_body(void *arg) {
int device_drivers_close() {
 
device_drivers_close();
KEYB26_close();
 
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
INPUT26_close();
 
sys_end();
return 0;
 
return NULL;
}
 
void set_shutdown_task() {
#define SHUTDOWN_TIMEOUT_SEC 3
 
NRT_TASK_MODEL nrt;
void call_shutdown_task(void *arg)
{
struct timespec t;
 
nrt_task_default_model(nrt);
nrt_task_def_system(nrt);
nrt_task_def_nokill(nrt);
sys_gettime(&t);
t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
 
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();
}
/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
 
}
 
void call_shutdown_task(void *arg) {
 
task_activate(shutdown_task_PID);
 
}
 
TASK __init__(void *arg)
{
struct multiboot_info *mb = (struct multiboot_info *)arg;
TASK shutdown_task_body(void *arg) {
 
HARTPORT_init();
device_drivers_close();
 
set_shutdown_task();
sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
 
device_drivers_init();
sys_abort_shutdown(0);
 
sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
return NULL;
 
__call_main__(mb);
 
return (void *)0;
}