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

📄 seedpciapi.c

📁 该文件是DM642的PCI方面的开发DDK
💻 C
字号:


/************************************************************/
/*	Filename:		SeedPciApi.c							*/
/*	Designor:		xianghe chen							*/
/*	Date:			2006-02-23								*/
/************************************************************/

#include "SeedPciApi.h"

/*
 The base address of command area, User shouldn't change it,
 otherwise, all related application are abnormal
*/
#define BASEADD		0x0001FF00

// Interrupt flag address, indicate record interrupt or display interrupt
#define	DSPINTFLGADD	(*(volatile Uint32 *)(BASEADD+0x0))			
#define	FIRCHNCAP	0x11111111		// First channel video capture interrupt  
#define	SECCHNCAP	0x22222222		// Second channel video capture interrupt 
#define	THICHNCAP	0x33333333		// Third channel video capture interrupt  
#define	FOUCHNCAP	0x44444444		// Fourth channel video capture interrupt 

#define	FIRCHNRDY	0x55555555		// First channel ready interrupt 
#define SECCHNRDY	0x66666666		// Second channel ready interrupt 
#define	THICHNRDY	0x77777777		// Third channel ready interrupt 
#define	FOUCHNRDY	0x88888888		// Fourth channel ready interrupt 

#define FIRCHNRCD	0x99999999		// First channel record interrupt
#define SECCHNRCD   0xAAAAAAAA		// First channel record interrupt
#define THICHNRCD	0xBBBBBBBB		// First channel record interrupt
#define FOUCHNRCD   0xCCCCCCCC		// First channel record interrupt

// Video capture flag address, indicate corresponding channel if start capture video
#define	FIRCHNCAPADD	(*(volatile Uint32 *)(BASEADD + 0x4))		 	
#define	SECCHNCAPADD	(*(volatile Uint32 *)(BASEADD + 0x8))		 	
#define	THICHNCAPADD	(*(volatile Uint32 *)(BASEADD + 0xC))			
#define	FOUCHNCAPADD	(*(volatile Uint32 *)(BASEADD + 0x10))		 		
#define	CHNCAPSTA	0x55551111		// Start capture and display
#define	CHNCAPPAU	0xAAAACCCC		// Pause capture and display
#define	CHNCAPSTP	0x11115555		// Stop capture and display

// Video record flag address, indicate corresponding channel if start record video
#define FIRCHNRCDADD	(*(volatile Uint32 *)(BASEADD+0x14))	
#define SECCHNRCDADD	(*(volatile Uint32 *)(BASEADD+0x18))	
#define THICHNRCDADD	(*(volatile Uint32 *)(BASEADD+0x1C))	
#define FOUCHNRCDADD	(*(volatile Uint32 *)(BASEADD+0x20))	
#define CHNRCDSTA	0x55551111		// Start record compressed video data
#define CHNRCDSTP	0x11115555		// Stop record compressed video data

// Host interrupt dsp flag address
#define HSTINTFLGADD	(*(volatile Uint32 *)(BASEADD+0x24))
#define	FIRCHNREQ	0x11111111		// Host request first channel to send capture data  
#define	SECCHNREQ	0x22222222		// Host request second channel to send capture data 
#define	THICHNREQ	0x33333333		// Host request third channel to send capture data  
#define	FOUCHNREQ	0x44444444		// Host request fourth channel to send capture data 
#define DWNLADREQ	0x9999AAAA		// Host download data to dsp request

// Logical address, dsp get host logical address from this address
#define HSTLOGADD		(*(volatile Uint32 *)(BASEADD+0x28))

// The length of common buffer
#define CMNBUFLENADD	(*(volatile Uint32 *)(BASEADD+0x2C))

/************************/
/* 0x30 is reserved		*/
/************************/

// The ring buffer overflow flag
#define RBFOVFADD		(*(volatile Uint32 *)(BASEADD+0x34))
#define RBFOVF		0x55551111		// Ringbuffer overflow

// Frame exchange enable/disable flag address
#define FRMEXCADD		(*(volatile Uint32 *)(BASEADD+0x38))
#define FRMEXCENB	0x55551111		// Enable frame exchange
#define FRMEXCDIS	0x11115555		// Disable frame exchange

// The address of DMA state flag
#define DMASTATADD		(*(volatile Uint32 *)(BASEADD+0x3C))
#define DMABUSY		0x55551111		// DMA busy
#define DMAIDLE		0x11115555		// DMA idle

// The address of DMA interrupt completition flag
#define DMACMPADD		(*(volatile Uint32 *)(BASEADD+0x40))
#define FIRCAPDMA	0x11111111
#define SECCAPDMA	0x22222222
#define THICAPDMA	0x33333333
#define FOUCAPDMA	0x44444444

#define FIRRCDDMA	0x55555555
#define SECRCDDMA	0x66666666
#define THIRCDDMA	0x77777777
#define FOURCDDMA	0x88888888

// The address of video compress format
#define VIDEOFORMATADD	(*(volatile Uint32 *)(BASEADD+0x44))

/************************************************************/
/* 0x48--0x5C is reserved for future using, User is not		*/
/* recommend to use this area								*/
/************************************************************/

// The begginning address of S/G DMA, The length is 0x40
#define SGCOMMANDADD	(Uint32 *)(BASEADD+0x60)
#define ENDCOMMAND	0x11223344		// S/G DMA ending indicator

/************************************************************/
/* Althougth 0x90--0x100 is reserved,						*/
/* User can use it											*/
/************************************************************/

Uint32 v_Dspadd, v_Pciadd, v_Pcimc, v_Sourceadd;
Uint32 *Cmdbuf;			// The pointer of command buffer

/************************************************************
// 	Name:		InitPciDrvLib		
//	Function:	Initialize seed ti6x PCI interface library	
//  Parameter:	
//		None
//  Return:
//		None			
************************************************************/
void InitPciDrvLib(void)
{
	// Clear command area
	memset((Uint32 *)(BASEADD),0xFF,0x400);
	
	// Set initial value
	DMASTATADD = DMAIDLE;
	FRMEXCADD = FRMEXCDIS;
	
	// Enalbe system and pci interrupt				 		
	IRQ_reset(IRQ_EVT_DSPINT);
	IRQ_enable(IRQ_EVT_DSPINT);
	
	PCI_dspIntReqClear();
	PCI_intEnable(PCI_EVT_HOSTSW);
	PCI_intEnable(PCI_EVT_MASTEROK);

}

/************************************************************
// 	Name:		CheckPciDmaState		
//	Function:	Chech pci dma transfer if busy	
//  Parameter:	
//		None
//  Return:
//		If True, pci dma busy; 
//		else, pci dma idle.			
************************************************************/
Bool CheckPciDmaState(void)
{
	if(DMASTATADD == DMABUSY)
		return TRUE;
	else
		return FALSE;
}

/************************************************************
// 	Name:		SetCapDmaSrcAdd		
//	Function:	Setup dma transfer capture video data source address,	
//  Parameter:	
//		DspAdd--Captured video frame starting address
//  Return:
//		None				
************************************************************/
void SetCapDmaSrcAdd(Uint32 DspAdd)
{
	v_Sourceadd = DspAdd;
}

/************************************************************
// 	Name:		IsCapStart		
//	Function:	Judge video channel capture display if started	
//  Parameter:	
//		Num--Video channel number
//  Return:
//		If True, corresponding channel capture is started;
//      else,corresponding channel capture is closed.			
************************************************************/
Bool IsCapStart(CHANNUM Num)
{
	Bool Status;
	
	switch(Num)
	{
	case FIRCHN:
		if(FIRCHNCAPADD == CHNCAPSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	case SECCHN:
		if(SECCHNCAPADD == CHNCAPSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	case THICHN:
		if(THICHNCAPADD == CHNCAPSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	case FOUCHN:
		if(FOUCHNCAPADD == CHNCAPSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	default:
		printf("Error channel number");
		Status = FALSE;
		break;
	}
	
	return Status;
}

/************************************************************
// 	Name:		IsRcdStart		
//	Function:	Judge video channel record if started or stopped	
//  Parameter:	
//		Num--Video channel number
//	Return:	
//		If True, corresponding channel record is started;
//      else,corresponding channel record is closed.			
************************************************************/
Bool IsRcdStart(CHANNUM Num)
{
	Bool Status;
	switch(Num)
	{
	case FIRCHN:
		if(FIRCHNRCDADD == CHNRCDSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	case SECCHN:
		if(SECCHNRCDADD == CHNRCDSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	case THICHN:
		if(THICHNRCDADD == CHNRCDSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	case FOUCHN:
		if(FOUCHNRCDADD == CHNRCDSTA)
			Status = TRUE;
		else
			Status = FALSE;
		break;
	default:
		Status = FALSE;
		break;	
	}
	
	return Status; 
}

/************************************************************
// 	Name:		SendFrmRdy		
//	Function:	Send corresponding video channel ready to capture command	
//  Parameter:	
//		Num--Video channel number
//  Return:
//		None				
************************************************************/
void SendFrmRdy(CHANNUM Num)
{	
	/*
	// Enable interrupt
	IRQ_enable(IRQ_EVT_DSPINT);
	PCI_intEnable(PCI_EVT_HOSTSW);
	PCI_intEnable(PCI_EVT_MASTEROK);
	*/
	switch(Num)
	{
		case FIRCHN:
			DSPINTFLGADD = FIRCHNRDY;
			break;
		case SECCHN:
			DSPINTFLGADD = SECCHNRDY;
			break;
		case THICHN:
			DSPINTFLGADD = THICHNRDY;
			break;
		case FOUCHN:
			DSPINTFLGADD = FOUCHNRDY;
			break;
		default:
			printf("Error channel number");
			break;
	}
	
	// Send interrupt command
	PCI_FSET(RSTSRC, INTRST, 1);			
	PCI_dspIntReqSet();				
}

/************************************************************
// 	Name:		WaitFrmTransOvr		
//	Function:	Waitting for frame transfer completed	
//  Parameter:	
//		None
//  Return:
//		None				
************************************************************/
void WaitFrmTransOvr(void)
{	
	while(FRMEXCADD == FRMEXCDIS)
	{}
}

/************************************************************
// 	Name:		SendEncodedData		
//	Function:	Send corresponding video channel ready to capture command	
//  Parameter:	
//		Num--Video channel number
//		DspAdd--Encoded data starting address
//		DataLen--The data length of will transfer	
//  Return:
//		None			
************************************************************/
void SendEncodedData(CHANNUM Num, Uint32 DspAdd, Uint32 DataLen)
{
	Uint32 LogAdd;					// Logical address
	
	LogAdd = HSTLOGADD;

	// Check if dma is busy
	while(DMASTATADD == DMABUSY)
	{}	
	
	// Set up record interrupt flag
	DMASTATADD = DMABUSY;
	VIDEOFORMATADD = DataLen;
	switch(Num)
	{
		case FIRCHN:
			DSPINTFLGADD = FIRCHNRCD;
			DMACMPADD = FIRRCDDMA;
			break;
		case SECCHN:
			DSPINTFLGADD = SECCHNRCD;
			DMACMPADD = SECRCDDMA;
			break;
		case THICHN:
			DSPINTFLGADD = THICHNRCD;
			DMACMPADD = THIRCDDMA;
			break;
		case FOUCHN:
			DSPINTFLGADD = FOUCHNRCD;
			DMACMPADD = FOURCDDMA;
			break;
		default:
			break;
	}	
		
	// start dma transfer 
	PCI_FSET(PCIMC,START,0);				
	PCI_RSET(PCIMA, LogAdd);
	PCI_RSET(DSPMA, DspAdd);
	PCI_RSET(PCIMC, (DataLen<<16) +1);	
}

/************************************************************
// 	Name:		TransCaptureFrm		
//	Function:	Transfer corresponding video channel capture data to pc host	
//  Parameter:	
//		First--
//		Num--Video channel number
//		DspAdd--Captured video frame starting address
//  Return:
//		None				
************************************************************/
void TransCaptureFrm(Bool First, CHANNUM Num, Uint32 DspAdd)
{
	if(First)
	{
		Cmdbuf = SGCOMMANDADD;		// Get the s/g dma beginning address
		FRMEXCADD = FRMEXCDIS;		// Disable frame exchange
		v_Dspadd = DspAdd;	
	}
	if(*Cmdbuf != ENDCOMMAND)		// If s/g dma not completed
	{
		v_Pcimc = *Cmdbuf;
		v_Pciadd = *(Cmdbuf+1);
	 	
	//	while(DMASTATADD == DMABUSY);	
	 	
	 	// Setup dma flag
	 	switch(Num)
		{
		case FIRCHN:
			DMACMPADD = FIRCAPDMA;
			break;
		case SECCHN:
			DMACMPADD = SECCAPDMA;
			break;
		case THICHN:
			DMACMPADD = THICAPDMA;
			break;
		case FOUCHN:
			DMACMPADD = FOUCAPDMA;
			break;
		default:
			printf("Error channel number");
			break;
		}
		
		PCI_FSET(PCIMC,START,0);		// Flash DMA
		PCI_RSET(PCIMA, v_Pciadd);
		PCI_RSET(DSPMA, v_Dspadd);
		PCI_RSET(PCIMC, (v_Pcimc<<16) +1);
	 		
		v_Dspadd += v_Pcimc;
		Cmdbuf += 2;				
	}				
	else								// If s/g dma completed
	{	
		// Setup capture interrupt flag
		switch(Num)
		{
		case FIRCHN:
			DSPINTFLGADD = FIRCHNCAP;
			break;
		case SECCHN:
			DSPINTFLGADD = SECCHNCAP;
			break;
		case THICHN:
			DSPINTFLGADD = THICHNCAP;
			break;
		case FOUCHN:
			DSPINTFLGADD = FOUCHNCAP;
			break;
		default:
			printf("Error channel number");
			break;
		}
		
		PCI_FSET(RSTSRC, INTRST, 1);	
		PCI_dspIntReqSet();				
		FRMEXCADD = FRMEXCENB;			// Enable frame exchange
	}	
}

/************************************************************
// 	Name:		PciDmaTransInterrupt		
//	Function:	Dsp pci interrupt dealer function	
//  Parameter:	
//		None
//  Return:
//		None				
************************************************************/
void PciDmaTransInterrupt()
{
	IRQ_clear(IRQ_EVT_DSPINT);				// Clear interrupt flag
	
	// If host interrupt dsp
	if(PCI_FGET(PCIIS, HOSTSW))
	{
		PCI_intClear(PCI_EVT_HOSTSW);		// Clear interrupt flag
		switch(HSTINTFLGADD)
		{
			case FIRCHNREQ:
				TransCaptureFrm(TRUE, FIRCHN, v_Sourceadd);
				break;
			case SECCHNREQ:
				TransCaptureFrm(TRUE, SECCHN, v_Sourceadd);
				break;
			case THICHNREQ:
				TransCaptureFrm(TRUE, THICHN, v_Sourceadd);
				break;
			case FOUCHNREQ:
				TransCaptureFrm(TRUE, FOUCHN, v_Sourceadd);
				break;
			default:
				break;
		}		
	}
	
	// If dma completed interrupt
	else if(PCI_FGET(PCIIS, MASTEROK))
	{
		
		PCI_intClear(PCI_EVT_MASTEROK);		// Clear interrupt flag
		DMASTATADD = DMAIDLE;				// Setup dma idle flag
			
		// Judge the completion interrupt type
		switch(DMACMPADD)
		{
		// If transfer encoded data dma completed interrupt	
			case FIRRCDDMA:
			case SECRCDDMA:
			case THIRCDDMA:
			case FOURCDDMA:		
				PCI_FSET(RSTSRC, INTRST, 1);	
				PCI_dspIntReqSet();				
				break;	
		// If transfer capture video data dma completed interrupt	
			case FIRCAPDMA:
				TransCaptureFrm(FALSE, FIRCHN, v_Sourceadd);	
				break;
			case SECCAPDMA:
				TransCaptureFrm(FALSE, SECCHN, v_Sourceadd);
				break;
			case THICAPDMA:
				TransCaptureFrm(FALSE, THICHN, v_Sourceadd);
				break;
			case FOUCAPDMA:
				TransCaptureFrm(FALSE, FOUCHN, v_Sourceadd);
				break;
			default:
				break;	
		}			
	}	
}

/************************************************************/
/*	No	more												*/
/************************************************************/

⌨️ 快捷键说明

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