Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1151 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
 *
1360 giacomo 8
 * Authors     :
9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
1512 giacomo 10
 *   Mauro Marinoni
1151 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
 * 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
#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"
1151 giacomo 42
 
1552 pj 43
#include "sem/sem/sem.h"
44
#include "hartport/hartport/hartport.h"
45
#include "cabs/cabs/cabs.h"
1151 giacomo 46
 
1360 giacomo 47
#include "drivers/shark_linuxc26.h"
48
#include "drivers/shark_input26.h"
1525 giacomo 49
#include "drivers/shark_pci26.h"
1360 giacomo 50
#include "drivers/shark_keyb26.h"
1512 giacomo 51
#include "drivers/shark_cpu26.h"
1151 giacomo 52
 
53
/*+ sysyem tick in us +*/
1483 giacomo 54
#define TICK 0
1151 giacomo 55
 
56
/*+ RR tick in us +*/
57
#define RRTICK 10000
58
 
1360 giacomo 59
/*+ IntDrive Server +*/
60
#define INTDRIVE_Q 1000
1567 mauro 61
#define INTDRIVE_U 1000
1360 giacomo 62
#define INTDRIVE_FLAGS 0
63
 
1394 giacomo 64
void call_shutdown_task(void *arg);
65
int device_drivers_init();
66
int device_drivers_close();
67
void set_shutdown_task();
68
TASK shutdown_task_body(void *arg);
69
 
70
PID shutdown_task_PID = -1;
71
 
1151 giacomo 72
TIME __kernel_register_levels__(void *arg)
73
{
74
  struct multiboot_info *mb = (struct multiboot_info *)arg;
75
 
1567 mauro 76
  INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAGS);
1151 giacomo 77
  EDF_register_level(EDF_ENABLE_ALL);
1360 giacomo 78
  HCBS_register_level(HCBS_ENABLE_ALL, 1);
1151 giacomo 79
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
80
  dummy_register_level();
81
 
82
  SEM_register_module();
83
 
84
  CABS_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
  HARTPORT_init();
94
 
1394 giacomo 95
  /* Create the shutdown task. It will be activated at RUNLEVEL
96
     SHUTDOWN */
97
  set_shutdown_task();
98
 
99
  /* Init the drivers */
100
  device_drivers_init();
101
 
102
  /* Set the shutdown task activation */
103
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
1429 mauro 104
 
1431 mauro 105
  //sys_set_reboot(EXIT_MODE_HALT);
1394 giacomo 106
 
1151 giacomo 107
  __call_main__(mb);
108
 
1394 giacomo 109
  return (void *)0;
110
}
111
 
112
void set_shutdown_task() {
113
 
114
  /* WARNING: the shutdown task is a background thread. It cannot execute
115
              if the system is overloaded */
116
  NRT_TASK_MODEL nrt;
117
 
118
  nrt_task_default_model(nrt);
119
  nrt_task_def_system(nrt);
120
 
121
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
122
  if (shutdown_task_PID == NIL) {
123
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 124
    exit(1);
1394 giacomo 125
  }
126
 
127
}
128
 
129
int device_drivers_init() {
130
 
131
  KEYB_PARMS kparms = BASE_KEYB;
132
 
1567 mauro 133
  LINUXC26_register_module(TRUE);
1394 giacomo 134
 
1525 giacomo 135
  PCI26_init();
136
 
1512 giacomo 137
  CPU26_init();
138
 
139
  CPU26_DVS_init();
140
 
1394 giacomo 141
  INPUT26_init();
142
 
143
  keyb_def_ctrlC(kparms, NULL);
144
 
145
  KEYB26_init(&kparms);
146
 
147
  return 0;
148
 
149
}
150
 
151
int device_drivers_close() {
152
 
153
  KEYB26_close();
154
 
155
  INPUT26_close();
156
 
157
  return 0;
158
 
159
}
160
 
161
#define SHUTDOWN_TIMEOUT_SEC 3
162
 
163
void call_shutdown_task(void *arg)
164
{
165
  struct timespec t;
166
 
167
  sys_gettime(&t);
168
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
169
 
170
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
171
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
172
 
173
  task_activate(shutdown_task_PID);
174
}
175
 
176
TASK shutdown_task_body(void *arg) {
177
 
178
  device_drivers_close();
179
 
180
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
181
 
1360 giacomo 182
  return NULL;
1394 giacomo 183
 
1151 giacomo 184
}
185