Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

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