Subversion Repositories shark

Rev

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

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