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
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
 
17
#include "kernel/kern.h"
1552 pj 18
#include "edf/edf/edf.h"
19
#include "cbs/cbs/cbs.h"
20
#include "rr/rr/rr.h"
21
#include "dummy/dummy/dummy.h"
22
#include "intdrive/intdrive/intdrive.h"
1163 giacomo 23
 
1552 pj 24
#include "sem/sem/sem.h"
25
#include "hartport/hartport/hartport.h"
1163 giacomo 26
 
1423 giacomo 27
#include <drivers/shark_linuxc26.h>
28
#include <drivers/shark_pci26.h>
29
#include <drivers/shark_input26.h>
30
#include <drivers/shark_keyb26.h>
31
#include <drivers/shark_fb26.h>
32
#include <drivers/shark_i2c26.h>
33
#include <drivers/shark_bttv26.h>
34
#include <drivers/shark_videodev26.h>
1163 giacomo 35
 
1423 giacomo 36
#define FRAME_BUFFER_DEVICE 0
1428 giacomo 37
#define FRAME_GRABBER_DEVICE 0
1163 giacomo 38
 
39
/*+ sysyem tick in us +*/
1423 giacomo 40
#define TICK 0
1163 giacomo 41
 
42
/*+ RR tick in us +*/
43
#define RRTICK 10000
44
 
1423 giacomo 45
/*+ Interrup Server */
46
#define INTDRIVE_Q 1000
1569 tullio 47
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1423 giacomo 48
#define INTDRIVE_FLAG 0
49
 
50
void call_shutdown_task(void *arg);
51
int device_drivers_init();
52
int device_drivers_close();
53
void set_shutdown_task();
54
TASK shutdown_task_body(void *arg);
55
 
56
PID shutdown_task_PID = -1;
57
 
1163 giacomo 58
TIME __kernel_register_levels__(void *arg)
59
{
1423 giacomo 60
        struct multiboot_info *mb = (struct multiboot_info *)arg;
1569 tullio 61
        LEVEL EDF_level;
1163 giacomo 62
 
1567 mauro 63
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1569 tullio 64
        EDF_level = EDF_register_level(EDF_ENABLE_ALL);
65
        CBS_register_level(CBS_ENABLE_ALL, EDF_level);
1423 giacomo 66
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
67
        dummy_register_level();
1163 giacomo 68
 
1423 giacomo 69
        SEM_register_module();
1163 giacomo 70
 
1423 giacomo 71
        return TICK;
1163 giacomo 72
}
73
 
74
TASK __init__(void *arg)
75
{
76
  struct multiboot_info *mb = (struct multiboot_info *)arg;
77
 
78
  HARTPORT_init();
79
 
1423 giacomo 80
  set_shutdown_task();
1163 giacomo 81
 
1423 giacomo 82
  device_drivers_init();
83
 
84
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
85
 
1163 giacomo 86
  __call_main__(mb);
87
 
88
  return (void *)0;
89
}
90
 
1423 giacomo 91
void set_shutdown_task() {
92
 
93
  NRT_TASK_MODEL nrt;
94
 
95
  nrt_task_default_model(nrt);
96
  nrt_task_def_system(nrt);
97
 
98
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
99
  if (shutdown_task_PID == NIL) {
100
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 101
    exit(1);
1423 giacomo 102
  }
103
 
104
}
105
 
106
int device_drivers_init() {
107
 
108
  int res;
109
  KEYB_PARMS kparms = BASE_KEYB;
110
 
1567 mauro 111
  LINUXC26_register_module(TRUE);
1423 giacomo 112
 
113
  PCI26_init();
114
 
115
  I2C26_init();
116
 
117
  INPUT26_init();
118
 
119
  keyb_def_ctrlC(kparms, NULL);
120
 
121
  KEYB26_init(&kparms);
122
 
1432 giacomo 123
  BTTV26_init();
124
 
1428 giacomo 125
  FB26_init();
1423 giacomo 126
 
127
  res = FB26_open(FRAME_BUFFER_DEVICE);
128
  if (res) {
129
    cprintf("Error: Cannot open graphical mode\n");
130
    KEYB26_close();
131
    INPUT26_close();
1550 pj 132
    exit(1);
1423 giacomo 133
  }                                                                                          
134
 
135
  FB26_use_grx(FRAME_BUFFER_DEVICE);
136
 
137
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
1485 giacomo 138
 
1423 giacomo 139
  return 0;
140
 
141
}
142
 
143
int device_drivers_close() {
1475 giacomo 144
 
1432 giacomo 145
  BTTV26_close();
146
 
1423 giacomo 147
  FB26_close(FRAME_BUFFER_DEVICE);
1475 giacomo 148
 
1423 giacomo 149
  KEYB26_close();
150
 
151
  INPUT26_close();
152
 
153
  return 0;
154
 
155
}
156
 
157
#define SHUTDOWN_TIMEOUT_SEC 3
158
 
159
void call_shutdown_task(void *arg)
160
{
161
  struct timespec t;
162
 
163
  sys_gettime(&t);
164
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
165
 
166
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
167
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
168
 
169
  task_activate(shutdown_task_PID);
170
}
171
 
172
TASK shutdown_task_body(void *arg) {
173
 
174
  device_drivers_close();
175
 
176
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
177
 
178
  return NULL;
179
 
180
}