Subversion Repositories shark

Rev

Rev 1098 | Rev 1382 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 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
 ------------
1123 pj 21
 CVS :        $Id: ego.c,v 1.3 2003-01-07 17:10:15 pj Exp $
1085 pj 22
 
23
 File:        $File$
1123 pj 24
 Revision:    $Revision: 1.3 $
25
 Last update: $Date: 2003-01-07 17:10:15 $
1085 pj 26
 ------------
27
**/
28
 
29
/*
30
 * Copyright (C) 2000 Paolo Gai and Giorgio Buttazzo
31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
/****************************************************************/
49
/*      PERIODIC PROCESS TEST                                   */
50
/****************************************************************/
51
 
52
#include <kernel/kern.h>
53
#include <drivers/glib.h>
54
#include <drivers/keyb.h>
55
 
56
#include <semaphore.h>
57
 
58
#define X0      10
59
 
60
/* task periods */
61
#define PERIOD_T1 100000
62
#define PERIOD_T2 200000
63
#define PERIOD_T3 300000
64
 
65
/* X position of the text printed by each task */
66
int     y[3] = {100, 180, 260};
67
 
68
/* text printed by each task */
69
char    talk[3][50] = { "I am ego1 and I print a character every 100 ms",
70
                        "I am ego2 and I print a character every 200 ms",
71
                        "I am ego3 and I print a character every 300 ms"};
72
 
73
/* A semaphore used to access Video Cards in mutual exclusion */
74
sem_t   mutex;
75
 
76
/***************************************************************/
77
 
78
TASK    ego(void *arg)
79
{
80
int     i = (int)arg;
81
int     leng;
82
char    s[2];
83
int     x;
84
int     j = 0;
85
 
86
        /* compute the length of the string to print */
87
        leng = 0;
88
        while (talk[i][leng] != 0) leng++;
89
 
90
        x = X0;
91
        s[1] = 0;
92
        task_endcycle();
93
 
94
        while (1) {
95
                s[0] = talk[i][j];
96
                sem_wait(&mutex);
97
                /* grx_text("TEST", 100,100,12,0); */
98
                grx_text(s,x,y[i],12+i,0);
99
                sem_post(&mutex);
100
                x += 8;
101
                if (++j == leng) {
102
                        j = 0;
103
                        x = X0;
104
                        y[i] += 8;
105
                        if (y[i]>340) y[i]=100;
106
                }
107
                task_endcycle();
108
        }
109
}
110
 
111
 
112
/****************************************************************/
113
 
114
/* This function is called when Alt-X is pressed.
115
   It simply shutdown the system using sys_end.
116
   Note that the byebye() function is called only if we exit from
117
   the system using sys_end()!!!!
118
*/
119
void my_end(KEY_EVT* e)
120
{
121
        sys_end();
122
}
123
 
124
/******************************************************************/
125
 
126
/* This function is called when the system exit correctly after Alt-X.
127
   It exits from the graphic mode and then it prints a small greeting.
128
   Note that:
129
   - The function calls grx_exit, so it must be registered using
130
     RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because
131
     at that point the kernel is already returned in real mode!!!)
132
   - When an exception is raised, the exception handler is called.
133
     Since the exception handler already exits from the graphic mode,
134
     this funcion has not to be called. For this reason:
135
     . we registered byebye using the flag NO_AT_ABORT
136
     . the exception handler exits using sys_abort; in that way byebye is
137
       NOT called
138
*/
139
 
140
void byebye(void *arg)
141
{
142
  grx_close();
1098 pj 143
  cprintf("Bye Bye!\n");
1085 pj 144
}
145
 
146
/****************************** MAIN ******************************/
147
 
148
int main(int argc, char **argv)
149
{
150
  PID             pid1, pid2, pid3;
151
  KEY_EVT         emerg;
152
  HARD_TASK_MODEL m1, m2, m3;
153
 
154
        /* Set the closing function */
1123 pj 155
        sys_atrunlevel(byebye, NULL, RUNLEVEL_BEFORE_EXIT);
1085 pj 156
 
157
        /* Initializes the semaphore */
158
        sem_init(&mutex,0,1);
159
 
160
        /* graphic card Initialization */
161
        if (grx_init() < 1) {
162
           sys_abort(1);
163
        }
164
 
165
        if (grx_open(640, 480, 8) < 0) {
1098 pj 166
            cprintf("GRX Err\n");
1085 pj 167
            sys_abort(1);
168
        }
169
 
170
        /* set the keyboard handler to exit correctly */
171
        emerg.ascii = 'x';
172
        emerg.scan = KEY_X;
173
        emerg.flag = ALTL_BIT;
174
        keyb_hook(emerg,my_end);
175
 
176
        emerg.ascii = 'x';
177
        emerg.scan = KEY_X;
178
        emerg.flag = ALTR_BIT;
179
        keyb_hook(emerg,my_end);
180
 
181
        /* a small banner */
182
        grx_text("EGO Test",8,8,WHITE,0);
183
        grx_text("Press Alt-X to exit",8,16,WHITE,0);
184
 
185
        /* ego1 creation */
186
        hard_task_default_model(m1);
187
        hard_task_def_ctrl_jet (m1);
188
        hard_task_def_arg      (m1, (void *)0);
189
        hard_task_def_wcet     (m1, 5000);
190
        hard_task_def_mit      (m1, PERIOD_T1);
191
        hard_task_def_group    (m1,1);
192
        pid1 = task_create("ego1", ego, &m1, NULL);
193
        if (pid1 == NIL) {
194
          grx_close();
195
          perror("Could not create task <ego1>");
196
          sys_abort(1);
197
        }
198
 
199
        /* ego2 creation */
200
        hard_task_default_model(m2);
201
        hard_task_def_ctrl_jet (m2);
202
        hard_task_def_arg      (m2, (void *)1);
203
        hard_task_def_wcet     (m2, 5000);
204
        hard_task_def_mit      (m2, PERIOD_T2);
205
        hard_task_def_group    (m2,1);
206
        pid2 = task_create("ego2", ego, &m2, NULL);
207
        if (pid2 == NIL) {
208
          grx_close();
209
          perror("Could not create task <ego2>");
210
          sys_abort(1);
211
        }
212
 
213
        /* ego3 creation */
214
        hard_task_default_model(m3);
215
        hard_task_def_ctrl_jet (m3);
216
        hard_task_def_arg      (m3, (void *)2);
217
        hard_task_def_wcet     (m3, 5000);
218
        hard_task_def_mit      (m3, PERIOD_T3);
219
        hard_task_def_group    (m3,1);
220
        pid3 = task_create("ego3", ego, &m3, NULL);
221
        if (pid3 == NIL) {
222
          grx_close();
223
          perror("Could not create task <ego3>");
224
          sys_abort(1);
225
        }
226
 
227
        /* and finally we activate the three threads... */
228
        group_activate(1);
229
 
230
        /*
231
           now the task main ends, but the system does not shutdown because
232
           there are the three task ego1, ego2, and ego3 running.
233
 
234
           The demo will finish if a Alt-X key is pressed.
235
        */
236
 
237
        return 0;
238
}
239
 
240
/****************************************************************/