bowen liu / Mbed OS mbed-os-example-blinky

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
tmboy
Date:
Tue Jul 18 09:08:52 2017 +0000
Revision:
50:9ecaa144d1f3
Parent:
47:9e361da97763
add .json

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 /* Copyright (C) 2002 Jean-Marc Valin */
TMBOY 47:9e361da97763 2 /**
TMBOY 47:9e361da97763 3 @file stack_alloc.h
TMBOY 47:9e361da97763 4 @brief Temporary memory allocation on stack
TMBOY 47:9e361da97763 5 */
TMBOY 47:9e361da97763 6 /*
TMBOY 47:9e361da97763 7 Redistribution and use in source and binary forms, with or without
TMBOY 47:9e361da97763 8 modification, are permitted provided that the following conditions
TMBOY 47:9e361da97763 9 are met:
TMBOY 47:9e361da97763 10
TMBOY 47:9e361da97763 11 - Redistributions of source code must retain the above copyright
TMBOY 47:9e361da97763 12 notice, this list of conditions and the following disclaimer.
TMBOY 47:9e361da97763 13
TMBOY 47:9e361da97763 14 - Redistributions in binary form must reproduce the above copyright
TMBOY 47:9e361da97763 15 notice, this list of conditions and the following disclaimer in the
TMBOY 47:9e361da97763 16 documentation and/or other materials provided with the distribution.
TMBOY 47:9e361da97763 17
TMBOY 47:9e361da97763 18 - Neither the name of the Xiph.org Foundation nor the names of its
TMBOY 47:9e361da97763 19 contributors may be used to endorse or promote products derived from
TMBOY 47:9e361da97763 20 this software without specific prior written permission.
TMBOY 47:9e361da97763 21
TMBOY 47:9e361da97763 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
TMBOY 47:9e361da97763 23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
TMBOY 47:9e361da97763 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
TMBOY 47:9e361da97763 25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
TMBOY 47:9e361da97763 26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
TMBOY 47:9e361da97763 27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
TMBOY 47:9e361da97763 28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
TMBOY 47:9e361da97763 29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
TMBOY 47:9e361da97763 30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
TMBOY 47:9e361da97763 31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
TMBOY 47:9e361da97763 32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TMBOY 47:9e361da97763 33 */
TMBOY 47:9e361da97763 34
TMBOY 47:9e361da97763 35 #ifndef STACK_ALLOC_H
TMBOY 47:9e361da97763 36 #define STACK_ALLOC_H
TMBOY 47:9e361da97763 37
TMBOY 47:9e361da97763 38 #ifdef USE_ALLOCA
TMBOY 47:9e361da97763 39 #ifdef WIN32
TMBOY 47:9e361da97763 40 #include <malloc.h>
TMBOY 47:9e361da97763 41 #else
TMBOY 47:9e361da97763 42 #include <alloca.h>
TMBOY 47:9e361da97763 43 #endif
TMBOY 47:9e361da97763 44 #endif
TMBOY 47:9e361da97763 45
TMBOY 47:9e361da97763 46 /**
TMBOY 47:9e361da97763 47 * @def ALIGN(stack, size)
TMBOY 47:9e361da97763 48 *
TMBOY 47:9e361da97763 49 * Aligns the stack to a 'size' boundary
TMBOY 47:9e361da97763 50 *
TMBOY 47:9e361da97763 51 * @param stack Stack
TMBOY 47:9e361da97763 52 * @param size New size boundary
TMBOY 47:9e361da97763 53 */
TMBOY 47:9e361da97763 54
TMBOY 47:9e361da97763 55 /**
TMBOY 47:9e361da97763 56 * @def PUSH(stack, size, type)
TMBOY 47:9e361da97763 57 *
TMBOY 47:9e361da97763 58 * Allocates 'size' elements of type 'type' on the stack
TMBOY 47:9e361da97763 59 *
TMBOY 47:9e361da97763 60 * @param stack Stack
TMBOY 47:9e361da97763 61 * @param size Number of elements
TMBOY 47:9e361da97763 62 * @param type Type of element
TMBOY 47:9e361da97763 63 */
TMBOY 47:9e361da97763 64
TMBOY 47:9e361da97763 65 /**
TMBOY 47:9e361da97763 66 * @def PUSHS(stack, type)
TMBOY 47:9e361da97763 67 *
TMBOY 47:9e361da97763 68 * Allocates a struct stack
TMBOY 47:9e361da97763 69 *
TMBOY 47:9e361da97763 70 * @param stack Stack
TMBOY 47:9e361da97763 71 * @param type Struct type
TMBOY 47:9e361da97763 72 */
TMBOY 47:9e361da97763 73
TMBOY 47:9e361da97763 74 /**
TMBOY 47:9e361da97763 75 * @def VARDECL(var)
TMBOY 47:9e361da97763 76 *
TMBOY 47:9e361da97763 77 * Declare variable on stack
TMBOY 47:9e361da97763 78 *
TMBOY 47:9e361da97763 79 * @param var Variable to declare
TMBOY 47:9e361da97763 80 */
TMBOY 47:9e361da97763 81
TMBOY 47:9e361da97763 82 /**
TMBOY 47:9e361da97763 83 * @def ALLOC(var, size, type)
TMBOY 47:9e361da97763 84 *
TMBOY 47:9e361da97763 85 * Allocate 'size' elements of 'type' on stack
TMBOY 47:9e361da97763 86 *
TMBOY 47:9e361da97763 87 * @param var Name of variable to allocate
TMBOY 47:9e361da97763 88 * @param size Number of elements
TMBOY 47:9e361da97763 89 * @param type Type of element
TMBOY 47:9e361da97763 90 */
TMBOY 47:9e361da97763 91
TMBOY 47:9e361da97763 92 #ifdef BAIDU_SPEEX_ENCODE_STACK_MONITOR
TMBOY 47:9e361da97763 93 extern char *g_p_spx_enc_stk_top;
TMBOY 47:9e361da97763 94 #endif
TMBOY 47:9e361da97763 95
TMBOY 47:9e361da97763 96 #ifdef ENABLE_VALGRIND
TMBOY 47:9e361da97763 97
TMBOY 47:9e361da97763 98 #include <valgrind/memcheck.h>
TMBOY 47:9e361da97763 99
TMBOY 47:9e361da97763 100 #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
TMBOY 47:9e361da97763 101
TMBOY 47:9e361da97763 102 #define PUSH(stack, size, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(type)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type))),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
TMBOY 47:9e361da97763 103
TMBOY 47:9e361da97763 104 #define PUSHS(stack, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(long)),VALGRIND_MAKE_WRITABLE(stack, (sizeof(type))),(stack)+=(sizeof(type)),(type*)((stack)-(sizeof(type))))
TMBOY 47:9e361da97763 105
TMBOY 47:9e361da97763 106 #else
TMBOY 47:9e361da97763 107
TMBOY 47:9e361da97763 108 #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
TMBOY 47:9e361da97763 109
TMBOY 47:9e361da97763 110 #ifdef BAIDU_SPEEX_ENCODE_STACK_MONITOR
TMBOY 47:9e361da97763 111 #define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)), (g_p_spx_enc_stk_top = (stack > g_p_spx_enc_stk_top) ? (stack):g_p_spx_enc_stk_top), (type*)((stack)-((size)*sizeof(type))))
TMBOY 47:9e361da97763 112 #else
TMBOY 47:9e361da97763 113 #define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
TMBOY 47:9e361da97763 114 #endif
TMBOY 47:9e361da97763 115
TMBOY 47:9e361da97763 116
TMBOY 47:9e361da97763 117 #define PUSHS(stack, type) (ALIGN((stack),sizeof(long)),(stack)+=(sizeof(type)),(type*)((stack)-(sizeof(type))))
TMBOY 47:9e361da97763 118
TMBOY 47:9e361da97763 119 #endif
TMBOY 47:9e361da97763 120
TMBOY 47:9e361da97763 121 #if defined(VAR_ARRAYS)
TMBOY 47:9e361da97763 122 #define VARDECL(var)
TMBOY 47:9e361da97763 123 #define ALLOC(var, size, type) type var[size]
TMBOY 47:9e361da97763 124 #elif defined(USE_ALLOCA)
TMBOY 47:9e361da97763 125 #define VARDECL(var) var
TMBOY 47:9e361da97763 126 #define ALLOC(var, size, type) var = alloca(sizeof(type)*(size))
TMBOY 47:9e361da97763 127 #else
TMBOY 47:9e361da97763 128 #define VARDECL(var) var
TMBOY 47:9e361da97763 129 #define ALLOC(var, size, type) var = PUSH(stack, size, type)
TMBOY 47:9e361da97763 130 #endif
TMBOY 47:9e361da97763 131
TMBOY 47:9e361da97763 132
TMBOY 47:9e361da97763 133 #endif