Rev 1091 | Rev 1123 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1091 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * (see the web pages for full authors list) |
||
13 | * |
||
14 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
15 | * |
||
16 | * http://www.sssup.it |
||
17 | * http://retis.sssup.it |
||
18 | * http://shark.sssup.it |
||
19 | */ |
||
20 | |||
1117 | pj | 21 | /* CVS : $Id: bca.c,v 1.3 2002-11-11 08:15:13 pj Exp $ */ |
1091 | pj | 22 | |
23 | /* |
||
24 | * Copyright (C) 2000 Fabio Calabrese <fabiocalabrese77@yahoo.it> |
||
25 | * |
||
26 | * This program is free software; you can redistribute it and/or modify |
||
27 | * it under the terms of the GNU General Public License as published by |
||
28 | * the Free Software Foundation; either version 2 of the License, or |
||
29 | * (at your option) any later version. |
||
30 | * |
||
31 | * This program is distributed in the hope that it will be useful, |
||
32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
34 | * GNU General Public License for more details. |
||
35 | * |
||
36 | * You should have received a copy of the GNU General Public License |
||
37 | * along with this program; if not, write to the Free Software |
||
38 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
39 | * |
||
40 | */ |
||
41 | |||
42 | /**************************************************** |
||
43 | * * |
||
44 | * file: bca.c * |
||
45 | * header file: bca.h * |
||
46 | * data: 15/09/2002 * |
||
47 | * creato da: Fabio CALABRESE * |
||
48 | * * |
||
49 | ****************************************************** |
||
50 | * * |
||
51 | * descrizione: e' il file in cui è descritto il task* |
||
52 | * main del programma S.Ha.R.K. * |
||
53 | * "(B)ase(C)ontr(A)rea". * |
||
54 | * Il codice del programma comprende * |
||
55 | * anche l'implementazione di altri task* |
||
56 | * distribuiti nei seguenti file che * |
||
57 | * quindi sono inclusi: * |
||
58 | * dummy.c * |
||
59 | * control.c * |
||
60 | * aereo.c * |
||
61 | * cannone.c * |
||
62 | * missile.c * |
||
63 | * esplo.c * |
||
64 | * Inoltre è incluso anche il file: * |
||
65 | * scenario.c * |
||
66 | * che descrive come disegnare lo * |
||
67 | * scenario grafico iniziale * |
||
68 | * * |
||
69 | ******************************************************/ |
||
70 | |||
71 | |||
72 | // *** Librerie S.Ha.R.K *** |
||
73 | #include <kernel/kern.h> |
||
74 | #include <drivers/keyb.h> |
||
75 | #include <ll/i386/cons.h> |
||
76 | #include <drivers/glib.h> |
||
77 | // *** Librerie Standard C *** |
||
78 | #include <stdlib.h> |
||
79 | // *** Librerie FAB *** |
||
80 | #include "fab_lib/fab_msg.h" |
||
81 | #include "fab_lib/fab_show.h" |
||
82 | #include "fab_lib/fab_tool.h" |
||
83 | #include "fab_lib/fab_grx.h" |
||
84 | // *** Librerie BCA *** |
||
85 | #include "bca.h" |
||
86 | |||
87 | |||
88 | char * titolo[10]; |
||
89 | |||
90 | void scenario(); |
||
91 | void info(); |
||
92 | #include"scenario.c" |
||
93 | |||
94 | PID crea_soft_dummy_radar (); |
||
95 | TASK dummy_radar(void *); |
||
96 | #include"dummy.c" |
||
97 | |||
98 | PID crea_soft_control(); |
||
99 | TASK control(void *); |
||
100 | #include"control.c" |
||
101 | |||
102 | PID crea_soft_aereo_creator(); |
||
103 | TASK aereo_creator(); |
||
104 | PID crea_hard_aereo(int index); |
||
105 | PID crea_soft_aereo(int index); |
||
106 | TASK aereo(void * index); |
||
107 | #include"aereo.c" |
||
108 | |||
109 | PID crea_soft_cannone_creator(); |
||
110 | TASK cannone_creator(); |
||
111 | PID crea_hard_cannone(int index); |
||
112 | PID crea_soft_cannone(int index); |
||
113 | TASK cannone(void * index); |
||
114 | #include"cannone.c" |
||
115 | |||
116 | PID crea_hard_missile(); |
||
117 | PID crea_soft_missile(); |
||
118 | TASK missile(); |
||
119 | #include"missile.c" |
||
120 | |||
121 | PID crea_soft_esplo(); |
||
122 | TASK esplo(void *); |
||
123 | #include"esplo.c" |
||
124 | |||
125 | void demo_exc_handler(int signo, siginfo_t *info, void *extra) |
||
126 | { |
||
127 | struct timespec t; |
||
128 | |||
129 | grx_close(); |
||
130 | |||
131 | /* Default action for an kern exception is */ |
||
132 | kern_cli(); |
||
133 | ll_gettime(TIME_EXACT, &t), |
||
134 | kern_printf("\nS.Ha.R.K. Exception raised!!!" |
||
1117 | pj | 135 | "\nTime (s:ns) :%ld:%ld" |
1091 | pj | 136 | "\nException number:%d" |
137 | "\nPID :%d\n", |
||
138 | t.tv_sec, t.tv_nsec, info->si_value.sival_int, |
||
139 | info->si_task); |
||
140 | sys_end(); |
||
141 | } |
||
142 | |||
143 | void my_close(void *arg) |
||
144 | { FAB_grx_close(); |
||
145 | place(0,0); |
||
146 | info(); |
||
147 | } |
||
148 | |||
149 | void end_fun(KEY_EVT* k) |
||
150 | { cprintf("Ending...\n"); |
||
151 | sys_end(); |
||
152 | } |
||
153 | void incrementa_aerei_fun(KEY_EVT* k) |
||
154 | { if (aereo_count<AEREO_N_MAX) aereo_count++; |
||
155 | } |
||
156 | void decrementa_aerei_fun(KEY_EVT* k) |
||
157 | { if (aereo_count>AEREO_N_MIN) aereo_count--; |
||
158 | } |
||
159 | void incrementa_cannoni_fun(KEY_EVT* k) |
||
160 | { if (cannone_count<CANNONE_N_MAX) cannone_count++; |
||
161 | } |
||
162 | void decrementa_cannoni_fun(KEY_EVT* k) |
||
163 | { if (cannone_count>CANNONE_N_MIN) cannone_count--; |
||
164 | } |
||
165 | |||
166 | int main(int argc, char **argv) |
||
167 | { |
||
168 | PID pid; |
||
169 | |||
170 | KEY_EVT k; |
||
171 | keyb_set_map(itaMap); |
||
172 | |||
173 | k.flag = 0; |
||
174 | k.scan = KEY_ENT; |
||
175 | k.ascii = 13; |
||
176 | keyb_hook(k,end_fun); |
||
177 | k.flag = 0; |
||
178 | k.scan = KEY_1; |
||
179 | k.ascii = '1'; |
||
180 | keyb_hook(k,incrementa_aerei_fun); |
||
181 | k.flag = 0; |
||
182 | k.scan = KEY_2; |
||
183 | k.ascii = '2'; |
||
184 | keyb_hook(k,decrementa_aerei_fun); |
||
185 | k.flag = 0; |
||
186 | k.scan = KEY_3; |
||
187 | k.ascii = '3'; |
||
188 | keyb_hook(k,incrementa_cannoni_fun); |
||
189 | k.flag = 0; |
||
190 | k.scan = KEY_4; |
||
191 | k.ascii = '4'; |
||
192 | keyb_hook(k,decrementa_cannoni_fun); |
||
193 | |||
194 | set_exchandler_grx(); |
||
195 | |||
196 | sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
||
197 | |||
198 | FAB_grx_open(800,600); |
||
199 | |||
200 | /* inizializza il mutex grafico */ |
||
201 | app_mutex_init(&grx_mutex); |
||
202 | |||
203 | scenario(); |
||
204 | |||
205 | //---init--- |
||
206 | srand(sys_gettime(NULL)); |
||
207 | aereo_count = AEREO_N_MIN; |
||
208 | cannone_count = CANNONE_N_MIN; |
||
209 | |||
210 | pid=crea_soft_dummy_radar(); |
||
211 | task_activate(pid); |
||
212 | |||
213 | pid=crea_soft_aereo_creator(); |
||
214 | task_activate(pid); |
||
215 | |||
216 | pid=crea_soft_cannone_creator(); |
||
217 | task_activate(pid); |
||
218 | |||
219 | pid=crea_soft_control(); |
||
220 | task_activate(pid); |
||
221 | //---------- |
||
222 | } |
||
223 | |||
224 |