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