winceoam.cpp

来自「SAMSUNG S3C6410 CPU BSP for winmobile6」· C++ 代码 · 共 547 行 · 第 1/2 页

CPP
547
字号
/*****************************************************************************/
/*                                                                           */
/* PROJECT : AnyStore II                                                     */
/* MODULE  : XSR OAM                                                         */
/* NAME    : Windows CE OAM                                                  */
/* FILE    : WinCEOAM.cpp                                                    */
/* PURPOSE : This file contain the OS Adaptation Modules for WinCE OS        */
/*                                                                           */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/*          COPYRIGHT 2002,2003 SAMSUNG ELECTRONICS CO., LTD.                */
/*                          ALL RIGHTS RESERVED                              */
/*                                                                           */
/*   Permission is hereby granted to licensees of Samsung Electronics        */
/*   Co., Ltd. products to use or abstract this computer program for the     */
/*   sole purpose of implementing a product based on Samsung                 */
/*   Electronics Co., Ltd. products. No other rights to reproduce, use,      */
/*   or disseminate this computer program, whether in part or in whole,      */
/*   are granted.                                                            */
/*                                                                           */
/*   Samsung Electronics Co., Ltd. makes no representation or warranties     */
/*   with respect to the performance of this computer program, and           */
/*   specifically disclaims any responsibility for any damages,              */
/*   special or consequential, connected with the use of this program.       */
/*                                                                           */
/*---------------------------------------------------------------------------*/
/*                                                                           */
/* REVISION HISTORY                                                          */
/*                                                                           */
/*   29-DEC-2003 [SongHo Yoon] : first writing                               */
/*   04-NOV-2005 [Hyunsoo Cho] : added OAM_GetROLockFlag(VOID)               */
/*                                                                           */
/*****************************************************************************/
#include <windows.h>

#include <XsrTypes.h>
#include <OAM.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>

/*****************************************************************************/
/* Global variables definitions                                              */
/*****************************************************************************/

/*****************************************************************************/
/* Local #defines                                                            */
/*****************************************************************************/

/*****************************************************************************/
/* Local typedefs                                                            */
/*****************************************************************************/

/*****************************************************************************/
/* Local constant definitions                                                */
/*****************************************************************************/

/*****************************************************************************/
/* Static variables definitions                                              */
/*****************************************************************************/

/*****************************************************************************/
/* Static function prototypes                                                */
/*****************************************************************************/

#if STL_BENCHAMRK
UINT32 nSTLHeapUsage = 0;
#endif

/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*      OAM_Malloc                                                           */
/* DESCRIPTION                                                               */
/*      This function allocates memory for XSR                               */
/*                                                                           */
/* PARAMETERS                                                                */
/*      nSize       [IN]                                                     */
/*            Size to be allocated                                           */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      Pointer of allocated memory                                          */
/*                                                                           */
/* NOTES                                                                     */
/*      This function is called by function that wants to use memory         */
/*                                                                           */
/*****************************************************************************/
VOID *
OAM_Malloc(UINT32 nSize)
{
#if STL_BENCHAMRK
    nSTLHeapUsage += nSize;
#endif

    if (nSize < 64) nSize = 64;     /* I don't know.. Why this is needed */
    return (void *)malloc(nSize);
}

/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*  OAM_Free                                                                 */
/* DESCRIPTION                                                               */
/*      This function free memory that XSR allocated                         */
/*                                                                           */
/* PARAMETERS                                                                */
/*  pMem        Pointer to be free                                           */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      none                                                                 */
/*                                                                           */
/* NOTES                                                                     */
/*      This function is called by function that wants to free memory        */
/*                                                                           */
/*                                                                           */
/*****************************************************************************/
VOID
OAM_Free(VOID  *pMem)
{
    free(pMem);
}

/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*  OAM_Memcpy                                                               */
/* DESCRIPTION                                                               */
/*      This function copies data from source to destination.                */
/*                                                                           */
/* PARAMETERS                                                                */
/*  pDst        Destination array Pointer to be copied                       */
/*  pSrc        Source data allocated Pointer                                */
/*  nLen        length to be copied                                          */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      none                                                                 */
/*                                                                           */
/* NOTES                                                                     */
/*      This function is called by function that wants to copy source buffer */
/*  to destination buffer.                                                   */
/*                                                                           */
/*****************************************************************************/
VOID
OAM_Memcpy(VOID *pDst, VOID *pSrc, UINT32 nLen)
{
	memcpy((void *) pDst,(void *) pSrc, nLen);
}

/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*  OAM_Memset                                                               */
/* DESCRIPTION                                                               */
/*      This function set data of specific buffer.                           */
/*                                                                           */
/* PARAMETERS                                                                */
/*  pSrc        Source data allocated Pointer                                */
/*  nV          Value to be setted                                           */
/*  nLen        length to be setted                                          */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      none                                                                 */
/*                                                                           */
/* NOTES                                                                     */
/*      This function is called by function that wants to set source buffer  */
/*  own data.                                                                */
/*                                                                           */
/*****************************************************************************/
VOID
OAM_Memset(VOID *pDst, UINT8 nData, UINT32 nLen)
{
	memset((void *) pDst, (int) nData, nLen);
}

/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*  OAM_Memcmp                                                               */
/* DESCRIPTION                                                               */
/*      This function compare data of two buffer.                            */
/*                                                                           */
/* PARAMETERS                                                                */
/*  pSrc        Source data allocated Pointer                                */
/*  pDst        Destination array Pointer to be compared                     */
/*  nLen        length to be compared                                        */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      none                                                                 */
/*                                                                           */
/* NOTES                                                                     */
/*      This function is called by function that wants to compare source     */
/*  buffer and destination buffer.                                           */
/*                                                                           */
/*****************************************************************************/
INT32
OAM_Memcmp(VOID  *pCmp1, VOID  *pCmp2, UINT32 nLen)
{
	return memcmp(pCmp1, pCmp2, nLen);
}

typedef struct {
	BOOL32 bUsed;
	HANDLE hHandle;
} OAMSmCxt;

static OAMSmCxt gSMCxt[XSR_MAX_SEMAPHORE] = {
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0},
									{FALSE32, 0}};
/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */
/*  OAM_CreateSM                                                             */
/* DESCRIPTION                                                               */
/*      This function creates semaphore.                                     */
/*                                                                           */
/* PARAMETERS                                                                */
/*  pHandle        Handle of semaphore                                       */
/*                                                                           */
/* RETURN VALUES                                                             */
/*      If this function creates semaphore successfully, it returns TRUE32.  */
/*      else it returns FALSE32.                                             */
/* NOTES                                                                     */
/*      This function is called by function that wants to create semaphore   */
/*                                                                           */
/*                                                                           */
/*****************************************************************************/
BOOL32
OAM_CreateSM(SM32 *pHandle)
{
	UINT32  nIdx;
	BOOL32  bFound = FALSE32;

	/* search free slot */
	for (nIdx = 0; nIdx < XSR_MAX_SEMAPHORE; nIdx++)
	{
		if (gSMCxt[nIdx].bUsed == FALSE32)
		{
			bFound = TRUE32;
			break;
		}
	}

	/* if there is no free slot, return FALSE32 */
	if (bFound == FALSE32)
	{
		return FALSE32;
	}

	gSMCxt[nIdx].hHandle = CreateSemaphore(
							(LPSECURITY_ATTRIBUTES) NULL, 
							(LONG) 1,
							(LONG) 1,
							(LPCTSTR) NULL);

	if ((UINT32) gSMCxt[nIdx].hHandle == 0)
		return FALSE32;

	gSMCxt[nIdx].bUsed = TRUE32;
	*pHandle           = (SM32) nIdx;

	return TRUE32;
}

/*****************************************************************************/
/*                                                                           */
/* NAME                                                                      */

⌨️ 快捷键说明

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