Subversion Repositories shark

Rev

Rev 1448 | Rev 1469 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1091 pj 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     :
1448 giacomo 9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
1091 pj 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
 
1448 giacomo 36
#define PI_MUTEX
1091 pj 37
 
38
#include "kernel/kern.h"
1448 giacomo 39
#include "modules/intdrive.h"
1091 pj 40
#include "modules/edf.h"
1468 giacomo 41
#include "modules/cbs.h"
1091 pj 42
#include "modules/rr.h"
43
#include "modules/dummy.h"
1448 giacomo 44
 
1091 pj 45
#include "modules/sem.h"
46
#include "modules/hartport.h"
47
#include "modules/cabs.h"
48
 
1448 giacomo 49
#include "modules/pi.h"
50
#include "modules/nop.h"
1091 pj 51
 
1448 giacomo 52
#include "bca.h"
53
 
54
#include <drivers/shark_linuxc26.h>
55
#include <drivers/shark_pci26.h>
56
#include <drivers/shark_input26.h>
57
#include <drivers/shark_keyb26.h>
58
#include <drivers/shark_fb26.h>
59
 
60
#define FRAME_BUFFER_DEVICE 0
61
 
62
/*+ sysyem tick in us +*/
63
#define TICK 0
64
 
1091 pj 65
/*+ RR tick in us +*/
1448 giacomo 66
#define RRTICK 2000
1091 pj 67
 
1448 giacomo 68
/*+ Interrupt Server +*/
69
#define INTDRIVE_Q 1000
70
#define INTDRIVE_T 10000
71
#define INTDRIVE_FLAG 0
72
 
73
void call_shutdown_task(void *arg);
74
int device_drivers_init();
75
int device_drivers_close();
76
void set_shutdown_task();
77
TASK shutdown_task_body(void *arg);
78
 
79
PID shutdown_task_PID = -1;
80
 
1091 pj 81
TIME __kernel_register_levels__(void *arg)
82
{
83
  struct multiboot_info *mb = (struct multiboot_info *)arg;
84
 
1448 giacomo 85
  INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG);
1091 pj 86
  EDF_register_level(EDF_ENABLE_ALL);
1468 giacomo 87
  CBS_register_level(CBS_ENABLE_ALL, 1);
1091 pj 88
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
89
  dummy_register_level();
90
 
91
  SEM_register_module();
92
  CABS_register_module();
1448 giacomo 93
 
1091 pj 94
  PI_register_module();
95
  NOP_register_module();
96
 
97
  kern_init_bca();
98
 
99
  return TICK;
100
}
101
 
102
TASK __init__(void *arg)
103
{
104
  struct multiboot_info *mb = (struct multiboot_info *)arg;
105
 
106
  HARTPORT_init();
107
 
1448 giacomo 108
  /* Create the shutdown task. It will be activated at RUNLEVEL
109
     SHUTDOWN */
110
  set_shutdown_task();
1091 pj 111
 
1448 giacomo 112
  /* Init the drivers */
113
  device_drivers_init();
114
 
115
  /* Set the shutdown task activation */
116
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
117
 
1091 pj 118
  __call_main__(mb);
119
 
120
  return (void *)0;
121
}
122
 
1448 giacomo 123
#ifdef PI_MUTEX
1091 pj 124
int app_mutex_init(mutex_t *m)
125
{
126
  PI_mutexattr_t attr;
1448 giacomo 127
 
1091 pj 128
  PI_mutexattr_default(attr);
1448 giacomo 129
 
1091 pj 130
  return mutex_init(m, &attr);
131
}
132
#else
133
int app_mutex_init(mutex_t *m)
134
{
135
  NOP_mutexattr_t attr;
1448 giacomo 136
 
1091 pj 137
  NOP_mutexattr_default(attr);
1448 giacomo 138
 
1091 pj 139
  return mutex_init(m, &attr);
140
}
141
#endif
142
 
1448 giacomo 143
void set_shutdown_task() {
144
 
145
  /* WARNING: the shutdown task is a background thread. It cannot execute
146
              if the system is overloaded */
147
  NRT_TASK_MODEL nrt;
148
 
149
  nrt_task_default_model(nrt);
150
  nrt_task_def_system(nrt);
151
 
152
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
153
  if (shutdown_task_PID == NIL) {
154
    sys_shutdown_message("Error: Cannot create shutdown task\n");
155
    sys_end();
156
  }
157
 
158
}
159
 
160
int device_drivers_init() {
161
 
162
  int res;
163
  KEYB_PARMS kparms = BASE_KEYB;
164
 
165
  LINUXC26_register_module();
166
 
167
  PCI26_init();
168
 
169
  INPUT26_init();
170
 
171
  keyb_def_ctrlC(kparms, NULL);
172
 
173
  KEYB26_init(&kparms);
174
 
175
  FB26_init();
176
 
177
  res = FB26_open(FRAME_BUFFER_DEVICE);
178
  if (res) {
179
    cprintf("Error: Cannot open graphical mode\n");
180
    KEYB26_close();
181
    INPUT26_close();
182
    sys_end();
183
  }                                                                                          
184
 
185
  FB26_use_grx(FRAME_BUFFER_DEVICE);
186
 
187
  FB26_setmode(FRAME_BUFFER_DEVICE,"800x600-16");
188
 
189
  return 0;
190
 
191
}
192
 
193
int device_drivers_close() {
194
 
195
  FB26_close(FRAME_BUFFER_DEVICE);
196
 
197
  KEYB26_close();
198
 
199
  INPUT26_close();
200
 
201
  return 0;
202
 
203
}
204
 
205
#define SHUTDOWN_TIMEOUT_SEC 3
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
  sys_abort_shutdown(0);
227
 
228
  return NULL;
229
 
230
}