Subversion Repositories shark

Rev

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

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