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