Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1667 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
 *
8
 * Authors     :
9
 *   Giacomo Guidi       <giacomo@gandalf.sssup.it>
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
 */
1665 pj 18
 
1667 giacomo 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
 */
1665 pj 35
 
36
#include "kernel/kern.h"
1667 giacomo 37
#include "modules/intdrive.h"
1665 pj 38
#include "modules/edf.h"
1667 giacomo 39
#include "modules/hardcbs.h"
1665 pj 40
#include "modules/rr.h"
41
#include "modules/dummy.h"
42
 
43
#include "modules/sem.h"
1667 giacomo 44
#include "modules/pi.h"
1665 pj 45
#include "modules/hartport.h"
46
#include "modules/cabs.h"
47
 
1667 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>
1665 pj 53
 
1667 giacomo 54
#define FRAME_BUFFER_DEVICE 0
1665 pj 55
 
1667 giacomo 56
/*+ sysyem tick in us +*/
1665 pj 57
#define TICK 0
58
 
59
/*+ RR tick in us +*/
60
#define RRTICK 2000
61
 
1667 giacomo 62
/*+ Interrupt Server +*/
63
#define INTDRIVE_Q 1000
64
#define INTDRIVE_T 10000
65
#define INTDRIVE_FLAG 0
66
 
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
 
1665 pj 75
TIME __kernel_register_levels__(void *arg)
76
{
77
  struct multiboot_info *mb = (struct multiboot_info *)arg;
78
 
1667 giacomo 79
  INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG);
80
  EDF_register_level(EDF_ENABLE_ALL);
81
  HCBS_register_level(HCBS_ENABLE_ALL, 1);
1665 pj 82
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
83
  dummy_register_level();
84
 
1667 giacomo 85
  SEM_register_module();
1665 pj 86
  PI_register_module();
87
 
1667 giacomo 88
  CABS_register_module();
89
 
1665 pj 90
  return TICK;
91
}
92
 
93
TASK __init__(void *arg)
94
{
95
  struct multiboot_info *mb = (struct multiboot_info *)arg;
96
 
97
  HARTPORT_init();
98
 
1667 giacomo 99
  /* Create the shutdown task. It will be activated at RUNLEVEL
100
     SHUTDOWN */
101
  set_shutdown_task();
1665 pj 102
 
1667 giacomo 103
  /* Init the drivers */
104
  device_drivers_init();
105
 
106
  /* Set the shutdown task activation */
107
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
108
 
1665 pj 109
  __call_main__(mb);
110
 
111
  return (void *)0;
112
}
113
 
1667 giacomo 114
void set_shutdown_task() {
115
 
116
  /* WARNING: the shutdown task is a background thread. It cannot execute
117
              if the system is overloaded */
118
  NRT_TASK_MODEL nrt;
119
 
120
  nrt_task_default_model(nrt);
121
  nrt_task_def_system(nrt);
122
 
123
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
124
  if (shutdown_task_PID == NIL) {
125
    sys_shutdown_message("Error: Cannot create shutdown task\n");
126
    sys_end();
127
  }
128
 
129
}
130
 
131
int device_drivers_init() {
132
 
133
  int res;
134
  KEYB_PARMS kparms = BASE_KEYB;
135
 
136
  LINUXC26_register_module();
137
 
138
  PCI26_init();
139
 
140
  INPUT26_init();
141
 
142
  keyb_def_ctrlC(kparms, NULL);
143
 
144
  KEYB26_init(&kparms);
145
 
146
  FB26_init();
147
 
148
  res = FB26_open(FRAME_BUFFER_DEVICE);
149
  if (res) {
150
    cprintf("Error: Cannot open graphical mode\n");
151
    KEYB26_close();
152
    INPUT26_close();
153
    sys_end();
154
  }                                                                                          
155
 
156
  FB26_use_grx(FRAME_BUFFER_DEVICE);
157
 
158
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
159
 
160
  return 0;
161
 
162
}
163
 
164
int device_drivers_close() {
165
 
166
  FB26_close(FRAME_BUFFER_DEVICE);
167
 
168
  KEYB26_close();
169
 
170
  INPUT26_close();
171
 
172
  return 0;
173
 
174
}
175
 
176
#define SHUTDOWN_TIMEOUT_SEC 3
177
 
178
void call_shutdown_task(void *arg)
179
{
180
  struct timespec t;
181
 
182
  sys_gettime(&t);
183
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
184
 
185
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
186
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
187
 
188
  task_activate(shutdown_task_PID);
189
}
190
 
191
TASK shutdown_task_body(void *arg) {
192
 
193
  device_drivers_close();
194
 
195
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
196
 
197
  sys_abort_shutdown(0);
198
 
199
  return NULL;
200
 
201
}