Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1254 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
1441 giacomo 4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
1254 giacomo 5
 *
1441 giacomo 6
 * Authors     : Mauro Marinoni <mauro.marinoni@unipv.it>
7
 * (see authors.txt for full list of hartik's authors)
1254 giacomo 8
 *
9
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
10
 *
11
 * http://www.sssup.it
12
 * http://retis.sssup.it
1441 giacomo 13
 * http://hartik.sssup.it
1254 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
 
1441 giacomo 32
 
33
#include <kernel/kern.h>
34
 
1254 giacomo 35
#include "modules/edf.h"
36
#include "modules/cbs.h"
1441 giacomo 37
#include "modules/rr.h"
1254 giacomo 38
#include "modules/dummy.h"
1441 giacomo 39
#include "modules/intdrive.h"
1254 giacomo 40
 
1441 giacomo 41
#include "modules/posix.h"
42
#include "grubstar.h"
1254 giacomo 43
#include "fsf_contract.h"
44
 
45
#include "modules/pi.h"
46
#include "modules/pc.h"
47
 
1441 giacomo 48
#include "pthread.h"
49
 
50
#include "modules/sem.h"
51
#include "modules/hartport.h"
52
 
53
#include <drivers/shark_linuxc26.h>
54
#include <drivers/shark_pci26.h>
55
 
56
/*+ sysyem tick in us +*/
1254 giacomo 57
#define TICK 0
58
 
1441 giacomo 59
/*+ RR tick in us +*/
1254 giacomo 60
#define RRTICK 10000
61
 
1441 giacomo 62
/*+ Interrupt Server +*/
63
#define INTDRIVE_Q 1000
64
#define INTDRIVE_T 10000
65
#define INTDRIVE_FLAG 0
66
 
67
void call_shutdown_task(void *arg);
68
int device_drivers_init();
69
int device_drivers_close();
70
void set_shutdown_task();
71
TASK shutdown_task_body(void *arg);
72
 
73
PID shutdown_task_PID = 1;
74
 
1254 giacomo 75
TIME __kernel_register_levels__(void *arg)
76
{
1441 giacomo 77
        struct multiboot_info *mb = (struct multiboot_info *)arg;
78
        int grubstar_level;
1254 giacomo 79
 
1441 giacomo 80
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_T, INTDRIVE_FLAG);
81
        EDF_register_level(EDF_ENABLE_ALL);
82
        POSIX_register_level(RRTICK, 1, mb, 32);
83
        grubstar_level = GRUBSTAR_register_level(FSF_MAX_N_SERVERS, 1);
84
        FSF_register_module(grubstar_level, (int)(MAX_BANDWIDTH * 0.9));
85
        dummy_register_level();
86
 
87
        CBS_register_level(CBS_ENABLE_ALL,1);
88
 
89
        SEM_register_module();
90
 
91
        PI_register_module();
92
        PC_register_module();
93
 
94
        PTHREAD_register_module(2, 0, 1);
1254 giacomo 95
 
1441 giacomo 96
        return TICK;
97
}
1254 giacomo 98
 
1441 giacomo 99
int device_drivers_close() {
100
 
101
        return 0;
102
 
103
}
1254 giacomo 104
 
1441 giacomo 105
int device_drivers_init() {
1254 giacomo 106
 
1441 giacomo 107
        LINUXC26_register_module();
108
        PCI26_init();
1254 giacomo 109
 
1441 giacomo 110
        return 0;
1254 giacomo 111
}
112
 
1441 giacomo 113
TASK shutdown_task_body(void *arg) {
114
 
115
        device_drivers_close();
116
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
117
        sys_abort_shutdown(0);
118
 
119
        return NULL;
120
}
121
 
122
#define SHUTDOWN_TIMEOUT_SEC 3
123
 
124
void set_shutdown_task() {
125
 
126
        NRT_TASK_MODEL nrt;
127
 
128
        nrt_task_default_model(nrt);
129
        nrt_task_def_system(nrt);
130
 
131
        shutdown_task_PID = task_create("Shutdown Task", shutdown_task_body, &nrt, NULL);
132
        if (shutdown_task_PID == NIL) {
133
                sys_shutdown_message("Error: Cannot create shutdown task\n");
134
                sys_end();
135
        }
136
 
137
}
138
 
139
void call_shutdown_task(void *arg) {
140
 
141
        struct timespec t;
142
 
143
        sys_gettime(&t);
144
        t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
145
 
146
        /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
147
        kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
148
 
149
        task_activate(shutdown_task_PID);
150
}
151
 
1254 giacomo 152
TASK __init__(void *arg)
153
{
1441 giacomo 154
        struct multiboot_info *mb = (struct multiboot_info *)arg;
1254 giacomo 155
 
1441 giacomo 156
        HARTPORT_init();
1254 giacomo 157
 
1441 giacomo 158
        set_shutdown_task();
1254 giacomo 159
 
1441 giacomo 160
        device_drivers_init();
161
 
162
        sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
163
 
164
        __call_main__(mb);
165
 
166
        return (void *)0;
1254 giacomo 167
}
168
 
169
int main() {
170
 
171
  return start_environment();
1441 giacomo 172
 
1254 giacomo 173
}
174