forked from xuos/xiuos
				
			23/08/02 1.Fix ByteManager Bug; 2.Move net delay to webnet(wn_session.h) so it wont affect other net functions.
This commit is contained in:
		
							parent
							
								
									fc4411dad4
								
							
						
					
					
						commit
						fce13fe874
					
				| 
						 | 
					@ -15,6 +15,107 @@
 | 
				
			||||||
// #include <user_api.h>
 | 
					// #include <user_api.h>
 | 
				
			||||||
#include <transform.h>
 | 
					#include <transform.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pthread_mutex_t* get_memtest_mtx() {
 | 
				
			||||||
 | 
						static pthread_mutex_t mem_test_mtx;
 | 
				
			||||||
 | 
						return &mem_test_mtx;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void ShowMemory();
 | 
				
			||||||
 | 
					void malloc_thread(void* size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int tid = GetKTaskDescriptor()->id.id;
 | 
				
			||||||
 | 
					    int* tmp = (int*)size;
 | 
				
			||||||
 | 
						int malloc_size = *tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PrivMutexObtain(get_memtest_mtx());
 | 
				
			||||||
 | 
					    printf("TID: %d Working. size: %d\n", tid, malloc_size);
 | 
				
			||||||
 | 
						PrivMutexAbandon(get_memtest_mtx());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void* ptr_allocated = NULL;
 | 
				
			||||||
 | 
					    while ((ptr_allocated = malloc(malloc_size)) != NULL) {
 | 
				
			||||||
 | 
							PrivMutexObtain(get_memtest_mtx());
 | 
				
			||||||
 | 
					        printf("\n[TID: %d]==================================================\n", tid);
 | 
				
			||||||
 | 
					        ShowMemory();
 | 
				
			||||||
 | 
							PrivMutexAbandon(get_memtest_mtx());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PrivMutexObtain(get_memtest_mtx());
 | 
				
			||||||
 | 
					    printf("TID: %d Exiting.\n", tid);
 | 
				
			||||||
 | 
						PrivMutexAbandon(get_memtest_mtx());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <xs_ktask.h>
 | 
				
			||||||
 | 
					int testMemMain()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						PrivMutexCreate(get_memtest_mtx(), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int malloc_size = 10 * 1024;
 | 
				
			||||||
 | 
					    int tid = KTaskCreate("mem1", malloc_thread, (void*)&malloc_size, 2048, 20);
 | 
				
			||||||
 | 
					    StartupKTask(tid);
 | 
				
			||||||
 | 
						// malloc_thread(&malloc_size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// void* ptr_allocated[5] = { NULL };
 | 
				
			||||||
 | 
						// ptr_allocated[0] = malloc(malloc_size);
 | 
				
			||||||
 | 
					    // printf("0x%x ==================================================\n", ptr_allocated[0]);
 | 
				
			||||||
 | 
						// ShowMemory();
 | 
				
			||||||
 | 
						// ptr_allocated[1] = malloc(malloc_size);
 | 
				
			||||||
 | 
					    // printf("0x%x ==================================================\n", ptr_allocated[1]);
 | 
				
			||||||
 | 
						// ShowMemory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // malloc_size = 996;
 | 
				
			||||||
 | 
						// ptr_allocated[2] = malloc(malloc_size);
 | 
				
			||||||
 | 
					    // printf("0x%x ==================================================\n", ptr_allocated[2]);
 | 
				
			||||||
 | 
						// ShowMemory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// free(ptr_allocated[0]);
 | 
				
			||||||
 | 
					    // printf("==================================================\n");
 | 
				
			||||||
 | 
						// ShowMemory();
 | 
				
			||||||
 | 
						// ptr_allocated[0] = malloc(malloc_size);
 | 
				
			||||||
 | 
					    // printf("0x%x ==================================================\n", ptr_allocated[0]);
 | 
				
			||||||
 | 
						// ShowMemory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ptr_allocated[3] = malloc(malloc_size);
 | 
				
			||||||
 | 
						// free(ptr_allocated[2]);
 | 
				
			||||||
 | 
					    // printf("0x%x ==================================================\n", ptr_allocated[3]);
 | 
				
			||||||
 | 
						// ShowMemory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// malloc_size = 333;
 | 
				
			||||||
 | 
						// ptr_allocated[2] = malloc(malloc_size);
 | 
				
			||||||
 | 
						// ptr_allocated[4] = malloc(malloc_size);
 | 
				
			||||||
 | 
					    // printf("0x%x ==================================================\n", ptr_allocated[2]);
 | 
				
			||||||
 | 
					    // printf("0x%x ==================================================\n", ptr_allocated[4]);
 | 
				
			||||||
 | 
						// ShowMemory();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// free(ptr_allocated[0]);
 | 
				
			||||||
 | 
						// free(ptr_allocated[1]);
 | 
				
			||||||
 | 
						// free(ptr_allocated[2]);
 | 
				
			||||||
 | 
						// free(ptr_allocated[3]);
 | 
				
			||||||
 | 
						// free(ptr_allocated[4]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int malloc_size2 = 1024;
 | 
				
			||||||
 | 
					    int tid2 = KTaskCreate("mem2", malloc_thread, &malloc_size2, 2048, 20);
 | 
				
			||||||
 | 
					    StartupKTask(tid2);
 | 
				
			||||||
 | 
						// malloc_thread(&malloc_size);
 | 
				
			||||||
 | 
					    int malloc_size3 = 127;
 | 
				
			||||||
 | 
					    int tid3 = KTaskCreate("mem3", malloc_thread, &malloc_size3, 2048, 20);
 | 
				
			||||||
 | 
					    StartupKTask(tid3);
 | 
				
			||||||
 | 
						// malloc_thread(&malloc_size);
 | 
				
			||||||
 | 
						int malloc_size4 = 45;
 | 
				
			||||||
 | 
					    int tid4 = KTaskCreate("mem4", malloc_thread, &malloc_size4, 2048, 20);
 | 
				
			||||||
 | 
					    StartupKTask(tid4);
 | 
				
			||||||
 | 
						// malloc_thread(&malloc_size);
 | 
				
			||||||
 | 
					    int malloc_size5 = 16;
 | 
				
			||||||
 | 
					    int tid5 = KTaskCreate("mem5", malloc_thread, &malloc_size5, 2048, 20);
 | 
				
			||||||
 | 
					    StartupKTask(tid5);
 | 
				
			||||||
 | 
						// malloc_thread(&malloc_size);
 | 
				
			||||||
 | 
						MdelayKTask(5000);
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC) | SHELL_CMD_PARAM_NUM(0),
 | 
				
			||||||
 | 
					    testMemMain, testMemMain, list memory usage information);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern int FrameworkInit();
 | 
					extern int FrameworkInit();
 | 
				
			||||||
extern void ApplicationOtaTaskInit(void);
 | 
					extern void ApplicationOtaTaskInit(void);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
Subproject commit 956eafa24bb65f5bb84d293ab35bf27084473edf
 | 
					Subproject commit 83d987597cf027177fb3798c6da547a3d3e3d5e1
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,11 @@
 | 
				
			||||||
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
 | 
					export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
 | 
					export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
 | 
				
			||||||
 | 
					# export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
 | 
				
			||||||
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb  -gdwarf-2
 | 
					export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb  -gdwarf-2
 | 
				
			||||||
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-edu-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
 | 
					export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-edu-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
 | 
				
			||||||
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
 | 
					export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -Werror
 | 
				
			||||||
 | 
					# export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export APPLFLAGS := 
 | 
					export APPLFLAGS := 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,8 +53,10 @@
 | 
				
			||||||
#define ALLOC_BLOCK_MASK                     0xc0000000
 | 
					#define ALLOC_BLOCK_MASK                     0xc0000000
 | 
				
			||||||
#define DYNAMIC_REMAINING_MASK               0x3fffffff
 | 
					#define DYNAMIC_REMAINING_MASK               0x3fffffff
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SIZEOF_32B	                (32)
 | 
					enum SmallSizeAllocSize {
 | 
				
			||||||
#define SIZEOF_64B	                (64)
 | 
						SIZEOF_32B = 32,
 | 
				
			||||||
 | 
						SIZEOF_64B = 64,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SMALL_SIZE_32B(ITEMSIZE)    ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_32B)    /* Calculate the total size for SIZEOF_32B blocks*/
 | 
					#define SMALL_SIZE_32B(ITEMSIZE)    ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_32B)    /* Calculate the total size for SIZEOF_32B blocks*/
 | 
				
			||||||
#define SMALL_SIZE_64B(ITEMSIZE)    ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_64B)    /* Calculate the total size for SIZEOF_64B blocks*/
 | 
					#define SMALL_SIZE_64B(ITEMSIZE)    ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_64B)    /* Calculate the total size for SIZEOF_64B blocks*/
 | 
				
			||||||
| 
						 | 
					@ -143,7 +145,7 @@ struct ByteMemory
 | 
				
			||||||
struct StaticMemoryDone
 | 
					struct StaticMemoryDone
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	void (*init)(struct ByteMemory *byte_memory);
 | 
						void (*init)(struct ByteMemory *byte_memory);
 | 
				
			||||||
	void* (*malloc)(struct ByteMemory *byte_memory, x_size_t size);
 | 
						void* (*malloc)(struct ByteMemory *byte_memory, enum SmallSizeAllocSize size);
 | 
				
			||||||
	void (*release)(void *pointer);
 | 
						void (*release)(void *pointer);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -349,11 +351,18 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* best-fit method */
 | 
						/* best-fit method */
 | 
				
			||||||
	 for (node = dynamic_buddy->mm_freenode_list[ndx].next;
 | 
						node = dynamic_buddy->mm_freenode_list[ndx].next;
 | 
				
			||||||
	 		 (ndx < MEM_LINKNRS ) && (node->size < allocsize);
 | 
						while(ndx < MEM_LINKNRS && (NONE == node || node->size < allocsize)) {
 | 
				
			||||||
	 		 node = node->next) {
 | 
							if (NONE == node) { 
 | 
				
			||||||
			ndx++;
 | 
								ndx++;
 | 
				
			||||||
	 };
 | 
								if (ndx == MEM_LINKNRS) { // no space to allocate
 | 
				
			||||||
 | 
									return NONE;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								node = dynamic_buddy->mm_freenode_list[ndx].next;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								node = node->next;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	/* get the best-fit freeNode */
 | 
						/* get the best-fit freeNode */
 | 
				
			||||||
	if (node && (node->size >= allocsize)) {
 | 
						if (node && (node->size >= allocsize)) {
 | 
				
			||||||
		struct DynamicFreeNode *remainder;
 | 
							struct DynamicFreeNode *remainder;
 | 
				
			||||||
| 
						 | 
					@ -385,7 +394,6 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* handle the case of an exact size match */
 | 
							/* handle the case of an exact size match */
 | 
				
			||||||
 | 
					 | 
				
			||||||
		node->flag = extsram_mask;
 | 
							node->flag = extsram_mask;
 | 
				
			||||||
        result = (void *)((char *)node + SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
					        result = (void *)((char *)node + SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -551,6 +559,8 @@ static void SmallMemFree(void *pointer)
 | 
				
			||||||
    /* update the statistic information of static_segment */
 | 
					    /* update the statistic information of static_segment */
 | 
				
			||||||
	node->size = (x_size_t)static_segment->freelist;
 | 
						node->size = (x_size_t)static_segment->freelist;
 | 
				
			||||||
    static_segment->freelist = (uint8 *)node;
 | 
					    static_segment->freelist = (uint8 *)node;
 | 
				
			||||||
 | 
						node->flag = 0; // it's unnecessary, actually
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static_segment->block_free_count++;
 | 
					    static_segment->block_free_count++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* parameter detection */
 | 
					    /* parameter detection */
 | 
				
			||||||
| 
						 | 
					@ -565,7 +575,7 @@ static void SmallMemFree(void *pointer)
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return pointer address on success; NULL on failure
 | 
					 * @return pointer address on success; NULL on failure
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
 | 
					static void *SmallMemMalloc(struct ByteMemory *byte_memory, enum SmallSizeAllocSize size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint8 i = 0;
 | 
						uint8 i = 0;
 | 
				
			||||||
	void *result = NONE;
 | 
						void *result = NONE;
 | 
				
			||||||
| 
						 | 
					@ -592,27 +602,14 @@ static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
 | 
				
			||||||
		node->size = (long)static_segment;
 | 
							node->size = (long)static_segment;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(result) {
 | 
						if (NONE != result) {
 | 
				
			||||||
	    /* return static memory block */
 | 
						    /* return static memory block */
 | 
				
			||||||
		return (char*)result + SIZEOF_DYNAMICALLOCNODE_MEM;
 | 
							return (char*)result + SIZEOF_DYNAMICALLOCNODE_MEM;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* the static memory block is exhausted, now turn to dynamic buddy memory for allocation. */
 | 
						/* the static memory block is exhausted, now turn to dynamic buddy memory for allocation. */
 | 
				
			||||||
    result = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
 | 
						// fall to dynamic allocation
 | 
				
			||||||
#ifdef MEM_EXTERN_SRAM
 | 
						return NONE;
 | 
				
			||||||
	if(NONE == result) {
 | 
					 | 
				
			||||||
		for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
 | 
					 | 
				
			||||||
			if(NONE != ExtByteManager[i].done) {
 | 
					 | 
				
			||||||
				result = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
 | 
					 | 
				
			||||||
				if (result){
 | 
					 | 
				
			||||||
					CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
				}	
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	return result;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct StaticMemoryDone StaticDone = {
 | 
					static struct StaticMemoryDone StaticDone = {
 | 
				
			||||||
| 
						 | 
					@ -634,41 +631,46 @@ void *x_malloc(x_size_t size)
 | 
				
			||||||
	void *ret = NONE;
 | 
						void *ret = NONE;
 | 
				
			||||||
	register x_base lock = 0;
 | 
						register x_base lock = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	 /* parameter detection */
 | 
						/* hold lock before allocation */
 | 
				
			||||||
 | 
						lock = CriticalAreaLock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* alignment */
 | 
				
			||||||
 | 
						size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* parameter detection */
 | 
				
			||||||
#ifdef MEM_EXTERN_SRAM
 | 
					#ifdef MEM_EXTERN_SRAM
 | 
				
			||||||
		/* parameter detection */
 | 
							/* parameter detection */
 | 
				
			||||||
	if(size == 0 ){
 | 
						if(size == 0 ){
 | 
				
			||||||
 | 
							CriticalAreaUnLock(lock);
 | 
				
			||||||
		return NONE;
 | 
							return NONE;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if((size >  ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
 | 
						if((size >  ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
 | 
				
			||||||
		lock = CriticalAreaLock();
 | 
					 | 
				
			||||||
		/* alignment */
 | 
							/* alignment */
 | 
				
			||||||
		size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
 | 
							size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
 | 
				
			||||||
		goto try_extmem;
 | 
							goto try_extmem;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	   
 | 
					 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
	/* parameter detection */
 | 
						/* parameter detection */
 | 
				
			||||||
	if((size == 0) || (size >  ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory))
 | 
						if((size == 0) || (size >  ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
 | 
				
			||||||
 | 
							CriticalAreaUnLock(lock);
 | 
				
			||||||
	    return NONE;
 | 
						    return NONE;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	/* hold lock before allocation */
 | 
					
 | 
				
			||||||
	lock = CriticalAreaLock();
 | 
					 | 
				
			||||||
    /* alignment */
 | 
					 | 
				
			||||||
	size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
 | 
					 | 
				
			||||||
	/* determine allocation operation from static segments or dynamic buddy memory */
 | 
						/* determine allocation operation from static segments or dynamic buddy memory */
 | 
				
			||||||
#ifdef KERNEL_SMALL_MEM_ALLOC
 | 
					#ifdef KERNEL_SMALL_MEM_ALLOC
 | 
				
			||||||
	if(size <= SIZEOF_32B) {
 | 
						if(size <= SIZEOF_32B) {
 | 
				
			||||||
		ret = ByteManager.static_manager[0].done->malloc(&ByteManager, SIZEOF_32B);
 | 
							ret = ByteManager.static_manager[0].done->malloc(&ByteManager, SIZEOF_32B);
 | 
				
			||||||
	} else if (size <= SIZEOF_64B) {
 | 
						} else if (size <= SIZEOF_64B) {
 | 
				
			||||||
		ret = ByteManager.static_manager[1].done->malloc(&ByteManager, SIZEOF_64B);
 | 
							ret = ByteManager.static_manager[1].done->malloc(&ByteManager, SIZEOF_64B);
 | 
				
			||||||
	} else
 | 
						} 
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	{
 | 
					
 | 
				
			||||||
 | 
						if (ret == NONE) {
 | 
				
			||||||
        ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
 | 
					        ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
 | 
				
			||||||
		if(ret != NONE)
 | 
							if (ret != NONE) {
 | 
				
			||||||
        	CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
 | 
					        	CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef MEM_EXTERN_SRAM
 | 
					#ifdef MEM_EXTERN_SRAM
 | 
				
			||||||
try_extmem:
 | 
					try_extmem:
 | 
				
			||||||
| 
						 | 
					@ -686,6 +688,7 @@ try_extmem:
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* release lock */
 | 
						/* release lock */
 | 
				
			||||||
	CriticalAreaUnLock(lock);
 | 
						CriticalAreaUnLock(lock);
 | 
				
			||||||
  	return ret;
 | 
					  	return ret;
 | 
				
			||||||
| 
						 | 
					@ -781,13 +784,19 @@ void x_free(void *pointer)
 | 
				
			||||||
	struct DynamicAllocNode *node = NONE;
 | 
						struct DynamicAllocNode *node = NONE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* parameter detection */
 | 
					    /* parameter detection */
 | 
				
			||||||
	if (pointer == NONE)
 | 
						if (pointer == NONE) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
    CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager,pointer));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* hold lock before release */
 | 
					    /* hold lock before release */
 | 
				
			||||||
	lock = CriticalAreaLock();
 | 
						lock = CriticalAreaLock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer)) {
 | 
				
			||||||
 | 
							CriticalAreaUnLock(lock);
 | 
				
			||||||
 | 
							SYS_ERR("[%s] Freeing a no allocated address.\n", __func__);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	node = PTR2ALLOCNODE((char*)pointer -  SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
						node = PTR2ALLOCNODE((char*)pointer -  SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
				
			||||||
    CHECK(ByteManager.done->JudgeAllocated(node));
 | 
					    CHECK(ByteManager.done->JudgeAllocated(node));
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
| 
						 | 
					@ -812,6 +821,7 @@ void x_free(void *pointer)
 | 
				
			||||||
		ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
 | 
							ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
 | 
				
			||||||
#endif		
 | 
					#endif		
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* release the lock */
 | 
						/* release the lock */
 | 
				
			||||||
	CriticalAreaUnLock(lock);
 | 
						CriticalAreaUnLock(lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -888,6 +898,7 @@ void InitBoardMemory(void *start_phy_address, void *end_phy_address)
 | 
				
			||||||
    /* parameter detection */
 | 
					    /* parameter detection */
 | 
				
			||||||
	if (ByteManager.dynamic_buddy_manager.dynamic_buddy_start >= ByteManager.dynamic_buddy_manager.dynamic_buddy_end) {
 | 
						if (ByteManager.dynamic_buddy_manager.dynamic_buddy_start >= ByteManager.dynamic_buddy_manager.dynamic_buddy_end) {
 | 
				
			||||||
		//KPrintf("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address);
 | 
							//KPrintf("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address);
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(KDBG_MEM, ("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue