Rev 1550 | Rev 1567 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1163 | giacomo | 1 | /* |
1423 | giacomo | 2 | * Project: S.Ha.R.K |
1163 | giacomo | 3 | * |
1423 | giacomo | 4 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
1163 | giacomo | 5 | * |
6 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
7 | * |
||
8 | * http://www.sssup.it |
||
9 | * http://retis.sssup.it |
||
1423 | giacomo | 10 | * http://hartik.sssup.it |
1163 | 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" |
||
1163 | giacomo | 19 | |
1552 | pj | 20 | #include "sem/sem/sem.h" |
21 | #include "hartport/hartport/hartport.h" |
||
1163 | giacomo | 22 | |
1423 | giacomo | 23 | #include <drivers/shark_linuxc26.h> |
24 | #include <drivers/shark_pci26.h> |
||
25 | #include <drivers/shark_input26.h> |
||
26 | #include <drivers/shark_keyb26.h> |
||
27 | #include <drivers/shark_fb26.h> |
||
28 | #include <drivers/shark_i2c26.h> |
||
29 | #include <drivers/shark_bttv26.h> |
||
30 | #include <drivers/shark_videodev26.h> |
||
1163 | giacomo | 31 | |
1423 | giacomo | 32 | #define FRAME_BUFFER_DEVICE 0 |
1428 | giacomo | 33 | #define FRAME_GRABBER_DEVICE 0 |
1163 | giacomo | 34 | |
35 | /*+ sysyem tick in us +*/ |
||
1423 | giacomo | 36 | #define TICK 0 |
1163 | giacomo | 37 | |
38 | /*+ RR tick in us +*/ |
||
39 | #define RRTICK 10000 |
||
40 | |||
1423 | giacomo | 41 | /*+ Interrup Server */ |
42 | #define INTDRIVE_Q 1000 |
||
43 | #define INTDRIVE_T 10000 |
||
44 | #define INTDRIVE_FLAG 0 |
||
45 | |||
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 | |||
52 | PID shutdown_task_PID = -1; |
||
53 | |||
1163 | giacomo | 54 | TIME __kernel_register_levels__(void *arg) |
55 | { |
||
1423 | giacomo | 56 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
1163 | giacomo | 57 | |
1423 | giacomo | 58 | INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG); |
59 | EDF_register_level(EDF_ENABLE_ALL); |
||
1424 | giacomo | 60 | CBS_register_level(CBS_ENABLE_ALL, 1); |
1423 | giacomo | 61 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
62 | dummy_register_level(); |
||
1163 | giacomo | 63 | |
1423 | giacomo | 64 | SEM_register_module(); |
1163 | giacomo | 65 | |
1423 | giacomo | 66 | return TICK; |
1163 | giacomo | 67 | } |
68 | |||
69 | TASK __init__(void *arg) |
||
70 | { |
||
71 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
72 | |||
73 | HARTPORT_init(); |
||
74 | |||
1423 | giacomo | 75 | set_shutdown_task(); |
1163 | giacomo | 76 | |
1423 | giacomo | 77 | device_drivers_init(); |
78 | |||
79 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
80 | |||
1163 | giacomo | 81 | __call_main__(mb); |
82 | |||
83 | return (void *)0; |
||
84 | } |
||
85 | |||
1423 | giacomo | 86 | void set_shutdown_task() { |
87 | |||
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); |
1423 | giacomo | 97 | } |
98 | |||
99 | } |
||
100 | |||
101 | int device_drivers_init() { |
||
102 | |||
103 | int res; |
||
104 | KEYB_PARMS kparms = BASE_KEYB; |
||
105 | |||
106 | LINUXC26_register_module(); |
||
107 | |||
108 | PCI26_init(); |
||
109 | |||
110 | I2C26_init(); |
||
111 | |||
112 | INPUT26_init(); |
||
113 | |||
114 | keyb_def_ctrlC(kparms, NULL); |
||
115 | |||
116 | KEYB26_init(&kparms); |
||
117 | |||
1432 | giacomo | 118 | BTTV26_init(); |
119 | |||
1428 | giacomo | 120 | FB26_init(); |
1423 | giacomo | 121 | |
122 | res = FB26_open(FRAME_BUFFER_DEVICE); |
||
123 | if (res) { |
||
124 | cprintf("Error: Cannot open graphical mode\n"); |
||
125 | KEYB26_close(); |
||
126 | INPUT26_close(); |
||
1550 | pj | 127 | exit(1); |
1423 | giacomo | 128 | } |
129 | |||
130 | FB26_use_grx(FRAME_BUFFER_DEVICE); |
||
131 | |||
132 | FB26_setmode(FRAME_BUFFER_DEVICE,"640x480-16"); |
||
1485 | giacomo | 133 | |
1423 | giacomo | 134 | return 0; |
135 | |||
136 | } |
||
137 | |||
138 | int device_drivers_close() { |
||
1475 | giacomo | 139 | |
1432 | giacomo | 140 | BTTV26_close(); |
141 | |||
1423 | giacomo | 142 | FB26_close(FRAME_BUFFER_DEVICE); |
1475 | giacomo | 143 | |
1423 | giacomo | 144 | KEYB26_close(); |
145 | |||
146 | INPUT26_close(); |
||
147 | |||
148 | return 0; |
||
149 | |||
150 | } |
||
151 | |||
152 | #define SHUTDOWN_TIMEOUT_SEC 3 |
||
153 | |||
154 | void call_shutdown_task(void *arg) |
||
155 | { |
||
156 | struct timespec t; |
||
157 | |||
158 | sys_gettime(&t); |
||
159 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
160 | |||
161 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
||
162 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
163 | |||
164 | task_activate(shutdown_task_PID); |
||
165 | } |
||
166 | |||
167 | TASK shutdown_task_body(void *arg) { |
||
168 | |||
169 | device_drivers_close(); |
||
170 | |||
171 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
172 | |||
173 | return NULL; |
||
174 | |||
175 | } |