Subversion Repositories shark

Rev

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