mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
StevieWray
Date:
Wed Sep 28 08:45:18 2016 +0000
Revision:
148:e70627d019e9
Parent:
147:30b64687e01f
Fixed DAC output on STM32F3 boards to allow 3 outputs

Who changed what in which revision?

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