The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

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