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

📄 jpgdriver.c

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Project Name JPEG DRIVER IN WINCE
 * Copyright  2007 Samsung Electronics Co, Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Samsung Electronics  ("Confidential Information").
 * you shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Samsung Electronics
 *
 * This file implements JPEG driver.
 *
 * @name JPEG DRIVER MODULE Module (JPGDriver.c)
 * @author Jiyoung Shin (idon.shin@samsung.com)
 * @date 28-05-07
 */

#include "JPGDriver.h"
#include "JPGMem.h"
#include "JPGMisc.h"
#include "JPGOpr.h"
#include <s3c6410_syscon.h>
#include <s3c6410_base_regs.h>
#include <pmplatform.h>
#include <bsp_cfg.h>

HANDLE		hPwrControl;
volatile	S3C6410_SYSCON_REG *s6410PWR = NULL;
UINT8		instanceNo = 0;
BOOL		PowerChange = FALSE;


static void JPGPowerControl(BOOL bOnOff);
static void Delay(UINT32 count);
static BOOL JPGSetClkDiv(int divider);
/*----------------------------------------------------------------------------
*Function: JPG_Init

*Parameters: 		dwContext		:
*Return Value:		True/False
*Implementation Notes: Initialize JPEG Hardware
-----------------------------------------------------------------------------*/
DWORD
JPG_Init(
    DWORD dwContext
    )
{

	S3C6410_JPG_CTX *JPGMem;
	HANDLE			h_Mutex;
	DWORD			ret;

	printD("DD::JPG_Init\n");

	// PWM clock Virtual alloc
	s6410PWR = (S3C6410_SYSCON_REG *)Phy2VirAddr(S3C6410_BASE_REG_PA_SYSCON, sizeof(S3C6410_SYSCON_REG));
	if (s6410PWR == NULL)
	{
		RETAILMSG(1,(TEXT("DD:: For s6410PWR: DrvLib_MapIoSpace failed!\r\n")));
		return FALSE;;
	}

	hPwrControl = CreateFile( L"PWC0:", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
	if (INVALID_HANDLE_VALUE == hPwrControl )
	{
		RETAILMSG(1, (TEXT("DD:: JPEG - PWC0 Open Device Failed\r\n")));
		return FALSE;
	}

	if(JPGSetClkDiv(4) == FALSE){
		RETAILMSG(1, (TEXT("DD:: JPEG - Set Clock Divider Failed\r\n")));
		return FALSE;
	}

	// Mutex initialization
	h_Mutex = CreateJPGmutex();
	if (h_Mutex == NULL)
	{
		RETAILMSG(1, (TEXT("DD::JPG Mutex Initialize error : %d \r\n"),GetLastError()));
		return FALSE;
	}

	ret = LockJPGMutex();
	if(!ret){
		RETAILMSG(1, (TEXT("DD::JPG Mutex Lock Fail\r\n")));
		return FALSE;
	}

	// Memory initialization
	JPGMem = (S3C6410_JPG_CTX *)malloc(sizeof(S3C6410_JPG_CTX));
	memset(JPGMem, 0x00, sizeof(S3C6410_JPG_CTX));

	if( !JPGMemMapping(JPGMem) ){
		RETAILMSG(1, (TEXT("DD::JPEG-HOST-MEMORY Initialize error : %d \r\n"),GetLastError()));
		UnlockJPGMutex();
		return FALSE;
	}
	else{
		if(!JPGBuffMapping(JPGMem)){
			RETAILMSG(1, (TEXT("DD::JPEG-DATA-MEMORY Initialize error : %d \r\n"),GetLastError()));
			UnlockJPGMutex();
			return FALSE;
		}
	}

	instanceNo = 0;

	UnlockJPGMutex();
	return (DWORD)JPGMem;
}


/*----------------------------------------------------------------------------
*Function: JPG_DeInit

*Parameters: 		InitHandle		:
*Return Value:		True/False
*Implementation Notes: Deinitialize JPEG Hardware
-----------------------------------------------------------------------------*/
BOOL
JPG_Deinit(
    DWORD InitHandle
    )
{
	DWORD	ret;
	S3C6410_JPG_CTX *JPGRegCtx;

	printD("DD::JPG_Deinit\n");
	JPGRegCtx = (S3C6410_JPG_CTX *)InitHandle;

	if(!JPGRegCtx){
		RETAILMSG(1, (TEXT("DD::JPG Invalid Input Handle\r\n")));
		return FALSE;
	}

	ret = LockJPGMutex();
	if(!ret){
		RETAILMSG(1, (TEXT("DD::JPG Mutex Lock Fail\r\n")));
		return FALSE;
	}

	JPGBuffFree(JPGRegCtx);
	JPGMemFree(JPGRegCtx);
	UnlockJPGMutex();

	DeleteJPGMutex();
	return TRUE;
}


/*----------------------------------------------------------------------------
*Function: JPG_Open

*Parameters: 		InitHandle		:Handle to JPEG  context
					dwAccess		:
					dwShareMode		:File share mode of JPEG
*Return Value:		This function returns a handle that identifies the
					open context of JPEG  to the calling application.
*Implementation Notes: Opens JPEG CODEC device for reading, writing, or both
-----------------------------------------------------------------------------*/
DWORD
JPG_Open(
	DWORD InitHandle,
    DWORD dwAccess,
    DWORD dwShareMode
    )
{
	S3C6410_JPG_CTX *JPGRegCtx;
	DWORD	ret;

	printD("DD::JPG_open \r\n");

	JPGPowerControl(TRUE);

	JPGRegCtx = (S3C6410_JPG_CTX *)InitHandle;
	if(!JPGRegCtx){
		RETAILMSG(1, (TEXT("DD::JPG Invalid Input Handle\r\n")));
		return FALSE;
	}


	ret = LockJPGMutex();
	if(!ret){
		RETAILMSG(1, (TEXT("DD::JPG Mutex Lock Fail\r\n")));
		return FALSE;
	}

	// check the number of instance
	if(instanceNo > MAX_INSTANCE_NUM){
		RETAILMSG(1, (TEXT("DD::Instance Number error-JPEG is running\r\n")));
		UnlockJPGMutex();
		return FALSE;
	}
	instanceNo++;
	PowerChange = FALSE;

	printD("instanceNo : %d\n", instanceNo);

	UnlockJPGMutex();
	return (DWORD)JPGRegCtx;
}


/*----------------------------------------------------------------------------
*Function: JPG_Close

*Parameters: 		OpenHandle		:
*Return Value:		True/False
*Implementation Notes: This function closes the device context identified by
						OpenHandle
-----------------------------------------------------------------------------*/
BOOL
JPG_Close(
    DWORD OpenHandle
    )
{
	DWORD	ret;
	S3C6410_JPG_CTX *JPGRegCtx;
	BOOL        r;

	printD("DD::JPG_Close\n");
	if(PowerChange == TRUE){
		RETAILMSG(1, (TEXT("DD::Power state is changed after open\r\n")));
		return FALSE;
	}

	JPGRegCtx = (S3C6410_JPG_CTX *)OpenHandle;

	if(!JPGRegCtx){
		RETAILMSG(1, (TEXT("DD::JPG Invalid Input Handle\r\n")));
		return FALSE;
	}

	ret = LockJPGMutex();
	if(!ret){
		RETAILMSG(1, (TEXT("DD::JPG Mutex Lock Fail\r\n")));
		return FALSE;
	}
	if((--instanceNo) < 0)
		instanceNo = 0;

#if	(_WIN32_WCE >= 600)
	printD("JPGRegCtx->callerProcess : 0x%x\n", JPGRegCtx->callerProcess);
	if(JPGRegCtx->strUserBuf != NULL){
		printD("decommit strUsrBuf\n");
		r = VirtualFreeEx(JPGRegCtx->callerProcess,	// HANDLE hProcess
	                  			JPGRegCtx->strUserBuf,
	                  			JPG_STREAM_BUF_SIZE,
	                  			MEM_DECOMMIT);
		if (r == FALSE)
			RETAILMSG(1, (L"DD::JPG VirtualFreeEx(strUserBuf) returns FALSE.\n"));
	}

	if(JPGRegCtx->strUserThumbBuf != NULL){
		printD("decommit strUserThumbBuf\n");
		r = VirtualFreeEx(JPGRegCtx->callerProcess,	// HANDLE hProcess
	                  			JPGRegCtx->strUserThumbBuf,
	                  			JPG_STREAM_THUMB_BUF_SIZE,
	                  			MEM_DECOMMIT);
		if (r == FALSE)
			RETAILMSG(1, (L"DD::JPG  VirtualFreeEx(strUserThumbBuf) returns FALSE.\n"));
	}

	if(JPGRegCtx->frmUserBuf != NULL){
		printD("decommit frmUserBuf\n");
		r = VirtualFreeEx(JPGRegCtx->callerProcess,	// HANDLE hProcess
	                  			JPGRegCtx->strUserBuf,
	                  			JPG_STREAM_BUF_SIZE,
	                  			MEM_DECOMMIT);
		if (r == FALSE)
			RETAILMSG(1, (L"DD::JPG  VirtualFreeEx(STRM_BUF) returns FALSE.\n"));
	}

	if(JPGRegCtx->frmUserThumbBuf != NULL){
		printD("decommit frmUserThumbBuf\n");
		r = VirtualFreeEx(JPGRegCtx->callerProcess,	// HANDLE hProcess
	                  			JPGRegCtx->frmUserThumbBuf,
	                  			JPG_FRAME_THUMB_BUF_SIZE,
	                  			MEM_DECOMMIT);
		if (r == FALSE)
			RETAILMSG(1, (L"DD::JPG  VirtualFreeEx(frmUserThumbBuf) returns FALSE.\n"));
	}

	if(JPGRegCtx->rgbBuf != NULL){
		printD("decommit rgbBuf\n");
		r = VirtualFreeEx(JPGRegCtx->callerProcess,	// HANDLE hProcess
	                  			JPGRegCtx->rgbBuf,
	                  			JPG_RGB_BUF_SIZE,
	                  			MEM_DECOMMIT);
		if (r == FALSE)
			RETAILMSG(1, (L"DD::JPG  VirtualFreeEx(rgbBuf) returns FALSE.\n"));
	}
	
#endif

	UnlockJPGMutex();

	JPGPowerControl(FALSE);
	return TRUE;
}


/*----------------------------------------------------------------------------
*Function: JPG_IOControl

*Parameters: 		OpenHandle		:
					dwIoControlCode	:
*Return Value:		True/False

⌨️ 快捷键说明

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