Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1624 giacomo 1
/*
1647 giacomo 2
 * Project: S.Ha.R.K
1624 giacomo 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
 
1647 giacomo 13
#include "kernel/kern.h"
1651 pj 14
#include "edf/edf/edf.h"
15
#include "cbs/cbs/cbs.h"
16
#include "rr/rr/rr.h"
17
#include "dummy/dummy/dummy.h"
18
#include "intdrive/intdrive/intdrive.h"
1624 giacomo 19
 
1651 pj 20
#include "sem/sem/sem.h"
21
#include "hartport/hartport/hartport.h"
1624 giacomo 22
 
1651 pj 23
#include "pi/pi/pi.h"
24
#include "pc/pc/pc.h"
25
#include "srp/srp/srp.h"
26
#include "npp/npp/npp.h"
27
#include "nop/nop/nop.h"
1647 giacomo 28
 
29
#include <drivers/shark_linuxc26.h>
30
#include <drivers/shark_input26.h>
31
#include <drivers/shark_pci26.h>
32
#include <drivers/shark_cpu26.h>
33
#include <drivers/shark_keyb26.h>
34
 
35
#define FRAME_BUFFER_DEVICE 0
36
 
1624 giacomo 37
/*+ sysyem tick in us +*/
1647 giacomo 38
#define TICK 0
1624 giacomo 39
 
40
/*+ RR tick in us +*/
41
#define RRTICK 10000
42
 
1647 giacomo 43
/*+ Interrupt Server +*/
1624 giacomo 44
#define INTDRIVE_Q 1000
1653 mauro 45
#define INTDRIVE_U 1000
1647 giacomo 46
#define INTDRIVE_FLAG 0
1624 giacomo 47
 
1647 giacomo 48
void call_shutdown_task(void *arg);
49
int device_drivers_init();
50
int device_drivers_close();
51
void set_shutdown_task();
52
TASK shutdown_task_body(void *arg);
1624 giacomo 53
 
1647 giacomo 54
PID shutdown_task_PID = -1;
55
 
1624 giacomo 56
TIME __kernel_register_levels__(void *arg)
57
{
1647 giacomo 58
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1624 giacomo 59
 
1653 mauro 60
  INTDRIVE_register_level(INTDRIVE_Q, INTDRIVE_Q, INTDRIVE_U, INTDRIVE_FLAG);
1647 giacomo 61
  EDF_register_level(EDF_ENABLE_ALL);
62
  CBS_register_level(CBS_ENABLE_ALL, 1);
63
  RR_register_level(RRTICK, RR_MAIN_YES, mb);
64
  dummy_register_level();
1624 giacomo 65
 
1647 giacomo 66
  SEM_register_module();
1624 giacomo 67
 
1647 giacomo 68
  PI_register_module();
69
 
70
  return TICK;
1624 giacomo 71
}
72
 
73
TASK __init__(void *arg)
74
{
1647 giacomo 75
  struct multiboot_info *mb = (struct multiboot_info *)arg;
1624 giacomo 76
 
1647 giacomo 77
  HARTPORT_init();
1624 giacomo 78
 
1647 giacomo 79
  /* Create the shutdown task. It will be activated at RUNLEVEL
80
     SHUTDOWN */
81
  set_shutdown_task();
1624 giacomo 82
 
1647 giacomo 83
  /* Init the drivers */
84
  device_drivers_init();
1624 giacomo 85
 
1647 giacomo 86
  /* Set the shutdown task activation */
87
  sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN);
1624 giacomo 88
 
1647 giacomo 89
  __call_main__(mb);
90
 
91
  return (void *)0;
1624 giacomo 92
}
1647 giacomo 93
 
94
void set_shutdown_task() {
95
 
96
  /* WARNING: the shutdown task is a background thread. It cannot execute
97
              if the system is overloaded */
98
  NRT_TASK_MODEL nrt;
99
 
100
  nrt_task_default_model(nrt);
101
  nrt_task_def_system(nrt);
102
 
103
  shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL);
104
  if (shutdown_task_PID == NIL) {
105
    sys_shutdown_message("Error: Cannot create shutdown task\n");
1650 pj 106
    exit(1);
1647 giacomo 107
  }
108
 
109
}
110
 
111
int device_drivers_init() {
112
 
113
  KEYB_PARMS kparms = BASE_KEYB;
114
 
1653 mauro 115
  LINUXC26_register_module(TRUE);
1647 giacomo 116
 
117
  PCI26_init();
118
 
119
  CPU26_init();
120
 
121
  CPU26_DVS_init();
122
 
123
  INPUT26_init();
124
 
125
  keyb_def_ctrlC(kparms, NULL);
126
 
127
  KEYB26_init(&kparms);
128
 
129
  return 0;
130
 
131
}
132
 
133
int device_drivers_close() {
134
 
135
  KEYB26_close();
136
 
137
  INPUT26_close();
138
 
139
  return 0;
140
 
141
}
142
 
143
#define SHUTDOWN_TIMEOUT_SEC 3
144
 
145
void call_shutdown_task(void *arg)
146
{
147
  struct timespec t;
148
 
149
  sys_gettime(&t);
150
  t.tv_sec += SHUTDOWN_TIMEOUT_SEC;
151
 
152
  /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */
153
  kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0);
154
 
155
  task_activate(shutdown_task_PID);
156
}
157
 
158
TASK shutdown_task_body(void *arg) {
159
 
160
  device_drivers_close();
161
 
162
  sys_shutdown_message("-- S.Ha.R.K. Closed --\n");
163
 
164
  return NULL;
165
 
166
}