Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1194 giacomo 1
/*
1464 giacomo 2
 * Project: S.Ha.R.K
1194 giacomo 3
 *
1464 giacomo 4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
1194 giacomo 5
 *
6
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
7
 *
1569 tullio 8
 * Authors:
9
 *   ...
10
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
11
 *
1194 giacomo 12
 * http://www.sssup.it
13
 * http://retis.sssup.it
1464 giacomo 14
 * http://hartik.sssup.it
1194 giacomo 15
 */
16
 
1606 tullio 17
/*
18
 * This program is free software; you can redistribute it and/or modify
19
 * it under the terms of the GNU General Public License as published by
20
 * the Free Software Foundation; either version 2 of the License, or
21
 * (at your option) any later version.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
 * GNU General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU General Public License
29
 * along with this program; if not, write to the Free Software
30
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31
 *
32
 */
33
 
1194 giacomo 34
#include "kernel/kern.h"
1552 pj 35
#include "edf/edf/edf.h"
36
#include "cbs/cbs/cbs.h"
37
#include "rr/rr/rr.h"
38
#include "dummy/dummy/dummy.h"
39
#include "intdrive/intdrive/intdrive.h"
1194 giacomo 40
 
1552 pj 41
#include "sem/sem/sem.h"
42
#include "hartport/hartport/hartport.h"
1194 giacomo 43
 
1464 giacomo 44
#include <drivers/shark_linuxc26.h>
45
#include <drivers/shark_input26.h>
46
#include <drivers/shark_keyb26.h>
47
 
48
#define FRAME_BUFFER_DEVICE 0
49
 
1194 giacomo 50
/*+ sysyem tick in us +*/
51
#define TICK 0
52
 
53
/*+ RR tick in us +*/
54
#define RRTICK 10000
55
 
1464 giacomo 56
/*+ Interrupt Server +*/
57
#define INTDRIVE_Q 1000
1569 tullio 58
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1464 giacomo 59
#define INTDRIVE_FLAG 0
60
 
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
 
1194 giacomo 69
TIME __kernel_register_levels__(void *arg)
70
{
71
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1569 tullio 72
  LEVEL EDF_level;
1194 giacomo 73
 
1567 mauro 74
  INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1569 tullio 75
  EDF_level = EDF_register_level(EDF_ENABLE_ALL);
76
  CBS_register_level(CBS_ENABLE_ALL, EDF_level);
1194 giacomo 77
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
78
  dummy_register_level();
79
 
80
  SEM_register_module();
81
 
82
  return TICK;
83
}
84
 
85
TASK __init__(void *arg)
86
{
87
  struct multiboot_info *mb = (struct multiboot_info *)arg;
88
 
89
  HARTPORT_init();
90
 
1464 giacomo 91
  /* Create the shutdown task. It will be activated at RUNLEVEL
92
     SHUTDOWN */
93
  set_shutdown_task();
1213 giacomo 94
 
1464 giacomo 95
  /* Init the drivers */
96
  device_drivers_init();
97
 
98
  /* Set the shutdown task activation */
99
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
100
 
1194 giacomo 101
  __call_main__(mb);
102
 
103
  return (void *)0;
104
}
105
 
1464 giacomo 106
void set_shutdown_task() {
107
 
108
  /* WARNING: the shutdown task is a background thread. It cannot execute
109
              if the system is overloaded */
110
  NRT_TASK_MODEL nrt;
111
 
112
  nrt_task_default_model(nrt);
113
  nrt_task_def_system(nrt);
114
 
115
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
116
  if (shutdown_task_PID == NIL) {
117
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 118
    exit(1);
1464 giacomo 119
  }
120
 
121
}
122
 
123
int device_drivers_init() {
124
 
125
  KEYB_PARMS kparms = BASE_KEYB;
126
 
1567 mauro 127
  LINUXC26_register_module(TRUE);
1464 giacomo 128
 
129
  INPUT26_init();
130
 
1479 giacomo 131
  //keyb_def_ctrlC(kparms, NULL);
1464 giacomo 132
 
133
  KEYB26_init(&kparms);
134
 
135
  return 0;
136
 
137
}
138
 
139
int device_drivers_close() {
140
 
141
  KEYB26_close();
142
 
143
  INPUT26_close();
144
 
145
  return 0;
146
 
147
}
148
 
149
#define SHUTDOWN_TIMEOUT_SEC 3
150
 
151
void call_shutdown_task(void *arg)
152
{
153
  struct timespec t;
154
 
155
  sys_gettime(&t);
156
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
157
 
158
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
159
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
160
 
161
  task_activate(shutdown_task_PID);
162
}
163
 
164
TASK shutdown_task_body(void *arg) {
165
 
166
  device_drivers_close();
167
 
168
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
169
 
170
  return NULL;
171
 
172
}