Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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