Subversion Repositories shark

Rev

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