Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1085 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     :
1451 giacomo 9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
1569 tullio 10
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
1085 pj 11
 *   (see the web pages for full authors list)
12
 *
13
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
14
 *
15
 * http://www.sssup.it
16
 * http://retis.sssup.it
17
 * http://shark.sssup.it
18
 */
19
 
20
/*
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 *
35
 */
36
 
37
#include "kernel/kern.h"
1552 pj 38
#include "intdrive/intdrive/intdrive.h"
39
#include "edf/edf/edf.h"
40
#include "hardcbs/hardcbs/hardcbs.h"
41
#include "rr/rr/rr.h"
42
#include "dummy/dummy/dummy.h"
1085 pj 43
 
1552 pj 44
#include "sem/sem/sem.h"
45
#include "hartport/hartport/hartport.h"
46
#include "cabs/cabs/cabs.h"
1085 pj 47
 
1451 giacomo 48
#include <drivers/shark_linuxc26.h>
49
#include <drivers/shark_pci26.h>
50
#include <drivers/shark_input26.h>
51
#include <drivers/shark_keyb26.h>
52
#include <drivers/shark_fb26.h>
1085 pj 53
 
1451 giacomo 54
#define FRAME_BUFFER_DEVICE 0
1085 pj 55
 
56
/*+ sysyem tick in us +*/
57
#define TICK 0
58
 
59
/*+ RR tick in us +*/
1451 giacomo 60
#define RRTICK 2000
1085 pj 61
 
1451 giacomo 62
/*+ Interrupt Server +*/
63
#define INTDRIVE_Q 1000
1569 tullio 64
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1451 giacomo 65
#define INTDRIVE_FLAG 0
1085 pj 66
 
1451 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
 
73
PID shutdown_task_PID = -1;
74
 
1085 pj 75
TIME __kernel_register_levels__(void *arg)
76
{
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
  HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
1085 pj 83
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
84
  dummy_register_level();
85
 
86
  SEM_register_module();
87
  CABS_register_module();
88
 
1451 giacomo 89
  //read_file();
1085 pj 90
 
91
  return TICK;
92
}
93
 
94
TASK __init__(void *arg)
95
{
96
  struct multiboot_info *mb = (struct multiboot_info *)arg;
97
 
98
  HARTPORT_init();
99
 
1451 giacomo 100
  /* Create the shutdown task. It will be activated at RUNLEVEL
101
     SHUTDOWN */
102
  set_shutdown_task();
1085 pj 103
 
1451 giacomo 104
  /* Init the drivers */
105
  device_drivers_init();
106
 
107
  /* Set the shutdown task activation */
108
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
109
 
1085 pj 110
  __call_main__(mb);
111
 
112
  return (void *)0;
113
}
114
 
1451 giacomo 115
void set_shutdown_task() {
116
 
117
  /* WARNING: the shutdown task is a background thread. It cannot execute
118
              if the system is overloaded */
119
  NRT_TASK_MODEL nrt;
120
 
121
  nrt_task_default_model(nrt);
122
  nrt_task_def_system(nrt);
123
 
124
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
125
  if (shutdown_task_PID == NIL) {
126
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 127
    exit(1);
1451 giacomo 128
  }
129
 
130
}
131
 
132
int device_drivers_init() {
133
 
134
  int res;
135
  KEYB_PARMS kparms = BASE_KEYB;
136
 
1567 mauro 137
  LINUXC26_register_module(TRUE);
1451 giacomo 138
 
139
  PCI26_init();
140
 
141
  INPUT26_init();
142
 
143
  keyb_def_ctrlC(kparms, NULL);
144
 
145
  KEYB26_init(&kparms);
146
 
147
  FB26_init();
148
 
149
  res = FB26_open(FRAME_BUFFER_DEVICE);
150
  if (res) {
151
    cprintf("Error: Cannot open graphical mode\n");
152
    KEYB26_close();
153
    INPUT26_close();
1550 pj 154
    exit(1);
1451 giacomo 155
  }                                                                                          
156
 
157
  FB26_use_grx(FRAME_BUFFER_DEVICE);
158
 
159
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
160
 
161
  return 0;
162
 
163
}
164
 
165
int device_drivers_close() {
166
 
167
  FB26_close(FRAME_BUFFER_DEVICE);
168
 
169
  KEYB26_close();
170
 
171
  INPUT26_close();
172
 
173
  return 0;
174
 
175
}
176
 
177
#define SHUTDOWN_TIMEOUT_SEC 3
178
 
179
void call_shutdown_task(void *arg)
180
{
181
  struct timespec t;
182
 
183
  sys_gettime(&t);
184
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
185
 
186
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
187
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
188
 
189
  task_activate(shutdown_task_PID);
190
}
191
 
192
TASK shutdown_task_body(void *arg) {
193
 
194
  device_drivers_close();
195
 
196
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
197
 
198
  return NULL;
199
 
200
}