Choco OS  V.0.16.9.0
Join to the chocolate world
oc_stdlib.h
1 
28 #ifndef SYSTEM_LIBRARIES_INC_OC_STDLIB_H_
29 #define SYSTEM_LIBRARIES_INC_OC_STDLIB_H_
30 
31 #include <oc_stdtypes.h>
32 #include <stdbool.h>
33 #include <oc_memory.h>
34 #include <oc_compiler.h>
35 
36 #ifdef oC_CORE_SPACE
37 
38 #define malloc_array(type,array_size,flags) _malloc(sizeof(type)*array_size,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore)
39 
40 #define malloc(size,flags) _malloc(size,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore)
41 #define free(address,flags) _free(address,flags)
42 
43 #define rawmalloc(size,flags) _rawmalloc(size,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore)
44 #define rawfree(address,size) _rawfree(address,size)
45 
46 #define smartalloc(size,flags) _smartalloc(size,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore)
47 #define smartfree(address,size,flags) _smartfree(address,size,flags)
48 
49 #define kmalloc(size,allocator,flags) _kmalloc(size,allocator,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore,0)
50 #define kfree(address,flags) _kfree(address,flags)
51 
52 #define kamalloc(size,allocator,flags,alignment) _kmalloc(size,allocator,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore,alignment)
53 #define kafree(address,flags) _kfree(address,flags)
54 
55 #define krawmalloc(map,size,flags) _krawmalloc(map,size,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore)
56 #define krawfree(map,address,size) _krawfree(map,address,size)
57 
58 #define ksmartalloc(size,allocator,flags) _ksmartalloc(size,allocator,oC_FUNCTION, __LINE__,flags | AllocationFlags_ReleaseOnlyInCore)
59 #define ksmartfree(address,size,flags) _ksmartfree(address,size,flags | AllocationFlags_ReleaseOnlyInCore)
60 
61 #define isarrayinram(array,size) isbufferinram(array,size*sizeof(array[0]))
62 #define isarrayinrom(array,size) isbufferinrom(array,size*sizeof(array[0]))
63 #define isarraycorrect(array,size) isarrayinram(array,size) || isarrayinrom(array,size)
64 
65 #endif
66 
72 #define _________________________________________TYPES_SECTION______________________________________________________________________________
73 
74 
75 //==========================================================================================================================================
85 //==========================================================================================================================================
86 typedef enum
87 {
88  MemoryEventFlags_NotError = 0x8000 ,
89 
90  MemoryEventFlags_MemoryFault = (1<<0),
91  MemoryEventFlags_BusFault = (1<<1),
92  MemoryEventFlags_AllocationError = (1<<2),
93  MemoryEventFlags_ReleaseError = (1<<3),
94  MemoryEventFlags_PossibleMemoryLeak = (1<<4),
95  MemoryEventFlags_BufferOverflow = (1<<5),
96  MemoryEventFlags_MemoryAllocated = MemoryEventFlags_NotError | (1<<6),
97  MemoryEventFlags_MemoryReleased = MemoryEventFlags_NotError | (1<<7),
98  MemoryEventFlags_RawMemoryAllocated = MemoryEventFlags_NotError | (1<<8),
99  MemoryEventFlags_RawMemoryReleased = MemoryEventFlags_NotError | (1<<9),
100  MemoryEventFlags_ModuleTurningOff = (1<<10),
101  MemoryEventFlags_MemoryExhausted = (1<<11),
102  MemoryEventFlags_PanicMemoryExhausted = (1<<12),
103  MemoryEventFlags_DataSectionOverflow = (1<<13),
104  MemoryEventFlags_ExternalMemoryExhausted = (1<<14),
105  MemoryEventFlags_PanicExternalMemoryExhausted = (1<<15),
106 
107  MemoryEventFlags_AllErrors = 0x7FFF ,
108  MemoryEventFlags_All = 0xFFFF ,
109 } MemoryEventFlags_t;
110 
111 //==========================================================================================================================================
117 //==========================================================================================================================================
118 typedef enum
119 {
120  AllocationFlags_Default = 0 ,
121  AllocationFlags_ZeroFill = 1<<0 ,
122  AllocationFlags_NoWait = 1<<1 ,
123  AllocationFlags_CanWait500Msecond = 1<<2 ,
124  AllocationFlags_CanWait1Second = 1<<3 ,
125  AllocationFlags_CanWaitForever = 1<<4 ,
126  AllocationFlags_ForceBlock = 1<<5 ,
127  AllocationFlags_UseExternalRam = 1<<6 ,
128  AllocationFlags_UseInternalRam = 1<<7 ,
129  AllocationFlags_UseDmaRam = 1<<8 ,
130  AllocationFlags_DmaRamFirst = 1<<8 ,
131  AllocationFlags_InternalRamFirst = 0<<9 ,
132  AllocationFlags_ExternalRamFirst = 1<<9 ,
133  AllocationFlags_ReleaseOnlyInCore = 1<<10,
134 } AllocationFlags_t;
135 
136 //==========================================================================================================================================
148 //==========================================================================================================================================
149 typedef void (*MemoryEventHandler_t)( void * Address , MemoryEventFlags_t Event, const char * Function, uint32_t LineNumber );
150 
151 //==========================================================================================================================================
158 //==========================================================================================================================================
159 typedef struct
160 {
161  const char * Name;
162  MemoryEventHandler_t EventHandler;
163  MemoryEventFlags_t EventFlags;
164  oC_MemorySize_t Limit;
166 
167 //==========================================================================================================================================
174 //==========================================================================================================================================
175 typedef struct _HeapMap_t * oC_HeapMap_t;
176 
177 //==========================================================================================================================================
183 //==========================================================================================================================================
184 typedef const oC_Allocator_t * Allocator_t;
185 
186 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
187 
188 
194 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
195 
196 extern void * _malloc ( oC_UInt_t Size , const char * Function , uint32_t LineNumber , AllocationFlags_t Flags );
197 extern bool _free ( void * Address , AllocationFlags_t Flags );
198 
199 extern void * _rawmalloc ( oC_UInt_t Size , const char * Function , uint32_t LineNumber , AllocationFlags_t Flags);
200 extern bool _rawfree ( void * Address , oC_UInt_t Size);
201 
202 extern void * _kmalloc ( oC_UInt_t Size , Allocator_t Allocator , const char * Function , uint32_t LineNumber , AllocationFlags_t Flags , oC_UInt_t Alignment );
203 extern bool _kfree ( void * Address , AllocationFlags_t Flags );
204 
205 extern void * _krawmalloc ( oC_HeapMap_t Map , oC_UInt_t Size , const char * Function , uint32_t LineNumber , AllocationFlags_t Flags );
206 extern bool _krawfree ( oC_HeapMap_t Map , void * Address , oC_UInt_t Size );
207 
208 extern void * _smartalloc ( oC_UInt_t Size , const char * Function , uint32_t LineNumber , AllocationFlags_t Flags );
209 extern bool _smartfree ( void * Address , oC_UInt_t Size , AllocationFlags_t Flags );
210 
211 extern void * _ksmartalloc ( oC_UInt_t Size , Allocator_t Allocator , const char * Function , uint32_t LineNumber , AllocationFlags_t Flags);
212 extern bool _ksmartfree ( void * Address , oC_UInt_t Size , AllocationFlags_t Flags);
213 
214 extern bool isram ( const void * Address );
215 extern bool isrom ( const void * Address );
216 
217 extern bool isbufferinram ( const void * Buffer , oC_UInt_t Size );
218 extern bool isbufferinrom ( const void * Buffer , oC_UInt_t Size );
219 
220 extern bool isaddresscorrect ( const void * Address );
221 
222 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
223 
224 
225 #endif /* SYSTEM_LIBRARIES_INC_OC_STDLIB_H_ */
The file with interface for the GPIO driver.
const char * Name
Definition: oc_stdlib.h:161
identifier for allocations
Definition: oc_stdlib.h:159
oC_MemorySize_t Limit
Definition: oc_stdlib.h:164
The file contains definitions for the compiler, that helps to manage errors, etc. ...
MemoryEventHandler_t EventHandler
Definition: oc_stdlib.h:162
static const oC_Allocator_t Allocator
Definition: oc_eth.c:152
MemoryEventFlags_t EventFlags
Definition: oc_stdlib.h:163
FILE__DESCRIPTION