1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** Thread-Metric Component */
16 /** */
17 /** Basic Processing Test */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /**************************************************************************/
24 /* */
25 /* FUNCTION RELEASE */
26 /* */
27 /* tm_basic_processing_test PORTABLE C */
28 /* 6.1.7 */
29 /* AUTHOR */
30 /* */
31 /* William E. Lamie, Microsoft Corporation */
32 /* */
33 /* DESCRIPTION */
34 /* */
35 /* This file defines the basic test for determining board processing */
36 /* capabilities */
37 /* */
38 /* RELEASE HISTORY */
39 /* */
40 /* DATE NAME DESCRIPTION */
41 /* */
42 /* 10-15-2021 William E. Lamie Initial Version 6.1.7 */
43 /* */
44 /**************************************************************************/
45 #include "tm_api.h"
46
47
48 /* Define the counters used in the demo application... */
49
50 unsigned long tm_basic_processing_counter;
51
52
53 /* Test array. We will just do a series of calculations on the
54 test array to eat up processing bandwidth. The idea is that
55 all RTOSes should produce the same metric here if everything
56 else is equal, e.g. processor speed, memory speed, etc. */
57
58 volatile unsigned long tm_basic_processing_array[1024];
59
60
61 /* Define the test thread prototypes. */
62
63 void tm_basic_processing_thread_0_entry(void);
64
65
66 /* Define the reporting thread prototype. */
67
68 void tm_basic_processing_thread_report(void);
69
70
71 /* Define the initialization prototype. */
72
73 void tm_basic_processing_initialize(void);
74
75
76 /* Define main entry point. */
77
tm_main()78 void tm_main()
79 {
80
81 /* Initialize the test. */
82 tm_initialize(tm_basic_processing_initialize);
83 }
84
85
86 /* Define the basic processing test initialization. */
87
tm_basic_processing_initialize(void)88 void tm_basic_processing_initialize(void)
89 {
90 /* Create thread 0 at priority 10. */
91 tm_thread_create(0, 10, tm_basic_processing_thread_0_entry);
92
93 /* Resume thread 0. */
94 tm_thread_resume(0);
95
96 /* Create the reporting thread. It will preempt the other
97 threads and print out the test results. */
98 tm_thread_create(5, 2, tm_basic_processing_thread_report);
99 tm_thread_resume(5);
100 }
101
102
103 /* Define the basic processing thread. */
tm_basic_processing_thread_0_entry(void)104 void tm_basic_processing_thread_0_entry(void)
105 {
106
107 int i;
108
109 /* Initialize the test array. */
110 for (i = 0; i < 1024; i++)
111 {
112
113 /* Clear the basic processing array. */
114 tm_basic_processing_array[i] = 0;
115 }
116
117 while(1)
118 {
119
120 /* Loop through the basic processing array, add the previous
121 contents with the contents of the tm_basic_processing_counter
122 and xor the result with the previous value... just to eat
123 up some time. */
124 for (i = 0; i < 1024; i++)
125 {
126
127 /* Update each array entry. */
128 tm_basic_processing_array[i] = (tm_basic_processing_array[i] + tm_basic_processing_counter) ^ tm_basic_processing_array[i];
129 }
130
131 /* Increment the basic processing counter. */
132 tm_basic_processing_counter++;
133 }
134 }
135
136
137 /* Define the basic processing reporting thread. */
tm_basic_processing_thread_report(void)138 void tm_basic_processing_thread_report(void)
139 {
140
141 unsigned long last_counter;
142 unsigned long relative_time;
143
144
145 /* Initialize the last counter. */
146 last_counter = 0;
147
148 /* Initialize the relative time. */
149 relative_time = 0;
150
151 while(1)
152 {
153
154 /* Sleep to allow the test to run. */
155 tm_thread_sleep(TM_TEST_DURATION);
156
157 /* Increment the relative time. */
158 relative_time = relative_time + TM_TEST_DURATION;
159
160 /* Print results to the stdio window. */
161 printf("**** Thread-Metric Basic Single Thread Processing Test **** Relative Time: %lu\n", relative_time);
162
163 /* See if there are any errors. */
164 if (tm_basic_processing_counter == last_counter)
165 {
166
167 printf("ERROR: Invalid counter value(s). Basic processing thread died!\n");
168 }
169
170 /* Show the time period total. */
171 printf("Time Period Total: %lu\n\n", tm_basic_processing_counter - last_counter);
172
173 /* Save the last counter. */
174 last_counter = tm_basic_processing_counter;
175 }
176 }
177