⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 这是EBF533试验板的源代码和使用说明手册
💻 C
字号:
#include "I2C.h"
#include "stdio.h"
#include "sys\exception.h"
#include "cpld.h"

#define RAM_Length 720
#define RAM_Length_y 288

EX_INTERRUPT_HANDLER(DMA0_PPI_ISR);
bool Init_ADV7181(void);
void Read_ADV7181(void);
void Init_EBIU(void);
void Init_CPLD(void);
void Init_PLL(void);
void Init_SDRAM(void);
void Init_PPI(void);
void Init_DMA(void);
void Close_ADV7181(void);



unsigned short PPI_DMA_DONE;
int *pTSdram;
int k;
unsigned char dataIn[40];

main()
{
	int o = 0;
	bool ret = true;
    while(o < 10)
    {
    	Init_PLL(); 
    	Init_EBIU();
    
    	//Initial Interrupt 
   		register_handler(ik_ivg8,DMA0_PPI_ISR);
    	*pSIC_IMASK = 0x00000100;

    	Init_CPLD();
		if (!I2C_Init(ADV7181_IDENT_W))
		{
			while(1);
		}

		if(!Init_ADV7181())
		{
			while(1);
		}
	
		Read_ADV7181();
	
		Init_DMA();
		Init_PPI();
		while(!PPI_DMA_DONE);
		o = o + 1;
		PPI_DMA_DONE = 0;

	}
	while(1);
}


bool Init_ADV7181(void)
{
	if(!I2C_Write(0x00,0x15))
	{return false;}
	
	if(!I2C_Write(0x41,0x17))
	{return false;}
	
	if(!I2C_Write(0x16,0x3a))
	{return false;}
	
	if(!I2C_Write(0x04,0x50))
	{return false;}
	
	if(!I2C_Write(0x05,0xc3))
	{return false;}

	if(!I2C_Write(0x80,0xc4))
	{return false;}
	
	if(!I2C_Write(0x80,0x0e))
	{return false;}
	
	if(!I2C_Write(0x20,0x50))
	{return false;}
	
	if(!I2C_Write(0x18,0x52))
	{return false;}
	
	if(!I2C_Write(0xed,0x58))
	{return false;}
	
	if(!I2C_Write(0xc5,0x77))
	{return false;}
	
	if(!I2C_Write(0x93,0x7c))
	{return false;}
	
	if(!I2C_Write(0x00,0x7d))
	{return false;}
	
	if(!I2C_Write(0x48,0xd0))
	{return false;}
	
	if(!I2C_Write(0xa0,0xd5))
	{return false;}
	
	if(!I2C_Write(0xea,0xd7))
	{return false;}
	
	if(!I2C_Write(0x3e,0xe4))
	{return false;}
	
	if(!I2C_Write(0x0f,0xea))
	{return false;}
	
	if(!I2C_Write(0x00,0x0e))
	{return false;}
	
	return true;
}

void Read_ADV7181(void)
{
	I2C_Read(&dataIn[0],0x15);
	I2C_Read(&dataIn[1],0x17);
	I2C_Read(&dataIn[2],0x3a);
	I2C_Read(&dataIn[3],0x50);
	I2C_Read(&dataIn[4],0xc3);
	I2C_Read(&dataIn[5],0xc4);
	I2C_Read(&dataIn[6],0x0e);
	I2C_Read(&dataIn[7],0x52);
	I2C_Read(&dataIn[8],0x58);
	I2C_Read(&dataIn[9],0x77);
	I2C_Read(&dataIn[10],0x7c);
	I2C_Read(&dataIn[11],0x7d);
	I2C_Read(&dataIn[12],0xd0);
	I2C_Read(&dataIn[13],0xd5);
	I2C_Read(&dataIn[14],0xd7);
	I2C_Read(&dataIn[15],0xe4);
	I2C_Read(&dataIn[16],0xea);

}
void Init_CPLD(void)
{ 
	int i;
	*pCtrlReg1 = 0x1;
	for(i = 0;i < 10000;i++);
	*pLED = 0x00;
	for(i = 0;i < 10000;i++); 
	*pCtrlReg2 = 0x2;
	for(i = 0;i < 10000;i++); 
	
}

void Init_EBIU(void)
{
	
	*pEBIU_AMBCTL0	= 0x7bb07bb0;	// <--|Write access time = 7 cycles, read access time = 11 cycles, no ARDY
	*pEBIU_AMBCTL1	= 0x7bb07bb0;	//    |Hold time = 2 cycles, setup time = 3 cycles, transition time = 4 cycles
	*pEBIU_AMGCTL	= 0x000F;		//	  |Enable all memory banks

}//end Init_EBIU

void Init_PLL(void)
{
    int iIMASK_Value;
	sysreg_write(reg_SYSCFG, 0x32);		//Initialize System Configuration Register

	// set VCO/CCLK = 1, and VCO/SCLK = 5 (take effect immediately)
	*pPLL_DIV = 0x0008;

	// prepare PLL changes (set CLKIN/VCO = 22; takes effect after PLL programming sequence)
	*pPLL_LOCKCNT	= 0x0200;					// time for PLL to stabilize
	*pPLL_CTL		= 0x2c00;					// set VCO/CLKIN = 22

	// execute PLL programming sequence
	*pSIC_IWR		= 0x00000001;				// enable only PLL wakeup interrupt
	iIMASK_Value	= cli();					// disable interrupts
	idle();										// wait for PLL wakeup interrupt
	sti(iIMASK_Value);	


}//end Init_PLL 


void Init_SDRAM(void)
{

	//SDRAM Refresh Rate Control Register
	*pEBIU_SDRRC = 0x00000817;	

	//SDRAM Memory Bank Control Register
	*pEBIU_SDBCTL = 0x00000013;

	//SDRAM Memory Global Control Register	
	*pEBIU_SDGCTL = 0x0091998d;	
														
		

}//end Init_SDRAM

void Init_PPI(void)
{

	//The PPI is set to receive 625 lines for each frame
	*pPPI_FRAME =   625;//PAL	

	//PPI enabled, input mode, active video only, receive field 1&2, 
	//packing enabled, DMA32 enabled, skipping disabled, 8bit data bus, nothing inverted
	*pPPI_CONTROL = PORT_EN | /*FLD_SEL |*/ PACK_EN | DLEN_8 /*& ~PORT_DIR*/;
}

void Init_DMA(void)
{
    *pDMA0_IRQ_STATUS = 0x3;
	//Target address of the DMA
	*pDMA0_START_ADDR = 0x0;	

	//RAM_Length 32bit transfers will be executed
	*pDMA0_X_COUNT = RAM_Length;

	//The modifier is set to 4 because of the 32bit transfers
	*pDMA0_X_MODIFY = 0x2;
	*pDMA0_Y_COUNT	= RAM_Length_y;
	*pDMA0_Y_MODIFY = 0x2;													

	//PPI Peripheral is used
	*pDMA0_PERIPHERAL_MAP = 0x0;	
	
	//DMA Config: Enable DMA | Memory write DMA | Discard DMA FIFO before start | enable assertation of interrupt | NDSIZE for stop mode | Enable STOP DMA
	//Enable 2D-DMA
	*pDMA0_CONFIG = DMAEN | DI_EN | WNR | WDSIZE_16 | RESTART | DMA2D ;//| DI_SEL;	
	
	

}//end Init_DMA

EX_INTERRUPT_HANDLER(DMA0_PPI_ISR)	// <--|declaration in  exception.h -->
{
//disable the interrupt request
        	*pDMA0_IRQ_STATUS = 0x1;   // to clear interrupt bit	
	        //temp2 = *pPPI_CONTROL;

	        *pPPI_CONTROL &= 0xfffe;
				
	       printf( "\nThe DMA0 PPI Interrupt has been entered!\n" );
		   PPI_DMA_DONE = 1;
}


⌨️ 快捷键说明

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