Subversion Repositories shark

Rev

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