Subversion Repositories shark

Rev

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