Subversion Repositories shark

Rev

Rev 1569 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1505 giacomo 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *               Gerardo Lamastra <gerardo@sssup.it>
6
 *
1569 tullio 7
 * Authors     :
8
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
9
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
1505 giacomo 10
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://hartik.sssup.it
16
 */
17
 
18
/*
19
 * This program is free software; you can redistribute it and/or modify
20
 * it under the terms of the GNU General Public License as published by
21
 * the Free Software Foundation; either version 2 of the License, or
22
 * (at your option) any later version.
23
 *
24
 * This program is distributed in the hope that it will be useful,
25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
 * GNU General Public License for more details.
28
 *
29
 * You should have received a copy of the GNU General Public License
30
 * along with this program; if not, write to the Free Software
31
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
32
 *
33
 */
34
 
35
 
36
#include "kernel/kern.h"
37
 
1552 pj 38
#include "intdrive/intdrive/intdrive.h"
39
#include "edf/edf/edf.h"
40
#include "hardcbs/hardcbs/hardcbs.h"
41
#include "rr/rr/rr.h"
42
#include "dummy/dummy/dummy.h"
1505 giacomo 43
 
1552 pj 44
#include "sem/sem/sem.h"
45
#include "hartport/hartport/hartport.h"
46
#include "cabs/cabs/cabs.h"
1505 giacomo 47
 
48
#include <drivers/shark_linuxc26.h>
49
#include <drivers/shark_pci26.h>
50
 
51
#include <drivers/shark_input26.h>
52
#include <drivers/shark_keyb26.h>
53
#include <drivers/shark_mouse26.h>
54
 
55
#include <drivers/shark_fb26.h>
56
 
57
#include <tracer.h>
58
 
59
#define FRAME_BUFFER_DEVICE 0
60
 
61
/*+ sysyem tick in us +*/
62
#define TICK 0
63
 
64
/*+ RR tick in us +*/
65
#define RRTICK 2000
66
 
67
/*+ Interrupt Server +*/
68
#define INTDRIVE_Q 1000
1568 tullio 69
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1505 giacomo 70
#define INTDRIVE_FLAG 0
71
 
72
void call_shutdown_task(void *arg);
73
int device_drivers_init();
74
int device_drivers_close();
75
void set_shutdown_task();
76
TASK shutdown_task_body(void *arg);
77
 
78
PID shutdown_task_PID = -1;
79
int a = -1;
80
 
1519 giacomo 81
extern unsigned int clk_per_msec;
82
 
1505 giacomo 83
TIME __kernel_register_levels__(void *arg)
84
{
85
        struct multiboot_info *mb = (struct multiboot_info *)arg;
1568 tullio 86
        LEVEL EDF_level;
87
 
1567 mauro 88
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1568 tullio 89
        EDF_level = EDF_register_level(EDF_ENABLE_ALL);
90
        HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
1505 giacomo 91
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
92
        dummy_register_level();
93
 
94
        SEM_register_module();
95
        CABS_register_module();
96
 
97
        return TICK;
98
}
99
 
100
TASK __init__(void *arg)
101
{
102
        struct multiboot_info *mb = (struct multiboot_info *)arg;
103
 
104
        HARTPORT_init();
105
 
106
        /* Create the shutdown task. It will be activated at RUNLEVEL SHUTDOWN */
107
        set_shutdown_task();
108
 
109
        /* Init the drivers */
110
        device_drivers_init();
111
 
112
        /* Set the shutdown task activation */
113
        sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
114
 
115
        /* Tracer init: 10MB single tracer chunk */
116
        a = FTrace_chunk_create(10000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);    
117
 
118
        FTrace_actual_chunk_select(a);
119
 
120
        FTrace_enable();
121
 
1519 giacomo 122
        TRACER_LOGEVENT(FTrace_EVT_trace_start,proc_table[exec_shadow].context,clk_per_msec);
1505 giacomo 123
 
1508 giacomo 124
        for (i=0;i<10;i++)
125
          if (proc_table[i].context != 0) TRACER_LOGEVENT(FTrace_EVT_id,
126
                                                        (unsigned short int)proc_table[i].context,i);
127
 
1505 giacomo 128
        __call_main__(mb);
129
 
130
        return (void *)0;
131
}
132
 
133
void set_shutdown_task()
134
{
135
/* WARNING: the shutdown task is a background thread. It cannot execute if the system is overloaded */
136
        NRT_TASK_MODEL nrt;
137
 
138
        nrt_task_default_model(nrt);
139
        nrt_task_def_system(nrt);
140
 
141
        shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
142
        if (shutdown_task_PID == NIL) {
143
                sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 144
                exit(1);
1505 giacomo 145
        }
146
}
147
 
148
int device_drivers_init()
149
{
150
        int res;
151
        KEYB_PARMS kparms = BASE_KEYB;
152
        MOUSE_PARMS mparms = BASE_MOUSE;
153
 
1567 mauro 154
        LINUXC26_register_module(TRUE);
1505 giacomo 155
 
156
        PCI26_init();
157
 
158
        INPUT26_init();
159
 
160
        /* keyb_def_map(kparms, KEYMAP_IT);*/
161
        keyb_def_ctrlC(kparms, NULL);
162
        KEYB26_init(&kparms);
163
 
164
        mouse_def_threshold(mparms, 5);
165
        mouse_def_xmin(mparms, 0);
166
        mouse_def_ymin(mparms, 0);
167
        mouse_def_xmax(mparms, 639);
168
        mouse_def_ymax(mparms, 479);
169
        MOUSE26_init(&mparms);
170
 
171
        FB26_init();
172
        res = FB26_open(FRAME_BUFFER_DEVICE);
173
        if (res) {
174
                cprintf("Error: Cannot open graphical mode\n");
175
                MOUSE26_close();
176
                KEYB26_close();
177
                INPUT26_close();
1550 pj 178
                exit(1);
1505 giacomo 179
        }                                                                                            
180
 
181
        FB26_use_grx(FRAME_BUFFER_DEVICE);
182
        FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
183
 
184
        return 0;
185
}
186
 
187
int device_drivers_close() {
188
 
189
        TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
190
 
191
        FTrace_disable();
192
 
193
        FTrace_OSD_init_udp(1, "192.168.1.10", "192.168.1.1");
194
 
195
        FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);       
196
 
197
        mouse_grxcursor(DISABLE, 0);
198
 
199
        FB26_close(FRAME_BUFFER_DEVICE);
200
 
201
        MOUSE26_close();
202
        KEYB26_close();
203
        INPUT26_close();
204
 
205
        return 0;                                                                                                                    
206
}
207
 
1507 giacomo 208
#define SHUTDOWN_TIMEOUT_SEC 120
1505 giacomo 209
 
210
void call_shutdown_task(void *arg)
211
{
212
        struct timespec t;
213
 
214
        sys_gettime(&t);
215
        t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
216
 
217
        /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
218
        kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
219
 
220
        task_activate(shutdown_task_PID);
221
}
222
 
223
TASK shutdown_task_body(void *arg)
224
{
225
        device_drivers_close();
226
 
227
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
228
 
229
        return NULL;
230
}