M4PSW_MemoryInterface.c revision 694816d7291f17364502ac5d3319684a0b180860
1/* 2 * Copyright (C) 2004-2011 NXP Software 3 * Copyright (C) 2011 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18************************************************************************* 19 * @file M4PSW_MemoryInterface.c 20 * @brief Memory Interface 21 * @note Implementation of the osal memory functions 22 ************************************************************************* 23*/ 24 25#include <stdlib.h> 26#include <memory.h> 27 28#include <time.h> 29#include "M4OSA_Memory.h" 30#ifndef M4VPS_ADVANCED_MEMORY_MANAGER 31/** 32 ************************************************************************ 33 * @fn M4OSA_MemAddr32 M4OSA_32bitAlignedMalloc(M4OSA_UInt32 size, 34 * M4OSA_CoreID coreID, 35 * M4OSA_Char* string) 36 * @brief this function allocates a memory block (at least 32 bits aligned) 37 * @note 38 * @param size (IN): size of allocated block in bytes 39 * @param coreID (IN): identification of the caller component 40 * @param string (IN): description of the allocated block (null terminated) 41 * @return address of the allocated block, M4OSA_NULL if no memory available 42 ************************************************************************ 43*/ 44 45M4OSA_MemAddr32 M4OSA_32bitAlignedMalloc(M4OSA_UInt32 size, 46 M4OSA_CoreID coreID, 47 M4OSA_Char* string) 48{ 49 M4OSA_MemAddr32 Address = M4OSA_NULL; 50 51 /** 52 * If size is 0, malloc on WIN OS allocates a zero-length item in 53 * the heap and returns a valid pointer to that item. 54 * On other platforms, malloc could returns an invalid pointer 55 * So, DON'T allocate memory of 0 byte */ 56 if (size == 0) 57 { 58 return Address; 59 } 60 61 if (size%4 != 0) 62 { 63 size = size + 4 - (size%4); 64 } 65 66 Address = (M4OSA_MemAddr32) malloc(size); 67 68 return Address; 69} 70 71/** 72 ************************************************************************ 73 * @fn M4OSA_MemAddr32 M4OSA_malloc(M4OSA_UInt32 size, 74 * M4OSA_CoreID coreID, 75 * M4OSA_Char* string) 76 * @brief this function allocates a memory block (at least 32 bits aligned) 77 * @note 78 * @param size (IN): size of allocated block in bytes 79 * @param coreID (IN): identification of the caller component 80 * @param string (IN): description of the allocated block (null terminated) 81 * @return address of the allocated block, M4OSA_NULL if no memory available 82 ************************************************************************ 83*/ 84 85M4OSA_MemAddr32 M4OSA_malloc(M4OSA_UInt32 size, 86 M4OSA_CoreID coreID, 87 M4OSA_Char* string) 88{ 89 M4OSA_MemAddr32 Address = M4OSA_NULL; 90 91 /** 92 * If size is 0, malloc on WIN OS allocates a zero-length item in 93 * the heap and returns a valid pointer to that item. 94 * On other platforms, malloc could returns an invalid pointer 95 * So, DON'T allocate memory of 0 byte */ 96 if (size == 0) 97 { 98 return Address; 99 } 100 101 if (size%4 != 0) 102 { 103 size = size + 4 - (size%4); 104 } 105 106 Address = (M4OSA_MemAddr32) malloc(size); 107 108 return Address; 109} 110 111 112/** 113 ************************************************************************ 114 * @fn M4OSA_Void M4OSA_free(M4OSA_MemAddr32 address) 115 * @brief this function free the provided memory block 116 * @note As in stlib.h, this function does nothing if address is NULL. 117 * @param address (IN): address of the block to free 118 * @return none 119 ************************************************************************ 120*/ 121 122M4OSA_Void M4OSA_free (M4OSA_MemAddr32 address) 123{ 124 free(address); 125} 126#endif 127 128