OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ucos-ii/] [2.91/] [tasks/] [tasks1.c] - Blame information for rev 471

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 471 julius
/*
2
  Example uC/OS-II tasks.
3
 
4
  Time-related tasks.
5
*/
6
 
7
#include "includes.h"
8
 
9
 
10
#define          TASK_STK_SIZE     512                /* Size of each task's stacks (# of WORDs)       */
11
 
12
#define          TASK_START_ID       0                /* Application tasks IDs                         */
13
#define          TASK_CLK_ID         1
14
#define          TASK_1_ID           2
15
#define          TASK_2_ID           3
16
#define          TASK_3_ID           4
17
 
18
#define          TASK_START_PRIO    10                /* Application tasks priorities                  */
19
#define          TASK_CLK_PRIO      11
20
#define          TASK_1_PRIO        12
21
#define          TASK_2_PRIO        13
22
#define          TASK_3_PRIO        14
23
 
24
OS_STK        TaskClkStk[TASK_STK_SIZE];              /* Clock      task stack                         */
25
OS_STK        Task1Stk[TASK_STK_SIZE];                /* Task #1    task stack                         */
26
OS_STK        Task2Stk[TASK_STK_SIZE];                /* Task #2    task stack                         */
27
OS_STK        Task3Stk[TASK_STK_SIZE];                /* Task #3    task stack                         */
28
 
29
void  TaskStartCreateTasks (void);
30
void  TaskClk(void *data);
31
void  Task1(void *data);
32
void  Task2(void *data);
33
void  Task3(void *data);
34
 
35
 
36
/* This function is called from TaskStart() in the same file as main() */
37
void  TaskStartCreateTasks (void)
38
{
39
 
40
  OSTaskCreateExt(TaskClk,
41
                  (void *)0,
42
                  &TaskClkStk[TASK_STK_SIZE - 1],
43
                  TASK_CLK_PRIO,
44
                  TASK_CLK_ID,
45
                  &TaskClkStk[0],
46
                  TASK_STK_SIZE,
47
                  (void *)0,
48
                  OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
49
 
50
  OSTaskCreateExt(Task1,
51
                  (void *)0,
52
                  &Task1Stk[TASK_STK_SIZE - 1],
53
                  TASK_1_PRIO,
54
                  TASK_1_ID,
55
                  &Task1Stk[0],
56
                  TASK_STK_SIZE,
57
                  (void *)0,
58
                  OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
59
 
60
  OSTaskCreateExt(Task2,
61
                  (void *)0,
62
                  &Task2Stk[TASK_STK_SIZE - 1],
63
                  TASK_2_PRIO,
64
                  TASK_2_ID,
65
                  &Task2Stk[0],
66
                  TASK_STK_SIZE,
67
                  (void *)0,
68
                  OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
69
 
70
  OSTaskCreateExt(Task3,
71
                  (void *)0,
72
                  &Task3Stk[TASK_STK_SIZE - 1],
73
                  TASK_3_PRIO,
74
                  TASK_3_ID,
75
                  &Task3Stk[0],
76
                  TASK_STK_SIZE,
77
                  (void *)0,
78
 
79
                  OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
80
 
81
  console_clear();
82
  console_puts(28,2,"************************");
83
  console_puts(28,3,"* uC/OS-II on OpenRISC *");
84
  console_puts(28,4,"************************");
85
  console_puts(28,6,"Tasks 1: four timer tasks");
86
  console_puts(18,20,"Press 'q' to exit simulator, or reset board.");
87
 
88
 
89
}
90
 
91
/*********************************************************************************************************
92
 *                                               TASK #1
93
 *
94
 * Description: This task executes every 100 mS and measures the time it task to perform stack checking
95
 *              for each of the 5 application tasks.  Also, this task displays the statistics related to
96
 *              each task's stack usage.
97
 *********************************************************************************************************
98
 */
99
 
100
void  Task1 (void *pdata)
101
{
102
  INT8U       err;
103
  OS_STK_DATA data;                       /* Storage for task stack data                             */
104
  INT16U      time;                       /* Execution time (in uS)                                  */
105
  INT8U       i;
106
  char        s[80];
107
 
108
 
109
  pdata = pdata;
110
 
111
  console_puts(28, 10, "Memory stats per task");
112
 
113
  console_puts(19, 11, "Total       Free        Used        Time Taken");
114
 
115
  for (;;) {
116
    for (i = 0; i < 5; i++) {
117
      //TODO: Some sort of timer PC_ElapsedStart();
118
      err  = OSTaskStkChk(TASK_START_PRIO + i, &data);
119
      //TODO: time = PC_ElapsedStop();
120
      if (err == OS_ERR_NONE) {
121
        sprintf(s, "%4d        %4d        %4d        %6d",
122
               data.OSFree + data.OSUsed,
123
               data.OSFree,
124
               data.OSUsed,
125
               time);
126
        console_puts(19, 12 + i, s/*, DISP_FGND_BLACK + DISP_BGND_LIGHT_GRAY*/);
127
      }
128
    }
129
    OSTimeDlyHMSM(0, 0, 0, 100);                       /* Delay for 100 mS                         */
130
  }
131
}
132
/*$PAGE*/
133
/*
134
*********************************************************************************************************
135
*                                               TASK #2
136
*
137
* Description: This task displays a clockwise rotating wheel on the screen.
138
*********************************************************************************************************
139
*/
140
#define SPIN1X 30
141
#define SPIN1Y 18
142
#define SPIN1DLY 20
143
void  Task2 (void *data)
144
{
145
  data = data;
146
  for (;;) {
147
    console_putc(SPIN1X, SPIN1Y, '|');
148
    OSTimeDly(SPIN1DLY);
149
    console_putc(SPIN1X, SPIN1Y, '/');
150
    OSTimeDly(SPIN1DLY);
151
    console_putc(SPIN1X, SPIN1Y, '-');
152
    OSTimeDly(SPIN1DLY);
153
    console_putc(SPIN1X, SPIN1Y, '\\');
154
    OSTimeDly(SPIN1DLY);
155
  }
156
}
157
/*$PAGE*/
158
/*
159
*********************************************************************************************************
160
*                                               TASK #3
161
*
162
* Description: This task displays a counter-clockwise rotating wheel on the screen.
163
*
164
* Note(s)    : I allocated 500 bytes of storage on the stack to artificially 'eat' up stack space.
165
*********************************************************************************************************
166
*/
167
#define SPIN2X 50
168
#define SPIN2Y 18
169
#define SPIN2DLY 10
170
void  Task3 (void *data)
171
{
172
  char    dummy[200];
173
  INT16U  i;
174
 
175
 
176
  data = data;
177
  for (i = 0; i < 199; i++) {
178
    dummy[i] = '?';
179
  }
180
  for (;;) {
181
    console_putc(SPIN2X, SPIN2Y, '|');
182
    OSTimeDly(SPIN2DLY);
183
    console_putc(SPIN2X, SPIN2Y, '\\');
184
    OSTimeDly(SPIN2DLY);
185
    console_putc(SPIN2X, SPIN2Y, '-');
186
    OSTimeDly(SPIN2DLY);
187
    console_putc(SPIN2X, SPIN2Y, '/');
188
    OSTimeDly(SPIN2DLY);
189
  }
190
}
191
/*$PAGE*/
192
/*
193
*********************************************************************************************************
194
*                                               CLOCK TASK
195
*********************************************************************************************************
196
*/
197
 
198
void  TaskClk (void *data)
199
{
200
  char s[64];
201
  int secs = 0;
202
 
203
  data = data;
204
  for (;;) {
205
    //PC_GetDateTime(s);
206
    //PC_DispStr(60, 23, s, DISP_FGND_YELLOW + DISP_BGND_BLUE);
207
    sprintf(s, "Seconds: %d\n",secs);
208
    console_puts(33, 8, s);
209
    OSTimeDly(OS_TICKS_PER_SEC);
210
    secs++;
211
  }
212
}
213
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.