Subversion Repositories shark

Rev

Rev 1505 | Rev 1508 | Go to most recent revision | 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
 *
7
 * Authors     : Giacomo Guidi <giacomo@gandalf.sssup.it>
8
 *
9
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
10
 *
11
 * http://www.sssup.it
12
 * http://retis.sssup.it
13
 * http://hartik.sssup.it
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
 */
32
 
33
 
34
#include "kernel/kern.h"
35
 
36
#include "modules/intdrive.h"
37
#include "modules/edf.h"
38
#include "modules/hardcbs.h"
39
#include "modules/rr.h"
40
#include "modules/dummy.h"
41
 
42
#include "modules/sem.h"
43
#include "modules/hartport.h"
44
#include "modules/cabs.h"
45
 
46
#include <drivers/shark_linuxc26.h>
47
#include <drivers/shark_pci26.h>
48
 
49
#include <drivers/shark_input26.h>
50
#include <drivers/shark_keyb26.h>
51
#include <drivers/shark_mouse26.h>
52
 
53
#include <drivers/shark_fb26.h>
54
 
55
#include <tracer.h>
56
 
57
#define FRAME_BUFFER_DEVICE 0
58
 
59
/*+ sysyem tick in us +*/
60
#define TICK 0
61
 
62
/*+ RR tick in us +*/
63
#define RRTICK 2000
64
 
65
/*+ Interrupt Server +*/
66
#define INTDRIVE_Q 1000
67
#define INTDRIVE_T 10000
68
#define INTDRIVE_FLAG 0
69
 
70
void call_shutdown_task(void *arg);
71
int device_drivers_init();
72
int device_drivers_close();
73
void set_shutdown_task();
74
TASK shutdown_task_body(void *arg);
75
 
76
PID shutdown_task_PID = -1;
77
int a = -1;
78
 
79
TIME __kernel_register_levels__(void *arg)
80
{
81
        struct multiboot_info *mb = (struct multiboot_info *)arg;
82
 
83
        INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG);
84
        EDF_register_level(EDF_ENABLE_ALL);
85
        HCBS_register_level(HCBS_ENABLE_ALL, 1);
86
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
87
        dummy_register_level();
88
 
89
        SEM_register_module();
90
        CABS_register_module();
91
 
92
        return TICK;
93
}
94
 
95
TASK __init__(void *arg)
96
{
97
        struct multiboot_info *mb = (struct multiboot_info *)arg;
98
 
99
        HARTPORT_init();
100
 
101
        /* Create the shutdown task. It will be activated at RUNLEVEL SHUTDOWN */
102
        set_shutdown_task();
103
 
104
        /* Init the drivers */
105
        device_drivers_init();
106
 
107
        /* Set the shutdown task activation */
108
        sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
109
 
110
        /* Tracer init: 10MB single tracer chunk */
111
        a = FTrace_chunk_create(10000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);    
112
 
113
        FTrace_actual_chunk_select(a);
114
 
115
        FTrace_enable();
116
 
117
        TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
118
 
119
        __call_main__(mb);
120
 
121
        return (void *)0;
122
}
123
 
124
void set_shutdown_task()
125
{
126
/* WARNING: the shutdown task is a background thread. It cannot execute if the system is overloaded */
127
        NRT_TASK_MODEL nrt;
128
 
129
        nrt_task_default_model(nrt);
130
        nrt_task_def_system(nrt);
131
 
132
        shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
133
        if (shutdown_task_PID == NIL) {
134
                sys_shutdown_message("Error: Cannot create shutdown task\n");
135
                sys_end();
136
        }
137
}
138
 
139
int device_drivers_init()
140
{
141
        int res;
142
        KEYB_PARMS kparms = BASE_KEYB;
143
        MOUSE_PARMS mparms = BASE_MOUSE;
144
 
145
        LINUXC26_register_module();
146
 
147
        PCI26_init();
148
 
149
        INPUT26_init();
150
 
151
        /* keyb_def_map(kparms, KEYMAP_IT);*/
152
        keyb_def_ctrlC(kparms, NULL);
153
        KEYB26_init(&kparms);
154
 
155
        mouse_def_threshold(mparms, 5);
156
        mouse_def_xmin(mparms, 0);
157
        mouse_def_ymin(mparms, 0);
158
        mouse_def_xmax(mparms, 639);
159
        mouse_def_ymax(mparms, 479);
160
        MOUSE26_init(&mparms);
161
 
162
        FB26_init();
163
        res = FB26_open(FRAME_BUFFER_DEVICE);
164
        if (res) {
165
                cprintf("Error: Cannot open graphical mode\n");
166
                MOUSE26_close();
167
                KEYB26_close();
168
                INPUT26_close();
169
                sys_end();
170
        }                                                                                            
171
 
172
        FB26_use_grx(FRAME_BUFFER_DEVICE);
173
        FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
174
 
175
        return 0;
176
}
177
 
178
int device_drivers_close() {
179
 
180
        TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
181
 
182
        FTrace_disable();
183
 
184
        FTrace_OSD_init_udp(1, "192.168.1.10", "192.168.1.1");
185
 
186
        FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);       
187
 
188
        mouse_grxcursor(DISABLE, 0);
189
 
190
        FB26_close(FRAME_BUFFER_DEVICE);
191
 
192
        MOUSE26_close();
193
        KEYB26_close();
194
        INPUT26_close();
195
 
196
        return 0;                                                                                                                    
197
}
198
 
1507 giacomo 199
#define SHUTDOWN_TIMEOUT_SEC 120
1505 giacomo 200
 
201
void call_shutdown_task(void *arg)
202
{
203
        struct timespec t;
204
 
205
        sys_gettime(&t);
206
        t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
207
 
208
        /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
209
        kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
210
 
211
        task_activate(shutdown_task_PID);
212
}
213
 
214
TASK shutdown_task_body(void *arg)
215
{
216
        device_drivers_close();
217
 
218
        sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
219
 
220
        sys_abort_shutdown(0);
221
 
222
        return NULL;
223
}