1 #ifndef _PSRAM_RESERVE_H_
2 #define _PSRAM_RESERVE_H_
3 
4 //#include <stdio.h>
5 #include <stdint.h>
6 #include <osdep_service.h>
7 
8 /* NOTE: struct size must be a 2's power! */
9 typedef struct _PsramMemChunk
10 {
11 	struct _PsramMemChunk *next;
12 	int size;
13 } PsramMemChunk;
14 
15 typedef PsramMemChunk Psram_heap_buf_t;
16 
17 // A heap
18 typedef struct Psram_Heap
19 {
20 	struct _PsramMemChunk *FreeList;	///< Head of the free list
21 } Psram_Heap;
22 
23 
24 /**
25  * Utility macro to allocate a heap of size \a size.
26  *
27  * \param name Variable name for the heap.
28  * \param size Heap size in bytes.
29  */
30 #define PSRAM_HEAP_DEFINE_BUF(name, size) \
31 	Psram_heap_buf_t name[((size) + sizeof(Psram_heap_buf_t) - 1) / sizeof(Psram_heap_buf_t)]
32 
33 
34 #define Psram_ROUND_UP2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1))
35 
36 /// Initialize \a heap within the buffer pointed by \a memory which is of \a size bytes
37 void Psram_heap_init(void);
38 
39 /// Allocate a chunk of memory of \a size bytes from the heap
40 void *Psram_heap_allocmem(int size);
41 
42 /// Free a chunk of memory of \a size bytes from the heap
43 void Psram_reserved_heap_freemem(void *mem, int size);
44 
45 int Psram_reserve_free_size(void);
46 
47 /**
48  * \name Compatibility interface with C standard library
49  * \{
50  */
51 void *Psram_reserve_malloc(int size);
52 void *Psram_reserve_calloc(int num, int size);
53 void Psram_reserve_free(void *mem);
54 /** \} */
55 
56 extern int g_Psram_heap_inited;
57 #endif /* _PSRAM_RESERVE_H_ */
58