The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
170:e95d10626187
Child:
172:65be27845400
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 156:ff21514d8981 1
AnnaBridge 156:ff21514d8981 2 /** \addtogroup platform */
AnnaBridge 156:ff21514d8981 3 /** @{*/
AnnaBridge 158:1c57384330a6 4 /**
AnnaBridge 158:1c57384330a6 5 * \defgroup platform_stats stats functions
AnnaBridge 158:1c57384330a6 6 * @{
AnnaBridge 158:1c57384330a6 7 */
AnnaBridge 156:ff21514d8981 8 /* mbed Microcontroller Library
AnnaBridge 170:e95d10626187 9 * Copyright (c) 2016-2018 ARM Limited
AnnaBridge 156:ff21514d8981 10 *
AnnaBridge 156:ff21514d8981 11 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 156:ff21514d8981 12 * you may not use this file except in compliance with the License.
AnnaBridge 156:ff21514d8981 13 * You may obtain a copy of the License at
AnnaBridge 156:ff21514d8981 14 *
AnnaBridge 156:ff21514d8981 15 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 156:ff21514d8981 16 *
AnnaBridge 156:ff21514d8981 17 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 156:ff21514d8981 18 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 156:ff21514d8981 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 156:ff21514d8981 20 * See the License for the specific language governing permissions and
AnnaBridge 156:ff21514d8981 21 * limitations under the License.
AnnaBridge 156:ff21514d8981 22 */
AnnaBridge 156:ff21514d8981 23 #ifndef MBED_STATS_H
AnnaBridge 156:ff21514d8981 24 #define MBED_STATS_H
AnnaBridge 156:ff21514d8981 25 #include <stdint.h>
AnnaBridge 156:ff21514d8981 26 #include <stddef.h>
Anna Bridge 169:a7c7b631e539 27 #include "hal/ticker_api.h"
AnnaBridge 156:ff21514d8981 28
AnnaBridge 156:ff21514d8981 29 #ifdef __cplusplus
AnnaBridge 156:ff21514d8981 30 extern "C" {
AnnaBridge 156:ff21514d8981 31 #endif
AnnaBridge 156:ff21514d8981 32
Anna Bridge 169:a7c7b631e539 33 #ifdef MBED_ALL_STATS_ENABLED
Anna Bridge 169:a7c7b631e539 34 #define MBED_SYS_STATS_ENABLED 1
Anna Bridge 169:a7c7b631e539 35 #define MBED_STACK_STATS_ENABLED 1
Anna Bridge 169:a7c7b631e539 36 #define MBED_CPU_STATS_ENABLED 1
Anna Bridge 169:a7c7b631e539 37 #define MBED_HEAP_STATS_ENABLED 1
Anna Bridge 169:a7c7b631e539 38 #define MBED_THREAD_STATS_ENABLED 1
Anna Bridge 169:a7c7b631e539 39 #endif
Anna Bridge 169:a7c7b631e539 40
AnnaBridge 158:1c57384330a6 41 /**
AnnaBridge 158:1c57384330a6 42 * struct mbed_stats_heap_t definition
AnnaBridge 158:1c57384330a6 43 */
AnnaBridge 156:ff21514d8981 44 typedef struct {
AnnaBridge 171:3a7713b1edbc 45 uint32_t current_size; /**< Bytes currently allocated on the heap */
AnnaBridge 171:3a7713b1edbc 46 uint32_t max_size; /**< Maximum bytes allocated on the heap at one time since reset */
AnnaBridge 171:3a7713b1edbc 47 uint32_t total_size; /**< Cumulative sum of bytes allocated on the heap that have not been freed */
AnnaBridge 171:3a7713b1edbc 48 uint32_t reserved_size; /**< Current number of bytes reserved for the heap */
AnnaBridge 171:3a7713b1edbc 49 uint32_t alloc_cnt; /**< Current number of allocations that have not been freed since reset */
AnnaBridge 171:3a7713b1edbc 50 uint32_t alloc_fail_cnt; /**< Number of failed allocations since reset */
AnnaBridge 171:3a7713b1edbc 51 uint32_t overhead_size; /**< Number of bytes used to store heap statistics. This overhead takes up space on the heap, reducing the available heap space */
AnnaBridge 156:ff21514d8981 52 } mbed_stats_heap_t;
AnnaBridge 156:ff21514d8981 53
AnnaBridge 156:ff21514d8981 54 /**
AnnaBridge 171:3a7713b1edbc 55 * Fill the passed in heap stat structure with the heap statistics.
AnnaBridge 156:ff21514d8981 56 *
AnnaBridge 156:ff21514d8981 57 * @param stats A pointer to the mbed_stats_heap_t structure to fill
AnnaBridge 156:ff21514d8981 58 */
AnnaBridge 156:ff21514d8981 59 void mbed_stats_heap_get(mbed_stats_heap_t *stats);
AnnaBridge 156:ff21514d8981 60
AnnaBridge 158:1c57384330a6 61 /**
AnnaBridge 158:1c57384330a6 62 * struct mbed_stats_stack_t definition
AnnaBridge 158:1c57384330a6 63 */
AnnaBridge 156:ff21514d8981 64 typedef struct {
AnnaBridge 171:3a7713b1edbc 65 uint32_t thread_id; /**< Identifier for the thread that owns the stack or 0 if representing accumulated statistics */
AnnaBridge 171:3a7713b1edbc 66 uint32_t max_size; /**< Maximum number of bytes used on the stack since the thread was started */
AnnaBridge 171:3a7713b1edbc 67 uint32_t reserved_size; /**< Current number of bytes reserved for the stack */
AnnaBridge 171:3a7713b1edbc 68 uint32_t stack_cnt; /**< The number of stacks represented in the accumulated statistics or 1 if repesenting a single stack */
AnnaBridge 156:ff21514d8981 69 } mbed_stats_stack_t;
AnnaBridge 156:ff21514d8981 70
AnnaBridge 156:ff21514d8981 71 /**
AnnaBridge 171:3a7713b1edbc 72 * Fill the passed in structure with stack statistics accumulated for all threads. The thread_id will be 0
AnnaBridge 156:ff21514d8981 73 * and stack_cnt will represent number of threads.
AnnaBridge 156:ff21514d8981 74 *
AnnaBridge 156:ff21514d8981 75 * @param stats A pointer to the mbed_stats_stack_t structure to fill
AnnaBridge 156:ff21514d8981 76 */
AnnaBridge 156:ff21514d8981 77 void mbed_stats_stack_get(mbed_stats_stack_t *stats);
AnnaBridge 156:ff21514d8981 78
AnnaBridge 156:ff21514d8981 79 /**
AnnaBridge 171:3a7713b1edbc 80 * Fill the passed array of structures with the stack statistics for each available thread.
AnnaBridge 156:ff21514d8981 81 *
AnnaBridge 156:ff21514d8981 82 * @param stats A pointer to an array of mbed_stats_stack_t structures to fill
AnnaBridge 156:ff21514d8981 83 * @param count The number of mbed_stats_stack_t structures in the provided array
AnnaBridge 171:3a7713b1edbc 84 * @return The number of mbed_stats_stack_t structures that have been filled.
AnnaBridge 171:3a7713b1edbc 85 * If the number of stacks on the system is less than or equal to count, it will equal the number of stacks on the system.
AnnaBridge 171:3a7713b1edbc 86 * If the number of stacks on the system is greater than count, it will equal count.
AnnaBridge 156:ff21514d8981 87 */
AnnaBridge 156:ff21514d8981 88 size_t mbed_stats_stack_get_each(mbed_stats_stack_t *stats, size_t count);
AnnaBridge 156:ff21514d8981 89
Anna Bridge 169:a7c7b631e539 90 /**
Anna Bridge 169:a7c7b631e539 91 * struct mbed_stats_cpu_t definition
Anna Bridge 169:a7c7b631e539 92 */
Anna Bridge 169:a7c7b631e539 93 typedef struct {
AnnaBridge 171:3a7713b1edbc 94 us_timestamp_t uptime; /**< Time since the system has started */
AnnaBridge 171:3a7713b1edbc 95 us_timestamp_t idle_time; /**< Time spent in the idle thread since the system has started */
AnnaBridge 171:3a7713b1edbc 96 us_timestamp_t sleep_time; /**< Time spent in sleep since the system has started */
AnnaBridge 171:3a7713b1edbc 97 us_timestamp_t deep_sleep_time; /**< Time spent in deep sleep since the system has started */
Anna Bridge 169:a7c7b631e539 98 } mbed_stats_cpu_t;
Anna Bridge 169:a7c7b631e539 99
Anna Bridge 169:a7c7b631e539 100 /**
Anna Bridge 169:a7c7b631e539 101 * Fill the passed in CPU stat structure with CPU statistics.
Anna Bridge 169:a7c7b631e539 102 *
Anna Bridge 169:a7c7b631e539 103 * @param stats A pointer to the mbed_stats_cpu_t structure to fill
Anna Bridge 169:a7c7b631e539 104 */
Anna Bridge 169:a7c7b631e539 105 void mbed_stats_cpu_get(mbed_stats_cpu_t *stats);
Anna Bridge 169:a7c7b631e539 106
Anna Bridge 169:a7c7b631e539 107 /**
Anna Bridge 169:a7c7b631e539 108 * struct mbed_stats_thread_t definition
Anna Bridge 169:a7c7b631e539 109 */
Anna Bridge 169:a7c7b631e539 110 typedef struct {
AnnaBridge 171:3a7713b1edbc 111 uint32_t id; /**< ID of the thread */
AnnaBridge 171:3a7713b1edbc 112 uint32_t state; /**< State of the thread */
AnnaBridge 171:3a7713b1edbc 113 uint32_t priority; /**< Priority of the thread (higher number indicates higher priority) */
AnnaBridge 171:3a7713b1edbc 114 uint32_t stack_size; /**< Current number of bytes reserved for the stack */
AnnaBridge 171:3a7713b1edbc 115 uint32_t stack_space; /**< Current number of free bytes remaining on the stack */
AnnaBridge 171:3a7713b1edbc 116 const char *name; /**< Name of the thread */
Anna Bridge 169:a7c7b631e539 117 } mbed_stats_thread_t;
Anna Bridge 169:a7c7b631e539 118
Anna Bridge 169:a7c7b631e539 119 /**
AnnaBridge 171:3a7713b1edbc 120 * Fill the passed array of stat structures with the thread statistics for each available thread.
Anna Bridge 169:a7c7b631e539 121 *
Anna Bridge 169:a7c7b631e539 122 * @param stats A pointer to an array of mbed_stats_thread_t structures to fill
Anna Bridge 169:a7c7b631e539 123 * @param count The number of mbed_stats_thread_t structures in the provided array
AnnaBridge 171:3a7713b1edbc 124 * @return The number of mbed_stats_thread_t structures that have been filled.
AnnaBridge 171:3a7713b1edbc 125 * If the number of threads on the system is less than or equal to count, it will equal the number of threads on the system.
AnnaBridge 171:3a7713b1edbc 126 * If the number of threads on the system is greater than count, it will equal count.
Anna Bridge 169:a7c7b631e539 127 */
Anna Bridge 169:a7c7b631e539 128 size_t mbed_stats_thread_get_each(mbed_stats_thread_t *stats, size_t count);
Anna Bridge 169:a7c7b631e539 129
Anna Bridge 169:a7c7b631e539 130 /**
Anna Bridge 169:a7c7b631e539 131 * enum mbed_compiler_id_t definition
Anna Bridge 169:a7c7b631e539 132 */
Anna Bridge 169:a7c7b631e539 133 typedef enum {
Anna Bridge 169:a7c7b631e539 134 ARM = 1, /**< ARM */
Anna Bridge 169:a7c7b631e539 135 GCC_ARM, /**< GNU ARM */
Anna Bridge 169:a7c7b631e539 136 IAR /**< IAR */
Anna Bridge 169:a7c7b631e539 137 } mbed_compiler_id_t;
Anna Bridge 169:a7c7b631e539 138
Anna Bridge 169:a7c7b631e539 139 /**
Anna Bridge 169:a7c7b631e539 140 * struct mbed_stats_sys_t definition
Anna Bridge 169:a7c7b631e539 141 */
Anna Bridge 169:a7c7b631e539 142 typedef struct {
AnnaBridge 171:3a7713b1edbc 143 uint32_t os_version; /**< Mbed OS version (populated only for tagged releases) */
AnnaBridge 171:3a7713b1edbc 144 uint32_t cpu_id; /**< CPUID register data (Cortex-M only supported) */
Anna Bridge 169:a7c7b631e539 145 mbed_compiler_id_t compiler_id; /**< Compiler ID \ref mbed_compiler_id_t */
Anna Bridge 169:a7c7b631e539 146 uint32_t compiler_version; /**< Compiler version */
Anna Bridge 169:a7c7b631e539 147 } mbed_stats_sys_t;
Anna Bridge 169:a7c7b631e539 148
Anna Bridge 169:a7c7b631e539 149 /**
AnnaBridge 171:3a7713b1edbc 150 * Fill the passed in system stat structure with system statistics.
Anna Bridge 169:a7c7b631e539 151 *
Anna Bridge 169:a7c7b631e539 152 * @param stats A pointer to the mbed_stats_sys_t structure to fill
Anna Bridge 169:a7c7b631e539 153 */
Anna Bridge 169:a7c7b631e539 154 void mbed_stats_sys_get(mbed_stats_sys_t *stats);
Anna Bridge 169:a7c7b631e539 155
AnnaBridge 156:ff21514d8981 156 #ifdef __cplusplus
AnnaBridge 156:ff21514d8981 157 }
AnnaBridge 156:ff21514d8981 158 #endif
AnnaBridge 156:ff21514d8981 159
AnnaBridge 156:ff21514d8981 160 #endif
AnnaBridge 156:ff21514d8981 161
AnnaBridge 156:ff21514d8981 162 /** @}*/
AnnaBridge 158:1c57384330a6 163
AnnaBridge 158:1c57384330a6 164 /** @}*/