USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zaitsev 10:41552d038a69 1 #include "mbed_stats.h"
Zaitsev 10:41552d038a69 2 #include <string.h>
Zaitsev 10:41552d038a69 3
Zaitsev 10:41552d038a69 4 #if MBED_CONF_RTOS_PRESENT
Zaitsev 10:41552d038a69 5 #include "cmsis_os.h"
Zaitsev 10:41552d038a69 6 #endif
Zaitsev 10:41552d038a69 7
Zaitsev 10:41552d038a69 8 // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp
Zaitsev 10:41552d038a69 9
Zaitsev 10:41552d038a69 10 void mbed_stats_stack_get(mbed_stats_stack_t *stats)
Zaitsev 10:41552d038a69 11 {
Zaitsev 10:41552d038a69 12 memset(stats, 0, sizeof(mbed_stats_stack_t));
Zaitsev 10:41552d038a69 13
Zaitsev 10:41552d038a69 14 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
Zaitsev 10:41552d038a69 15 osThreadEnumId enumid = _osThreadsEnumStart();
Zaitsev 10:41552d038a69 16 osThreadId threadid;
Zaitsev 10:41552d038a69 17
Zaitsev 10:41552d038a69 18 while ((threadid = _osThreadEnumNext(enumid))) {
Zaitsev 10:41552d038a69 19 osEvent e;
Zaitsev 10:41552d038a69 20
Zaitsev 10:41552d038a69 21 e = _osThreadGetInfo(threadid, osThreadInfoStackMax);
Zaitsev 10:41552d038a69 22 if (e.status == osOK) {
Zaitsev 10:41552d038a69 23 stats->max_size += (uint32_t)e.value.p;
Zaitsev 10:41552d038a69 24 }
Zaitsev 10:41552d038a69 25
Zaitsev 10:41552d038a69 26 e = _osThreadGetInfo(threadid, osThreadInfoStackSize);
Zaitsev 10:41552d038a69 27 if (e.status == osOK) {
Zaitsev 10:41552d038a69 28 stats->reserved_size += (uint32_t)e.value.p;
Zaitsev 10:41552d038a69 29 }
Zaitsev 10:41552d038a69 30
Zaitsev 10:41552d038a69 31 stats->stack_cnt += 1;
Zaitsev 10:41552d038a69 32 }
Zaitsev 10:41552d038a69 33 #endif
Zaitsev 10:41552d038a69 34 }
Zaitsev 10:41552d038a69 35
Zaitsev 10:41552d038a69 36 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count)
Zaitsev 10:41552d038a69 37 {
Zaitsev 10:41552d038a69 38 memset(stats, 0, count*sizeof(mbed_stats_stack_t));
Zaitsev 10:41552d038a69 39 size_t i = 0;
Zaitsev 10:41552d038a69 40
Zaitsev 10:41552d038a69 41 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
Zaitsev 10:41552d038a69 42 osThreadEnumId enumid = _osThreadsEnumStart();
Zaitsev 10:41552d038a69 43 osThreadId threadid;
Zaitsev 10:41552d038a69 44
Zaitsev 10:41552d038a69 45 while ((threadid = _osThreadEnumNext(enumid)) && i < count) {
Zaitsev 10:41552d038a69 46 osEvent e;
Zaitsev 10:41552d038a69 47
Zaitsev 10:41552d038a69 48 e = _osThreadGetInfo(threadid, osThreadInfoStackMax);
Zaitsev 10:41552d038a69 49 if (e.status == osOK) {
Zaitsev 10:41552d038a69 50 stats[i].max_size = (uint32_t)e.value.p;
Zaitsev 10:41552d038a69 51 }
Zaitsev 10:41552d038a69 52
Zaitsev 10:41552d038a69 53 e = _osThreadGetInfo(threadid, osThreadInfoStackSize);
Zaitsev 10:41552d038a69 54 if (e.status == osOK) {
Zaitsev 10:41552d038a69 55 stats[i].reserved_size = (uint32_t)e.value.p;
Zaitsev 10:41552d038a69 56 }
Zaitsev 10:41552d038a69 57
Zaitsev 10:41552d038a69 58 stats[i].thread_id = (uint32_t)threadid;
Zaitsev 10:41552d038a69 59 stats[i].stack_cnt = 1;
Zaitsev 10:41552d038a69 60 i += 1;
Zaitsev 10:41552d038a69 61 }
Zaitsev 10:41552d038a69 62 #endif
Zaitsev 10:41552d038a69 63
Zaitsev 10:41552d038a69 64 return i;
Zaitsev 10:41552d038a69 65 }
Zaitsev 10:41552d038a69 66
Zaitsev 10:41552d038a69 67 #if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT
Zaitsev 10:41552d038a69 68 #warning Stack statistics are currently not supported without the rtos.
Zaitsev 10:41552d038a69 69 #endif