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:
Wed Jun 21 17:31:38 2017 +0100
Revision:
145:64910690c574
Parent:
128:9bcdf88f62b0
Release 145 of the mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 128:9bcdf88f62b0 1
<> 128:9bcdf88f62b0 2 /** \addtogroup platform */
<> 128:9bcdf88f62b0 3 /** @{*/
<> 128:9bcdf88f62b0 4 /* mbed Microcontroller Library
<> 128:9bcdf88f62b0 5 * Copyright (c) 2006-2016 ARM Limited
<> 128:9bcdf88f62b0 6 *
<> 128:9bcdf88f62b0 7 * Licensed under the Apache License, Version 2.0 (the "License");
<> 128:9bcdf88f62b0 8 * you may not use this file except in compliance with the License.
<> 128:9bcdf88f62b0 9 * You may obtain a copy of the License at
<> 128:9bcdf88f62b0 10 *
<> 128:9bcdf88f62b0 11 * http://www.apache.org/licenses/LICENSE-2.0
<> 128:9bcdf88f62b0 12 *
<> 128:9bcdf88f62b0 13 * Unless required by applicable law or agreed to in writing, software
<> 128:9bcdf88f62b0 14 * distributed under the License is distributed on an "AS IS" BASIS,
<> 128:9bcdf88f62b0 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 128:9bcdf88f62b0 16 * See the License for the specific language governing permissions and
<> 128:9bcdf88f62b0 17 * limitations under the License.
<> 128:9bcdf88f62b0 18 */
<> 128:9bcdf88f62b0 19
<> 128:9bcdf88f62b0 20 #ifndef __MBED_MEM_TRACE_H__
<> 128:9bcdf88f62b0 21 #define __MBED_MEM_TRACE_H__
<> 128:9bcdf88f62b0 22
<> 128:9bcdf88f62b0 23 #ifdef __cplusplus
<> 128:9bcdf88f62b0 24 extern "C" {
<> 128:9bcdf88f62b0 25 #endif
<> 128:9bcdf88f62b0 26
<> 128:9bcdf88f62b0 27 #include <stdint.h>
<> 128:9bcdf88f62b0 28 #include <stddef.h>
<> 128:9bcdf88f62b0 29
<> 128:9bcdf88f62b0 30 /* Operation types for tracer */
<> 128:9bcdf88f62b0 31 enum {
<> 128:9bcdf88f62b0 32 MBED_MEM_TRACE_MALLOC,
<> 128:9bcdf88f62b0 33 MBED_MEM_TRACE_REALLOC,
<> 128:9bcdf88f62b0 34 MBED_MEM_TRACE_CALLOC,
<> 128:9bcdf88f62b0 35 MBED_MEM_TRACE_FREE
<> 128:9bcdf88f62b0 36 };
<> 128:9bcdf88f62b0 37
<> 128:9bcdf88f62b0 38 /* Prefix for the output of the default tracer */
<> 128:9bcdf88f62b0 39 #define MBED_MEM_DEFAULT_TRACER_PREFIX "#"
<> 128:9bcdf88f62b0 40
<> 128:9bcdf88f62b0 41 /**
<> 128:9bcdf88f62b0 42 * Type of the callback used by the memory tracer. This callback is called when a memory
<> 128:9bcdf88f62b0 43 * allocation operation (malloc, realloc, calloc, free) is called and tracing is enabled
<> 128:9bcdf88f62b0 44 * for that memory allocation function.
<> 128:9bcdf88f62b0 45 *
<> 128:9bcdf88f62b0 46 * @param op the ID of the operation (MBED_MEM_TRACE_MALLOC, MBED_MEM_TRACE_REALLOC,
<> 128:9bcdf88f62b0 47 * MBED_MEM_TRACE_CALLOC or MBED_MEM_TRACE_FREE).
<> 128:9bcdf88f62b0 48 * @param res the result that the memory operation returned (NULL for 'free').
<> 128:9bcdf88f62b0 49 * @param caller the caller of the memory operation. Note that the value of 'caller' might be
<> 128:9bcdf88f62b0 50 * unreliable.
<> 128:9bcdf88f62b0 51 *
<> 128:9bcdf88f62b0 52 * The rest of the parameters passed 'mbed_mem_trace_cb_t' are the same as the memory operations
<> 128:9bcdf88f62b0 53 * that triggered its call (see 'man malloc' for details):
<> 128:9bcdf88f62b0 54 *
<> 128:9bcdf88f62b0 55 * - for malloc: cb(MBED_MEM_TRACE_MALLOC, res, caller, size).
<> 128:9bcdf88f62b0 56 * - for realloc: cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size).
<> 128:9bcdf88f62b0 57 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size).
<> 128:9bcdf88f62b0 58 * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr).
<> 128:9bcdf88f62b0 59 */
<> 128:9bcdf88f62b0 60 typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...);
<> 128:9bcdf88f62b0 61
<> 128:9bcdf88f62b0 62 /**
<> 128:9bcdf88f62b0 63 * Set the callback used by the memory tracer (use NULL for disable tracing).
<> 128:9bcdf88f62b0 64 *
<> 128:9bcdf88f62b0 65 * @param cb the callback to call on each memory operation.
<> 128:9bcdf88f62b0 66 */
<> 128:9bcdf88f62b0 67 void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb);
<> 128:9bcdf88f62b0 68
<> 128:9bcdf88f62b0 69 /**
<> 128:9bcdf88f62b0 70 * Trace a call to 'malloc'.
<> 128:9bcdf88f62b0 71 * @param res the result of running 'malloc'.
<> 128:9bcdf88f62b0 72 * @param size the 'size' argument given to 'malloc'.
<> 128:9bcdf88f62b0 73 * @param caller the caller of the memory operation.
<> 128:9bcdf88f62b0 74 * @return 'res' (the first argument).
<> 128:9bcdf88f62b0 75 */
<> 128:9bcdf88f62b0 76 void *mbed_mem_trace_malloc(void *res, size_t size, void *caller);
<> 128:9bcdf88f62b0 77
<> 128:9bcdf88f62b0 78 /**
<> 128:9bcdf88f62b0 79 * Trace a call to 'realloc'.
<> 128:9bcdf88f62b0 80 * @param res the result of running 'realloc'.
<> 128:9bcdf88f62b0 81 * @param ptr the 'ptr' argument given to 'realloc'.
<> 128:9bcdf88f62b0 82 * @param size the 'size' argument given to 'realloc'.
AnnaBridge 145:64910690c574 83 * @param caller the caller of the memory operation.
<> 128:9bcdf88f62b0 84 * @return 'res' (the first argument).
<> 128:9bcdf88f62b0 85 */
<> 128:9bcdf88f62b0 86 void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller);
<> 128:9bcdf88f62b0 87
<> 128:9bcdf88f62b0 88 /**
<> 128:9bcdf88f62b0 89 * Trace a call to 'calloc'.
<> 128:9bcdf88f62b0 90 * @param res the result of running 'calloc'.
AnnaBridge 145:64910690c574 91 * @param num the 'nmemb' argument given to 'calloc'.
<> 128:9bcdf88f62b0 92 * @param size the 'size' argument given to 'calloc'.
<> 128:9bcdf88f62b0 93 * @param caller the caller of the memory operation.
AnnaBridge 145:64910690c574 94 * @return 'res' (the first argument).
<> 128:9bcdf88f62b0 95 */
<> 128:9bcdf88f62b0 96 void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller);
<> 128:9bcdf88f62b0 97
<> 128:9bcdf88f62b0 98 /**
<> 128:9bcdf88f62b0 99 * Trace a call to 'free'.
<> 128:9bcdf88f62b0 100 * @param ptr the 'ptr' argument given to 'free'.
<> 128:9bcdf88f62b0 101 * @param caller the caller of the memory operation.
<> 128:9bcdf88f62b0 102 */
<> 128:9bcdf88f62b0 103 void mbed_mem_trace_free(void *ptr, void *caller);
<> 128:9bcdf88f62b0 104
<> 128:9bcdf88f62b0 105 /**
<> 128:9bcdf88f62b0 106 * Default memory trace callback. DO NOT CALL DIRECTLY. It is meant to be used
<> 128:9bcdf88f62b0 107 * as the second argument of 'mbed_mem_trace_setup'.
<> 128:9bcdf88f62b0 108 *
<> 128:9bcdf88f62b0 109 * The default callback outputs trace data using 'printf', in a format that's
<> 128:9bcdf88f62b0 110 * easily parsable by an external tool. For each memory operation, the callback
AnnaBridge 145:64910690c574 111 * outputs a line that begins with "#<op>:<0xresult>;<0xcaller>-":
<> 128:9bcdf88f62b0 112 *
AnnaBridge 145:64910690c574 113 * @param op identifies the memory operation ('m' for 'malloc', 'r' for 'realloc',
AnnaBridge 145:64910690c574 114 * 'c' for 'calloc' and 'f' for 'free').
AnnaBridge 145:64910690c574 115 * @param res (base 16) is the result of the memor operation. This is always NULL
AnnaBridge 145:64910690c574 116 * for 'free', since 'free' doesn't return anything.
AnnaBridge 145:64910690c574 117 * @param caller (base 16) is the caller of the memory operation. Note that the value
AnnaBridge 145:64910690c574 118 * of 'caller' might be unreliable.
<> 128:9bcdf88f62b0 119 *
<> 128:9bcdf88f62b0 120 * The rest of the output depends on the operation being traced:
<> 128:9bcdf88f62b0 121 *
<> 128:9bcdf88f62b0 122 * - for 'malloc': 'size', where 'size' is the original argument to 'malloc'.
<> 128:9bcdf88f62b0 123 * - for 'realloc': '0xptr;size', where 'ptr' (base 16) and 'size' are the original arguments to 'realloc'.
<> 128:9bcdf88f62b0 124 * - for 'calloc': 'nmemb;size', where 'nmemb' and 'size' are the original arguments to 'calloc'.
<> 128:9bcdf88f62b0 125 * - for 'free': '0xptr', where 'ptr' (base 16) is the original argument to 'free'.
<> 128:9bcdf88f62b0 126 *
<> 128:9bcdf88f62b0 127 * Examples:
<> 128:9bcdf88f62b0 128 *
AnnaBridge 145:64910690c574 129 * - "#m:0x20003240;0x600d-50" encodes a 'malloc' that returned 0x20003240, was called
<> 128:9bcdf88f62b0 130 * by the instruction at 0x600D with a the 'size' argument equal to 50.
AnnaBridge 145:64910690c574 131 * - "#f:0x0;0x602f-0x20003240" encodes a 'free' that was called by the instruction at
<> 128:9bcdf88f62b0 132 * 0x602f with the 'ptr' argument equal to 0x20003240.
<> 128:9bcdf88f62b0 133 */
<> 128:9bcdf88f62b0 134 void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...);
<> 128:9bcdf88f62b0 135
<> 128:9bcdf88f62b0 136 #ifdef __cplusplus
<> 128:9bcdf88f62b0 137 }
<> 128:9bcdf88f62b0 138 #endif
<> 128:9bcdf88f62b0 139
<> 128:9bcdf88f62b0 140 #endif// #ifndef __MBED_MEM_TRACE_H__
<> 128:9bcdf88f62b0 141
<> 128:9bcdf88f62b0 142
<> 128:9bcdf88f62b0 143 /** @}*/