TUKS MCU Introductory course / TUKS-COURSE-2-LED
Committer:
elmot
Date:
Sat Feb 25 08:59:21 2017 +0000
Revision:
6:0018763974d3
Parent:
1:d0dfbce63a89
No comment

Who changed what in which revision?

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