Subversion Repositories shark

Rev

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

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