Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1670 | pj | 1 | #include "kernel/kern.h" |
2 | #include "modules/intdrive.h" |
||
3 | //#include "modules/edf.h" |
||
4 | #include "modules/rm.h" |
||
5 | //#include "modules/hardcbs.h" |
||
6 | #include "modules/cbs.h" |
||
7 | #include "modules/rr.h" |
||
8 | #include "modules/dummy.h" |
||
9 | |||
10 | #include "modules/sem.h" |
||
11 | #include "modules/hartport.h" |
||
12 | #include "modules/cabs.h" |
||
13 | #include "hlp.h" |
||
14 | //#include "modules/srp.h" |
||
15 | //#include "modules/pi.h" |
||
16 | //#include "modules/npp.h" |
||
17 | |||
18 | #include <drivers/shark_linuxc26.h> |
||
19 | #include <drivers/shark_pci26.h> |
||
20 | #include <drivers/shark_input26.h> |
||
21 | #include <drivers/shark_keyb26.h> |
||
22 | |||
23 | #include "ll/i386/x-dos.h" |
||
24 | |||
25 | /*+ sysyem tick in us +*/ |
||
26 | #define TICK 0 |
||
27 | |||
28 | /*+ RR tick in us +*/ |
||
29 | #define RRTICK 2000 |
||
30 | |||
31 | /*+ Interrupt Server +*/ |
||
32 | #define INTDRIVE_Q 1000 |
||
33 | #define INTDRIVE_T 10000 |
||
34 | #define INTDRIVE_FLAG 0 |
||
35 | |||
36 | void call_shutdown_task(void *arg); |
||
37 | int device_drivers_init(); |
||
38 | int device_drivers_close(); |
||
39 | void set_shutdown_task(); |
||
40 | TASK shutdown_task_body(void *arg); |
||
41 | |||
42 | PID shutdown_task_PID = -1; |
||
43 | |||
44 | /* This is the buffer used by read_myfile */ |
||
45 | char myfilebuf[1000]; |
||
46 | |||
47 | /* This is the number of bytes read by read_myfile */ |
||
48 | int myfilebuf_length; |
||
49 | |||
50 | void read_myfile() |
||
51 | { |
||
52 | /* DOS file descriptor */ |
||
53 | DOS_FILE *f; |
||
54 | |||
55 | /* Error code */ |
||
56 | int err; |
||
57 | |||
58 | /* open the DOS file for reading (you can specify only "r" or "w") */ |
||
59 | f = DOS_fopen("hlp.cfg","r"); |
||
60 | |||
61 | /* check for open errors */ |
||
62 | if (!f) { |
||
63 | /* error!! */ |
||
64 | err = DOS_error(); |
||
65 | |||
66 | /* note that if you call DOS_error() here, it return 0!!! */ |
||
67 | myfilebuf_length = 0; |
||
68 | return; |
||
69 | } |
||
70 | |||
71 | /* read up to 1000 chars */ |
||
72 | myfilebuf_length = DOS_fread(&myfilebuf,1,1000,f); |
||
73 | |||
74 | /* check for errors */ |
||
75 | err = DOS_error(); |
||
76 | |||
77 | if (err) { |
||
78 | cprintf("Error %d reading myfile.txt...\n", err); |
||
79 | myfilebuf_length = 0; |
||
80 | /* there is not return because I want to close the file! */ |
||
81 | } |
||
82 | |||
83 | /* Close the file */ |
||
84 | DOS_fclose(f); |
||
85 | } |
||
86 | |||
87 | |||
88 | TIME __kernel_register_levels__(void *arg) |
||
89 | { |
||
90 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
91 | |||
92 | INTDRIVE_register_level(INTDRIVE_Q,INTDRIVE_T,INTDRIVE_FLAG); |
||
93 | |||
94 | read_myfile(); |
||
95 | // EDF_register_level(EDF_ENABLE_ALL); |
||
96 | RM_register_level(RM_ENABLE_ALL); |
||
97 | // HCBS_register_level(HCBS_ENABLE_ALL, 1); |
||
98 | RR_register_level(RRTICK, RR_MAIN_YES, mb); |
||
99 | CBS_register_level(CBS_ENABLE_ALL, 1); |
||
100 | dummy_register_level(); |
||
101 | |||
102 | // SEM_register_module(); |
||
103 | //CABS_register_module(); |
||
104 | |||
105 | HLP_register_module(); |
||
106 | //SRP_register_module(); |
||
107 | // PI_register_module(); |
||
108 | // NPP_register_module(); |
||
109 | |||
110 | return TICK; |
||
111 | } |
||
112 | |||
113 | TASK __init__(void *arg) |
||
114 | { |
||
115 | struct multiboot_info *mb = (struct multiboot_info *)arg; |
||
116 | |||
117 | HARTPORT_init(); |
||
118 | |||
119 | /* Create the shutdown task. It will be activated at RUNLEVEL |
||
120 | SHUTDOWN */ |
||
121 | set_shutdown_task(); |
||
122 | |||
123 | /* Init the drivers */ |
||
124 | device_drivers_init(); |
||
125 | |||
126 | /* Set the shutdown task activation */ |
||
127 | sys_atrunlevel(call_shutdown_task, NULL, RUNLEVEL_SHUTDOWN); |
||
128 | |||
129 | __call_main__(mb); |
||
130 | |||
131 | return (void *)0; |
||
132 | } |
||
133 | |||
134 | void set_shutdown_task() { |
||
135 | |||
136 | /* WARNING: the shutdown task is a background thread. It cannot execute |
||
137 | if the system is overloaded */ |
||
138 | NRT_TASK_MODEL nrt; |
||
139 | |||
140 | nrt_task_default_model(nrt); |
||
141 | nrt_task_def_system(nrt); |
||
142 | |||
143 | shutdown_task_PID = task_create("Shutdown Task",shutdown_task_body,&nrt,NULL); |
||
144 | if (shutdown_task_PID == NIL) { |
||
145 | sys_shutdown_message("Error: Cannot create shutdown task\n"); |
||
146 | sys_end(); |
||
147 | } |
||
148 | |||
149 | } |
||
150 | |||
151 | int device_drivers_init() { |
||
152 | |||
153 | KEYB_PARMS kparms = BASE_KEYB; |
||
154 | |||
155 | LINUXC26_register_module(); |
||
156 | |||
157 | PCI26_init(); |
||
158 | |||
159 | INPUT26_init(); |
||
160 | |||
161 | keyb_def_ctrlC(kparms, NULL); |
||
162 | |||
163 | KEYB26_init(&kparms); |
||
164 | |||
165 | return 0; |
||
166 | |||
167 | } |
||
168 | |||
169 | int device_drivers_close() { |
||
170 | |||
171 | KEYB26_close(); |
||
172 | |||
173 | INPUT26_close(); |
||
174 | |||
175 | return 0; |
||
176 | |||
177 | } |
||
178 | |||
179 | #define SHUTDOWN_TIMEOUT_SEC 3 |
||
180 | |||
181 | void call_shutdown_task(void *arg) |
||
182 | { |
||
183 | struct timespec t; |
||
184 | |||
185 | sys_gettime(&t); |
||
186 | t.tv_sec += SHUTDOWN_TIMEOUT_SEC; |
||
187 | |||
188 | /* Emergency timeout to exit from RUNLEVEL_SHUTDOWN */ |
||
189 | kern_event_post(&t,(void *)((void *)sys_abort_shutdown),(void *)0); |
||
190 | |||
191 | task_activate(shutdown_task_PID); |
||
192 | } |
||
193 | |||
194 | TASK shutdown_task_body(void *arg) { |
||
195 | |||
196 | device_drivers_close(); |
||
197 | |||
198 | sys_shutdown_message("-- S.Ha.R.K. Closed --\n"); |
||
199 | |||
200 | sys_abort_shutdown(0); |
||
201 | |||
202 | return NULL; |
||
203 | |||
204 | } |