Subversion Repositories shark

Rev

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