source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/platform/mbed_stats.c@ 374

Last change on this file since 374 was 374, checked in by coas-nagasima, 5 years ago

mbed関連を更新
シリアルドライバをmbedのHALを使うよう変更
ファイルディスクリプタの処理を更新

  • Property charset set to UTF-8
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 4.2 KB
Line 
1#include "platform/mbed_assert.h"
2#include "mbed_stats.h"
3#include "mbed_power_mgmt.h"
4#include "platform/mbed_version.h"
5#include <string.h>
6#include <stdlib.h>
7
8#include "device.h"
9#if 0 //def MBED_CONF_RTOS_PRESENT
10#include "cmsis_os2.h"
11#include "rtos/rtos_idle.h"
12#elif defined(MBED_STACK_STATS_ENABLED) || defined(MBED_THREAD_STATS_ENABLED) || defined(MBED_CPU_STATS_ENABLED)
13#warning Statistics are currently not supported without the rtos.
14#endif
15
16#if defined(MBED_CPU_STATS_ENABLED) && (!defined(DEVICE_LPTICKER) || !defined(DEVICE_SLEEP))
17#warning CPU statistics are not supported without low power timer support.
18#endif
19
20void mbed_stats_cpu_get(mbed_stats_cpu_t *stats)
21{
22 MBED_ASSERT(stats != NULL);
23 memset(stats, 0, sizeof(mbed_stats_cpu_t));
24#if defined(MBED_CPU_STATS_ENABLED) && defined(DEVICE_LPTICKER) && defined(DEVICE_SLEEP)
25 stats->uptime = mbed_uptime();
26 stats->idle_time = mbed_time_idle();
27 stats->sleep_time = mbed_time_sleep();
28 stats->deep_sleep_time = mbed_time_deepsleep();
29#endif
30}
31
32// note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp
33void mbed_stats_stack_get(mbed_stats_stack_t *stats)
34{
35 MBED_ASSERT(stats != NULL);
36 memset(stats, 0, sizeof(mbed_stats_stack_t));
37
38#if defined(MBED_STACK_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT)
39 uint32_t thread_n = osThreadGetCount();
40 unsigned i;
41 osThreadId_t *threads;
42
43 threads = malloc(sizeof(osThreadId_t) * thread_n);
44 // Don't fail on lack of memory
45 if (!threads) {
46 return;
47 }
48
49 osKernelLock();
50 thread_n = osThreadEnumerate(threads, thread_n);
51
52 for (i = 0; i < thread_n; i++) {
53 uint32_t stack_size = osThreadGetStackSize(threads[i]);
54 stats->max_size += stack_size - osThreadGetStackSpace(threads[i]);
55 stats->reserved_size += stack_size;
56 stats->stack_cnt++;
57 }
58 osKernelUnlock();
59
60 free(threads);
61#endif
62}
63
64size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count)
65{
66 MBED_ASSERT(stats != NULL);
67 memset(stats, 0, count * sizeof(mbed_stats_stack_t));
68
69 size_t i = 0;
70
71#if defined(MBED_STACK_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT)
72 osThreadId_t *threads;
73
74 threads = malloc(sizeof(osThreadId_t) * count);
75 // Don't fail on lack of memory
76 if (!threads) {
77 return 0;
78 }
79
80 osKernelLock();
81 count = osThreadEnumerate(threads, count);
82
83 for (i = 0; i < count; i++) {
84 uint32_t stack_size = osThreadGetStackSize(threads[i]);
85 stats[i].max_size = stack_size - osThreadGetStackSpace(threads[i]);
86 stats[i].reserved_size = stack_size;
87 stats[i].thread_id = (uint32_t)threads[i];
88 stats[i].stack_cnt = 1;
89 }
90 osKernelUnlock();
91
92 free(threads);
93#endif
94
95 return i;
96}
97
98size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count)
99{
100 MBED_ASSERT(stats != NULL);
101 memset(stats, 0, count * sizeof(mbed_stats_thread_t));
102 size_t i = 0;
103
104#if defined(MBED_THREAD_STATS_ENABLED) && defined(MBED_CONF_RTOS_PRESENT)
105 osThreadId_t *threads;
106
107 threads = malloc(sizeof(osThreadId_t) * count);
108 MBED_ASSERT(threads != NULL);
109
110 osKernelLock();
111 count = osThreadEnumerate(threads, count);
112
113 for (i = 0; i < count; i++) {
114 stats[i].id = (uint32_t)threads[i];
115 stats[i].state = (uint32_t)osThreadGetState(threads[i]);
116 stats[i].priority = (uint32_t)osThreadGetPriority(threads[i]);
117 stats[i].stack_size = osThreadGetStackSize(threads[i]);
118 stats[i].stack_space = osThreadGetStackSpace(threads[i]);
119 stats[i].name = osThreadGetName(threads[i]);
120 }
121 osKernelUnlock();
122 free(threads);
123#endif
124 return i;
125}
126
127void mbed_stats_sys_get(mbed_stats_sys_t *stats)
128{
129 MBED_ASSERT(stats != NULL);
130 memset(stats, 0, sizeof(mbed_stats_sys_t));
131
132#if defined(MBED_SYS_STATS_ENABLED)
133 stats->os_version = MBED_VERSION;
134#if defined(__CORTEX_M)
135 stats->cpu_id = SCB->CPUID;
136#endif
137#if defined(__IAR_SYSTEMS_ICC__)
138 stats->compiler_id = IAR;
139 stats->compiler_version = __VER__;
140#elif defined(__CC_ARM)
141 stats->compiler_id = ARM;
142 stats->compiler_version = __ARMCC_VERSION;
143#elif defined(__GNUC__)
144 stats->compiler_id = GCC_ARM;
145 stats->compiler_version = (__GNUC__ * 10000 + __GNUC_MINOR__ * 100);
146#endif
147
148#endif
149 return;
150}
Note: See TracBrowser for help on using the repository browser.