Subversion Repositories shark

Rev

Rev 1581 | 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
 ------------
1581 tullio 21
 CVS :        $Id: ego.c,v 1.8 2006-07-03 12:47:33 tullio Exp $
1085 pj 22
 
23
 File:        $File$
1581 tullio 24
 Revision:    $Revision: 1.8 $
25
 Last update: $Date: 2006-07-03 12:47:33 $
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 */
1581 tullio 138
        emerg.ascii = 'c';
139
        emerg.scan = KEY_C;
140
        emerg.flag = CNTL_BIT;
1377 giacomo 141
        emerg.status = KEY_PRESSED;
142
        keyb_hook(emerg,my_end,FALSE);
1581 tullio 143
 
144
        emerg.flag = CNTR_BIT;
145
  emerg.status = KEY_PRESSED;
146
  keyb_hook(emerg,my_end,FALSE);
1085 pj 147
 
148
        /* a small banner */
1388 giacomo 149
        grx_text("EGO Test",8,8,rgb16(255,255,255),0);
1581 tullio 150
        grx_text("Press Ctrl-C to exit",8,16,rgb16(255,255,255),0);
1085 pj 151
 
152
        /* ego1 creation */
153
        hard_task_default_model(m1);
154
        hard_task_def_ctrl_jet (m1);
155
        hard_task_def_arg      (m1, (void *)0);
156
        hard_task_def_wcet     (m1, 5000);
157
        hard_task_def_mit      (m1, PERIOD_T1);
158
        hard_task_def_group    (m1,1);
159
        pid1 = task_create("ego1", ego, &m1, NULL);
160
        if (pid1 == NIL) {
1377 giacomo 161
          sys_shutdown_message("Could not create task <ego1>");
1547 pj 162
          exit(1);
1085 pj 163
        }
164
 
165
        /* ego2 creation */
166
        hard_task_default_model(m2);
167
        hard_task_def_ctrl_jet (m2);
168
        hard_task_def_arg      (m2, (void *)1);
169
        hard_task_def_wcet     (m2, 5000);
170
        hard_task_def_mit      (m2, PERIOD_T2);
171
        hard_task_def_group    (m2,1);
172
        pid2 = task_create("ego2", ego, &m2, NULL);
173
        if (pid2 == NIL) {
1377 giacomo 174
          sys_shutdown_message("Could not create task <ego2>");
1547 pj 175
          exit(1);
1085 pj 176
        }
177
 
178
        /* ego3 creation */
179
        hard_task_default_model(m3);
180
        hard_task_def_ctrl_jet (m3);
181
        hard_task_def_arg      (m3, (void *)2);
182
        hard_task_def_wcet     (m3, 5000);
183
        hard_task_def_mit      (m3, PERIOD_T3);
184
        hard_task_def_group    (m3,1);
185
        pid3 = task_create("ego3", ego, &m3, NULL);
186
        if (pid3 == NIL) {
1377 giacomo 187
          sys_shutdown_message("Could not create task <ego3>");
1547 pj 188
          exit(1);
1085 pj 189
        }
190
 
191
        /* and finally we activate the three threads... */
192
        group_activate(1);
193
 
194
        /*
195
           now the task main ends, but the system does not shutdown because
196
           there are the three task ego1, ego2, and ego3 running.
197
 
198
           The demo will finish if a Alt-X key is pressed.
199
        */
200
 
201
        return 0;
202
}
203
 
204
/****************************************************************/