Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1120 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>
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
 ------------
1584 tullio 21
 CVS :        $Id: iaster7.c,v 1.8 2006-07-03 12:57:33 tullio Exp $
1120 pj 22
 
23
 File:        $File$
1584 tullio 24
 Revision:    $Revision: 1.8 $
25
 Last update: $Date: 2006-07-03 12:57:33 $
1120 pj 26
 ------------
27
 
28
 System initialization file
29
 
30
 The tick is set to TICK ms.
31
 
32
 This file contains the 2 functions needed to initialize the system.
33
 
34
 These functions register a set of scheduling modules, in a fixed or
35
 dynamic priority way...
36
 
37
 It can accept these task models:
38
 
39
 HARD_TASK_MODEL (wcet+mit) at level 0
40
 SOFT_TASK_MODEL (periodicity=APERIODIC) at level 1
41
 NRT_TASK_MODEL  at level 2
42
 SOFT_TASK_MODEL (periodicity=APERIODIC, wcet (only if TBS) ) at level 3,4
43
 
44
**/
45
 
46
/*
47
 * Copyright (C) 2000 Paolo Gai
48
 *
49
 * This program is free software; you can redistribute it and/or modify
50
 * it under the terms of the GNU General Public License as published by
51
 * the Free Software Foundation; either version 2 of the License, or
52
 * (at your option) any later version.
53
 *
54
 * This program is distributed in the hope that it will be useful,
55
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
56
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57
 * GNU General Public License for more details.
58
 *
59
 * You should have received a copy of the GNU General Public License
60
 * along with this program; if not, write to the Free Software
61
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
62
 *
63
 */
64
 
65
 
66
 
67
#include "kernel/kern.h"
1552 pj 68
#include "intdrive/intdrive/intdrive.h"
69
#include "edf/edf/edf.h"
70
#include "tbs/tbs/tbs.h"
1120 pj 71
 
1552 pj 72
#include "rm/rm/rm.h"
73
#include "rr/rr/rr.h"
74
#include "ps/ps/ps.h"
1120 pj 75
 
1552 pj 76
#include "dummy/dummy/dummy.h"
1120 pj 77
 
1552 pj 78
#include "sem/sem/sem.h"
1120 pj 79
 
1393 giacomo 80
#include <drivers/shark_linuxc26.h>
81
#include <drivers/shark_input26.h>
82
#include <drivers/shark_keyb26.h>
83
 
1120 pj 84
/*+ sysyem tick in us +*/
1377 giacomo 85
#define TICK      0
1120 pj 86
 
1377 giacomo 87
#define RRTICK    10000
1120 pj 88
 
1377 giacomo 89
/*+ Interrupt Server +*/
90
#define INTDRIVE_Q 1000
1584 tullio 91
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1377 giacomo 92
#define INTDRIVE_FLAG 0
1120 pj 93
 
1393 giacomo 94
void call_shutdown_task(void *arg);
95
int device_drivers_init();
96
int device_drivers_close();
97
void set_shutdown_task();
98
TASK shutdown_task_body(void *arg);
99
 
1463 giacomo 100
PID shutdown_task_PID = -1;
1393 giacomo 101
 
1120 pj 102
TIME __kernel_register_levels__(void *arg)
103
{
104
  struct multiboot_info *mb = (struct multiboot_info *)arg;
105
 
1567 mauro 106
  INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1120 pj 107
  RM_register_level(RM_ENABLE_ALL);
1377 giacomo 108
  PS_register_level(PS_ENABLE_ALL_RM,1,1000,100000);
1120 pj 109
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
1377 giacomo 110
  PS_register_level(4,1,10000,100000);
111
  PS_register_level(4,1,30000,100000);
1120 pj 112
 
113
  dummy_register_level();
114
 
115
  SEM_register_module();
116
 
117
  return TICK;
118
}
119
 
120
TASK __init__(void *arg)
121
{
122
  struct multiboot_info *mb = (struct multiboot_info *)arg;
123
 
1393 giacomo 124
  /* Create the shutdown task. It will be activated at RUNLEVEL
125
     SHUTDOWN */
126
  set_shutdown_task();
127
 
128
  /* Init the drivers */
129
  device_drivers_init();
130
 
131
  /* Set the shutdown task activation */
132
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
133
 
1120 pj 134
  __call_main__(mb);
135
 
136
  return (void *)0;
137
}
138
 
1393 giacomo 139
void set_shutdown_task() {
140
 
141
  /* WARNING: the shutdown task is a background thread. It cannot execute
142
              if the system is overloaded */
143
  NRT_TASK_MODEL nrt;
144
 
145
  nrt_task_default_model(nrt);
146
  nrt_task_def_system(nrt);
147
 
148
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
149
  if (shutdown_task_PID == NIL) {
150
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1547 pj 151
    exit(1);
1393 giacomo 152
  }
153
 
154
}
155
 
156
int device_drivers_init() {
157
 
158
  KEYB_PARMS kparms = BASE_KEYB;
159
 
1567 mauro 160
  LINUXC26_register_module(TRUE);
1393 giacomo 161
 
162
  INPUT26_init();
163
 
164
  keyb_def_ctrlC(kparms, NULL);
165
 
166
  KEYB26_init(&kparms);
167
 
168
  return 0;
169
 
170
}
171
 
172
int device_drivers_close() {
173
 
174
  KEYB26_close();
175
 
176
  INPUT26_close();
177
 
178
  return 0;
179
 
180
}
181
 
182
#define SHUTDOWN_TIMEOUT_SEC 3
183
 
184
void call_shutdown_task(void *arg)
185
{
186
  struct timespec t;
187
 
188
  sys_gettime(&t);
189
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
190
 
191
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
192
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
193
 
194
  task_activate(shutdown_task_PID);
195
}
196
 
197
TASK shutdown_task_body(void *arg) {
198
 
199
  device_drivers_close();
200
 
201
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
202
 
203
  return NULL;
204
 
205
}
206
 
207
 
208
 
209