Example #1
0
void jz_nand_ssfdc_test(void)
{
	unsigned int *mybuffer;	
	unsigned char *data_ptr;
	unsigned int i,j,Sector;
	 
	data_ptr = (unsigned char *)alloc(BLOCK_SIZE);
	mybuffer = (unsigned int *)data_ptr;
	
	ssfdc_nftl_init();
		
	ssfdc_nftl_open(0);
	//ssfdc_nftl_format();
	
	printf("Nand data test\r\n");
	
	for(i = 0;i < BLOCK_SIZE / 4;i++)
		mybuffer[i] = i;
	
	for(i = 0; i < 1; i++)
	{
		Sector = 0 + i * 512;
		ssfdc_nftl_write(Sector,data_ptr,512);
	}
	ssfdc_nftl_flush_cache();

	printf("nand read data\r\n");
	for(i = 0; i < 1; i++) 
	{
		for(j = 0;j < BLOCK_SIZE / 4;j++)
			mybuffer[j] = -1;
		Sector = 0 + i * 512;
		ssfdc_nftl_read(Sector,data_ptr,512);
				
		for(j = 0;j < BLOCK_SIZE / 4;j++)
		{
			if(mybuffer[j] != j)
			{
				printf("read sector data error %d sector %d word->0x%x\r\n",i,j,mybuffer[j]);
				deAlloc(mybuffer);
				while(1);
			}
		}
	}
	
	printf("Test OK!xyzhang\r\n");
	deAlloc(mybuffer);
	while(1);
}
Example #2
0
void uc_free_static(void *addr)
{
    if(addr != NULL)
        deAlloc((unsigned int)addr);
}
Example #3
0
MEM_ULONG Drv_realloc(MEM_ULONG address,MEM_ULONG nbytes)
{
	unsigned int sr;
	sr = spin_lock_irqsave();
	MEM_ULONG rr,addr,oldsize;
	MEM_ULONG block,rblock,rrblock;
	MEM_ULONG bsize,rbsize,align;
	unsigned int len;
	oldsize = nbytes;
	
	nbytes = ((nbytes  + MIN_FREE_BYTES - 1)/ MIN_FREE_BYTES )  * MIN_FREE_BYTES;
	
	rr = address;
	if (nbytes == 0) {
			spin_unlock_irqrestore(sr);
			deAlloc(rr);
			return 0;
  }
	if (address == 0)
	{	
	    addr = my_alloc(nbytes);
	    if(addr != 0)
	    	setalign(addr,0);
	    spin_unlock_irqrestore(sr);
	    return addr;
	}
	align = getalign(address);
	len = (nbytes + align + MIN_FREE_BYTES - 1) &(~(MIN_FREE_BYTES - 1));
	address -= getalign(address);
	address -= SIZE_HEADER;    
	bsize = size(address);
	//printf("align = %d,address = %x  %d %d\n",align,address,nbytes,bsize);
	if(nbytes <= bsize-align)
	{
		spin_unlock_irqrestore(sr);
		return rr;
	}	
	
	rblock = next(address);
	if((rblock != 0) &&(status(rblock) == FREE) )
	{
		//printf("rblock = %x %d %d",rblock,status(rblock),size(rblock));
		bsize += size(rblock);
		if(bsize >= nbytes + align)
		{
			rrblock = next(rblock);
			next(address) = address + len + SIZE_HEADER;
			block = next(address);
			prev(block) = address;
			next(block) = rrblock;
			if(rrblock)
				prev(rrblock) = block; 
			status(block) = FREE;
			spin_unlock_irqrestore(sr);
			return rr;
	  }
	}   
	addr = my_alloc(len);
	//printf("realloc %x %x %x %x\n",addr,rr,nbytes,bsize);
	
	if(addr == 0)
	{
		spin_unlock_irqrestore(sr);
		return 0;
	}
  addr += align;		
	setalign(addr,align);	
	memcpy(addr,rr,bsize);
	spin_unlock_irqrestore(sr);
	deAlloc(rr);
  
  return addr;	
}