Subversion Repositories shark

Rev

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