Subversion Repositories shark

Rev

Rev 1163 | Rev 1424 | 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"
1423 giacomo 15
#include "modules/hardcbs.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);
59
        HCBS_register_level(HCBS_ENABLE_ALL, 1);
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
/*
120
  FB26_init();
121
 
122
  res = FB26_open(FRAME_BUFFER_DEVICE);
123
  if (res) {
124
    cprintf("Error: Cannot open graphical mode\n");
125
    KEYB26_close();
126
    INPUT26_close();
127
    sys_end();
128
  }                                                                                          
129
 
130
  FB26_use_grx(FRAME_BUFFER_DEVICE);
131
 
132
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
133
*/     
134
  return 0;
135
 
136
}
137
 
138
int device_drivers_close() {
139
/*                                                                                                                            
140
  FB26_close(FRAME_BUFFER_DEVICE);
141
*/                                                                                                                            
142
  KEYB26_close();
143
 
144
  INPUT26_close();
145
 
146
  return 0;
147
 
148
}
149
 
150
#define SHUTDOWN_TIMEOUT_SEC 3
151
 
152
void call_shutdown_task(void *arg)
153
{
154
  struct timespec t;
155
 
156
  sys_gettime(&t);
157
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
158
 
159
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
160
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
161
 
162
  task_activate(shutdown_task_PID);
163
}
164
 
165
TASK shutdown_task_body(void *arg) {
166
 
167
  device_drivers_close();
168
 
169
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
170
 
171
  sys_abort_shutdown(0);
172
 
173
  return NULL;
174
 
175
}