Subversion Repositories shark

Rev

Rev 1519 | Rev 1552 | 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
 
1519 giacomo 79
extern unsigned int clk_per_msec;
80
 
1505 giacomo 81
TIME __kernel_register_levels__(void *arg)
82
{
83
	struct multiboot_info *mb = (struct multiboot_info *)arg;
84
 
85
	INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG);
86
	EDF_register_level(EDF_ENABLE_ALL);
87
	HCBS_register_level(HCBS_ENABLE_ALL, 1);
88
	RR_register_level(RRTICK, RR_MAIN_YES, mb);
89
	dummy_register_level();
90
 
91
	SEM_register_module();
92
	CABS_register_module();
93
 
94
	return TICK;
95
}
96
 
97
TASK __init__(void *arg)
98
{
99
	struct multiboot_info *mb = (struct multiboot_info *)arg;
100
 
101
	HARTPORT_init();
102
 
103
	/* Create the shutdown task. It will be activated at RUNLEVEL SHUTDOWN */
104
	set_shutdown_task();
105
 
106
	/* Init the drivers */
107
	device_drivers_init();
108
 
109
	/* Set the shutdown task activation */
110
	sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
111
 
112
	/* Tracer init: 10MB single tracer chunk */
113
	a = FTrace_chunk_create(10000000, 1000000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
114
 
115
	FTrace_actual_chunk_select(a);
116
 
117
	FTrace_enable();
118
 
1519 giacomo 119
	TRACER_LOGEVENT(FTrace_EVT_trace_start,proc_table[exec_shadow].context,clk_per_msec);
1505 giacomo 120
 
1508 giacomo 121
	for (i=0;i<10;i++)
122
	  if (proc_table[i].context != 0) TRACER_LOGEVENT(FTrace_EVT_id,
123
							(unsigned short int)proc_table[i].context,i);
124
 
1505 giacomo 125
	__call_main__(mb);
126
 
127
	return (void *)0;
128
}
129
 
130
void set_shutdown_task()
131
{
132
/* WARNING: the shutdown task is a background thread. It cannot execute if the system is overloaded */
133
	NRT_TASK_MODEL nrt;
134
 
135
	nrt_task_default_model(nrt);
136
	nrt_task_def_system(nrt);
137
 
138
	shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
139
	if (shutdown_task_PID == NIL) {
140
		sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 141
		exit(1);
1505 giacomo 142
	}
143
}
144
 
145
int device_drivers_init()
146
{
147
	int res;
148
	KEYB_PARMS kparms = BASE_KEYB;
149
	MOUSE_PARMS mparms = BASE_MOUSE;
150
 
151
	LINUXC26_register_module();
152
 
153
	PCI26_init();
154
 
155
	INPUT26_init();
156
 
157
	/* keyb_def_map(kparms, KEYMAP_IT);*/
158
	keyb_def_ctrlC(kparms, NULL);
159
	KEYB26_init(&kparms);
160
 
161
	mouse_def_threshold(mparms, 5);
162
	mouse_def_xmin(mparms, 0);
163
	mouse_def_ymin(mparms, 0);
164
	mouse_def_xmax(mparms, 639);
165
	mouse_def_ymax(mparms, 479);
166
	MOUSE26_init(&mparms);
167
 
168
	FB26_init();
169
	res = FB26_open(FRAME_BUFFER_DEVICE);
170
	if (res) {
171
		cprintf("Error: Cannot open graphical mode\n");
172
		MOUSE26_close();
173
		KEYB26_close();
174
		INPUT26_close();
1550 pj 175
		exit(1);
1505 giacomo 176
	}
177
 
178
	FB26_use_grx(FRAME_BUFFER_DEVICE);
179
	FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
180
 
181
	return 0;
182
}
183
 
184
int device_drivers_close() {
185
 
186
	TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
187
 
188
	FTrace_disable();
189
 
190
	FTrace_OSD_init_udp(1, "192.168.1.10", "192.168.1.1");
191
 
192
	FTrace_send_chunk(a, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
193
 
194
	mouse_grxcursor(DISABLE, 0);
195
 
196
	FB26_close(FRAME_BUFFER_DEVICE);
197
 
198
	MOUSE26_close();
199
	KEYB26_close();
200
	INPUT26_close();
201
 
202
	return 0;
203
}
204
 
1507 giacomo 205
#define SHUTDOWN_TIMEOUT_SEC 120
1505 giacomo 206
 
207
void call_shutdown_task(void *arg)
208
{
209
	struct timespec t;
210
 
211
	sys_gettime(&t);
212
	t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
213
 
214
	/* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
215
	kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
216
 
217
	task_activate(shutdown_task_PID);
218
}
219
 
220
TASK shutdown_task_body(void *arg)
221
{
222
	device_drivers_close();
223
 
224
	sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
225
 
226
	return NULL;
227
}