Subversion Repositories shark

Rev

Rev 1389 | Rev 1550 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1363 mauro 1
/*
2
 * Project: HARTIK (HA-rd R-eal TI-me K-ernel)
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
7
 * Authors     : Mauro Marinoni <mauro.marinoni@unipv.it>
8
 * (see authors.txt for full list of hartik's authors)
9
 *
10
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
11
 *
12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
/*
18
 * This program is free software; you can redistribute it and/or modify
19
 * it under the terms of the GNU General Public License as published by
20
 * the Free Software Foundation; either version 2 of the License, or
21
 * (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31
 */
32
 
33
#include <kernel/kern.h>
34
 
35
#include "modules/edf.h"
36
#include "modules/cbs.h"
37
#include "modules/rr.h"
38
#include "modules/dummy.h"
39
#include "modules/intdrive.h"
40
 
41
#include "modules/sem.h"
42
#include "modules/hartport.h"
43
 
44
#include <drivers/shark_linuxc26.h>
45
#include <drivers/shark_input26.h>
46
#include <drivers/shark_mouse26.h>
47
#include <drivers/shark_keyb26.h>
48
 
49
/*+ sysyem tick in us +*/
50
#define TICK 0
51
 
52
/*+ RR tick in us +*/
53
#define RRTICK 10000
54
 
1389 mauro 55
/*+ Interrupt Server +*/
56
#define INTDRIVE_Q 1000
57
#define INTDRIVE_T 10000
58
#define INTDRIVE_FLAG 0
1363 mauro 59
 
1399 giacomo 60
void call_shutdown_task(void *arg);
61
int device_drivers_init();
62
int device_drivers_close();
63
void set_shutdown_task();
64
TASK shutdown_task_body(void *arg);
65
 
1389 mauro 66
PID shutdown_task_PID = 1;
1363 mauro 67
 
68
TIME __kernel_register_levels__(void *arg)
69
{
70
        struct multiboot_info *mb = (struct multiboot_info *)arg;
71
 
1389 mauro 72
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_T, INTDRIVE_FLAG);
1363 mauro 73
        EDF_register_level(EDF_ENABLE_ALL);
74
        CBS_register_level(CBS_ENABLE_ALL, 1);
75
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
76
        dummy_register_level();
77
 
78
        SEM_register_module();
79
 
80
        return TICK;
81
}
82
 
1389 mauro 83
int device_drivers_close() {
84
 
85
        MOUSE26_close();
86
        KEYB26_close();
87
        INPUT26_close();
88
 
1399 giacomo 89
        return 0;
1389 mauro 90
}
91
 
92
int device_drivers_init() {
93
 
1363 mauro 94
        KEYB_PARMS  kparms = BASE_KEYB;
95
        MOUSE_PARMS mparms = BASE_MOUSE;
1389 mauro 96
 
97
        LINUXC26_register_module();
98
        INPUT26_init();
1363 mauro 99
 
100
        /*keyb_def_map(kparms, KEYMAP_IT);*/
101
        keyb_def_ctrlC(kparms, NULL);
102
        KEYB26_init(&kparms);
103
 
1389 mauro 104
        MOUSE26_init(&mparms);
105
 
106
        return 0;
107
 
108
}
109
 
110
TASK shutdown_task_body(void *arg) {
111
 
112
        device_drivers_close();
113
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
1399 giacomo 114
        sys_abort_shutdown(0);
1389 mauro 115
 
116
        return NULL;
117
}
118
 
119
void set_shutdown_task() {
120
 
121
        NRT_TASK_MODEL nrt;
122
 
123
        nrt_task_default_model(nrt);
124
        nrt_task_def_system(nrt);
125
 
126
        shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL);
127
        if (shutdown_task_PID == NIL) {
128
                sys_shutdown_message("Error: Cannot create shutdown task\n");
129
                sys_end();
130
        }
131
 
132
}
133
 
1399 giacomo 134
#define SHUTDOWN_TIMEOUT_SEC 3
135
 
1389 mauro 136
void call_shutdown_task(void *arg) {
1399 giacomo 137
        struct timespec t;
138
 
139
        sys_gettime(&t);
140
        t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
141
 
142
        /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
143
        kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
144
 
1389 mauro 145
        task_activate(shutdown_task_PID);
146
}
147
 
148
TASK __init__(void *arg)
149
{
150
        struct multiboot_info *mb = (struct multiboot_info *)arg;
151
 
152
        HARTPORT_init();
153
 
154
        set_shutdown_task();
155
 
156
        device_drivers_init();
157
 
158
        sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
159
 
1363 mauro 160
        __call_main__(mb);
161
 
162
        return (void *)0;
163
}