-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniProject3Test.c
242 lines (228 loc) · 7.41 KB
/
MiniProject3Test.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
//// Lab2Test.c
//// Runs on LM4F120/TM4C123
//// You may use, edit, run or distribute this file
//// You are free to change the syntax/organization of this file
//// Jonathan W. Valvano 2/20/17, [email protected]
//// Modified by Sile Shu 10/4/17, [email protected]
//// Modified by Mustafa Hotaki 8/1/2018, [email protected]
//#include <stdint.h>
//#include "OS.h"
//#include "tm4c123gh6pm.h"
//#include "LCD.h"
//#include <string.h>
//#include "UART.h"
//#include "PLL.h"
//#include "PORTE.h"
//#define PERIOD TIME_500US // DAS 2kHz sampling period in system time units
//unsigned long NumCreated; // Number of foreground threads created
////******************* Measurement of context switch time **********
//// Run this to measure the time it takes to perform a task switch
//void Thread8(void){ // only thread running
// while(1){
// PE0 ^= 0x01; // debugging profile
// }
//}
//int Testmain0(void){ // Testmain7
// PortE_Init();
// OS_Init(); // initialize, disable interrupts
// NumCreated = 0 ;
// NumCreated += OS_AddThread(&Thread8, 128, 2);
// OS_Launch(TIME_1MS/10); // 100us, doesn't return, interrupts enabled in here
// return 0; // this never executes
//}
////******************* Initial TEST **********
//// Cooperative thread scheduler
//unsigned long Count1; // number of times thread1 loops
//unsigned long Count2; // number of times thread2 loops
//unsigned long Count3; // number of times thread3 loops
//unsigned long Count4; // number of times thread4 loops
//unsigned long Count5; // number of times thread5 loops
//void Thread1(void){
// Count1 = 0;
// for(;;){
// PE0 ^= 0x01; // heartbeat
// Count1++;
// OS_Suspend(); // cooperative multitasking
// }
//}
//void Thread2(void){
// Count2 = 0;
// for(;;){
// PE1 ^= 0x02; // heartbeat
// Count2++;
// OS_Suspend(); // cooperative multitasking
// }
//}
//void Thread3(void){
// Count3 = 0;
// for(;;){
// PE2 ^= 0x04; // heartbeat
// Count3++;
// OS_Suspend(); // cooperative multitasking
// }
//}
//int Testmain1(void){ // Testmain1
// OS_Init(); // initialize, disable interrupts
// PortE_Init(); // profile user threads
// NumCreated = 0 ;
// NumCreated += OS_AddThread(&Thread1, 128, 1);
// NumCreated += OS_AddThread(&Thread2, 128, 2);
// NumCreated += OS_AddThread(&Thread3, 128, 3);
// // Count1 Count2 Count3 should be equal or off by one at all times
// OS_Launch(TIME_2MS); // doesn't return, interrupts enabled in here
// return 0; // this never executes
//}
////*******************Second TEST**********
//// Preemptive thread scheduler
//void Thread1b(void){
// Count1 = 0;
// for(;;){
// PE0 ^= 0x01; // heartbeat
// Count1++;
// }
//}
//void Thread2b(void){
// Count2 = 0;
// for(;;){
// PE1 ^= 0x02; // heartbeat
// Count2++;
// }
//}
//void Thread3b(void){
// Count3 = 0;
// for(;;){
// PE2 ^= 0x04; // heartbeat
// Count3++;
// }
//}
//int Testmain2(void){ // Testmain2
// OS_Init(); // initialize, disable interrupts
// PortE_Init(); // profile user threads
// NumCreated = 0 ;
// NumCreated += OS_AddThread(&Thread1b, 128, 1);
// NumCreated += OS_AddThread(&Thread2b, 128, 2);
// NumCreated += OS_AddThread(&Thread3b, 128, 3);
//
// OS_Launch(TIME_2MS); // doesn't return, interrupts enabled in here
// return 0; // this never executes
//}
////*******************Third TEST**********
//// no UART1 interrupts
//// SYSTICK interrupts, with or without period established by OS_Launch
//// Timer interrupts, with or without period established by OS_AddPeriodicThread
//// PortF GPIO interrupts, active low
//// no ADC serial port or LCD output
//// tests the spinlock semaphores, tests Sleep and Kill
//Sema4Type Readyc; // set in background
//int Lost;
//void BackgroundThread1c(void){ // called at 1000 Hz
// Count1++;
// OS_Signal(&Readyc);
//}
//void Thread5c(void){
// for(;;){
// OS_Wait(&Readyc);
// Count5++; // Count2 + Count5 should equal Count1
// Lost = Count1-Count5-Count2;
// }
//}
//void Thread2c(void){
// OS_InitSemaphore(&Readyc,0);
// Count1 = 0; // number of times signal is called
// Count2 = 0;
// Count5 = 0; // Count2 + Count5 should equal Count1
// NumCreated += OS_AddThread(&Thread5c, 128, 3);
// OS_AddPeriodicThread(&BackgroundThread1c, TIME_1MS, 0);
// for(;;){
// OS_Wait(&Readyc);
// Count2++; // Count2 + Count5 should equal Count1
// }
//}
//void Thread3c(void){
// Count3 = 0;
// for(;;){
// Count3++;
// }
//}
//void Thread4c(void){ int i;
// for(i=0;i<64;i++){
// Count4++;
// OS_Sleep(10);
// }
// OS_Kill();
// Count4 = 0;
//}
//void BackgroundThread5c(void){ // called when Select button pushed
// NumCreated += OS_AddThread(&Thread4c, 128, 3);
//}
//
//int Testmain3(void){ // Testmain3
// Count4 = 0;
// OS_Init(); // initialize, disable interrupts
//// Count2 + Count5 should equal Count1
// NumCreated = 0 ;
// OS_AddSW1Task(&BackgroundThread5c,2);
// NumCreated += OS_AddThread(&Thread2c, 128, 2);
// NumCreated += OS_AddThread(&Thread3c, 128, 3);
// NumCreated += OS_AddThread(&Thread4c, 128, 3);
// OS_Launch(TIME_2MS); // doesn't return, interrupts enabled in here
// return 0; // this never executes
//}
////*******************Fourth TEST**********
//// Count1 should exactly equal Count2
//// Count3 should be very large
//// Count4 increases by 640 every time select is pressed
//// NumCreated increase by 1 every time select is pressed
//// no UART interrupts
//// SYSTICK interrupts, with or without period established by OS_Launch
//// Timer interrupts, with or without period established by OS_AddPeriodicThread
//// Select switch interrupts, active low
//// no ADC serial port or LCD output
//// tests the spinlock semaphores, tests Sleep and Kill
//Sema4Type Readyd; // set in background
//void BackgroundThread1d(void){ // called at 1000 Hz
//static int i=0;
// i++;
// if(i==50){
// i = 0; //every 50 ms
// Count1++;
// OS_bSignal(&Readyd);
// }
//}
//void Thread2d(void){
// OS_InitSemaphore(&Readyd, 0);
// Count1 = 0;
// Count2 = 0;
// for(;;){
// OS_bWait(&Readyd);
// Count2++;
// }
//}
//void Thread3d(void){
// Count3 = 0;
// for(;;){
// Count3++;
// }
//}
//void Thread4d(void){ int i;
// for(i=0;i<640;i++){
// Count4++;
// OS_Sleep(1);
// }
// OS_Kill();
//}
//void BackgroundThread5d(void){ // called when Select button pushed
// NumCreated += OS_AddThread(&Thread4d, 128, 3);
//}
//int Testmain4(void){ // Testmain4
// Count4 = 0;
// OS_Init(); // initialize, disable interrupts
// NumCreated = 0 ;
// OS_AddPeriodicThread(&BackgroundThread1d,PERIOD,0);
// OS_AddSW1Task(&BackgroundThread5d, 2);
// NumCreated += OS_AddThread(&Thread2d, 128, 2);
// NumCreated += OS_AddThread(&Thread3d, 128, 3);
// NumCreated += OS_AddThread(&Thread4d, 128, 3);
// OS_Launch(TIME_2MS); // doesn't return, interrupts enabled in here
// return 0; // this never executes
//}