Subversion Repositories shark

Rev

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

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