Subversion Repositories shark

Rev

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

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