-
Notifications
You must be signed in to change notification settings - Fork 0
/
ostest.c
executable file
·288 lines (249 loc) · 8.07 KB
/
ostest.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* main.c
*/
#include <stdint.h>
#include "OS_Critical/OS.h"
#include "OS_Critical/MutualExclusionManager/OS_Semaphore.h"
#include "OS_Critical/MemoryManager/heap.h"
#include "Shell/Shell.h"
#include "OS_Critical/BackgroundThreadManager/OS_BackgroundThread.h"
#include "Venkatware/FIFO.h"
#include "OS_Critical/HardwareManager/OS_Hardware.h"
#include "OS_Critical/CommunicationManager/OS_Communication.h"
#include "OS_Critical/EvaluationManager/Jitter.h"
#include "inc/tm4c123gh6pm.h"
#include "ProjectControl.h"
uint32_t Count1;
#ifdef LAB3_MAIN
#define PE0 (*((volatile unsigned long *)0x40024004))
#define PE1 (*((volatile unsigned long *)0x40024008))
#define PE2 (*((volatile unsigned long *)0x40024010))
#define PE3 (*((volatile unsigned long *)0x40024020))
Semaphore* ThreadSem;
uint32_t Done = 0;
void Thread1(void)
{
Count1 = 0;
for(;;)
{
//OS_DisplayOutString("Thread 1 running\n");
Count1++;
}
}
uint32_t Count2;
void Thread2()
{
Count2 = 0;
for(;;)
{
OS_DisplayOutString("Thread 2 running\n");
Count2++;
OS_Sleep(1000);
}
}
uint32_t Count3;
void Thread3()
{
Count3 = 0;
for(;;)
{
OS_DisplayOutString("Thread 3 running\n");
Count3++;
OS_Sleep(1000);
}
}
uint32_t Count4 = 0;
void Thread4()
{
Count4++;
}
uint32_t Count5 = 0;
void Thread5()
{
Count5++;
}
int myMain(void)
{
OS_Init();
OS_AddThread(&Thread2, 100, 3);
OS_AddThread(&Thread3, 100, 3);
OS_AddThread(&Thread1, 100, 4);
OS_AddThread(&Interpreter, 100, 4);
OS_AddPeriodicThread(Thread4, TIME_1MS, 4);
OS_AddPeriodicThread(Thread5, TIME_1MS, 5);
ThreadSem = OS_InitSemaphore(1);
OS_Launch(TIME_1MS/10);
return 0;
}
// TestMain5
//******************* Lab 3 Preparation 2**********
// Modify this so it runs with your RTOS (i.e., fix the time units to match your OS)
// run this with
// UART0, 115200 baud rate, used to output results
// SYSTICK interrupts, period established by OS_Launch
// first timer interrupts, period established by first call to OS_AddPeriodicThread
// second timer interrupts, period established by second call to OS_AddPeriodicThread
// SW1 no interrupts
// SW2 no interrupts
unsigned long CountA; // number of times Task A called
unsigned long CountB; // number of times Task B called
//*******PseudoWork*************
// simple time delay, simulates user program doing real work
// Input: amount of work in 100ns units (free free to change units
// Output: none
uint32_t NumCreated;
void PseudoWork(unsigned short work){
unsigned short startTime;
startTime = OS_Time(); // time in 20ns units
while(OS_TimeDifference(startTime,OS_Time()) <= work*5){}
}
void Thread6(void){ // foreground thread
Count1 = 0;
for(;;){
Count1++;
}
}
extern void Jitter(void); // prints jitter information (write this)
void Thread7(void){ // foreground thread
OS_SerialOutString("\n\rEE345M/EE380L, Lab 3 Preparation 2\n\r");
OS_Sleep(5000); // 10 seconds
JittertPrint();
OS_SerialOutString("\n\r\n\r");
OS_Kill();
}
#define workA 500 // {5,50,500 us} work in Task A
#define counts1us 10 // number of OS_Time counts per 1us
uint32_t counttime = 0;
uint64_t time1 = 0;
void TaskA(void){ // called every {1000, 2990us} in background
CountA++;
Jitter();
PseudoWork(workA*counts1us); // do work (100ns time resolution)
}
#define workB 250 // 250 us work in Task B
void TaskB(void){ // called every pB in background
CountB++;
PseudoWork(workB*counts1us); // do work (100ns time resolution)
}
int mainItLast(void){ // Testmain5 Lab 3
OS_Init(); // initialize, disable interrupts
NumCreated = 0 ;
NumCreated += OS_AddThread(&Thread6,128,2);
NumCreated += OS_AddThread(&Thread7,128,1);
OS_AddPeriodicThread(&TaskA,TIME_500US,0); // 1 ms, higher priority
OS_AddPeriodicThread(&TaskB,2*TIME_1MS,1); // 2 ms, lower priority
OS_Launch(TIME_2MS); // 2ms, doesn't return, interrupts enabled in here
return 0; // this never executes
}
////////////////
//Test Main 6//
//******************* Lab 3 Preparation 4**********
// Modify this so it runs with your RTOS used to test blocking semaphores
// run this with
// UART0, 115200 baud rate, used to output results
// SYSTICK interrupts, period established by OS_Launch
// first timer interrupts, period established by first call to OS_AddPeriodicThread
// second timer interrupts, period established by second call to OS_AddPeriodicThread
// SW1 no interrupts,
// SW2 no interrupts
void PortE_Init(void){ unsigned long volatile delay;
SYSCTL_RCGC2_R |= 0x10; // activate port E
delay = SYSCTL_RCGC2_R;
delay = SYSCTL_RCGC2_R;
GPIO_PORTE_DIR_R |= 0x0F; // make PE3-0 output heartbeats
GPIO_PORTE_AFSEL_R &= ~0x0F; // disable alt funct on PE3-0
GPIO_PORTE_DEN_R |= 0x0F; // enable digital I/O on PE3-0
GPIO_PORTE_PCTL_R = ~0x0000FFFF;
GPIO_PORTE_AMSEL_R &= ~0x0F;; // disable analog functionality on PF
}
Semaphore* s; // test of this counting semaphore
unsigned long SignalCount1; // number of times s is signaled
unsigned long SignalCount2; // number of times s is signaled
unsigned long SignalCount3; // number of times s is signaled
unsigned long WaitCount1; // number of times s is successfully waited on
unsigned long WaitCount2; // number of times s is successfully waited on
unsigned long WaitCount3; // number of times s is successfully waited on
#define MAXCOUNT 20000
void OutputThread(void){ // foreground thread
OS_SerialOutString("\n\rEE345M/EE380L, Lab 3 Preparation 4\n\r");
while(SignalCount1+SignalCount2+SignalCount3<100*MAXCOUNT){
OS_Sleep(1000); // 1 second
OS_SerialOutString(".");
}
OS_SerialOutString(" done\n\r");
OS_SerialOutString("Signalled="); OS_SerialOutUDec(SignalCount1+SignalCount2+SignalCount3);
OS_SerialOutString(", Waited="); OS_SerialOutUDec(WaitCount1+WaitCount2+WaitCount3);
OS_SerialOutString("\n\r");
OS_Kill();
}
void Wait1(void){ // foreground thread
for(;;){
OS_Wait(s); // three threads waiting
PE1 ^=0x02;
WaitCount1++;
}
}
void Wait2(void){ // foreground thread
for(;;){
OS_Wait(s); // three threads waiting
PE2 ^=0x04;
WaitCount2++;
}
}
void Wait3(void){ // foreground thread
for(;;){
OS_Wait(s); // three threads waiting
PE3 ^= 0x08;
WaitCount3++;
}
}
void Signal1(void){ // called every 799us in background
if(SignalCount1<MAXCOUNT){
OS_Signal(s);
SignalCount1++;
}
}
// edit this so it changes the periodic rate
void Signal2(void){ // called every 1111us in background
if(SignalCount2<MAXCOUNT){
OS_Signal(s);
SignalCount2++;
}
}
void Signal3(void){ // foreground
while(SignalCount3<98*MAXCOUNT){
OS_Signal(s);
SignalCount3++;
}
OS_Kill();
}
long add(const long n, const long m){
static long result;
result = m+n;
return result;
}
int main(void){ // Testmain6 Lab 3
volatile unsigned long delay;
OS_Init(); // initialize, disable interrupts
PortE_Init();
delay = add(3,4);
SignalCount1 = 0; // number of times s is signaled
SignalCount2 = 0; // number of times s is signaled
SignalCount3 = 0; // number of times s is signaled
WaitCount1 = 0; // number of times s is successfully waited on
WaitCount2 = 0; // number of times s is successfully waited on
WaitCount3 = 0; // number of times s is successfully waited on
s = OS_InitSemaphore(0); // this is the test semaphore
OS_AddPeriodicThread(&Signal1,(799*TIME_1MS)/1000,0); // 0.799 ms, higher priority
OS_AddPeriodicThread(&Signal2,(1111*TIME_1MS)/1000,1); // 1.111 ms, lower priority
NumCreated = 0 ;
NumCreated += OS_AddThread(&Thread6,128,6); // idle thread to keep from crashing
NumCreated += OS_AddThread(&OutputThread,128,2); // results output thread
NumCreated += OS_AddThread(&Signal3,128,2); // signalling thread
NumCreated += OS_AddThread(&Wait1,128,2); // waiting thread
NumCreated += OS_AddThread(&Wait2,128,2); // waiting thread
NumCreated += OS_AddThread(&Wait3,128,2); // waiting thread
OS_Launch(TIME_1MS); // 1ms, doesn't return, interrupts enabled in here
return 0; // this never executes
}
#endif