Subversion Repositories shark

Rev

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

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