Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:01:39 2017 +0000
Revision:
167:1657b442184c
Opencv 3.1 project on GR-PEACH board, 4 apps

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 167:1657b442184c 1 /* mbed Microcontroller Library
thedo 167:1657b442184c 2 * Copyright (c) 2006-2016 ARM Limited
thedo 167:1657b442184c 3 *
thedo 167:1657b442184c 4 * Licensed under the Apache License, Version 2.0 (the "License");
thedo 167:1657b442184c 5 * you may not use this file except in compliance with the License.
thedo 167:1657b442184c 6 * You may obtain a copy of the License at
thedo 167:1657b442184c 7 *
thedo 167:1657b442184c 8 * http://www.apache.org/licenses/LICENSE-2.0
thedo 167:1657b442184c 9 *
thedo 167:1657b442184c 10 * Unless required by applicable law or agreed to in writing, software
thedo 167:1657b442184c 11 * distributed under the License is distributed on an "AS IS" BASIS,
thedo 167:1657b442184c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
thedo 167:1657b442184c 13 * See the License for the specific language governing permissions and
thedo 167:1657b442184c 14 * limitations under the License.
thedo 167:1657b442184c 15 */
thedo 167:1657b442184c 16
thedo 167:1657b442184c 17 #include <stdlib.h>
thedo 167:1657b442184c 18 #include <stdarg.h>
thedo 167:1657b442184c 19 #include <stdio.h>
thedo 167:1657b442184c 20 #include "platform/mbed_mem_trace.h"
thedo 167:1657b442184c 21 #include "platform/mbed_critical.h"
thedo 167:1657b442184c 22
thedo 167:1657b442184c 23 /******************************************************************************
thedo 167:1657b442184c 24 * Internal variables, functions and helpers
thedo 167:1657b442184c 25 *****************************************************************************/
thedo 167:1657b442184c 26
thedo 167:1657b442184c 27 /* The callback function that will be called after a traced memory operations finishes. */
thedo 167:1657b442184c 28 static mbed_mem_trace_cb_t mem_trace_cb;
thedo 167:1657b442184c 29 /* 'trave_level' guards "trace inside trace" situations (for example, the implementation
thedo 167:1657b442184c 30 * of realloc() might call malloc() internally, and since malloc() is also traced, this could
thedo 167:1657b442184c 31 * result in two calls to the callback function instead of one. */
thedo 167:1657b442184c 32 static uint8_t trace_level;
thedo 167:1657b442184c 33
thedo 167:1657b442184c 34 /******************************************************************************
thedo 167:1657b442184c 35 * Public interface
thedo 167:1657b442184c 36 *****************************************************************************/
thedo 167:1657b442184c 37
thedo 167:1657b442184c 38 void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb) {
thedo 167:1657b442184c 39 mem_trace_cb = cb;
thedo 167:1657b442184c 40 }
thedo 167:1657b442184c 41
thedo 167:1657b442184c 42 void *mbed_mem_trace_malloc(void *res, size_t size, void *caller) {
thedo 167:1657b442184c 43 if (mem_trace_cb) {
thedo 167:1657b442184c 44 if (core_util_atomic_incr_u8(&trace_level, 1) == 1) {
thedo 167:1657b442184c 45 mem_trace_cb(MBED_MEM_TRACE_MALLOC, res, caller, size);
thedo 167:1657b442184c 46 }
thedo 167:1657b442184c 47 core_util_atomic_decr_u8(&trace_level, 1);
thedo 167:1657b442184c 48 }
thedo 167:1657b442184c 49 return res;
thedo 167:1657b442184c 50 }
thedo 167:1657b442184c 51
thedo 167:1657b442184c 52 void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller) {
thedo 167:1657b442184c 53 if (mem_trace_cb) {
thedo 167:1657b442184c 54 if (core_util_atomic_incr_u8(&trace_level, 1) == 1) {
thedo 167:1657b442184c 55 mem_trace_cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size);
thedo 167:1657b442184c 56 }
thedo 167:1657b442184c 57 core_util_atomic_decr_u8(&trace_level, 1);
thedo 167:1657b442184c 58 }
thedo 167:1657b442184c 59 return res;
thedo 167:1657b442184c 60 }
thedo 167:1657b442184c 61
thedo 167:1657b442184c 62 void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller) {
thedo 167:1657b442184c 63 if (mem_trace_cb) {
thedo 167:1657b442184c 64 if (core_util_atomic_incr_u8(&trace_level, 1) == 1) {
thedo 167:1657b442184c 65 mem_trace_cb(MBED_MEM_TRACE_CALLOC, res, caller, num, size);
thedo 167:1657b442184c 66 }
thedo 167:1657b442184c 67 core_util_atomic_decr_u8(&trace_level, 1);
thedo 167:1657b442184c 68 }
thedo 167:1657b442184c 69 return res;
thedo 167:1657b442184c 70 }
thedo 167:1657b442184c 71
thedo 167:1657b442184c 72 void mbed_mem_trace_free(void *ptr, void *caller) {
thedo 167:1657b442184c 73 if (mem_trace_cb) {
thedo 167:1657b442184c 74 if (core_util_atomic_incr_u8(&trace_level, 1) == 1) {
thedo 167:1657b442184c 75 mem_trace_cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr);
thedo 167:1657b442184c 76 }
thedo 167:1657b442184c 77 core_util_atomic_decr_u8(&trace_level, 1);
thedo 167:1657b442184c 78 }
thedo 167:1657b442184c 79 }
thedo 167:1657b442184c 80
thedo 167:1657b442184c 81 void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...) {
thedo 167:1657b442184c 82 va_list va;
thedo 167:1657b442184c 83 size_t temp_s1, temp_s2;
thedo 167:1657b442184c 84 void *temp_ptr;
thedo 167:1657b442184c 85
thedo 167:1657b442184c 86 va_start(va, caller);
thedo 167:1657b442184c 87 switch(op) {
thedo 167:1657b442184c 88 case MBED_MEM_TRACE_MALLOC:
thedo 167:1657b442184c 89 temp_s1 = va_arg(va, size_t);
thedo 167:1657b442184c 90 printf(MBED_MEM_DEFAULT_TRACER_PREFIX "m:%p;%p-%u\n", res, caller, temp_s1);
thedo 167:1657b442184c 91 break;
thedo 167:1657b442184c 92
thedo 167:1657b442184c 93 case MBED_MEM_TRACE_REALLOC:
thedo 167:1657b442184c 94 temp_ptr = va_arg(va, void*);
thedo 167:1657b442184c 95 temp_s1 = va_arg(va, size_t);
thedo 167:1657b442184c 96 printf(MBED_MEM_DEFAULT_TRACER_PREFIX "r:%p;%p-%p;%u\n", res, caller, temp_ptr, temp_s1);
thedo 167:1657b442184c 97 break;
thedo 167:1657b442184c 98
thedo 167:1657b442184c 99 case MBED_MEM_TRACE_CALLOC:
thedo 167:1657b442184c 100 temp_s1 = va_arg(va, size_t);
thedo 167:1657b442184c 101 temp_s2 = va_arg(va, size_t);
thedo 167:1657b442184c 102 printf(MBED_MEM_DEFAULT_TRACER_PREFIX "c:%p;%p-%u;%u\n", res, caller, temp_s1, temp_s2);
thedo 167:1657b442184c 103 break;
thedo 167:1657b442184c 104
thedo 167:1657b442184c 105 case MBED_MEM_TRACE_FREE:
thedo 167:1657b442184c 106 temp_ptr = va_arg(va, void*);
thedo 167:1657b442184c 107 printf(MBED_MEM_DEFAULT_TRACER_PREFIX "f:%p;%p-%p\n", res, caller, temp_ptr);
thedo 167:1657b442184c 108 break;
thedo 167:1657b442184c 109
thedo 167:1657b442184c 110 default:
thedo 167:1657b442184c 111 printf("?\n");
thedo 167:1657b442184c 112 }
thedo 167:1657b442184c 113 va_end(va);
thedo 167:1657b442184c 114 }
thedo 167:1657b442184c 115
thedo 167:1657b442184c 116