forked from jorya/raw-os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw_stat.c
286 lines (165 loc) · 5.03 KB
/
raw_stat.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
/*
raw os - Copyright (C) Lingjun Chen(jorya_txj).
This file is part of raw os.
raw os is free software; you can redistribute it it under the terms of the
GNU General Public License as published by the Free Software Foundation;
either version 3 of the License, or (at your option) any later version.
raw os is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. if not, write email to jorya.txj@gmail.com
---
A special exception to the LGPL can be applied should you wish to
distribute
a combined work that includes raw os, without being obliged to provide
the source code for any proprietary components. See the file exception.txt
for full details of how and when the exception can be applied.
*/
/* 2014-1 Created by jorya_txj
* xxxxxx please added here
*/
#include <raw_api.h>
#if (RAW_CPU_STACK_DOWN > 0)
void raw_stack_check(void)
{
PORT_STACK *task_stack_start;
task_stack_start = raw_task_active->task_stack_base;
/*statck check method 1*/
if (*task_stack_start != RAW_TASK_STACK_CHECK_WORD) {
port_system_error_process(RAW_SYSTEM_CRITICAL_ERROR, 0, 0, 0, 0, 0, 0);
}
/*statck check method 2*/
if ((PORT_STACK *)(raw_task_active->task_stack) < task_stack_start) {
port_system_error_process(RAW_SYSTEM_CRITICAL_ERROR, 0, 0, 0, 0, 0, 0);
}
}
#else
void raw_stack_check(void)
{
PORT_STACK *task_stack_start;
PORT_STACK *task_stack_end;
task_stack_start = raw_task_active->task_stack_base;
task_stack_end = task_stack_start + raw_task_active->stack_size;
if (*(task_stack_end - 1) != RAW_TASK_STACK_CHECK_WORD) {
port_system_error_process(RAW_SYSTEM_CRITICAL_ERROR, 0, 0, 0, 0, 0, 0);
}
if ((PORT_STACK *)(raw_task_active->task_stack) > task_stack_end) {
port_system_error_process(RAW_SYSTEM_CRITICAL_ERROR, 0, 0, 0, 0, 0, 0);
}
}
#endif
#if (CONFIG_RAW_SYSTEM_STATISTICS > 0)
void raw_statistics_check(void)
{
RAW_HARD_TIME_TYPE task_current_time;
RAW_HARD_TIME_TYPE task_exec_time;
task_current_time = (RAW_HARD_TIME_TYPE)RAW_SYSTEM_TIME_GET();
task_exec_time = task_current_time - raw_task_active->task_time_start;
raw_task_active->task_time_total_run += (RAW_SYS_TIME_TYPE)task_exec_time;
high_ready_obj->task_time_start = task_current_time;
}
#endif
#if (RAW_SCHE_LOCK_MEASURE_CHECK > 0)
void sche_disable_measure_start(void)
{
/*start measure system lock time*/
if (raw_sched_lock == 0u) {
raw_sche_disable_time_start = RAW_CPU_TIME_GET();
}
}
void sche_disable_measure_stop(void)
{
PORT_TIMER_TYPE diff;
/*stop measure system lock time*/
if (raw_sched_lock == 1u) {
diff = RAW_CPU_TIME_GET() - raw_sche_disable_time_start;
if (raw_sche_disable_time_max < diff) {
raw_sche_disable_time_max = diff;
}
}
}
#endif
#if (RAW_CPU_INT_DIS_MEASURE_CHECK > 0)
void int_disable_measure_start(void)
{
int_disable_times++;
/*start measure interrupt disable time*/
if (int_disable_times == 1u) {
raw_int_disable_time_start = RAW_CPU_TIME_GET();
}
}
void int_disable_measure_stop(void)
{
PORT_TIMER_TYPE diff;
int_disable_times--;
/*stop measure interrupt enable time*/
if (int_disable_times == 0u) {
diff = RAW_CPU_TIME_GET() - raw_int_disable_time_start;
if (raw_int_disable_time_max < diff) {
raw_int_disable_time_max = diff;
}
}
}
#endif
#if (RAW_CONFIG_CPU_TIME > 0)
void measure_overhead(void)
{
PORT_TIMER_TYPE diff;
PORT_TIMER_TYPE m1;
PORT_TIMER_TYPE m2;
m1 = RAW_CPU_TIME_GET();
RAW_CPU_TIME_GET();
RAW_CPU_TIME_GET();
m2 = RAW_CPU_TIME_GET();
diff = m2 - m1;
/*measure time overhead*/
system_meaure_overhead = diff;
}
#endif
#if (RAW_CONFIG_CPU_TASK > 0)
void cpu_task_init(void)
{
RAW_SR_ALLOC();
#if (CONFIG_RAW_TIMER > 0)
raw_task_suspend(&raw_timer_obj);
#endif
raw_sleep(1);
USER_CPU_INT_DISABLE();
raw_idle_count = 0;
USER_CPU_INT_ENABLE();
raw_sleep(RAW_TICKS_PER_SECOND / 10);
raw_idle_count_max = raw_idle_count;
raw_task_resume(&raw_cpu_obj);
#if (CONFIG_RAW_TIMER > 0)
raw_task_resume(&raw_timer_obj);
#endif
}
static void cpu_task(void *pa)
{
RAW_SR_ALLOC();
while (1) {
raw_sleep(1);
USER_CPU_INT_DISABLE();
raw_idle_count = 0;
USER_CPU_INT_ENABLE();
raw_sleep(RAW_TICKS_PER_SECOND / 10);
if (raw_idle_count < raw_idle_count_max) {
/*since raw_idle_count is 64 bit so it is not easy to be overflowed*/
cpu_usuage = 10000 - (RAW_U32)((raw_idle_count * 10000) / raw_idle_count_max);
}
if (cpu_usuage > cpu_usuage_max) {
cpu_usuage_max = cpu_usuage;
}
}
}
void cpu_task_start(void)
{
/*Create a cpu statistics task to calculate cpu usuage*/
raw_task_create(&raw_cpu_obj, (RAW_U8 *)"cpu_object", 0,
CPU_TASK_PRIORITY, 0, cpu_task_stack,
CPU_STACK_SIZE, cpu_task, 0);
}
#endif