mbed library sources. Supersedes mbed-src.

Dependents:   SPIne CH_Communicatuin_Test CH_Communicatuin_Test2 MCP_SPIne ... more

Fork of mbed-dev-f303 by Ben Katz

Committer:
AnnaBridge
Date:
Wed Jun 21 17:46:44 2017 +0100
Revision:
167:e84263d55307
Parent:
152:9a67f0b066fc
This updates the lib to the mbed lib v 145

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 152:9a67f0b066fc 1 #include "mbed_stats.h"
<> 152:9a67f0b066fc 2 #include <string.h>
AnnaBridge 167:e84263d55307 3 #include <stdlib.h>
AnnaBridge 167:e84263d55307 4 #include "mbed_assert.h"
<> 152:9a67f0b066fc 5
<> 152:9a67f0b066fc 6 #if MBED_CONF_RTOS_PRESENT
AnnaBridge 167:e84263d55307 7 #include "cmsis_os2.h"
<> 152:9a67f0b066fc 8 #endif
<> 152:9a67f0b066fc 9
<> 152:9a67f0b066fc 10 // note: mbed_stats_heap_get defined in mbed_alloc_wrappers.cpp
<> 152:9a67f0b066fc 11
<> 152:9a67f0b066fc 12 void mbed_stats_stack_get(mbed_stats_stack_t *stats)
<> 152:9a67f0b066fc 13 {
<> 152:9a67f0b066fc 14 memset(stats, 0, sizeof(mbed_stats_stack_t));
<> 152:9a67f0b066fc 15
<> 152:9a67f0b066fc 16 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
AnnaBridge 167:e84263d55307 17 uint32_t thread_n = osThreadGetCount();
AnnaBridge 167:e84263d55307 18 unsigned i;
AnnaBridge 167:e84263d55307 19 osThreadId_t *threads;
<> 152:9a67f0b066fc 20
AnnaBridge 167:e84263d55307 21 threads = malloc(sizeof(osThreadId_t) * thread_n);
AnnaBridge 167:e84263d55307 22 MBED_ASSERT(threads != NULL);
AnnaBridge 167:e84263d55307 23
AnnaBridge 167:e84263d55307 24 osKernelLock();
AnnaBridge 167:e84263d55307 25 thread_n = osThreadEnumerate(threads, thread_n);
<> 152:9a67f0b066fc 26
AnnaBridge 167:e84263d55307 27 for(i = 0; i < thread_n; i++) {
AnnaBridge 167:e84263d55307 28 uint32_t stack_size = osThreadGetStackSize(threads[i]);
AnnaBridge 167:e84263d55307 29 stats->max_size += stack_size - osThreadGetStackSpace(threads[i]);
AnnaBridge 167:e84263d55307 30 stats->reserved_size += stack_size;
AnnaBridge 167:e84263d55307 31 stats->stack_cnt++;
AnnaBridge 167:e84263d55307 32 }
AnnaBridge 167:e84263d55307 33 osKernelUnlock();
<> 152:9a67f0b066fc 34
AnnaBridge 167:e84263d55307 35 free(threads);
<> 152:9a67f0b066fc 36 #endif
<> 152:9a67f0b066fc 37 }
<> 152:9a67f0b066fc 38
<> 152:9a67f0b066fc 39 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count)
<> 152:9a67f0b066fc 40 {
<> 152:9a67f0b066fc 41 memset(stats, 0, count*sizeof(mbed_stats_stack_t));
<> 152:9a67f0b066fc 42 size_t i = 0;
<> 152:9a67f0b066fc 43
<> 152:9a67f0b066fc 44 #if MBED_STACK_STATS_ENABLED && MBED_CONF_RTOS_PRESENT
AnnaBridge 167:e84263d55307 45 osThreadId_t *threads;
<> 152:9a67f0b066fc 46
AnnaBridge 167:e84263d55307 47 threads = malloc(sizeof(osThreadId_t) * count);
AnnaBridge 167:e84263d55307 48 MBED_ASSERT(threads != NULL);
AnnaBridge 167:e84263d55307 49
AnnaBridge 167:e84263d55307 50 osKernelLock();
AnnaBridge 167:e84263d55307 51 count = osThreadEnumerate(threads, count);
<> 152:9a67f0b066fc 52
AnnaBridge 167:e84263d55307 53 for(i = 0; i < count; i++) {
AnnaBridge 167:e84263d55307 54 uint32_t stack_size = osThreadGetStackSize(threads[i]);
AnnaBridge 167:e84263d55307 55 stats[i].max_size = stack_size - osThreadGetStackSpace(threads[i]);
AnnaBridge 167:e84263d55307 56 stats[i].reserved_size = stack_size;
AnnaBridge 167:e84263d55307 57 stats[i].thread_id = (uint32_t)threads[i];
AnnaBridge 167:e84263d55307 58 stats[i].stack_cnt = 1;
AnnaBridge 167:e84263d55307 59 }
AnnaBridge 167:e84263d55307 60 osKernelUnlock();
<> 152:9a67f0b066fc 61
AnnaBridge 167:e84263d55307 62 free(threads);
<> 152:9a67f0b066fc 63 #endif
<> 152:9a67f0b066fc 64
<> 152:9a67f0b066fc 65 return i;
<> 152:9a67f0b066fc 66 }
<> 152:9a67f0b066fc 67
<> 152:9a67f0b066fc 68 #if MBED_STACK_STATS_ENABLED && !MBED_CONF_RTOS_PRESENT
<> 152:9a67f0b066fc 69 #warning Stack statistics are currently not supported without the rtos.
<> 152:9a67f0b066fc 70 #endif