mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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