欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

rbwmain.c

在ccs中调试DSP外部存储sdram的反色代码
C
字号:
/*
 *  Copyright 2008 by Boss.H Lab.
 *  All rights reserved. Property of Boss.H Lab.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  	
 */
/* copy_in_out 2008.07.07 ver 1.0 */
/*
 *输入一副24位深的BMP黑白图像,反转颜色输出
 */

/*
 *  ======== rBWmain.c ========
 */
 
/*引用头文件*/
#include <std.h>
#include <csl_stdinc.h>
#include <hst.h>
#include <pip.h>
#include <swi.h>
#include <log.h>
#include "rBWcfg.h"	/*DSP_BIOS头文件,由CCS根据CDB配置自动生成*/

/*SDRAM映射地址0x80000000,长度0x08000000,共128MB*/
#define MT48_SDRAM_BASE		0x88000000

/*定义全局变量*/
static Uns count;	/*根据文件大小控制执行次数*/
static Uns filesize;/*文件大小*/
static Uns key;/*控制mailbox的加减*/
static Uns glut_filesize;/*算burst掉内容的大小*/
static unsigned int in_addr,out_addr;

/*子函数列表,功能见下*/
Void intomem(HST_Obj *input);
Void glut(HST_Obj *output);
Void reversalBW(Void);
Void inputReady(Void);
Void outputReady(Void);


/*
 *  ======== main ========
 *主函数,初始化相关变量w
 */
Void main(Int argc, String argv[])
{
	CSL_init();
	EMIFA_config(&MT48);
	
	count = 0x0;
	filesize = 0x0;
	key = 0;/*不在burst循环体内激活outputReady就应该key坚决为零*/
	in_addr = MT48_SDRAM_BASE;
    out_addr = MT48_SDRAM_BASE;
			
    LOG_printf(&trace, "reversal Black&White started.");
	
    /* fall into BIOS idle loop */
    return;                 
}

/*
 *  ======== intomem ========
 *HST_input通道数据拷贝进SDRAM 0x80000000开始的区域
 *1、读取传输文件大小
 */
Void intomem(HST_Obj *input)
{
    PIP_Obj     *in;
    Uns         *src;
    Uns         size;
    Uns			intomem_filesize;
        
    /*LOG_printf(&trace, "intomem started.");*/
    /*创建PIP对象in,设定相关参数*/
    in = HST_getpipe(input);/*绑定in到HST对象input上*/
    PIP_get(in); /*get input data */
    src = PIP_getReaderAddr(in);/*得到in的地址*/
    size = PIP_getReaderSize(in);/*得到in的size长度*/
        
    /* copy input data to SDRAM 0x80000000 */
    for (; size > 0; size--) {
	   /* if (((in_addr + (count<<2)) & 0x00000080) != 0x00000000)
		{  in_addr = in_addr + 0x80;
		}
		if (((in_addr + (count<<2)) & 0x00010000) != 0x00000000)
		{  in_addr = in_addr + 0x10000;
		}*/
    	*((Uint32 *)(in_addr + (count<<2))) = *src++;
    	count++;
    }
		
    /* free input buffer */    
    PIP_free(in);
    
    /* 判断文件长度, 并把长度付给filesize*/
    /*if (count == 0x80){
    	filesize = *((Uint8 *)(MT48_SDRAM_BASE + 2)) + ((*((Uint8 *)(MT48_SDRAM_BASE + 3)))<<8) + ((*((Uint8 *)(MT48_SDRAM_BASE + 4)))<<16) + ((*((Uint8 *)(MT48_SDRAM_BASE + 5)))<<24);
    }*/
    	filesize = *((Uint8 *)(MT48_SDRAM_BASE + 2)) + ((*((Uint8 *)(MT48_SDRAM_BASE + 3)))<<8) + ((*((Uint8 *)(MT48_SDRAM_BASE + 4)))<<16) + ((*((Uint8 *)(MT48_SDRAM_BASE + 5)))<<24);    
    /*文件小于512B的时候只有这样有效,有没有解决方法?*/
    
    /*正确的BMP图像都是54个字节+4的倍数字节,一定除四余二,最后两个字节input也不认
     *BMP 文件分为是被四除尽和余二两种
     */
    if (filesize%4==2){intomem_filesize = filesize - 2;}
    else {intomem_filesize = filesize;}
        
    /* 判断文件传输结束, 激活reversal程序*/
    if (count == (intomem_filesize/4)){
    	//*((Uint32 *)(MT48_SDRAM_BASE + ((count+1)<<2))) = 0; /*补四位*/
    	reversalBW();
    }
    /*else {LOG_printf(&trace, "The BMP File is Error.");}*/
    
    
    /*测试各种函数的返回值*/    
    /*
     *循环体内放LOG_printf(&trace, "count = %d ; MT48_SDRAM_BASE = %x\n", count, *src);
     *测试输出值
     *LOG_printf(&trace, "PIP_getReaderNumFrames = %x\n", PIP_getReaderNumFrames(in));
     *LOG_printf(&trace, "PIP_getReaderSize = %x\n", size);
	 *LOG_printf(&trace, "1d = %x\n", *((Uint8 *)(MT48_SDRAM_BASE + 2)));
	 *LOG_printf(&trace, "2d = %x\n", ((*((Uint8 *)(MT48_SDRAM_BASE + 3)))));
	 *LOG_printf(&trace, "3d = %x\n", ((*((Uint8 *)(MT48_SDRAM_BASE + 4)))));
	 *LOG_printf(&trace, "4d = %x\n", ((*((Uint8 *)(MT48_SDRAM_BASE + 5)))));
	 *LOG_printf(&trace, "The files size = %d\n", filesize);	     
     */	
}

/*
 *  ======== reversalBW ========
 
 *2、读取图像行列
 *3、每行按位取反
 *4、跳过行尾添加的0x00
 *5、判断操作结束,激活outofmem
 */
Void reversalBW(Void)
{
	Uns rows , columns;
	Uns bs, ys,n,j;
	Uns addr = MT48_SDRAM_BASE + 54;
	
	LOG_printf(&trace, "reversalBW started.");
	LOG_printf(&trace, "reversalBW read filesize == %d", filesize);
	
	rows = 0;
	columns = 0;
	
	/*2、读取图像行列*/
	n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}
	    rows 	= *((Uint8 *)(MT48_SDRAM_BASE + 22));
	n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}    
    rows = rows + ((*((Uint8 *)(MT48_SDRAM_BASE + 23)))<<8);
	n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}        
    rows = rows + ((*((Uint8 *)(MT48_SDRAM_BASE + 24)))<<16);
    n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}        
    rows = rows + ((*((Uint8 *)(MT48_SDRAM_BASE + 25)))<<24);
	n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}             
    columns = *((Uint8 *)(MT48_SDRAM_BASE + 18));
	n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}                 
    columns = columns + ((*((Uint8 *)(MT48_SDRAM_BASE + 19)))<<8);
    	n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}                 
    columns = columns + ((*((Uint8 *)(MT48_SDRAM_BASE + 20)))<<16);
    	n=0;
	for(j=0;j<300;j++){    		
	n=n+1;
	}                 
    columns = columns + ((*((Uint8 *)(MT48_SDRAM_BASE + 21)))<<24); 
    LOG_printf(&trace, "columns X rows = %d X %d\n", columns, rows);
    
    /*3、每行按位取反 + 4、跳过行尾添加的0x00*/
    /*bs = columns*3/4;	取按32位需要循环次数*/
    ys = (columns*3)%4;	/*取每行字节被4除的余数*/
    /*LOG_printf(&trace, "bs _ ys = %d _ %d\n", bs, ys);*/
    
    for( ; rows > 0 ; rows--){
    	for(bs = columns * 3 ; bs > 0 ; bs--){
           /* if ((addr & 0x00000080) != 0x00000000)
		       { addr = addr + 0x80 ;
		       }
			if ((addr & 0x00010000) != 0x00000000)
		    { addr = addr + 0x10000 ;
		    }*/
		    n=0;
    		for(j=0;j<300;j++){    		
    		n=n+1;
    		}
    		*((Uint8 *)addr) = ~(*((Uint8 *)addr));
    		addr++;
    	}
    	if( ys == 1 ){addr = addr + 3;}
    	if( ys == 2 ){addr = addr + 2;}
    	if( ys == 3 ){addr = addr + 1;}    	
    }
    
    /*LOG_printf(&trace, "reversalBW end.");*/
    
    /*激活outofmem程序【曾经想过的一种解决方法】
    bs = filesize / 512;
    ys = filesize % 512;
    for( ; bs > 0 ; bs--){
    	outofmem(HST_Obj *output);
    }
    if ( ~(ys == 0) ){
    	key = ys;
    	outofmem(HST_Obj *output);	
    }*/
    
    /*要输出完整的最后一个32位, 需要再补回四位*/
	if (filesize%4==2){glut_filesize = filesize + 2;}
    else {glut_filesize = filesize;}    
    
    SWI_dec(&glut_Swi);
    
}

/*
 * ======== inputReady ========
 */
Void inputReady(Void)
{	
	/*LOG_printf(&trace, "inputReady started.");*/
	SWI_andn(&intomemSwi, 1);/* clear swi mbx bit position 0 */
}

/*
 * ======== outputReady ========
 */
Void outputReady(Void)
{
/*	LOG_printf(&trace, "outputReady started.");*/
	
	if( key==1 ){
		glut_Swi.mailbox++;
		/*LOG_printf(&trace, "Mailbox = ", glut_Swi.mailbox);*/
		/*SWI_inc(&outofmemSwi);*/
	}/*outofmem is running, so mailbox+1*/
	else{
		/*LOG_printf(&trace, "Mailbox-1.");*/
		/*LOG_printf(&trace, "Mailbox - 1 = ", glut_Swi.mailbox - 1);*/
		SWI_dec(&glut_Swi);
	}/*outofmem stop, so mailbox-1*/
}

/*
 * ======== glut ========
 * 传输整整一个64KB的数据
 */
Void glut(HST_Obj *output)
{
	PIP_Obj     *out;
    Uns         *dst;
    Uns			size,n,j;

    
	/*LOG_printf(&trace, "glut started.");*/
	
	/*判断文件是否大于64KB
	 *64KB由这几个量决定
	 *output.bufalign 4B * output.framesize 128 * output.numframes 128 = 64KB
	 *PIP_getWriterNumFrames(out) 取 output.numframes还剩的值
	 *PIP_setWriterSize(out, size)设定 output.framesize值
	 */        
    if (glut_filesize >= 512 ){
	    /*LOG_printf(&trace, "burst 64KB Data into files......");*/
	    
	    key = 1;/*开关值,这样outputReady将选择向mailbox内加一*/
	    size = 0x80; /*0x80*4=512*/
	    /*LOG_printf(&trace, "Mailbox = %d", SWI_getmbox());*/
	    
		out = HST_getpipe(output);
		
		/*testpoint = PIP_getWriterNumFrames(out);测试PIP_getWriterNumFrames*/
					
		PIP_alloc(out);/*allocate output buffer*/
		dst = PIP_getWriterAddr(out);
		PIP_setWriterSize(out, size);
		
		/* burst data into output$buf*/
			for (; size > 0; size--) 
			{   
			   /* if (((out_addr + ((filesize/4 - count)<<2)) & 0x00000080) != 0x00000000)
		        {  out_addr = out_addr + 0x80;
		        }
				if (((out_addr + ((filesize/4 - count)<<2)) & 0x00010000) != 0x00000000)
		        {  out_addr = out_addr + 0x10000;
		        }*/
		        n=0;
    		    for(j=0;j<300;j++){    		
    		    n=n+1;
    		    }
				*dst++ = *((Uint32 *)(out_addr + ((filesize/4 - count)<<2)));
				count--;
		    }	
		/* output copied data and free input buffer*/ 
		PIP_put(out);	
		
		
	    /*LOG_printf(&trace, "Mailbox = %d", SWI_getmbox());*/
		
		key = 0;/*开关值,这样outputReady将选择向mailbox内减一*/	
		
		glut_Swi.mailbox = 1;/**/
		
		glut_filesize = glut_filesize - 512;
		
		/*LOG_printf(&trace, "burst stop......");*/	
	}
	else{
		key = 1;/*开关值,这样outputReady将选择向mailbox内加一*/
	    size = glut_filesize / 4; /*0x80*4=512*/
	    /*LOG_printf(&trace, "Mailbox = %d", SWI_getmbox());*/
	    
		out = HST_getpipe(output);
		
		/*testpoint = PIP_getWriterNumFrames(out);测试PIP_getWriterNumFrames*/
					
		PIP_alloc(out);/*allocate output buffer*/
		dst = PIP_getWriterAddr(out);
		PIP_setWriterSize(out, size);
		/* burst data into output$buf*/
			for (; size > 0; size--) 
			{   
			    /*if (((out_addr + ((filesize/4 - count)<<2)) & 0x00000080) != 0x00000000)
		        {  out_addr = out_addr + 0x80;
		        }
				if (((out_addr + ((filesize/4 - count)<<2)) & 0x00010000) != 0x00000000)
		        {  out_addr = out_addr + 0x10000;
		        }*/
		        n=0;
    		    for(j=0;j<300;j++){    		
    		    n=n+1;
    		    }
				*dst++ = *((Uint32 *)(out_addr  + ((filesize/4 - count)<<2)));
				count--;
		    }	
		/* output copied data and free input buffer*/ 
		PIP_put(out);	
		
		
	    /*LOG_printf(&trace, "Mailbox = %d", SWI_getmbox());*/
		
		key = 0;/*开关值,这样outputReady将选择向mailbox内减一*/	
		
		glut_Swi.mailbox = 2;
		
		LOG_printf(&trace, "reversal Black&White end.\n");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -