Subversion Repositories shark

Rev

Rev 1567 | Rev 1579 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1162 tavani 1
/*
1349 giacomo 2
 * Project: S.Ha.R.K
1162 tavani 3
 *
4
 * Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
5
 *
6
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
7
 *
1569 tullio 8
 * Authors:
9
 *   ...
10
 *   Tullio Facchinetti  <tullio.facchinetti@unipv.it>
11
 *
1162 tavani 12
 * http://www.sssup.it
13
 * http://retis.sssup.it
14
 * http://hartik.sssup.it
15
 */
16
 
17
#include "kernel/kern.h"
1552 pj 18
#include "edf/edf/edf.h"
19
#include "hardcbs/hardcbs/hardcbs.h"
20
#include "rr/rr/rr.h"
21
#include "dummy/dummy/dummy.h"
22
#include "intdrive/intdrive/intdrive.h"
1162 tavani 23
 
1552 pj 24
#include "sem/sem/sem.h"
25
#include "hartport/hartport/hartport.h"
1349 giacomo 26
 
1392 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
 
33
#define FRAME_BUFFER_DEVICE 0
34
 
1162 tavani 35
/*+ sysyem tick in us +*/
1349 giacomo 36
#define TICK 0
1162 tavani 37
 
38
/*+ RR tick in us +*/
1349 giacomo 39
#define RRTICK 10000
1162 tavani 40
 
1349 giacomo 41
/*+ Interrup Server */
42
#define INTDRIVE_Q 1000
1569 tullio 43
#define INTDRIVE_U 0.1*MAX_BANDWIDTH
1349 giacomo 44
#define INTDRIVE_FLAG 0
45
 
1392 giacomo 46
void call_shutdown_task(void *arg);
47
int device_drivers_init();
48
int device_drivers_close();
49
void set_shutdown_task();
50
TASK shutdown_task_body(void *arg);
51
 
52
PID shutdown_task_PID = -1;
53
 
1162 tavani 54
TIME __kernel_register_levels__(void *arg)
55
{
56
        struct multiboot_info *mb = (struct multiboot_info *)arg;
1569 tullio 57
        LEVEL EDF_level;
1162 tavani 58
 
1567 mauro 59
        INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1569 tullio 60
        EDF_level = EDF_register_level(EDF_ENABLE_ALL);
61
        HCBS_register_level(HCBS_ENABLE_ALL, EDF_level);
62
 
1349 giacomo 63
        HCBS_register_level(HCBS_ENABLE_ALL, 1);
1162 tavani 64
        RR_register_level(RRTICK, RR_MAIN_YES, mb);
65
        dummy_register_level();
66
 
67
        SEM_register_module();
68
 
69
        return TICK;
70
}
71
 
72
TASK __init__(void *arg)
73
{
1392 giacomo 74
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1162 tavani 75
 
1392 giacomo 76
  HARTPORT_init();
1162 tavani 77
 
1392 giacomo 78
  set_shutdown_task();
1162 tavani 79
 
1392 giacomo 80
  device_drivers_init();
81
 
82
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
83
 
84
  __call_main__(mb);
85
 
86
  return (void *)0;
1162 tavani 87
}
1392 giacomo 88
 
89
void set_shutdown_task() {
90
 
91
  NRT_TASK_MODEL nrt;
92
 
93
  nrt_task_default_model(nrt);
94
  nrt_task_def_system(nrt);
95
 
96
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
97
  if (shutdown_task_PID == NIL) {
98
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1550 pj 99
    exit(1);
1392 giacomo 100
  }
101
 
102
}
103
 
104
int device_drivers_init() {
105
 
106
  int res;
107
  KEYB_PARMS kparms = BASE_KEYB;
108
 
1567 mauro 109
  LINUXC26_register_module(TRUE);
1392 giacomo 110
 
111
  PCI26_init();
112
 
113
  INPUT26_init();
114
 
115
  keyb_def_ctrlC(kparms, NULL);
116
 
117
  KEYB26_init(&kparms);
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();
1550 pj 126
    exit(1);
1392 giacomo 127
  }                                                                                          
128
 
129
  FB26_use_grx(FRAME_BUFFER_DEVICE);
130
 
131
  FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16");
132
 
133
  return 0;
134
 
135
}
136
 
137
int device_drivers_close() {
138
 
139
  FB26_close(FRAME_BUFFER_DEVICE);
140
 
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
  return NULL;
171
 
172
}