Subversion Repositories shark

Rev

Rev 1547 | Rev 1567 | Go to most recent revision | 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
 * Copyright (C) 2000 Paolo Gai
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 "rr/rr/rr.h"
42
#include "tbs/tbs/tbs.h"
43
#include "cbs/cbs/cbs.h"
44
#include "rrsoft/rrsoft/rrsoft.h"
45
#include "dummy/dummy/dummy.h"
46
#include "sem/sem/sem.h"
47
#include "hartport/hartport/hartport.h"
1120 pj 48
 
49
/*+ sysyem tick in us +*/
50
#define TICK 0
51
 
52
#define RRTICK    5000
53
#define TBS_NUM      1
54
#define TBS_DEN     10
55
 
1377 giacomo 56
/*+ Interrupt Server +*/
57
#define INTDRIVE_Q 1000
58
#define INTDRIVE_T 10000
59
#define INTDRIVE_FLAG 0
1120 pj 60
 
1388 giacomo 61
#include <drivers/shark_linuxc26.h>
62
#include <drivers/shark_input26.h>
63
#include <drivers/shark_keyb26.h>
1377 giacomo 64
 
1388 giacomo 65
#define FRAME_BUFFER_DEVICE 0
66
 
67
void call_shutdown_task(void *arg);
68
int device_drivers_init();
69
int device_drivers_close();
70
void set_shutdown_task();
71
TASK shutdown_task_body(void *arg);
72
 
1463 giacomo 73
PID shutdown_task_PID = -1;
1388 giacomo 74
 
1120 pj 75
TIME __kernel_register_levels__(void *arg)
76
{
77
  struct multiboot_info *mb = (struct multiboot_info *)arg;
78
 
1377 giacomo 79
  INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG);
1120 pj 80
  EDF_register_level(EDF_ENABLE_ALL);
81
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
1377 giacomo 82
  TBS_register_level(TBS_ENABLE_ALL, 1, TBS_NUM, TBS_DEN);
83
  TBS_register_level(TBS_ENABLE_ALL, 1, TBS_NUM*3, TBS_DEN);
84
  CBS_register_level(CBS_ENABLE_ALL, 1);
1120 pj 85
 
86
  dummy_register_level();
87
 
88
  SEM_register_module();
89
 
90
  return TICK;
91
}
92
 
93
TASK __init__(void *arg)
94
{
95
  struct multiboot_info *mb = (struct multiboot_info *)arg;
96
 
97
  HARTPORT_init();
98
 
1388 giacomo 99
  /* Create the shutdown task. It will be activated at RUNLEVEL
100
     SHUTDOWN */
101
  set_shutdown_task();
102
 
103
  /* Init the drivers */
104
  device_drivers_init();
105
 
106
  /* Set the shutdown task activation */
107
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
108
 
1120 pj 109
  __call_main__(mb);
110
 
111
  return (void *)0;
112
}
113
 
1388 giacomo 114
void set_shutdown_task() {
115
 
116
  /* WARNING: the shutdown task is a background thread. It cannot execute
117
              if the system is overloaded */
118
  NRT_TASK_MODEL nrt;
119
 
120
  nrt_task_default_model(nrt);
121
  nrt_task_def_system(nrt);
122
 
123
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
124
  if (shutdown_task_PID == NIL) {
125
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1547 pj 126
    exit(1);
1388 giacomo 127
  }
128
 
129
}
130
 
131
int device_drivers_init() {
132
 
133
  KEYB_PARMS kparms = BASE_KEYB;
134
 
135
  LINUXC26_register_module();
136
 
137
  INPUT26_init();
138
 
139
  keyb_def_ctrlC(kparms, NULL);
140
 
141
  KEYB26_init(&kparms);
142
 
143
  return 0;
144
 
145
}
146
 
147
int device_drivers_close() {
148
 
149
  KEYB26_close();
150
 
151
  INPUT26_close();
152
 
153
  return 0;
154
 
155
}
156
 
157
#define SHUTDOWN_TIMEOUT_SEC 3
158
 
159
void call_shutdown_task(void *arg)
160
{
161
  struct timespec t;
162
 
163
  sys_gettime(&t);
164
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
165
 
166
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
167
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
168
 
169
  task_activate(shutdown_task_PID);
170
}
171
 
172
TASK shutdown_task_body(void *arg) {
173
 
174
  device_drivers_close();
175
 
176
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
177
 
178
  return NULL;
179
 
180
}