Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1085 pj 1
/*
1377 giacomo 2
 * Project: S.Ha.R.K
1085 pj 3
 *
1377 giacomo 4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
1085 pj 5
 *
6
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
7
 *
1569 tullio 8
 * Authors:
9
 *   ...
10
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
11
 *
1085 pj 12
 * http://www.sssup.it
13
 * http://retis.sssup.it
1377 giacomo 14
 * http://hartik.sssup.it
1085 pj 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
 
1085 pj 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"
1085 pj 40
 
1552 pj 41
#include "sem/sem/sem.h"
42
#include "hartport/hartport/hartport.h"
1085 pj 43
 
1552 pj 44
#include "pi/pi/pi.h"
45
#include "pc/pc/pc.h"
46
#include "srp/srp/srp.h"
47
#include "npp/npp/npp.h"
48
#include "nop/nop/nop.h"
1388 giacomo 49
 
1382 giacomo 50
#include <drivers/shark_linuxc26.h>
51
#include <drivers/shark_input26.h>
52
#include <drivers/shark_keyb26.h>
53
 
54
#define FRAME_BUFFER_DEVICE 0
55
 
1085 pj 56
/*+ sysyem tick in us +*/
57
#define TICK 0
58
 
59
/*+ RR tick in us +*/
60
#define RRTICK 10000
61
 
1377 giacomo 62
/*+ Interrupt Server +*/
63
#define INTDRIVE_Q 1000
1569 tullio 64
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1377 giacomo 65
#define INTDRIVE_FLAG 0
66
 
1387 giacomo 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;
1382 giacomo 74
 
1085 pj 75
TIME __kernel_register_levels__(void *arg)
76
{
1387 giacomo 77
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1569 tullio 78
  LEVEL EDF_level;
1085 pj 79
 
1567 mauro 80
  INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1569 tullio 81
  EDF_level = EDF_register_level(EDF_ENABLE_ALL);
82
  CBS_register_level(CBS_ENABLE_ALL, EDF_level);
1387 giacomo 83
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
84
  dummy_register_level();
1085 pj 85
 
1387 giacomo 86
  SEM_register_module();
1085 pj 87
 
1388 giacomo 88
  PI_register_module();
89
  PC_register_module();
90
  NPP_register_module();
91
  SRP_register_module();
92
  NOP_register_module();
93
 
1387 giacomo 94
  return TICK;
1085 pj 95
}
96
 
1387 giacomo 97
TASK __init__(void *arg)
98
{
99
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1382 giacomo 100
 
1387 giacomo 101
  HARTPORT_init();
1382 giacomo 102
 
1387 giacomo 103
  /* Create the shutdown task. It will be activated at RUNLEVEL
104
     SHUTDOWN */
105
  set_shutdown_task();
1382 giacomo 106
 
1387 giacomo 107
  /* Init the drivers */
108
  device_drivers_init();
1382 giacomo 109
 
1387 giacomo 110
  /* Set the shutdown task activation */
111
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
1382 giacomo 112
 
1387 giacomo 113
  __call_main__(mb);
1382 giacomo 114
 
1387 giacomo 115
  return (void *)0;
1382 giacomo 116
}
117
 
1387 giacomo 118
void set_shutdown_task() {
1382 giacomo 119
 
1387 giacomo 120
  /* WARNING: the shutdown task is a background thread. It cannot execute
121
              if the system is overloaded */
122
  NRT_TASK_MODEL nrt;
1382 giacomo 123
 
1387 giacomo 124
  nrt_task_default_model(nrt);
125
  nrt_task_def_system(nrt);
1382 giacomo 126
 
1387 giacomo 127
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
128
  if (shutdown_task_PID == NIL) {
129
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1547 pj 130
    exit(1);
1387 giacomo 131
  }
1382 giacomo 132
 
133
}
134
 
1387 giacomo 135
int device_drivers_init() {
1382 giacomo 136
 
1387 giacomo 137
  KEYB_PARMS kparms = BASE_KEYB;
138
 
1567 mauro 139
  LINUXC26_register_module(TRUE);
1382 giacomo 140
 
1387 giacomo 141
  INPUT26_init();
1382 giacomo 142
 
1387 giacomo 143
  keyb_def_ctrlC(kparms, NULL);
1382 giacomo 144
 
1387 giacomo 145
  KEYB26_init(&kparms);
1382 giacomo 146
 
1387 giacomo 147
  return 0;
1382 giacomo 148
 
1387 giacomo 149
}
1382 giacomo 150
 
1387 giacomo 151
int device_drivers_close() {
152
 
153
  KEYB26_close();
154
 
155
  INPUT26_close();
156
 
157
  return 0;
158
 
1382 giacomo 159
}
160
 
1387 giacomo 161
#define SHUTDOWN_TIMEOUT_SEC 3
162
 
163
void call_shutdown_task(void *arg)
1085 pj 164
{
1387 giacomo 165
  struct timespec t;
1085 pj 166
 
1387 giacomo 167
  sys_gettime(&t);
168
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
1085 pj 169
 
1387 giacomo 170
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
171
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
1382 giacomo 172
 
1387 giacomo 173
  task_activate(shutdown_task_PID);
174
}
1382 giacomo 175
 
1387 giacomo 176
TASK shutdown_task_body(void *arg) {
1382 giacomo 177
 
1387 giacomo 178
  device_drivers_close();
1085 pj 179
 
1387 giacomo 180
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
181
 
182
  return NULL;
183
 
1085 pj 184
}