Rev 1387 | Rev 1547 | 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 | * |
||
8 | * http://www.sssup.it |
||
9 | * http://retis.sssup.it |
||
1377 | giacomo | 10 | * http://hartik.sssup.it |
1085 | pj | 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" |
||
1377 | giacomo | 18 | #include "modules/intdrive.h" |
1085 | pj | 19 | |
20 | #include "modules/sem.h" |
||
21 | #include "modules/hartport.h" |
||
22 | |||
1388 | 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" |
||
28 | |||
1382 | 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 | |||
1085 | pj | 35 | /*+ sysyem tick in us +*/ |
36 | #define TICK 0 |
||
37 | |||
38 | /*+ RR tick in us +*/ |
||
39 | #define RRTICK 10000 |
||
40 | |||
1377 | giacomo | 41 | /*+ Interrupt Server +*/ |
42 | #define INTDRIVE_Q 1000 |
||
43 | #define INTDRIVE_T 10000 |
||
44 | #define INTDRIVE_FLAG 0 |
||
45 | |||
1387 | giacomo | 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 | |||
1382 | giacomo | 52 | PID shutdown_task_PID = 1; |
53 | |||
1085 | pj | 54 | TIME __kernel_register_levels__(void *arg) |
55 | { |
||
1387 | giacomo | 56 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
1085 | pj | 57 | |
1387 | giacomo | 58 | INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG); |
59 | EDF_register_level(EDF_ENABLE_ALL); |
||
60 | CBS_register_level(CBS_ENABLE_ALL, 1); |
||
61 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
||
62 | dummy_register_level(); |
||
1085 | pj | 63 | |
1387 | giacomo | 64 | SEM_register_module(); |
1085 | pj | 65 | |
1388 | giacomo | 66 | PI_register_module(); |
67 | PC_register_module(); |
||
68 | NPP_register_module(); |
||
69 | SRP_register_module(); |
||
70 | NOP_register_module(); |
||
71 | |||
1387 | giacomo | 72 | return TICK; |
1085 | pj | 73 | } |
74 | |||
1387 | giacomo | 75 | TASK __init__(void *arg) |
76 | { |
||
77 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
1382 | giacomo | 78 | |
1387 | giacomo | 79 | HARTPORT_init(); |
1382 | giacomo | 80 | |
1387 | giacomo | 81 | /* Create the shutdown task. It will be activated at RUNLEVEL |
82 | SHUTDOWN */ |
||
83 | set_shutdown_task(); |
||
1382 | giacomo | 84 | |
1387 | giacomo | 85 | /* Init the drivers */ |
86 | device_drivers_init(); |
||
1382 | giacomo | 87 | |
1387 | giacomo | 88 | /* Set the shutdown task activation */ |
89 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
1382 | giacomo | 90 | |
1387 | giacomo | 91 | __call_main__(mb); |
1382 | giacomo | 92 | |
1387 | giacomo | 93 | return (void *)0; |
1382 | giacomo | 94 | } |
95 | |||
1387 | giacomo | 96 | void set_shutdown_task() { |
1382 | giacomo | 97 | |
1387 | giacomo | 98 | /* WARNING: the shutdown task is a background thread. It cannot execute |
99 | if the system is overloaded */ |
||
100 | NRT_TASK_MODEL nrt; |
||
1382 | giacomo | 101 | |
1387 | giacomo | 102 | nrt_task_default_model(nrt); |
103 | nrt_task_def_system(nrt); |
||
1382 | giacomo | 104 | |
1387 | giacomo | 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 | } |
||
1382 | giacomo | 110 | |
111 | } |
||
112 | |||
1387 | giacomo | 113 | int device_drivers_init() { |
1382 | giacomo | 114 | |
1387 | giacomo | 115 | KEYB_PARMS kparms = BASE_KEYB; |
116 | |||
117 | LINUXC26_register_module(); |
||
1382 | giacomo | 118 | |
1387 | giacomo | 119 | INPUT26_init(); |
1382 | giacomo | 120 | |
1387 | giacomo | 121 | keyb_def_ctrlC(kparms, NULL); |
1382 | giacomo | 122 | |
1387 | giacomo | 123 | KEYB26_init(&kparms); |
1382 | giacomo | 124 | |
1387 | giacomo | 125 | return 0; |
1382 | giacomo | 126 | |
1387 | giacomo | 127 | } |
1382 | giacomo | 128 | |
1387 | giacomo | 129 | int device_drivers_close() { |
130 | |||
131 | KEYB26_close(); |
||
132 | |||
133 | INPUT26_close(); |
||
134 | |||
135 | return 0; |
||
136 | |||
1382 | giacomo | 137 | } |
138 | |||
1387 | giacomo | 139 | #define SHUTDOWN_TIMEOUT_SEC 3 |
140 | |||
141 | void call_shutdown_task(void *arg) |
||
1085 | pj | 142 | { |
1387 | giacomo | 143 | struct timespec t; |
1085 | pj | 144 | |
1387 | giacomo | 145 | sys_gettime(&t); |
146 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
1085 | pj | 147 | |
1387 | giacomo | 148 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
149 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
1382 | giacomo | 150 | |
1387 | giacomo | 151 | task_activate(shutdown_task_PID); |
152 | } |
||
1382 | giacomo | 153 | |
1387 | giacomo | 154 | TASK shutdown_task_body(void *arg) { |
1382 | giacomo | 155 | |
1387 | giacomo | 156 | device_drivers_close(); |
1085 | pj | 157 | |
1387 | giacomo | 158 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
159 | |||
160 | sys_abort_shutdown(0); |
||
161 | |||
162 | return NULL; |
||
163 | |||
1085 | pj | 164 | } |