Subversion Repositories shark

Rev

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

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