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

📄 dma.c

📁 以TI 公司的OMAP5910为例
💻 C
字号:
//////////////////////////////////////////////////////////////////////////
//            Copyright (C) 2004, Eyoka @ Microunit
//                           All Rights Reserved
//________________________________________________________________________
//
// FILENAME:    dma.c
// PROJECT:     High-Resolution Video System On OMAP
// MODULE:      MPU System
// DESCRIPTION: System DMA Controller Interface
// TARGET CPU:  ARM-925T of OMAP5910
// VERSION:     0.2
//________________________________________________________________________
//
// REVISE HISTORY
// DATE         VERSION AUTHOR  DESCRIPTION
// 2004-11-08   0.2     Eyoka   Checked.
// 2004-11-01   0.1     Eyoka   Created.
//////////////////////////////////////////////////////////////////////////

#include "dma.h"


/////////////////////////////////////////////////////////////////////
// FUNCTIONS
/////////////////////////////////////////////////////////////////////

//___________________________________________________________________
// Function: DMA_Setup
// Usage: Config DMA settings.
// Parameters:
//	pConfig			pointer to the configuration struct
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_Setup(DMA_PARAM *pConfig)
{
	DMA_Stop(pConfig->ch);

	DMA_CSDP(pConfig->ch) = (pConfig->dst_burst<<15) |
							(pConfig->dst_pack<<13)  |
							(pConfig->dst_port<<9)   |
							(pConfig->src_burst<<8)  |
							(pConfig->src_pack<<6)   |
							(pConfig->src_port<<2)   |
							pConfig->data_type;

	DMA_CCR(pConfig->ch) = (pConfig->dst_amode<<14) |
						   (pConfig->src_amode<<12) |
						   (pConfig->repeat<<9)     |
						   (pConfig->auto_init<<8)  |
						   (pConfig->priority<<6)   |
						   (pConfig->frame_sync<<5) |
						   pConfig->sync_req;

	DMA_SetDstAddr(pConfig->ch, pConfig->dst_addr);
	DMA_SetSrcAddr(pConfig->ch, pConfig->src_addr);

	DMA_SetElementNumber(pConfig->ch, pConfig->ele_n);
	DMA_SetElementIndex(pConfig->ch, pConfig->ele_i);

	DMA_SetFrameNumber(pConfig->ch, pConfig->frame_n);
	DMA_SetFrameIndex(pConfig->ch, pConfig->frame_i);
}

//___________________________________________________________________
// Function: DMA_Init
// Usage: Config DMA global settings.
// Parameters:		N/A
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_Init(void)
{
	DMA_GCR = 0x000C;
}

//___________________________________________________________________
// Function: DMA_EnableDstBurst
// Usage: Enable/Disable destination 4-BYTE burst ability.
// Parameters:
//	ch				channel ID.
//	bEnable			TRUE to Enable, FALSE to Disable.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_EnableDstBurst(BYTE ch, BOOL bEnable)
{
	DMA_CSDP(ch) = (bEnable<<15) | (DMA_CSDP(ch) & 0x3FFF);
}

//___________________________________________________________________
// Function: DMA_EnableSrcBurst
// Usage: Enable/Disable source 4-BYTE burst ability.
// Parameters:
//	ch				channel ID.
//	bEnable			TRUE to Enable, FALSE to Disable.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_EnableSrcBurst(BYTE ch, BOOL bEnable)
{
	DMA_CSDP(ch) = (bEnable<<8) | (DMA_CSDP(ch) & 0xFE7F);
}

//___________________________________________________________________
// Function: DMA_EnableDstPack
// Usage: Enable/Disable destination pack ability.
// Parameters:
//	ch				channel ID.
//	bEnable			TRUE to Enable, FALSE to Disable.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_EnableDstPack(BYTE ch, BOOL bEnable)
{
	DMA_CSDP(ch) = (bEnable<<13) | (DMA_CSDP(ch) & 0xDFFF);
}

//___________________________________________________________________
// Function: DMA_EnableSrcPack
// Usage: Enable/Disable source pack ability.
// Parameters:
//	ch				channel ID.
//	bEnable			TRUE to Enable, FALSE to Disable.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_EnableSrcPack(BYTE ch, BOOL bEnable)
{
	DMA_CSDP(ch) = (bEnable<<6) | (DMA_CSDP(ch) & 0xFFBF);
}

//___________________________________________________________________
// Function: DMA_SetDstPort
// Usage: Set destination port.
// Parameters:
//	ch				channel ID.
//	port			can be: PORT_EMIFF, PORT_EMIFS,
//					PORT_IMIF, PORT_TIPB, PORT_Local, PORT_TIPB_MPUI.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetDstPort(BYTE ch, DMA_PORT_t port)
{
	DMA_CSDP(ch) = (port<<9) | (DMA_CSDP(ch) & 0xE1FF);
}

//___________________________________________________________________
// Function: DMA_SetSrcPort
// Usage: Set source port.
// Parameters:
//	ch				channel ID.
//	port			can be: PORT_EMIFF, PORT_EMIFS,
//					PORT_IMIF, PORT_TIPB, PORT_Local, PORT_TIPB_MPUI.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetSrcPort(BYTE ch, DMA_PORT_t port)
{
	DMA_CSDP(ch) = (port<<2) | (DMA_CSDP(ch) & 0xFFC3);
}

//___________________________________________________________________
// Function: DMA_SetDataType
// Usage: Set transfer data type.
// Parameters:
//	ch				channel ID.
//	type			can be: DATATYPE_8BIT, DATATYPE_16BIT, DATATYPE_32BIT.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetDataType(BYTE ch, DMA_DATATYPE_t type)
{
	DMA_CSDP(ch) = type | (DMA_CSDP(ch) & 0xFFFC);
}

//___________________________________________________________________
// Function: DMA_SetDstAdMode
// Usage: Set destination addressing mode.
// Parameters:
//	ch				channel ID.
//	addr_mode		can be: AMODE_CONST, AMODE_AUTO, AMODE_SINGLE
//					or AMODE_DOUBLE.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetDstAdMode(BYTE ch, DMA_AMODE_t addr_mode)
{
	DMA_CCR(ch) = (addr_mode<<14) | (DMA_CCR(ch) & 0x3FFF);
}

//___________________________________________________________________
// Function: DMA_SetSrcAdMode
// Usage: Set source addressing mode.
// Parameters:
//	ch				channel ID.
//	addr_mode		can be: AMODE_CONST, AMODE_AUTO, AMODE_SINGLE
//					or AMODE_DOUBLE.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetSrcAdMode(BYTE ch, DMA_AMODE_t addressing_mode)
{
	DMA_CCR(ch) = (addressing_mode<<12) | (DMA_CCR(ch) & 0xCFFF);
}

//___________________________________________________________________
// Function: DMA_Programing
// Usage: 
// Parameters:
//	ch				channel ID.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_Programing(BYTE ch, BOOL bPrograming)
{
	// UNFINISHED.
}

//___________________________________________________________________
// Function: DMA_SetRepeat
// Usage: Set repeat mode.
// Parameters:
//	ch				channel ID.
//	bRepeat			TRUE to disregard END_PROG, otherwise FALSE.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetRepeat(BYTE ch, BOOL bRepeat)
{
	DMA_CCR(ch) = (bRepeat<<9) | (DMA_CCR(ch) & 0xFDFF);
}

//___________________________________________________________________
// Function: DMA_SetAutoInit
// Usage: Set autoinit mode.
// Parameters:
//	ch				channel ID.
//	bAuto			auto restart or not.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetAutoInit(BYTE ch, BOOL bAuto)
{
	DMA_CCR(ch) = (bAuto<<8) | (DMA_CCR(ch) & 0xFEFF);
}

//___________________________________________________________________
// Function: DMA_Start
// Usage: Start DMA transfer.
// Parameters:
//	ch				channel ID.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_Start(BYTE ch)
{
	DMA_CCR(ch) |= 0x0080;
}

//___________________________________________________________________
// Function: DMA_Stop
// Usage: Stop DMA transfer.
// Parameters:
//	ch				channel ID.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_Stop(BYTE ch)
{
	DMA_CCR(ch) &= 0xFF7F;
}

//___________________________________________________________________
// Function: DMA_IsBusy
// Usage: Query whether the DMA channel is busy.
// Parameters:
//	ch				channel ID.
// Return Values:
//	BOOL			TRUE if busy, FALSE if idle.
//___________________________________________________________________
//
BOOL DMA_IsBusy(BYTE ch)
{
	return (BOOL)((DMA_CCR(ch) & 0x0080) >> 7);
}

//___________________________________________________________________
// Function: DMA_SetPriority
// Usage: Set priority of current channel.
// Parameters:
//	ch				channel ID.
//	bHigh			TRUE if is high-priority.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetPriority(BYTE ch, BOOL bHigh)
{
	DMA_CCR(ch) = (bHigh<<6) | (DMA_CCR(ch) & 0xFFBF);
}

//___________________________________________________________________
// Function: DMA_FrameSync
// Usage: Set DMA request synchronize mode.
// Parameters:
//	ch				channel ID.
//	bSync			TRUE: a frame is transferred each DMA request,
//				  	FALSE: a element is transferred each DMA request.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_FrameSync(BYTE ch, BOOL bSync)
{
	DMA_CCR(ch) = (bSync<<5) | (DMA_CCR(ch) & 0xFFDF);
}

//___________________________________________________________________
// Function: DMA_SetSyncReq
// Usage: Set the external request to synchronize the DMA transfer.
// Parameters:
//	ch				channel ID.
//	req				external request ID, see defination of DMA_EXTREQ_t.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetSyncReq(BYTE ch, DMA_EXTREQ_t req)
{
	DMA_CCR(ch) = req | (DMA_CCR(ch) & 0xFFE0);
}


//___________________________________________________________________
// Function: DMA_EnableINT
// Usage: Enable/Disable DMA generated interrupts.
// Parameters:
//	ch				channel ID.
//	intID			interrupt ID, can be:
//						DMA_INT_BLOCK_DONE, DMA_INT_LAST_FRAME,
//						DMA_INT_FRAME_DONE,	DMA_INT_HALF_FRAME,
//						DMA_INT_DROP or DMA_INT_TIMEOUT.
//	bEnable			TRUE to Enable, FALSE to Disable.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_EnableINT(BYTE ch, DMA_INT_t intID, BOOL bEnable)
{
	DMA_CICR(ch) = (bEnable<<intID) | (DMA_CCR(ch) & (~(1<<intID)));
}

//___________________________________________________________________
// Function: DMA_SetSrcAddr
// Usage: Set source address.
// Parameters:
//	ch				channel ID.
//	src_addr		source BYTE address.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetSrcAddr(BYTE ch, DWORD src_addr)
{
	DMA_CSSA_L(ch) = (WORD)src_addr;
	DMA_CSSA_U(ch) = (WORD)(src_addr>>16);
}

//___________________________________________________________________
// Function: DMA_SetDstAddr
// Usage: Set destination address.
// Parameters:
//	ch				channel ID.
//	dst_addr		destination BYTE address.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetDstAddr(BYTE ch, DWORD dst_addr)
{
	DMA_CDSA_L(ch) = (WORD)dst_addr;
	DMA_CDSA_U(ch) = (WORD)(dst_addr>>16);
}

//___________________________________________________________________
// Function: DMA_SetElementNumber
// Usage: Set number of elements each frame.
// Parameters:
//	ch				channel ID.
//	element_number	number of elements each frame.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetElementNumber(BYTE ch, WORD element_number)
{
	DMA_CEN(ch) = element_number;
}

//___________________________________________________________________
// Function: DMA_SetFrameNumber
// Usage: Set number of frames each block.
// Parameters:
//	ch				channel ID.
//	frame_number	number of frames each block.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetFrameNumber(BYTE ch, WORD frame_number)
{
	DMA_CFN(ch) = frame_number;
}

//___________________________________________________________________
// Function: DMA_SetElementIndex
// Usage: Set element index.
// Parameters:
//	ch				channel ID.
//	element_index	element index.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetElementIndex(BYTE ch, WORD element_index)
{
	DMA_CEI(ch) = element_index;
}

//___________________________________________________________________
// Function: DMA_SetFrameIndex
// Usage: Set frame index.
// Parameters:
//	ch				channel ID.
//	frame_index		frame index.
// Return Values:	N/A
//___________________________________________________________________
//
void DMA_SetFrameIndex(BYTE ch, WORD frame_index)
{
	DMA_CFI(ch) = frame_index;
}


// the end
//////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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