Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1347 giacomo 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
 
1389 mauro 33
 
1347 giacomo 34
#include <kernel/kern.h>
35
 
1552 pj 36
#include "edf/edf/edf.h"
37
#include "cbs/cbs/cbs.h"
38
#include "rr/rr/rr.h"
39
#include "dummy/dummy/dummy.h"
40
#include "intdrive/intdrive/intdrive.h"
1347 giacomo 41
 
1552 pj 42
#include "sem/sem/sem.h"
43
#include "hartport/hartport/hartport.h"
1347 giacomo 44
 
45
#include <drivers/shark_linuxc26.h>
46
#include <drivers/shark_input26.h>
47
#include <drivers/shark_keyb26.h>
48
#include <drivers/shark_spk26.h>
49
 
50
/*+ sysyem tick in us +*/
51
#define TICK 0
52
 
53
/*+ RR tick in us +*/
54
#define RRTICK 10000
55
 
1389 mauro 56
/*+ Interrupt Server +*/
57
#define INTDRIVE_Q 1000
58
#define INTDRIVE_T 10000
59
#define INTDRIVE_FLAG 0
1347 giacomo 60
 
1389 mauro 61
PID shutdown_task_PID = 1;
1347 giacomo 62
 
63
TIME __kernel_register_levels__(void *arg)
64
{
65
        struct multiboot_info *mb = (struct multiboot_info *)arg;
66
 
1389 mauro 67
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_T, INTDRIVE_FLAG);
1347 giacomo 68
        EDF_register_level(EDF_ENABLE_ALL);
69
        CBS_register_level(CBS_ENABLE_ALL, 1);
70
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
71
        dummy_register_level();
72
 
73
        SEM_register_module();
74
 
75
        return TICK;
76
}
77
 
1389 mauro 78
int device_drivers_close() {
79
 
80
        KEYB26_close();
81
        SPEAK26_close();
82
        INPUT26_close();
83
 
84
        return 0;                                                                                                                        
85
}
1347 giacomo 86
 
1389 mauro 87
int device_drivers_init() {
1347 giacomo 88
 
1389 mauro 89
        KEYB_PARMS  kparms = BASE_KEYB;
90
 
1347 giacomo 91
        LINUXC26_register_module();
92
        INPUT26_init();
1389 mauro 93
 
94
        /*keyb_def_map(kparms, KEYMAP_IT);*/
95
        keyb_def_ctrlC(kparms, NULL);
1347 giacomo 96
        KEYB26_init(&kparms);
1389 mauro 97
 
1347 giacomo 98
        SPEAK26_init();
1389 mauro 99
        return 0;
100
}
1347 giacomo 101
 
1389 mauro 102
TASK shutdown_task_body(void *arg) {
103
 
104
        device_drivers_close();
105
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
106
        return NULL;
107
}
108
 
109
void set_shutdown_task() {
110
 
111
        NRT_TASK_MODEL nrt;
112
 
113
        nrt_task_default_model(nrt);
114
        nrt_task_def_system(nrt);
115
 
116
        shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL);
117
        if (shutdown_task_PID == NIL) {
118
                sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 119
                exit(1);
1389 mauro 120
        }
121
 
122
}
123
 
1399 giacomo 124
#define SHUTDOWN_TIMEOUT_SEC 3
125
 
1389 mauro 126
void call_shutdown_task(void *arg) {
1399 giacomo 127
        struct timespec t;
128
 
129
        sys_gettime(&t);
130
        t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
131
 
132
        /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
133
        kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
134
 
1389 mauro 135
        task_activate(shutdown_task_PID);
136
}
137
 
138
TASK __init__(void *arg)
139
{
140
        struct multiboot_info *mb = (struct multiboot_info *)arg;
141
 
142
        HARTPORT_init();
143
 
144
        set_shutdown_task();
145
 
146
        device_drivers_init();
147
 
148
        sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
149
 
1347 giacomo 150
        __call_main__(mb);
151
 
152
        return (void *)0;
153
}