-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab4b_app.c
72 lines (55 loc) · 1.5 KB
/
lab4b_app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
File: lab4b_app.c
Revision date: 23 December 2003
Description: Application code for EE 425 lab 4B (Kernel essentials B)
*/
#include "clib.h"
#include "yakk.h"
#define ASTACKSIZE 256 /* Size of each stack in words */
#define BSTACKSIZE 256
#define CSTACKSIZE 256
int AStk[ASTACKSIZE]; /* Space for each task's stack */
int BStk[BSTACKSIZE];
int CStk[CSTACKSIZE];
void ATask(void); /* Function prototypes for task code */
void BTask(void);
void CTask(void);
void main(void)
{
YKInitialize();
printString("Creating task A...\n");
YKNewTask(ATask, (void *)&AStk[ASTACKSIZE], 5);
printString("Starting kernel...\n");
YKRun();
}
void ATask(void)
{
printString("Task A started!\n");
printString("Creating low priority task B...\n");
YKNewTask(BTask, (void *)&BStk[BSTACKSIZE], 7);
printString("Creating task C...\n");
YKNewTask(CTask, (void *)&CStk[CSTACKSIZE], 2);
printString("Task A is still running! Oh no! Task A was supposed to stop.\n");
exit(0);
}
void BTask(void)
{
printString("Task B started! Oh no! Task B wasn't supposed to run.\n");
exit(0);
}
void CTask(void)
{
int count;
unsigned numCtxSwitches;
YKEnterMutex();
numCtxSwitches = YKCtxSwCount;
YKExitMutex();
printString("Task C started after ");
printUInt(numCtxSwitches);
printString(" context switches!\n");
while (1)
{
printString("Executing in task C.\n");
for(count = 0; count < 5000; count++);
}
}