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

📄 dmawince.c

📁 编译环境为PB,或AK,实现27x平台上对DMA的控制,由于270平台上DMA都处在同一个一级中断下,要使用单个的DMA通道,通常也可以在OAL重新映射其中断号,但比较费事,本驱动实现对DMA的管理,
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
**
**  COPYRIGHT (C) 2001, 2002 Intel Corporation.
**
**  This software as well as the software described in it is furnished under
**  license and may only be used or copied in accordance with the terms of the
**  license. The information in this file is furnished for informational use
**  only, is subject to change without notice, and should not be construed as
**  a commitment by Intel Corporation. Intel Corporation assumes no
**  responsibility or liability for any errors or inaccuracies that may appear
**  in this document or any software that may be provided in association with
**  this document. 
**  Except as permitted by such license, no part of this document may be 
**  reproduced, stored in a retrieval system, or transmitted in any form or by
**  any means without the express written consent of Intel Corporation. 
**
**  FILENAME: dmawince.c
**
**  PURPOSE: Contains all WinCE OS specific functions for DMA Controller Engine 
**           access and control
**                  
******************************************************************************/

#include <windows.h>
#include <bulverde_intr.h>
#include <bulverde_dma.h>
#include <bulverde_base_regs.h>
#include <string.h>
#include <stdio.h>
#include <tchar.h>
#include <ceddk.h>

#include <nkintr.h>
#include <bsp_cfg.h>
#include "dmawince.h"

//
// DMA IST routine
//
INT WINAPI DmacIntrThread(void);


//
// Externs
//

extern void     XllpDmacHwInit();
extern PVOID    VirtualAllocCopy(unsigned size,char *str,PVOID pVirtualAddress);
extern PVOID    VirtualAllocCopyPhysical(unsigned size,char *str,PVOID pVirtualAddress);

volatile DMA_GLOBALS *pDMAGlobals = NULL;
volatile P_XLLP_DMAC_T	pDmacHandle = NULL;
HANDLE		hFirstTime;

#define DMA_CHANNEL_0  _T("DMA_CHANNEL_0")
#define DMA_CHANNEL_1  _T("DMA_CHANNEL_1")
#define DMA_CHANNEL_2  _T("DMA_CHANNEL_2")
#define DMA_CHANNEL_3  _T("DMA_CHANNEL_3")
#define DMA_CHANNEL_4  _T("DMA_CHANNEL_4")
#define DMA_CHANNEL_5  _T("DMA_CHANNEL_5")
#define DMA_CHANNEL_6  _T("DMA_CHANNEL_6")
#define DMA_CHANNEL_7  _T("DMA_CHANNEL_7")
#define DMA_CHANNEL_8  _T("DMA_CHANNEL_8")
#define DMA_CHANNEL_9  _T("DMA_CHANNEL_9")
#define DMA_CHANNEL_10  _T("DMA_CHANNEL_10")
#define DMA_CHANNEL_11  _T("DMA_CHANNEL_11")
#define DMA_CHANNEL_12  _T("DMA_CHANNEL_12")
#define DMA_CHANNEL_13  _T("DMA_CHANNEL_13")
#define DMA_CHANNEL_14  _T("DMA_CHANNEL_14")
#define DMA_CHANNEL_15  _T("DMA_CHANNEL_15")
#define DMA_CHANNEL_16  _T("DMA_CHANNEL_16")
#define DMA_CHANNEL_17  _T("DMA_CHANNEL_17")
#define DMA_CHANNEL_18  _T("DMA_CHANNEL_18")
#define DMA_CHANNEL_19  _T("DMA_CHANNEL_19")
#define DMA_CHANNEL_20  _T("DMA_CHANNEL_20")
#define DMA_CHANNEL_21  _T("DMA_CHANNEL_21")
#define DMA_CHANNEL_22  _T("DMA_CHANNEL_22")
#define DMA_CHANNEL_23  _T("DMA_CHANNEL_23")
#define DMA_CHANNEL_24  _T("DMA_CHANNEL_24")
#define DMA_CHANNEL_25  _T("DMA_CHANNEL_25")
#define DMA_CHANNEL_26  _T("DMA_CHANNEL_26")
#define DMA_CHANNEL_27  _T("DMA_CHANNEL_27")
#define DMA_CHANNEL_28  _T("DMA_CHANNEL_28")
#define DMA_CHANNEL_29  _T("DMA_CHANNEL_29")
#define DMA_CHANNEL_30  _T("DMA_CHANNEL_30")
#define DMA_CHANNEL_31  _T("DMA_CHANNEL_31")


//******************************************************************************
//
// Function Name: DllMain
//
// Description: Function called at dll load time and whenever a process/thread
//              attaches to the dll.
//  			   
//  
// Input Arguments:
//	    hInstDLL:       Instance handle..specifies base address of dll
//      Op:             Operation code
//      lpvReserved:    Reserved
//	                 
// Output Arguments:
//  	
//
// Return Value: 
//	    TRUE:   if Ok to load the dll
//      FALSE:  otherwise
//
// Notes:
//
//*******************************************************************************
BOOL WINAPI
DllMain
(
    HANDLE  hinstDLL,
    DWORD   Op,
    LPVOID  lpvReserved
)
{  
    //
    // Ref count of processes attaching to DMA library
    //
    static unsigned long processCount=0;

    switch (Op) 
	{

        case DLL_PROCESS_ATTACH :
			++processCount;
			//RETAILMSG(1,(TEXT("Dma DllMain Proc Attach: 0x%X\r\n"),processCount));
			//NKDbgPrintfW(TEXT("\r\nDMA Engine Loaded -- Process...\r\n"));
			//XllpDmacInit();
            break;

        case DLL_PROCESS_DETACH :
			--processCount;
			//RETAILMSG(1,(TEXT("Dma DllMain Proc Detach: 0x%X\r\n"),processCount));
            break;
            
        case DLL_THREAD_DETACH :
			//--z;
			//RETAILMSG(1,(TEXT("DMA DllMain Thrd Detach: 0x%X\r\n"),z));			
            break; 
            
        case DLL_THREAD_ATTACH :
			//++z;
			//RETAILMSG(1,(TEXT("Dma DllMain Thread Attach: 0x%X\r\n"),processCount));
			//NKDbgPrintfW(TEXT("DMA Engine, Thread Attach, XllpDmacInit...\r\n"));
			//XllpDmacInit();
			//NKDbgPrintfW(TEXT("DMA Engine, Thread Attach...\r\n"));
			
            break;
            
        default :
            break;
    }

	return TRUE;
}


//******************************************************************************
//
//	Function Name: GDE_Init()
//
//	Other STream Interface functions stubbed.
//
//
//******************************************************************************
void ShowStartPercent(int percent)
{
	
	WORD * pDisplay = (WORD*)0xa0000480;//显存地址
	int rect[4]={142,309,235,314};
	int j,i;
	WORD * buffer;
	int progress_length ;
	

	progress_length = (int)((rect[2] - rect[0] )*percent/100);
	buffer = pDisplay + rect[1] * 240 + rect[0] ;
	for(j=0;j<rect[3] -rect[1] ;j++)
	{
		for(i=0;i<progress_length;i++)
		{
			(*buffer)= 0xd1e1f1;
			buffer ++;
		}
		buffer += (240-progress_length);
	}
}
DWORD	GDE_Init(DWORD p1, DWORD p2)
{
	HANDLE				hSharedMap_init;

	// Initialize the DMA system.
//	NKDbgPrintfW(TEXT("GDE_Init In = %x, %x...\r\n"), p1, p2);
	// Memory mapped file for sharing DMA Globals information.
	ShowStartPercent(8);
	hSharedMap_init = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
									0, sizeof(DMA_GLOBALS), GDE_SHARED_FILENAME );
	if(!hSharedMap_init)
	{
		//NKDbgPrintfW(TEXT("GDE_Init. No MemMap File. \r\n"));
		return 0; //  GDE failed to run.
	}

	// Get a valid process pointer to the memory mapper buffer.
	pDMAGlobals = (DMA_GLOBALS *)MapViewOfFile( hSharedMap_init, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
	// Initialize GDE for this process.
	if( !XllpDmacInit() )
	{
		return 0;   // Failed.
	}

	// Exit
//	NKDbgPrintfW(TEXT("GDE_Init Done...\r\n"));
	return 1;   // Use non-zero to indicate success.
} 

//*******************************************
//
//	Stubs
//
//*******************************************

XLLP_BOOL_T GDE_Deinit(DWORD p1)
{
	//NKDbgPrintfW(TEXT("GDE_Deinit..."));
		return XLLP_TRUE;
} 
//*******************************************
DWORD GDE_Open(DWORD P1, DWORD P2, DWORD P3 )
{
	//NKDbgPrintfW(TEXT("GDE_Open..."));
	return 1;
}
//*******************************************
BOOL GDE_Close( DWORD p1)
{
	//NKDbgPrintfW(TEXT("GDE_Close..."));
	return 1;
}
//*******************************************
BOOL GDE_IOControl(
  DWORD hOpenContext,
  DWORD dwCode,
  PBYTE pBufIn,
  DWORD dwLenIn,
  PBYTE pBufOut,
  DWORD dwLenOut,
  PDWORD pdwActualOut 
			)
{
	//NKDbgPrintfW(TEXT("GDE_IOControl..."));
	return 1;
}
//*******************************************
DWORD GDE_Read(
  DWORD hOpenContext,
  LPVOID pBuffer,
  DWORD Count 
			)
{
	//NKDbgPrintfW(TEXT("GDE_Read..."));
	return 1;
}
//*******************************************
DWORD GDE_Write(
  DWORD hOpenContext,
  LPCVOID pBuffer,
  DWORD Count 
			)
{
	//NKDbgPrintfW(TEXT("GDE_Write..."));
	return 1;
}
//*******************************************
DWORD GDE_Seek(
  DWORD hOpenContext,
  long Amount,
  WORD Type 
		)
{
	//NKDbgPrintfW(TEXT("GDE_Seek..."));
	return 1;
}
//*******************************************
void GDE_PowerUp(
  DWORD hDeviceContext 
		)
{
	//NKDbgPrintfW(TEXT("GDE_PowerUp..."));
	return;
}
//*******************************************
void GDE_PowerDown(
  DWORD hDeviceContext 
		)
{
	//NKDbgPrintfW(TEXT("GDE_PowerDown..."));
	return;
}
//*******************************************
	

//******************************************************************************
//
// Function Name: XllpDmacInit
//
// Description: Function called to initialize this dll
//              Creates DMA register mapping, sets up DMA IST and initializes hardware
//  			   
//  
// Input Arguments:
//	
//	                 
// Output Arguments:
//  	
//
// Return Value: 
//	TRUE:       when successful
//  FALSE:      otherwise
//
// Notes:
//
//*******************************************************************************
XLLP_STATUS_T	XllpDmacInit
(
)
{
    XLLP_UINT32_T       i;
	HANDLE				hSharedMap;

	if (pDMAGlobals == NULL)
	{
		// Memory mapped file for sharing DMA Globals information.
		hSharedMap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
										0, sizeof(DMA_GLOBALS), GDE_SHARED_FILENAME );
		// Memory mapped file should exist from init in GDE_Init() .
		if( ERROR_ALREADY_EXISTS != GetLastError() )
		{
			NKDbgPrintfW(TEXT("XllpDmacInit. No existing MemMapFile . \r\n"));
			return FALSE;	// DMA failed to intilize correctly.
		}
		// Get a valid process pointer to the buffer mapped above.
		pDMAGlobals = (DMA_GLOBALS *)MapViewOfFile( hSharedMap, FILE_MAP_ALL_ACCESS, 0, 0, 0 );
		if( !pDMAGlobals )
		{
			NKDbgPrintfW(TEXT("XllpDmacInit. MapViewOfFile failed . \r\n"));
			return FALSE;	// DMA failed to intilize correctly.
		}

	}

	if (pDmacHandle == NULL)
	{
		pDmacHandle = ( P_XLLP_DMAC_T)VirtualAllocCopyPhysical(sizeof(XLLP_DMAC_T),"pDmacHandle",(PVOID)(BULVERDE_BASE_REG_PA_DMAC));
		if (pDmacHandle == NULL)
			return FALSE;
	}


    //
    // Check for first time initialization Object.
    //  Note -- Other drivers can use this named object to check for and/or wait for
	//			GDE setup to complete.
	//
	hFirstTime = CreateEvent(NULL, TRUE, FALSE, GDE_FIRST_TIME_CHECK);  // Null, Manual, Set, Named.
	if(!hFirstTime)
	{
		NKDbgPrintfW(TEXT("XllpDmacInit. Failed to create FirstTime Object. \r\n"));
		return FALSE;	// DMA failed to intilize correctly.
	}
	// GDE Setup successfully occured if the object already exists.
	if( ERROR_ALREADY_EXISTS == GetLastError() )
	{
		return TRUE;	// First Time initialization already done.
	}

//    if( pDMAGlobals->notFirstTime )
//        return TRUE;    
//    pDMAGlobals->notFirstTime=1;



    //
    // Do all the only one time initialization
    // Create the DMAC interrupt event
    //
    for(i=0;i<32;++i)
        pDMAGlobals->pArrayChannel[i] = 0;
    
    //
    // These are taken by wave (audio) driver and Camera.
    //

⌨️ 快捷键说明

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