Rev 1386 | Rev 1547 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1098 | 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 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai |
||
21 | * |
||
22 | * This program is free software; you can redistribute it and/or modify |
||
23 | * it under the terms of the GNU General Public License as published by |
||
24 | * the Free Software Foundation; either version 2 of the License, or |
||
25 | * (at your option) any later version. |
||
26 | * |
||
27 | * This program is distributed in the hope that it will be useful, |
||
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | * GNU General Public License for more details. |
||
31 | * |
||
32 | * You should have received a copy of the GNU General Public License |
||
33 | * along with this program; if not, write to the Free Software |
||
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
35 | * |
||
36 | * |
||
1398 | giacomo | 37 | * CVS : $Id: cabs.c,v 1.7 2004-04-23 07:57:33 giacomo Exp $ |
1098 | pj | 38 | */ |
39 | |||
1085 | pj | 40 | /*--------------------------------------------------------------*/ |
41 | /* TEST ON CABS */ |
||
42 | /*--------------------------------------------------------------*/ |
||
43 | |||
44 | #include <kernel/kern.h> |
||
45 | #include <modules/cabs.h> |
||
46 | #include <string.h> |
||
47 | |||
1377 | giacomo | 48 | #include <drivers/shark_fb26.h> |
49 | #include <drivers/shark_keyb26.h> |
||
50 | |||
1085 | pj | 51 | #define NCAB 4 /* max number of CABs */ |
52 | #define NCAR 26 /* generated characters */ |
||
53 | |||
54 | #define YP 32 /* level of arrows */ |
||
55 | #define R 20 /* task radius */ |
||
56 | #define YY (YP+R+32) /* level of writing */ |
||
57 | #define DELTA (2*R+72) /* total channel hight */ |
||
58 | #define X1 120 /* start column for P1 */ |
||
59 | #define X2 360 /* start column for P2 */ |
||
60 | |||
61 | #define XP1 (X1+64) /* X position of task 1 */ |
||
62 | #define XP2 (X2+64) /* X position of task 2 */ |
||
63 | #define XC (XP1+96) /* X position of CAB */ |
||
64 | #define L 52 /* CAB rectangle length */ |
||
65 | |||
66 | void my_exit(KEY_EVT *k); |
||
67 | void draw_channel(int i); |
||
68 | void create_channel(int i); |
||
69 | void get_data(); |
||
70 | |||
71 | TASK producer(void *arg); |
||
72 | TASK consumer(void *arg); |
||
73 | |||
74 | char *cname[NCAB] = {"cab1", "cab2", "cab3", "cab4"}; |
||
75 | char *pname1[NCAB] = {"wr1", "wr2", "wr3", "wr4"}; |
||
76 | char *pname2[NCAB] = {"rd1", "rd2", "rd3", "rd4"}; |
||
77 | |||
78 | CAB cid[NCAB]; /* CAB identifiers */ |
||
79 | PID p1[NCAB], p2[NCAB]; /* task identifiers */ |
||
80 | |||
81 | /* Task Periods */ |
||
82 | TIME t1[NCAB] = {200000, 100000, 300000, 800000}; |
||
83 | TIME t2[NCAB] = {400000, 400000, 150000, 200000}; |
||
84 | |||
85 | /* Task WCETS */ |
||
86 | TIME w1[NCAB] = {10000, 10000, 10000, 10000}; |
||
87 | TIME w2[NCAB] = {10000, 10000, 10000, 10000}; |
||
88 | |||
89 | /****************************************************************/ |
||
90 | |||
91 | /* This function is called when Alt-X is pressed. |
||
92 | */ |
||
93 | void my_end(KEY_EVT* e) |
||
94 | { |
||
1382 | giacomo | 95 | sys_end(); |
1085 | pj | 96 | } |
97 | |||
98 | /******************************************************************/ |
||
99 | |||
100 | /* This function is called when the system exit correctly after Alt-X. |
||
101 | It exits from the graphic mode and then it prints a small greeting. |
||
102 | Note that: |
||
103 | - The function calls grx_exit, so it must be registered using |
||
104 | RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because |
||
105 | at that point the kernel is already returned in real mode!!!) |
||
106 | - When an exception is raised, the exception handler is called. |
||
107 | Since the exception handler already exits from the graphic mode, |
||
108 | this funcion has not to be called. For this reason: |
||
109 | . we registered byebye using the flag NO_AT_ABORT |
||
110 | . the exception handler exits using sys_abort; in that way byebye is |
||
111 | NOT called |
||
112 | */ |
||
113 | |||
114 | /*--------------------------------------------------------------*/ |
||
115 | /* Main task */ |
||
116 | /*--------------------------------------------------------------*/ |
||
117 | |||
118 | /****************************** MAIN ******************************/ |
||
119 | |||
120 | int main(int argc, char **argv) |
||
121 | { |
||
122 | char c = 0; /* character from keyboard */ |
||
123 | |||
124 | grx_clear(BLACK); |
||
125 | |||
1386 | giacomo | 126 | grx_text("Press a key [1-4]", 10, 16, rgb16(255,255,255), 0); |
127 | grx_text("to create a pair", 10, 24, rgb16(255,255,255), 0); |
||
128 | grx_text("ESC to exit demo", 10, 48, rgb16(255,255,255), 0); |
||
1085 | pj | 129 | |
130 | while (c != 27) { |
||
131 | c = keyb_getch(BLOCK); |
||
132 | if ((c >= '1') && (c <= '1'+NCAB-1)) |
||
133 | create_channel(c-'1'); |
||
134 | } |
||
135 | |||
1382 | giacomo | 136 | sys_end(); |
1085 | pj | 137 | |
138 | return 0; |
||
139 | } |
||
140 | |||
141 | |||
142 | /*--------------------------------------------------------------*/ |
||
143 | /* write data in a cab */ |
||
144 | /*--------------------------------------------------------------*/ |
||
145 | |||
146 | TASK producer(void *arg) |
||
147 | { |
||
148 | int i = (int)arg; |
||
149 | char c; /* message character */ |
||
150 | char *p; /* pointer to a cab buffer */ |
||
151 | char s[2]; /* string to display */ |
||
152 | int k = 0; |
||
153 | int x, y; |
||
1386 | giacomo | 154 | int col = rgb16(0,0,255); |
1085 | pj | 155 | int ybase = YY + i*DELTA; |
156 | |||
157 | x = X1; |
||
158 | y = ybase; |
||
159 | s[1] = 0; |
||
160 | |||
161 | k = 0; |
||
162 | while (1) { |
||
163 | c = 'A' + k; |
||
164 | p = cab_reserve(cid[i]); |
||
165 | *p = c; |
||
166 | cab_putmes(cid[i], p); |
||
167 | |||
168 | s[0] = c; |
||
169 | k = (k + 1) % NCAR; |
||
170 | grx_text(s,x,y,col,0); |
||
171 | |||
172 | x += 8; |
||
173 | if (x >= (X1 + NCAR*8)) { |
||
174 | x = X1; |
||
175 | y = y + 8; |
||
176 | if (y >= ybase+16) { |
||
177 | y = ybase; |
||
178 | } |
||
179 | } |
||
180 | |||
181 | task_endcycle(); |
||
182 | } |
||
183 | } |
||
184 | |||
185 | /*--------------------------------------------------------------*/ |
||
186 | /* read data from a cab */ |
||
187 | /*--------------------------------------------------------------*/ |
||
188 | |||
189 | TASK consumer(void *arg) |
||
190 | { |
||
191 | int i = (int)arg; |
||
192 | char *p; |
||
193 | char s[2]; |
||
194 | int x, y; |
||
195 | int col = 13; |
||
196 | int ybase = YY + i*DELTA; |
||
197 | |||
198 | x = X2; |
||
199 | y = ybase; |
||
200 | s[1] = 0; |
||
201 | |||
202 | while (1) { |
||
203 | p = cab_getmes(cid[i]); |
||
204 | s[0] = *p - 'A' + 'a'; |
||
205 | cab_unget(cid[i], p); |
||
206 | |||
207 | grx_text(s,x,y,col,0); |
||
208 | x += 8; |
||
209 | |||
210 | if (x >= (X2 + NCAR*8)) { |
||
211 | x = X2; |
||
212 | y = y + 8; |
||
213 | if (y >= ybase+16) { |
||
214 | y = ybase; |
||
215 | col = col % 15 + 1; |
||
216 | } |
||
217 | } |
||
218 | task_endcycle(); |
||
219 | } |
||
220 | } |
||
221 | |||
222 | /*--------------------------------------------------------------*/ |
||
223 | /* create the two tasks and a channel */ |
||
224 | /*--------------------------------------------------------------*/ |
||
225 | |||
226 | void create_channel(int i) |
||
227 | { |
||
228 | HARD_TASK_MODEL m; |
||
229 | |||
230 | draw_channel(i); |
||
231 | cid[i] = cab_create(cname[i], 1, 2); |
||
232 | |||
233 | hard_task_default_model(m); |
||
234 | hard_task_def_ctrl_jet (m); |
||
235 | hard_task_def_arg (m, (void *)i); |
||
236 | hard_task_def_wcet (m, w1[i]); |
||
237 | hard_task_def_mit (m, t1[i]); |
||
238 | hard_task_def_usemath (m); |
||
239 | p1[i] = task_create(pname1[i], producer, &m, NULL); |
||
240 | if (p1[i] == NIL) { |
||
1377 | giacomo | 241 | sys_shutdown_message("Could not create task <producer>"); |
1382 | giacomo | 242 | sys_end(); |
1377 | giacomo | 243 | return; |
1085 | pj | 244 | } |
245 | task_activate(p1[i]); |
||
246 | |||
247 | hard_task_default_model(m); |
||
248 | hard_task_def_ctrl_jet (m); |
||
249 | hard_task_def_arg (m, (void *)i); |
||
250 | hard_task_def_wcet (m, w2[i]); |
||
251 | hard_task_def_mit (m, t2[i]); |
||
252 | hard_task_def_usemath (m); |
||
253 | p2[i] = task_create(pname2[i], consumer, &m, NULL); |
||
254 | if (p2[i] == NIL) { |
||
1377 | giacomo | 255 | sys_shutdown_message("Could not create task <consumer>"); |
1382 | giacomo | 256 | sys_end(); |
1377 | giacomo | 257 | return; |
1085 | pj | 258 | } |
259 | task_activate(p2[i]); |
||
260 | } |
||
261 | |||
262 | /*--------------------------------------------------------------*/ |
||
263 | /* Disegna i processi e il canale di comunicazione */ |
||
264 | /*--------------------------------------------------------------*/ |
||
265 | |||
266 | void draw_channel(int i) |
||
267 | { |
||
268 | char buffer[32]; /* buffer per sprintf */ |
||
269 | int yc = YP + i*DELTA; /* altezza del canale */ |
||
270 | |||
1386 | giacomo | 271 | grx_circle(XP1,yc,R,rgb16(255,0,0)); |
272 | grx_text("P1",XP1-8,yc-4,rgb16(255,255,255),0); |
||
1085 | pj | 273 | |
1386 | giacomo | 274 | grx_circle(XP2,yc,R,rgb16(255,0,0)); |
275 | grx_text("P2",XP2-8,yc-4,rgb16(255,255,255),0); |
||
1085 | pj | 276 | |
1386 | giacomo | 277 | grx_rect(XC,yc-R,XC+L,yc+R,rgb16(255,255,255)); |
278 | grx_text("CAB",XC+16,yc-4,rgb16(255,255,255),0); |
||
1085 | pj | 279 | |
1386 | giacomo | 280 | grx_line(XP1+R,yc,XC,yc,rgb16(255,255,255)); |
281 | grx_line(XC+L,yc,XP2-R,yc,rgb16(255,255,255)); |
||
1085 | pj | 282 | |
1386 | giacomo | 283 | grx_text("T1 = ms",X1+40,yc+R+16,rgb16(255,255,255),0); |
1085 | pj | 284 | sprintf(buffer,"%ld", t1[i]); |
1386 | giacomo | 285 | grx_text(buffer,X1+88,yc+R+16,rgb16(255,255,255),0); |
1085 | pj | 286 | |
1386 | giacomo | 287 | grx_text("T2 = ms",X2+40,yc+R+16,rgb16(255,255,255),0); |
1085 | pj | 288 | sprintf(buffer,"%ld", t2[i]); |
1386 | giacomo | 289 | grx_text(buffer,X2+88,yc+R+16,rgb16(255,255,255),0); |
1085 | pj | 290 | } |