Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1162 tavani 1
/*
1349 giacomo 2
 * Project: S.Ha.R.K
1162 tavani 3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *
6
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
7
 *
1569 tullio 8
 * Authors:
9
 *   ...
10
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
11
 *
1162 tavani 12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
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
 
1162 tavani 34
#include "kernel/kern.h"
1552 pj 35
#include "edf/edf/edf.h"
36
#include "hardcbs/hardcbs/hardcbs.h"
37
#include "rr/rr/rr.h"
38
#include "dummy/dummy/dummy.h"
39
#include "intdrive/intdrive/intdrive.h"
1162 tavani 40
 
1552 pj 41
#include "sem/sem/sem.h"
42
#include "hartport/hartport/hartport.h"
1349 giacomo 43
 
1392 giacomo 44
#include <drivers/shark_linuxc26.h>
45
#include <drivers/shark_pci26.h>
46
#include <drivers/shark_input26.h>
47
#include <drivers/shark_keyb26.h>
48
#include <drivers/shark_fb26.h>
49
 
50
#define FRAME_BUFFER_DEVICE 0
51
 
1162 tavani 52
/*+ sysyem tick in us +*/
1349 giacomo 53
#define TICK 0
1162 tavani 54
 
55
/*+ RR tick in us +*/
1349 giacomo 56
#define RRTICK 10000
1162 tavani 57
 
1349 giacomo 58
/*+ Interrup Server */
59
#define INTDRIVE_Q 1000
1569 tullio 60
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1349 giacomo 61
#define INTDRIVE_FLAG 0
62
 
1392 giacomo 63
void call_shutdown_task(void *arg);
64
int device_drivers_init();
65
int device_drivers_close();
66
void set_shutdown_task();
67
TASK shutdown_task_body(void *arg);
68
 
69
PID shutdown_task_PID = -1;
70
 
1162 tavani 71
TIME __kernel_register_levels__(void *arg)
72
{
73
        struct multiboot_info *mb = (struct multiboot_info *)arg;
1569 tullio 74
        LEVEL EDF_level;
1162 tavani 75
 
1567 mauro 76
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1569 tullio 77
        EDF_level = EDF_register_level(EDF_ENABLE_ALL);
78
        HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
1162 tavani 79
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
80
        dummy_register_level();
81
 
82
        SEM_register_module();
83
 
84
        return TICK;
85
}
86
 
87
TASK __init__(void *arg)
88
{
1392 giacomo 89
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1162 tavani 90
 
1392 giacomo 91
  HARTPORT_init();
1162 tavani 92
 
1392 giacomo 93
  set_shutdown_task();
1162 tavani 94
 
1392 giacomo 95
  device_drivers_init();
96
 
97
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
98
 
99
  __call_main__(mb);
100
 
101
  return (void *)0;
1162 tavani 102
}
1392 giacomo 103
 
104
void set_shutdown_task() {
105
 
106
  NRT_TASK_MODEL nrt;
107
 
108
  nrt_task_default_model(nrt);
109
  nrt_task_def_system(nrt);
110
 
111
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
112
  if (shutdown_task_PID == NIL) {
113
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 114
    exit(1);
1392 giacomo 115
  }
116
 
117
}
118
 
119
int device_drivers_init() {
120
 
121
  int res;
122
  KEYB_PARMS kparms = BASE_KEYB;
123
 
1567 mauro 124
  LINUXC26_register_module(TRUE);
1392 giacomo 125
 
126
  PCI26_init();
127
 
128
  INPUT26_init();
129
 
130
  keyb_def_ctrlC(kparms, NULL);
131
 
132
  KEYB26_init(&kparms);
133
 
134
  FB26_init();
135
 
136
  res = FB26_open(FRAME_BUFFER_DEVICE);
137
  if (res) {
138
    cprintf("Error: Cannot open graphical mode\n");
139
    KEYB26_close();
140
    INPUT26_close();
1550 pj 141
    exit(1);
1392 giacomo 142
  }                                                                                          
143
 
144
  FB26_use_grx(FRAME_BUFFER_DEVICE);
145
 
146
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
147
 
148
  return 0;
149
 
150
}
151
 
152
int device_drivers_close() {
153
 
154
  FB26_close(FRAME_BUFFER_DEVICE);
155
 
156
  KEYB26_close();
157
 
158
  INPUT26_close();
159
 
160
  return 0;
161
 
162
}
163
 
164
#define SHUTDOWN_TIMEOUT_SEC 3
165
 
166
void call_shutdown_task(void *arg)
167
{
168
  struct timespec t;
169
 
170
  sys_gettime(&t);
171
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
172
 
173
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
174
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
175
 
176
  task_activate(shutdown_task_PID);
177
}
178
 
179
TASK shutdown_task_body(void *arg) {
180
 
181
  device_drivers_close();
182
 
183
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
184
 
185
  return NULL;
186
 
187
}