📄 wmplatform_os.h
字号:
/*-----------------------------------------------------------------------------
* Copyright (c) Wolfson Microelectronics plc. All rights reserved.
*
* This software as well as any related documentation 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 Wolfson Microelectronics plc. Wolfson Microelectronics plc
* 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 Wolfson Microelectronics plc.
*
* $Id: WMPlatform_OS.h 2046 2005-08-11 13:26:16Z fb $
*
* Common definitions to hide operating system differences.
*
* This file contains the Windows CE definitions.
*
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
*---------------------------------------------------------------------------*/
#ifndef __WMPLATFORM_OS_H__
#define __WMPLATFORM_OS_H__
/*
* Include files
*/
#include <windows.h> /* Note: this should define WIN32. */
#include <winbase.h>
#ifndef WIN32
# define WIN32
#endif
#include "WMDevice.h"
/*
* Definitions
*/
/*
* Length of Event name string
*/
#define WM_EVENT_STRING 20
/*
* The value of a time-out interval that never elapses.
*/
#define WM_INFINITE INFINITE
/******************************************************************************
* Mutex functions.
*/
/*
* The type used for a mutex.
*/
typedef HANDLE WMMutex_t;
/*
* CREATE_MUTEX should return WMS_SUCCESS on success, WMS_RESOURCE_FAIL on error
*/
#define CREATE_MUTEX( _pmutex, _name ) ( ( *(_pmutex) = CreateMutex( NULL, FALSE, _name ) ) ? WMS_SUCCESS : WMS_RESOURCE_FAIL )
/*
* ACQUIRE_MUTEX should return WMS_SUCCESS on success, WMS_LOCK_TIMED_OUT on error
*/
#define ACQUIRE_MUTEX( _mutex, _timeout ) ((WAIT_OBJECT_0 == WaitForSingleObject( _mutex, _timeout )?WMS_SUCCESS:WMS_LOCK_TIMED_OUT))
/*
* RELEASE_MUTEX should return WMS_SUCCESS on success, WMS_FAILURE on error
*/
#define RELEASE_MUTEX( _mutex ) ( ( TRUE == ReleaseMutex( _mutex ) ) ? WMS_SUCCESS:WMS_FAILURE )
/*
* DELETE_MUTEX should return WMS_SUCCESS on success, WMS_FAILURE on error
*/
#define DELETE_MUTEX( _mutex ) ( ( TRUE == CloseHandle( _mutex ) ) ? WMS_SUCCESS:WMS_FAILURE )
/******************************************************************************
* Event functions.
*/
/*
* The type used for an event.
*/
typedef HANDLE WMEvent_t;
/*
* CREATE_EVENT should return WMS_SUCCESS on success, WMS_RESOURCE_FAIL on error
*/
#define CREATE_EVENT( _pevent, _name ) ( ( *(_pevent) = CreateEvent( NULL, FALSE, FALSE, _name ) ) ? WMS_SUCCESS : WMS_RESOURCE_FAIL )
/*
* WAIT_FOR_EVENT takes a handle and time-out interval in milliseconds.
* Should return WMS_SUCCESS on success, WMS_EVENT_TIMED_OUT on error
*/
#define WAIT_FOR_EVENT( _event, _timeout_ms ) ( ( WAIT_OBJECT_0 == WaitForSingleObject( _event, _timeout_ms ) ? WMS_SUCCESS:WMS_EVENT_TIMED_OUT ) )
/*
* SET_EVENT should return WMS_SUCCESS on success, WMS_FAILURE on error
*/
#define SET_EVENT( _event ) ( ( 0 == SetEvent( _event ) ) ? WMS_FAILURE:WMS_SUCCESS )
/*
* DELETE_EVENT should return WMS_SUCCESS on success, WMS_FAILURE on error
*/
#define DELETE_EVENT( _event ) ( ( TRUE == CloseHandle( _event ) ) ? WMS_SUCCESS:WMS_FAILURE )
/******************************************************************************
* Atomic functions. These perform the operation in such a way that they are
* thread-safe, and return the new value.
*/
typedef LONG WMAtomic_t;
#define AtomicIncrement InterlockedIncrement
#define AtomicDecrement InterlockedDecrement
/******************************************************************************
* Mapping in registers, etc.
*/
/*-----------------------------------------------------------------------------
* Macro: ALLOC_MEMORY
*
* Allocate memory.
*
* Parameters:
* _type data type of the memory being allocated
* _size The size, in bytes, to allocate
*
* Returns: _type *
* The virtual address of the allocated area, or NULL on error.
*---------------------------------------------------------------------------*/
#define ALLOC_MEMORY( _type, _size ) \
(_type *) VirtualAlloc( NULL, _size, MEM_COMMIT, PAGE_READWRITE )
/*-----------------------------------------------------------------------------
* Macro: FREE_MEMORY
*
* Free memory allocated using ALLOC_MEMORY.
*
* Parameters:
* _addr Address of memory to free
*
* Returns: void
*---------------------------------------------------------------------------*/
#define FREE_MEMORY( _addr ) do { \
VirtualFree( (void *) _addr, 0, MEM_RELEASE ); \
_addr = NULL; \
} while (0)
/*-----------------------------------------------------------------------------
* Macro: ALLOC_SHARED_MEMORY
*
* Allocate memory which is shared across all processes (i.e. so all processes
* can access the same area of memory and have a shared common state).
*
* Parameters:
* _hDevice handle to the device (from WMOpenDevice)
* _type data type of the memory being allocated
* _size The size, in bytes, to allocate
* _name The "name", or unique identifier, of the shared memory.
*
* Returns: _type *
* The virtual address of the allocated area, or NULL on error.
*---------------------------------------------------------------------------*/
#define ALLOC_SHARED_MEMORY( _hDevice, _type, _size, _name ) \
(_type *) WMAllocateSharedMemory( _hDevice, _size, _name )
/*-----------------------------------------------------------------------------
* Macro: FREE_SHARED_MEMORY
*
* Free memory allocated using ALLOC_SHARED_MEMORY.
*
* Parameters:
* _addr Address of memory to free
*
* Returns: void
*---------------------------------------------------------------------------*/
#define FREE_SHARED_MEMORY( _addr ) do { \
WMFreeSharedMemory( (void *) _addr ); \
_addr = NULL; \
} while (0)
/*-----------------------------------------------------------------------------
* Macro: MAP_MEMORY
*
* Map physical memory to virtual memory (e.g. for mapping in hardware
* registers).
*
* Parameters:
* _hDevice handle to the device (from WMOpenDevice)
* _type data type of the memory being mapped
* _addr Physical address to map
* _size The size, in bytes, to map
* _comment Error message string indicating what was being mapped
*
* Returns: _type *
* The virtual address of the mapped area, or NULL on error.
*---------------------------------------------------------------------------*/
#define MAP_MEMORY( _hDevice, _type, _addr, _size, _comment ) \
(_type *) WMMapMemory( _hDevice, _size, (char *) _comment, (void *) _addr )
/*-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -