Subversion Repositories shark

Rev

Rev 1382 | Rev 1398 | 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
 *
1386 giacomo 37
 * CVS :        $Id: cabs.c,v 1.6 2004-04-19 14:11:07 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
                                col = col % 15 + 1;
179
                        }
180
                }
181
 
182
                task_endcycle();
183
        }
184
}
185
 
186
/*--------------------------------------------------------------*/
187
/* read data from a cab                                         */
188
/*--------------------------------------------------------------*/
189
 
190
TASK    consumer(void *arg)
191
{
192
int     i = (int)arg;
193
char    *p;
194
char    s[2];
195
int     x, y;
196
int     col = 13;
197
int     ybase = YY + i*DELTA;
198
 
199
        x = X2;
200
        y = ybase;
201
        s[1] = 0;
202
 
203
        while (1) {
204
                p = cab_getmes(cid[i]);
205
                s[0] = *p - 'A' + 'a';
206
                cab_unget(cid[i], p);
207
 
208
                grx_text(s,x,y,col,0);
209
                x += 8;
210
 
211
                if (x >= (X2 + NCAR*8)) {
212
                        x = X2;
213
                        y = y + 8;
214
                        if (y >= ybase+16) {
215
                                y = ybase;
216
                                col = col % 15 + 1;
217
                        }
218
                }
219
                task_endcycle();
220
        }
221
}
222
 
223
/*--------------------------------------------------------------*/
224
/* create the two tasks and a channel                           */
225
/*--------------------------------------------------------------*/
226
 
227
void    create_channel(int i)
228
{
229
        HARD_TASK_MODEL m;
230
 
231
        draw_channel(i);
232
        cid[i] = cab_create(cname[i], 1, 2);
233
 
234
        hard_task_default_model(m);
235
        hard_task_def_ctrl_jet (m);
236
        hard_task_def_arg      (m, (void *)i);
237
        hard_task_def_wcet     (m, w1[i]);
238
        hard_task_def_mit      (m, t1[i]);
239
        hard_task_def_usemath  (m);
240
        p1[i] = task_create(pname1[i], producer, &m, NULL);
241
        if (p1[i] == NIL) {
1377 giacomo 242
          sys_shutdown_message("Could not create task <producer>");
1382 giacomo 243
          sys_end();
1377 giacomo 244
          return;
1085 pj 245
        }
246
        task_activate(p1[i]);
247
 
248
        hard_task_default_model(m);
249
        hard_task_def_ctrl_jet (m);
250
        hard_task_def_arg      (m, (void *)i);
251
        hard_task_def_wcet     (m, w2[i]);
252
        hard_task_def_mit      (m, t2[i]);
253
        hard_task_def_usemath  (m);
254
        p2[i] = task_create(pname2[i], consumer, &m, NULL);
255
        if (p2[i] == NIL) {
1377 giacomo 256
          sys_shutdown_message("Could not create task <consumer>");
1382 giacomo 257
          sys_end();
1377 giacomo 258
          return;
1085 pj 259
        }
260
        task_activate(p2[i]);
261
}
262
 
263
/*--------------------------------------------------------------*/
264
/* Disegna i processi e il canale di comunicazione              */
265
/*--------------------------------------------------------------*/
266
 
267
void    draw_channel(int i)
268
{
269
char    buffer[32];                     /* buffer per sprintf   */
270
int     yc = YP + i*DELTA;              /* altezza del canale   */
271
 
1386 giacomo 272
        grx_circle(XP1,yc,R,rgb16(255,0,0));
273
        grx_text("P1",XP1-8,yc-4,rgb16(255,255,255),0);
1085 pj 274
 
1386 giacomo 275
        grx_circle(XP2,yc,R,rgb16(255,0,0));
276
        grx_text("P2",XP2-8,yc-4,rgb16(255,255,255),0);
1085 pj 277
 
1386 giacomo 278
        grx_rect(XC,yc-R,XC+L,yc+R,rgb16(255,255,255));
279
        grx_text("CAB",XC+16,yc-4,rgb16(255,255,255),0);
1085 pj 280
 
1386 giacomo 281
        grx_line(XP1+R,yc,XC,yc,rgb16(255,255,255));
282
        grx_line(XC+L,yc,XP2-R,yc,rgb16(255,255,255));
1085 pj 283
 
1386 giacomo 284
        grx_text("T1 =          ms",X1+40,yc+R+16,rgb16(255,255,255),0);
1085 pj 285
        sprintf(buffer,"%ld", t1[i]);
1386 giacomo 286
        grx_text(buffer,X1+88,yc+R+16,rgb16(255,255,255),0);
1085 pj 287
 
1386 giacomo 288
        grx_text("T2 =          ms",X2+40,yc+R+16,rgb16(255,255,255),0);
1085 pj 289
        sprintf(buffer,"%ld", t2[i]);
1386 giacomo 290
        grx_text(buffer,X2+88,yc+R+16,rgb16(255,255,255),0);
1085 pj 291
}