Fix FS#12824 : Malfunctioning FFT plugin in Sansa Clip Zip
[maemo-rb.git] / firmware / core_alloc.c
blob47faed6e955eaa8be2a13b211a76c03d84c54890
2 #include "config.h"
3 #include <string.h>
4 #include "system.h"
5 #include "core_alloc.h"
6 #include "buflib.h"
8 /* not static so it can be discovered by core_get_data() */
9 struct buflib_context core_ctx;
11 /* defined in linker script */
12 #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(__PCTOOL__)
13 #if defined(IPOD_VIDEO) && !defined(BOOTLOADER)
14 extern unsigned char *audiobufend_lds[];
15 unsigned char *audiobufend;
16 #else /* !IPOD_VIDEO */
17 extern unsigned char audiobufend[];
18 #endif
19 /* defined in linker script */
20 extern unsigned char audiobuffer[];
21 #else /* PLATFORM_HOSTED */
22 unsigned char audiobuffer[(MEMORYSIZE*1024-256)*1024];
23 unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer);
24 extern unsigned char *audiobufend;
25 #endif
27 /* debug test alloc */
28 static int test_alloc;
29 void core_allocator_init(void)
31 unsigned char *start = ALIGN_UP(audiobuffer, sizeof(intptr_t));
33 #if defined(IPOD_VIDEO) && !defined(BOOTLOADER) && !defined(SIMULATOR)
34 audiobufend=(unsigned char *)audiobufend_lds;
35 if(MEMORYSIZE==64 && probed_ramsize!=64)
37 audiobufend -= (32<<20);
39 #endif
41 buflib_init(&core_ctx, start, audiobufend - start);
43 test_alloc = core_alloc("test", 112);
46 bool core_test_free(void)
48 bool ret = test_alloc > 0;
49 if (ret)
50 test_alloc = core_free(test_alloc);
52 return ret;
55 int core_alloc(const char* name, size_t size)
57 return buflib_alloc_ex(&core_ctx, size, name, NULL);
60 int core_alloc_ex(const char* name, size_t size, struct buflib_callbacks *ops)
62 return buflib_alloc_ex(&core_ctx, size, name, ops);
65 size_t core_available(void)
67 return buflib_available(&core_ctx);
70 int core_free(int handle)
72 return buflib_free(&core_ctx, handle);
75 int core_alloc_maximum(const char* name, size_t *size, struct buflib_callbacks *ops)
77 return buflib_alloc_maximum(&core_ctx, name, size, ops);
80 bool core_shrink(int handle, void* new_start, size_t new_size)
82 return buflib_shrink(&core_ctx, handle, new_start, new_size);
85 int core_get_num_blocks(void)
87 return buflib_get_num_blocks(&core_ctx);
90 void core_print_block_at(int block_num, char* buf, size_t bufsize)
92 buflib_print_block_at(&core_ctx, block_num, buf, bufsize);