Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1498 mauro 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>
1569 tullio 10
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
1498 mauro 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"
1498 mauro 42
 
1552 pj 43
#include "sem/sem/sem.h"
44
#include "hartport/hartport/hartport.h"
45
#include "cabs/cabs/cabs.h"
1498 mauro 46
 
47
#include "drivers/shark_linuxc26.h"
48
#include "drivers/shark_input26.h"
49
#include "drivers/shark_keyb26.h"
50
 
51
#include <drivers/shark_cpu26.h>
52
 
53
/*+ sysyem tick in us +*/
54
#define TICK 0
55
 
56
/*+ RR tick in us +*/
57
#define RRTICK 10000
58
 
59
/*+ IntDrive Server +*/
60
#define INTDRIVE_Q 1000
1569 tullio 61
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
62
#define INTDRIVE_FLAG 0
1498 mauro 63
 
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
 
72
TIME __kernel_register_levels__(void *arg)
73
{
74
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1569 tullio 75
  LEVEL EDF_level;
1498 mauro 76
 
1569 tullio 77
  INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
78
  EDF_level = EDF_register_level(EDF_ENABLE_ALL);
79
  HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
1498 mauro 80
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
81
  dummy_register_level();
82
 
83
  SEM_register_module();
84
 
85
  CABS_register_module();
86
 
87
  return TICK;
88
}
89
 
90
TASK __init__(void *arg)
91
{
92
  struct multiboot_info *mb = (struct multiboot_info *)arg;
93
 
94
  HARTPORT_init();
95
 
96
  /* Create the shutdown task. It will be activated at RUNLEVEL
97
     SHUTDOWN */
98
  set_shutdown_task();
99
 
100
  /* Init the drivers */
101
  device_drivers_init();
102
 
103
  /* Set the shutdown task activation */
104
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
105
 
106
  //sys_set_reboot(EXIT_MODE_HALT);
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");
1550 pj 125
    exit(1);
1498 mauro 126
  }
127
 
128
}
129
 
130
int device_drivers_init() {
131
 
132
  KEYB_PARMS kparms = BASE_KEYB;
133
 
1567 mauro 134
  LINUXC26_register_module(TRUE);
1498 mauro 135
 
136
  CPU26_init();
137
 
1513 giacomo 138
  CPU26_DVS_init();
1498 mauro 139
 
140
  INPUT26_init();
141
 
142
  keyb_def_ctrlC(kparms, NULL);
143
 
144
  KEYB26_init(&kparms);
145
 
146
  return 0;
147
 
148
}
149
 
150
int device_drivers_close() {
151
 
1513 giacomo 152
  //CPU26_DVS_close();
1498 mauro 153
 
154
  KEYB26_close();
155
 
156
  INPUT26_close();
157
 
158
  return 0;
159
 
160
}
161
 
162
#define SHUTDOWN_TIMEOUT_SEC 3
163
 
164
void call_shutdown_task(void *arg)
165
{
166
  struct timespec t;
167
 
168
  sys_gettime(&t);
169
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
170
 
171
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
172
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
173
 
174
  task_activate(shutdown_task_PID);
175
}
176
 
177
TASK shutdown_task_body(void *arg) {
178
 
179
  device_drivers_close();
180
 
181
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
182
 
183
  return NULL;
184
 
185
}
186