Subversion Repositories shark

Rev

Rev 1431 | Rev 1512 | 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 +*/
1483 giacomo 51
#define TICK 0
1151 giacomo 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);
1429 mauro 101
 
1431 mauro 102
  //sys_set_reboot(EXIT_MODE_HALT);
1394 giacomo 103
 
1151 giacomo 104
  __call_main__(mb);
105
 
1394 giacomo 106
  return (void *)0;
107
}
108
 
109
void set_shutdown_task() {
110
 
111
  /* WARNING: the shutdown task is a background thread. It cannot execute
112
              if the system is overloaded */
113
  NRT_TASK_MODEL nrt;
114
 
115
  nrt_task_default_model(nrt);
116
  nrt_task_def_system(nrt);
117
 
118
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
119
  if (shutdown_task_PID == NIL) {
120
    sys_shutdown_message("Error: Cannot create shutdown task\n");
121
    sys_end();
122
  }
123
 
124
}
125
 
126
int device_drivers_init() {
127
 
128
  KEYB_PARMS kparms = BASE_KEYB;
129
 
130
  LINUXC26_register_module();
131
 
132
  INPUT26_init();
133
 
134
  keyb_def_ctrlC(kparms, NULL);
135
 
136
  KEYB26_init(&kparms);
137
 
138
  return 0;
139
 
140
}
141
 
142
int device_drivers_close() {
143
 
144
  KEYB26_close();
145
 
146
  INPUT26_close();
147
 
148
  return 0;
149
 
150
}
151
 
152
#define SHUTDOWN_TIMEOUT_SEC 3
153
 
154
void call_shutdown_task(void *arg)
155
{
156
  struct timespec t;
157
 
158
  sys_gettime(&t);
159
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
160
 
161
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
162
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
163
 
164
  task_activate(shutdown_task_PID);
165
}
166
 
167
TASK shutdown_task_body(void *arg) {
168
 
169
  device_drivers_close();
170
 
171
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
172
 
173
  sys_abort_shutdown(0);
174
 
1360 giacomo 175
  return NULL;
1394 giacomo 176
 
1151 giacomo 177
}
178