Merge "makefile: fix error message due to missing quotes"
[libvpx.git] / vpx_mem / nds / vpx_mem_nds.c
blobf2a3043b214aa0b0a7de901e77a0740feed66f54
1 /*
2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license and patent
5 * grant that can be found in the LICENSE file in the root of the source
6 * tree. All contributing project authors may be found in the AUTHORS
7 * file in the root of the source tree.
8 */
11 #define __VPX_MEM_C__
12 #include "vpx_mem.h"
13 #include <nitro.h>
14 #include "vpx_mem_intrnl.h"
16 // Allocate memory from the Arena specified by id. Align it to
17 // the value specified by align.
18 void *vpx_mem_nds_alloc(osarena_id id, osheap_handle handle, size_t size, size_t align)
20 void *addr,
21 * x = NULL;
23 addr = os_alloc_from_heap((osarena_id) id, handle,
24 size + align - 1 + ADDRESS_STORAGE_SIZE);
26 if (addr)
28 x = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE, (int)align);
30 // save the actual malloc address
31 ((size_t *)x)[-1] = (size_t)addr;
34 return x;
37 // Free them memory allocated by vpx_mem_nds_alloc
38 void vpx_mem_nds_free(osarena_id id, osheap_handle handle, void *mem)
40 if (mem)
42 void *addr = (void *)(((size_t *)mem)[-1]);
43 os_free_to_heap(id, handle, addr);
47 int vpx_nds_alloc_heap(osarena_id id, u32 size)
49 osheap_handle arena_handle;
50 void *nstart;
51 void *heap_start;
53 nstart = os_init_alloc(id, os_get_arena_lo(id), os_get_arena_hi(id), 1);
54 os_set_arena_lo(id, nstart);
56 heap_start = os_alloc_from_arena_lo(id, size, 32);
57 arena_handle = os_create_heap(id, heap_start, (void *)((u32)heap_start + size));
59 if (os_check_heap(id, arena_handle) == -1)
60 return -1; //ERROR: DTCM heap is not consistent
62 (void)os_set_current_heap(id, arena_handle);
64 return arena_handle;