Subversion Repositories shark

Rev

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

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