Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1664 | pj | 1 | #include "include/auto.h" |
2 | #include "include/const.h" |
||
3 | |||
4 | |||
5 | PID pid1,pid2,pid3,pid4; |
||
6 | SOFT_TASK_MODEL mp; |
||
7 | |||
8 | |||
9 | /* Semaphores */ |
||
10 | sem_t grx_mutex; |
||
11 | |||
12 | /* Useful colors */ |
||
13 | int black1 = rgb16( 0, 0, 0); |
||
14 | int red = rgb16(255, 0, 0); |
||
15 | int green = rgb16( 0,255, 0); |
||
16 | int blue = rgb16( 0, 0,255); |
||
17 | int lightgray = rgb16(192,192,192); |
||
18 | int car_colour = rgb16( 40, 80,125); |
||
19 | int track_colour = rgb16( 15, 70,175); |
||
20 | int track_direction; |
||
21 | |||
22 | void drive_car(); |
||
23 | /* -------------------------------------------------------*/ |
||
24 | |||
25 | /* Closing function */ |
||
26 | void byebye() |
||
27 | { |
||
28 | grx_close(); |
||
29 | |||
30 | // we need clear to reposition the cursor in the right place after |
||
31 | // going back from the graphical mode. |
||
32 | clear(); |
||
33 | |||
34 | kern_printf("ROAD CROSS GAME IS OVER, WERE U HURT!\n"); |
||
35 | } |
||
36 | |||
37 | /* -------------------------------------------------------*/ |
||
38 | |||
39 | |||
40 | void draw_highway() |
||
41 | { |
||
42 | /* Track drawing */ |
||
43 | sem_wait(&grx_mutex); |
||
44 | grx_box(0,HIGHWAY_Y_MIN,800,HIGHWAY_Y_MAX,track_colour); |
||
45 | grx_line(0,HIGHWAY_Y_MIN ,800,HIGHWAY_Y_MIN ,115); |
||
46 | grx_line(0,HIGHWAY_Y_MIN+75,800,HIGHWAY_Y_MIN+75,115); |
||
47 | grx_line(0,HIGHWAY_Y_MIN+150,800,HIGHWAY_Y_MIN+150,115); |
||
48 | grx_line(0,HIGHWAY_Y_MIN+225,800,HIGHWAY_Y_MIN+225,115); |
||
49 | grx_line(0,HIGHWAY_Y_MAX,800,HIGHWAY_Y_MAX,115); |
||
50 | grx_line(390,450,390,0,25); |
||
51 | grx_line(410,450,410,0,25); |
||
52 | sem_post(&grx_mutex); |
||
53 | |||
54 | } |
||
55 | |||
56 | //task for car on each |
||
57 | TASK drive_car1(void *arg) |
||
58 | { |
||
59 | while (1) |
||
60 | { |
||
61 | drive_car(1); |
||
62 | task_endcycle(); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | TASK drive_car2(void *arg) |
||
67 | { |
||
68 | while (1) |
||
69 | { |
||
70 | drive_car(2); |
||
71 | task_endcycle(); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | TASK drive_car3(void *arg) |
||
76 | { |
||
77 | while (1) |
||
78 | { |
||
79 | drive_car(3); |
||
80 | task_endcycle(); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | TASK drive_car4(void *arg) |
||
85 | { |
||
86 | while (1) |
||
87 | { |
||
88 | drive_car(4); |
||
89 | task_endcycle(); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | |||
94 | void drive_car(int track) |
||
95 | { |
||
96 | int x1=0; |
||
97 | int x2=0; |
||
98 | int y1=0; |
||
99 | int y2=0; |
||
100 | int x1o=0; |
||
101 | int x2o=0; |
||
102 | int x_size=50; |
||
103 | int y_size=35; |
||
104 | |||
105 | switch(track) |
||
106 | { |
||
107 | case 1: |
||
108 | x1=0; |
||
109 | y1=110; |
||
110 | track_direction = FORWARD; |
||
111 | break; |
||
112 | |||
113 | case 2: |
||
114 | x1=0; |
||
115 | y1=185 ; |
||
116 | track_direction = FORWARD; |
||
117 | break; |
||
118 | |||
119 | case 3: |
||
120 | x1=800-x_size; |
||
121 | y1=260; |
||
122 | track_direction =BACKWARD; |
||
123 | break; |
||
124 | case 4: |
||
125 | |||
126 | x1=800-x_size; |
||
127 | y1=335; |
||
128 | track_direction =BACKWARD; |
||
129 | break; |
||
130 | |||
131 | }//end of switch |
||
132 | |||
133 | x2=x1+x_size; |
||
134 | y2=y1+y_size; |
||
135 | |||
136 | if(track_direction == FORWARD) |
||
137 | { |
||
138 | do |
||
139 | { |
||
140 | x1o=x1; |
||
141 | x2o=x2; |
||
142 | x1 =x1o+5*track; |
||
143 | x2 =x1+x_size; |
||
144 | task_delay(60000); |
||
145 | grx_box(x1o,y1,x2o,y2,track_colour) ; |
||
146 | grx_box(x1,y1,x2,y2,car_colour); |
||
147 | } while(x1<800); |
||
148 | }//end of true condition of if |
||
149 | else |
||
150 | {//TRACK == BACKWARD |
||
151 | do |
||
152 | { |
||
153 | x1o=x1; |
||
154 | x2o=x2; |
||
155 | x1 =x1o-(5*track); |
||
156 | x2 =x1+x_size; |
||
157 | task_delay(70000); |
||
158 | |||
159 | grx_box(x1o,y1,x2o,y2,track_colour) ; |
||
160 | grx_box(x1,y1,x2,y2,car_colour); |
||
161 | if(track==3) |
||
162 | grx_box(0,260,x_size,265+y_size,track_colour) ; |
||
163 | // if(track==4) |
||
164 | grx_box(700,405,800,500,black1) ; |
||
165 | } while(x1>0); |
||
166 | }//end of else |
||
167 | } //end of the method drive_car |
||
168 | |||
169 | |||
170 | |||
171 | |||
172 | |||
173 | /* -------------------------------------------------------*/ |
||
174 | void initiate_task(){ |
||
175 | |||
176 | soft_task_default_model(mp); |
||
177 | soft_task_def_level(mp,1); |
||
178 | soft_task_def_ctrl_jet(mp); |
||
179 | soft_task_def_arg(mp,NULL); |
||
180 | soft_task_def_group(mp, 1); |
||
181 | soft_task_def_met(mp,100); |
||
182 | soft_task_def_period(mp,700); |
||
183 | soft_task_def_usemath(mp); |
||
184 | pid1 = task_create("track1", drive_car1, &mp, NULL); |
||
185 | pid2 = task_create("track2", drive_car2, &mp, NULL); |
||
186 | pid3 = task_create("track3", drive_car3, &mp, NULL); |
||
187 | pid4 = task_create("track4", drive_car4, &mp, NULL); |
||
188 | task_activate(pid1); |
||
189 | task_activate(pid2); |
||
190 | task_activate(pid3); |
||
191 | task_activate(pid4); |
||
192 | create_man(); |
||
193 | |||
194 | while(1) |
||
195 | { |
||
196 | grx_line(390,450,390,0,25); |
||
197 | grx_line(410,450,410,0,25); |
||
198 | task_endcycle(); |
||
199 | } |
||
200 | } |
||
201 | |||
202 | |||
203 | /* ------------------- */ |
||
204 | /* The main function */ |
||
205 | /* ------------------- */ |
||
206 | |||
207 | int main(int argc, char **argv) { |
||
208 | |||
209 | HARD_TASK_MODEL m; |
||
210 | PID main_pid; |
||
211 | |||
212 | /* Set the exception handler */ |
||
213 | set_exchandler_grx(); |
||
214 | |||
215 | /* Set the closing function */ |
||
216 | sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT); |
||
217 | |||
218 | /* Keyboard handling */ |
||
219 | keyb_handler(); |
||
220 | kern_printf("KEYBOARD initialized...\n"); |
||
221 | |||
222 | /* Graphics mutex */ |
||
223 | sem_init(&grx_mutex, 0, 1); |
||
224 | |||
225 | /* Graphics init */ |
||
226 | grx_init(); |
||
227 | grx_open(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BIT_COLORS); |
||
228 | |||
229 | draw_highway(); |
||
230 | sem_post(&grx_mutex); |
||
231 | |||
232 | /* Command and info display */ |
||
233 | cmd_display(); |
||
234 | |||
235 | /* ------------ */ |
||
236 | /* Task Calls */ |
||
237 | /* ------------ */ |
||
238 | |||
239 | hard_task_default_model(m); |
||
240 | hard_task_def_arg(m,NULL); |
||
241 | hard_task_def_wcet(m, CONTROL_WCET); |
||
242 | hard_task_def_mit(m, CONTROL_PERIOD); |
||
243 | hard_task_def_usemath(m); |
||
244 | main_pid = task_create("controller",initiate_task, &m, NULL); |
||
245 | if(main_pid == -1) |
||
246 | sys_end(); |
||
247 | task_activate(main_pid); |
||
248 | return 0; |
||
249 | } |
||
250 | |||
251 | /* -------------------------------------------------------*/ |
||
252 |