Subversion Repositories shark

Rev

Rev 1388 | 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
 ------------
1547 pj 21
 CVS :        $Id: ego.c,v 1.7 2005-01-08 14:31:38 pj Exp $
1085 pj 22
 
23
 File:        $File$
1547 pj 24
 Revision:    $Revision: 1.7 $
25
 Last update: $Date: 2005-01-08 14:31:38 $
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
 
1382 giacomo 54
#include <drivers/shark_keyb26.h>
1377 giacomo 55
#include <drivers/shark_fb26.h>
1085 pj 56
#define X0      10
57
 
58
/* task periods */
59
#define PERIOD_T1 100000
60
#define PERIOD_T2 200000
61
#define PERIOD_T3 300000
62
 
63
/* X position of the text printed by each task */
64
int     y[3] = {100, 180, 260};
65
 
66
/* text printed by each task */
67
char    talk[3][50] = { "I am ego1 and I print a character every 100 ms",
68
                        "I am ego2 and I print a character every 200 ms",
69
                        "I am ego3 and I print a character every 300 ms"};
70
 
71
/***************************************************************/
72
 
73
TASK    ego(void *arg)
74
{
75
int     i = (int)arg;
76
int     leng;
77
char    s[2];
78
int     x;
79
int     j = 0;
80
 
81
        /* compute the length of the string to print */
82
        leng = 0;
83
        while (talk[i][leng] != 0) leng++;
84
 
85
        x = X0;
86
        s[1] = 0;
87
        task_endcycle();
88
 
89
        while (1) {
90
                s[0] = talk[i][j];
1388 giacomo 91
                grx_text(s,x,y[i],rgb16(255,255,255),0);
1085 pj 92
                x += 8;
93
                if (++j == leng) {
94
                        j = 0;
95
                        x = X0;
96
                        y[i] += 8;
97
                        if (y[i]>340) y[i]=100;
98
                }
99
                task_endcycle();
100
        }
101
}
102
 
103
 
104
/****************************************************************/
105
 
106
/* This function is called when Alt-X is pressed.
107
*/
108
void my_end(KEY_EVT* e)
109
{
1547 pj 110
        exit(0);
1085 pj 111
}
112
 
113
/******************************************************************/
114
 
115
/* This function is called when the system exit correctly after Alt-X.
116
   It exits from the graphic mode and then it prints a small greeting.
117
   Note that:
118
   - The function calls grx_exit, so it must be registered using
119
     RUNLEVEL_BEFORE_EXIT (RUNLEVEL_AFTER_EXIT does not work because
120
     at that point the kernel is already returned in real mode!!!)
121
   - When an exception is raised, the exception handler is called.
122
     Since the exception handler already exits from the graphic mode,
123
     this funcion has not to be called. For this reason:
124
     . we registered byebye using the flag NO_AT_ABORT
1547 pj 125
     . the exception handler exits using exit; in that way byebye is
1085 pj 126
       NOT called
127
*/
128
 
129
/****************************** MAIN ******************************/
130
 
131
int main(int argc, char **argv)
132
{
133
  PID             pid1, pid2, pid3;
134
  KEY_EVT         emerg;
135
  HARD_TASK_MODEL m1, m2, m3;
136
 
137
        /* set the keyboard handler to exit correctly */
138
        emerg.ascii = 'x';
139
        emerg.scan = KEY_X;
140
        emerg.flag = ALTL_BIT;
1377 giacomo 141
        emerg.status = KEY_PRESSED;
142
        keyb_hook(emerg,my_end,FALSE);
1085 pj 143
 
144
        /* a small banner */
1388 giacomo 145
        grx_text("EGO Test",8,8,rgb16(255,255,255),0);
146
        grx_text("Press Alt-X to exit",8,16,rgb16(255,255,255),0);
1085 pj 147
 
148
        /* ego1 creation */
149
        hard_task_default_model(m1);
150
        hard_task_def_ctrl_jet (m1);
151
        hard_task_def_arg      (m1, (void *)0);
152
        hard_task_def_wcet     (m1, 5000);
153
        hard_task_def_mit      (m1, PERIOD_T1);
154
        hard_task_def_group    (m1,1);
155
        pid1 = task_create("ego1", ego, &m1, NULL);
156
        if (pid1 == NIL) {
1377 giacomo 157
          sys_shutdown_message("Could not create task <ego1>");
1547 pj 158
          exit(1);
1085 pj 159
        }
160
 
161
        /* ego2 creation */
162
        hard_task_default_model(m2);
163
        hard_task_def_ctrl_jet (m2);
164
        hard_task_def_arg      (m2, (void *)1);
165
        hard_task_def_wcet     (m2, 5000);
166
        hard_task_def_mit      (m2, PERIOD_T2);
167
        hard_task_def_group    (m2,1);
168
        pid2 = task_create("ego2", ego, &m2, NULL);
169
        if (pid2 == NIL) {
1377 giacomo 170
          sys_shutdown_message("Could not create task <ego2>");
1547 pj 171
          exit(1);
1085 pj 172
        }
173
 
174
        /* ego3 creation */
175
        hard_task_default_model(m3);
176
        hard_task_def_ctrl_jet (m3);
177
        hard_task_def_arg      (m3, (void *)2);
178
        hard_task_def_wcet     (m3, 5000);
179
        hard_task_def_mit      (m3, PERIOD_T3);
180
        hard_task_def_group    (m3,1);
181
        pid3 = task_create("ego3", ego, &m3, NULL);
182
        if (pid3 == NIL) {
1377 giacomo 183
          sys_shutdown_message("Could not create task <ego3>");
1547 pj 184
          exit(1);
1085 pj 185
        }
186
 
187
        /* and finally we activate the three threads... */
188
        group_activate(1);
189
 
190
        /*
191
           now the task main ends, but the system does not shutdown because
192
           there are the three task ego1, ego2, and ego3 running.
193
 
194
           The demo will finish if a Alt-X key is pressed.
195
        */
196
 
197
        return 0;
198
}
199
 
200
/****************************************************************/