Subversion Repositories shark

Rev

Rev 1567 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1158 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     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
1569 tullio 10
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
1158 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
 ------------
1569 tullio 22
 CVS :        $Id: ern.c,v 1.9 2006-03-09 14:17:03 tullio Exp $
1158 pj 23
 
24
 File:        $File$
1569 tullio 25
 Revision:    $Revision: 1.9 $
26
 Last update: $Date: 2006-03-09 14:17:03 $
1158 pj 27
 ------------
28
**/
29
 
30
/*
31
 * Copyright (C) 2003 Paolo Gai
32
 *
33
 * This program is free software; you can redistribute it and/or modify
34
 * it under the terms of the GNU General Public License as published by
35
 * the Free Software Foundation; either version 2 of the License, or
36
 * (at your option) any later version.
37
 *
38
 * This program is distributed in the hope that it will be useful,
39
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41
 * GNU General Public License for more details.
42
 *
43
 * You should have received a copy of the GNU General Public License
44
 * along with this program; if not, write to the Free Software
45
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
46
 *
47
 */
48
 
49
#include "kernel/kern.h"
1552 pj 50
#include "intdrive/intdrive/intdrive.h"
51
#include "edf/edf/edf.h"
52
#include "rr/rr/rr.h"
53
#include "rrsoft/rrsoft/rrsoft.h"
54
#include "dummy/dummy/dummy.h"
1158 pj 55
 
1552 pj 56
#include "sem/sem/sem.h"
57
#include "hartport/hartport/hartport.h"
58
#include "cabs/cabs/cabs.h"
1158 pj 59
 
1552 pj 60
#include "nop/nop/nop.h"
1380 giacomo 61
 
1381 giacomo 62
#include <drivers/shark_linuxc26.h>
63
#include <drivers/shark_pci26.h>
64
#include <drivers/shark_input26.h>
65
#include <drivers/shark_keyb26.h>
66
#include <drivers/shark_fb26.h>
67
 
68
#define FRAME_BUFFER_DEVICE 0
69
 
70
 
1158 pj 71
/*+ sysyem tick in us +*/
72
#define TICK 0
73
 
74
/*+ RR tick in us +*/
75
#define RRTICK 2000
76
 
1379 giacomo 77
/*+ Interrupt Server +*/
78
#define INTDRIVE_Q 1000
1569 tullio 79
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1379 giacomo 80
#define INTDRIVE_FLAG 0
81
 
1384 giacomo 82
void call_shutdown_task(void *arg);
83
int device_drivers_init();
84
int device_drivers_close();
85
void set_shutdown_task();
86
TASK shutdown_task_body(void *arg);
87
 
1381 giacomo 88
PID shutdown_task_PID = -1;
89
 
1158 pj 90
TIME __kernel_register_levels__(void *arg)
91
{
92
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1569 tullio 93
  LEVEL EDF_level;
1158 pj 94
 
1567 mauro 95
  INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1569 tullio 96
  EDF_level = EDF_register_level(EDF_ENABLE_ALL);
1158 pj 97
  EDF_register_level(EDF_ENABLE_ALL);
98
  RRSOFT_register_level(RRTICK, RR_MAIN_NO, mb, RRSOFT_ONLY_HARD|RRSOFT_ONLY_SOFT);
99
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
100
  dummy_register_level();
101
 
102
  SEM_register_module();
103
 
104
  CABS_register_module();
105
 
1380 giacomo 106
  NOP_register_module();
107
 
1158 pj 108
  return TICK;
109
}
110
 
1384 giacomo 111
TASK __init__(void *arg)
112
{
113
  struct multiboot_info *mb = (struct multiboot_info *)arg;
114
 
115
  HARTPORT_init();
116
 
117
  set_shutdown_task();
118
 
119
  device_drivers_init();
120
 
121
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
122
 
123
  __call_main__(mb);
124
 
125
  return (void *)0;
1381 giacomo 126
}
127
 
1384 giacomo 128
void set_shutdown_task() {
129
 
130
  NRT_TASK_MODEL nrt;
131
 
132
  nrt_task_default_model(nrt);
133
  nrt_task_def_system(nrt);
134
 
135
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
136
  if (shutdown_task_PID == NIL) {
137
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 138
    exit(1);
1384 giacomo 139
  }
140
 
141
}
142
 
1381 giacomo 143
int device_drivers_init() {
144
 
145
  int res;
146
  KEYB_PARMS kparms = BASE_KEYB;
147
 
1567 mauro 148
  LINUXC26_register_module(TRUE);
1381 giacomo 149
 
150
  PCI26_init();
151
 
152
  INPUT26_init();
153
 
154
  keyb_def_ctrlC(kparms, NULL);
155
 
156
  KEYB26_init(&kparms);
157
 
158
  FB26_init();
159
 
160
  res = FB26_open(FRAME_BUFFER_DEVICE);
161
  if (res) {
162
    cprintf("Error: Cannot open graphical mode\n");
163
    KEYB26_close();
164
    INPUT26_close();
1550 pj 165
    exit(1);
1381 giacomo 166
  }                                                                                          
167
 
168
  FB26_use_grx(FRAME_BUFFER_DEVICE);
169
 
170
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
171
 
172
  return 0;
173
 
174
}
175
 
1384 giacomo 176
int device_drivers_close() {
177
 
178
  FB26_close(FRAME_BUFFER_DEVICE);
179
 
180
  KEYB26_close();
181
 
182
  INPUT26_close();
183
 
184
  return 0;
185
 
1381 giacomo 186
}
187
 
1384 giacomo 188
#define SHUTDOWN_TIMEOUT_SEC 3
1381 giacomo 189
 
1384 giacomo 190
void call_shutdown_task(void *arg)
191
{
192
  struct timespec t;
1381 giacomo 193
 
1384 giacomo 194
  sys_gettime(&t);
195
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
1381 giacomo 196
 
1384 giacomo 197
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
198
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
1381 giacomo 199
 
200
  task_activate(shutdown_task_PID);
201
}
202
 
1384 giacomo 203
TASK shutdown_task_body(void *arg) {
1158 pj 204
 
1384 giacomo 205
  device_drivers_close();
1158 pj 206
 
1384 giacomo 207
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
1381 giacomo 208
 
1384 giacomo 209
  return NULL;
1381 giacomo 210
 
1158 pj 211
}
1380 giacomo 212
 
213
void app_mutex_init(mutex_t *m)
214
{
215
  NOP_mutexattr_t attr;
216
 
217
  NOP_mutexattr_default(attr);
218
 
219
  mutex_init(m, &attr);
220
}
221