Subversion Repositories shark

Rev

Rev 1507 | Rev 1516 | 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
 
1508 giacomo 119
	for (i=0;i<10;i++)
120
	  if (proc_table[i].context != 0) TRACER_LOGEVENT(FTrace_EVT_id,
121
							(unsigned short int)proc_table[i].context,i);
122
 
1505 giacomo 123
	__call_main__(mb);
124
 
125
	return (void *)0;
126
}
127
 
128
void set_shutdown_task()
129
{
130
/* WARNING: the shutdown task is a background thread. It cannot execute if the system is overloaded */
131
	NRT_TASK_MODEL nrt;
132
 
133
	nrt_task_default_model(nrt);
134
	nrt_task_def_system(nrt);
135
 
136
	shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
137
	if (shutdown_task_PID == NIL) {
138
		sys_shutdown_message("Error: Cannot create shutdown task\n");
139
		sys_end();
140
	}
141
}
142
 
143
int device_drivers_init()
144
{
145
	int res;
146
	KEYB_PARMS kparms = BASE_KEYB;
147
	MOUSE_PARMS mparms = BASE_MOUSE;
148
 
149
	LINUXC26_register_module();
150
 
151
	PCI26_init();
152
 
153
	INPUT26_init();
154
 
155
	/* keyb_def_map(kparms, KEYMAP_IT);*/
156
	keyb_def_ctrlC(kparms, NULL);
157
	KEYB26_init(&kparms);
158
 
159
	mouse_def_threshold(mparms, 5);
160
	mouse_def_xmin(mparms, 0);
161
	mouse_def_ymin(mparms, 0);
162
	mouse_def_xmax(mparms, 639);
163
	mouse_def_ymax(mparms, 479);
164
	MOUSE26_init(&mparms);
165
 
166
	FB26_init();
167
	res = FB26_open(FRAME_BUFFER_DEVICE);
168
	if (res) {
169
		cprintf("Error: Cannot open graphical mode\n");
170
		MOUSE26_close();
171
		KEYB26_close();
172
		INPUT26_close();
173
		sys_end();
174
	}
175
 
176
	FB26_use_grx(FRAME_BUFFER_DEVICE);
177
	FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
178
 
179
	return 0;
180
}
181
 
182
int device_drivers_close() {
183
 
184
	TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
185
 
186
	FTrace_disable();
187
 
188
	FTrace_OSD_init_udp(1, "192.168.1.10", "192.168.1.1");
189
 
190
	FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
191
 
192
	mouse_grxcursor(DISABLE, 0);
193
 
194
	FB26_close(FRAME_BUFFER_DEVICE);
195
 
196
	MOUSE26_close();
197
	KEYB26_close();
198
	INPUT26_close();
199
 
200
	return 0;
201
}
202
 
1507 giacomo 203
#define SHUTDOWN_TIMEOUT_SEC 120
1505 giacomo 204
 
205
void call_shutdown_task(void *arg)
206
{
207
	struct timespec t;
208
 
209
	sys_gettime(&t);
210
	t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
211
 
212
	/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
213
	kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
214
 
215
	task_activate(shutdown_task_PID);
216
}
217
 
218
TASK shutdown_task_body(void *arg)
219
{
220
	device_drivers_close();
221
 
222
	sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
223
 
224
	sys_abort_shutdown(0);
225
 
226
	return NULL;
227
}