SW 개발

winCE / 커널소스 / 레지스터 접근매크로 / io 다루기 관련..

. . . 2010. 3. 23. 16:28
반응형

Xeno's Study Blog (http://XenoStudy.tistory.com)
- 글쓴이 : Xeno
- 출처 : 나
- 기타사항 : winCE / Windows Moblie 공통. 틀린사항은 댓글로 수정바랍니다.

플랫폼 빌더 5.0에서 쓰는 I/O 관련 매크로에 대하여..
MSDN : http://msdn.microsoft.com/en-us/library/aa447176.aspx
IO 관련 reference
MSDN : http://msdn.microsoft.com/en-us/library/aa447177.aspx

I/O Reference Kernel Interface
I/O Reference OAL Interface
I/O Functions
I/O IOCTLs
I/O Macros
I/O Structures

#define INREG8(x)           READ_REGISTER_UCHAR(x)
#define OUTREG8(x, y)       WRITE_REGISTER_UCHAR(x, (UCHAR)(y))
#define SETREG8(x, y)       OUTREG8(x, INREG8(x)|(y))
#define CLRREG8(x, y)       OUTREG8(x, INREG8(x)&~(y))
#define INREG16(x)          READ_REGISTER_USHORT(x)
#define OUTREG16(x, y)      WRITE_REGISTER_USHORT(x,(USHORT)(y))
#define SETREG16(x, y)      OUTREG16(x, INREG16(x)|(y))
#define CLRREG16(x, y)      OUTREG16(x, INREG16(x)&~(y))
#define INREG32(x)          READ_REGISTER_ULONG(x)
#define OUTREG32(x, y)      WRITE_REGISTER_ULONG(x, (ULONG)(y))
#define SETREG32(x, y)      OUTREG32(x, INREG32(x)|(y))
#define CLRREG32(x, y)      OUTREG32(x, INREG32(x)&~(y))

위의 메크로 들이 커널소스에서 봤던 함수들이다. (주로 레지스터에 바로 접근할때 쓰는 메크로가 되겠다)
위의 함수들이 포함된 해더파일..
winCE Platform Builder에서는 아래 함수에만 선언되어있으므로.. 모든 소스가 공통으로 사용하는듯..


D:\WINCE500\PLATFORM\COMMON\SRC\INC\oal_io.h

// 
// Copyright (c) Microsoft Corporation.  All rights reserved. 
// 
// 
// Use of this source code is subject to the terms of the Microsoft end-user 
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT. 
// If you did not accept the terms of the EULA, you are not authorized to use 
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your 
// install media. 
// 
//------------------------------------------------------------------------------ 
// 
//  File:  oal_io.h 
// 
//  This header file defines OAL input-output module. 
// 
//  Depending on platform hardware I/O operations can be implemented as macros 
//  or as functions. By default code uses functions. If platform doesn't allow 
//  direct inline I/O operation the OAL_DDK_NOMACRO enviroment variable must 
//  be set before OAL libraries are compiled. 
// 
//  Export for kernel/public interface: 
//      * OEMIoControl/IOCTL_HAL_DDK_CALL 
// 
//  Export for other OAL modules/protected interface: 
//      * INPORTx/OUTPORTx/SETPORTx/CLRPORTx 
//      * INREGx/OUTREGx/SETREGx/CLREGx 
//      * OALIoReadBusData 
//      * OALIoWriteBusData 
//      * OALIoTransBusAddress 
//      * OALIoTransSystemAddress 
//      * OALIoBusPowerOff 
//      * OALIoBusPowerOn 
// 
#ifndef __OAL_IO_H 
#define __OAL_IO_H 
//------------------------------------------------------------------------------ 
#include <ceddk.h> 
#include <pkfuncs.h> 
//------------------------------------------------------------------------------ 
#if __cplusplus 
extern "C" { 
#endif 
//------------------------------------------------------------------------------ 
// 
//  Macros:  INPORTx/OUTPORTx/SETPORTx/CLRPORTx 
// 
//  This macros encapsulates basic I/O operations. Depending on OAL_DDK_NOMACRO 
//  definition they will expand to direct memory operation or function call. 
//  On x86 platform IO address space operation is generated. On other platforms 
//  operation is identical with INREGx/OUTREGx/SETREGx/CLRREGx. 
// 
#define INPORT8(x)          READ_PORT_UCHAR(x) 
#define OUTPORT8(x, y)      WRITE_PORT_UCHAR(x, (UCHAR)(y)) 
#define SETPORT8(x, y)      OUTPORT8(x, INPORT8(x)|(y)) 
#define CLRPORT8(x, y)      OUTPORT8(x, INPORT8(x)&~(y)) 
#define INPORT16(x)         READ_PORT_USHORT(x) 
#define OUTPORT16(x, y)     WRITE_PORT_USHORT(x,(USHORT)(y)) 
#define SETPORT16(x, y)     OUTPORT16(x, INPORT16(x)|(y)) 
#define CLRPORT16(x, y)     OUTPORT16(x, INPORT16(x)&~(y)) 
#define INPORT32(x)         READ_PORT_ULONG(x) 
#define OUTPORT32(x, y)     WRITE_PORT_ULONG(x, (ULONG)(y)) 
#define SETPORT32(x, y)     OUTPORT32(x, INPORT32(x)|(y)) 
#define CLRPORT32(x, y)     OUTPORT32(x, INPORT32(x)&~(y)) 
//------------------------------------------------------------------------------ 
// 
//  Macros:  INREGx/OUTREGx/SETREGx/CLRREGx 
// 
//  This macros encapsulates basic I/O operations. Depending on OAL_DDK_NOMACRO 
//  definition they will expand to direct memory operation or function call. 
//  Memory address space operation is used on all platforms. 
// 
#define INREG8(x)           READ_REGISTER_UCHAR(x) 
#define OUTREG8(x, y)       WRITE_REGISTER_UCHAR(x, (UCHAR)(y)) 
#define SETREG8(x, y)       OUTREG8(x, INREG8(x)|(y)) 
#define CLRREG8(x, y)       OUTREG8(x, INREG8(x)&~(y)) 
#define INREG16(x)          READ_REGISTER_USHORT(x) 
#define OUTREG16(x, y)      WRITE_REGISTER_USHORT(x,(USHORT)(y)) 
#define SETREG16(x, y)      OUTREG16(x, INREG16(x)|(y)) 
#define CLRREG16(x, y)      OUTREG16(x, INREG16(x)&~(y)) 
#define INREG32(x)          READ_REGISTER_ULONG(x) 
#define OUTREG32(x, y)      WRITE_REGISTER_ULONG(x, (ULONG)(y)) 
#define SETREG32(x, y)      OUTREG32(x, INREG32(x)|(y)) 
#define CLRREG32(x, y)      OUTREG32(x, INREG32(x)&~(y)) 
//------------------------------------------------------------------------------ 
#define IOCTL_OAL_READBUSDATA           0x03 
#define IOCTL_OAL_WRITEBUSDATA          0x04 
#define IOCTL_OAL_TRANSBUSADDRESS       0x05 
#define IOCTL_OAL_TRANSSYSADDRESS       0x06 
#define IOCTL_OAL_BUSPOWEROFF           0x07 
#define IOCTL_OAL_BUSPOWERON            0x08 
typedef struct { 
    UINT32 function; 
    UINT32 rc; 
union { 
struct { 
            DEVICE_LOCATION devLoc; 
            UINT32 offset; 
            UINT32 length; 
VOID *pBuffer; 
} busData; 
struct { 
            INTERFACE_TYPE ifcType; 
            UINT32 busNumber; 
            UINT32 space; 
            UINT64 address; 
} transAddress; 
struct { 
            INTERFACE_TYPE ifcType; 
            UINT32 busNumber; 
} busPower; 
}; 
} OAL_DDK_PARAMS; 
//------------------------------------------------------------------------------ 
// 
//  Function:  OALIoCtrlHalDdkCall 
// 
//  This function is called form OEMIoControl for IOCTL_HAL_DDK_CALL. 
// 
BOOL OALIoCtlHalDdkCall(UINT32, VOID*, UINT32, VOID*, UINT32, UINT32*); 
//------------------------------------------------------------------------------ 
// 
//  Function:  OALIoReadBusData 
// 
//  This function reads data from device configuration space. On most platform 
//  this function will support only PCI bus based devices. 
// 
UINT32 OALIoReadBusData( 
    DEVICE_LOCATION *pDevLoc, UINT32 address, UINT32 size, VOID *pData 
); 
//------------------------------------------------------------------------------ 
// 
//  Function:  OALIoWriteBusData 
// 
//  This function write data to device configuration space. On most platform 
//  this function will support only PCI bus based devices. 
// 
UINT32 OALIoWriteBusData( 
    DEVICE_LOCATION *pDevLoc, UINT32 address, UINT32 size, VOID *pData 
); 
//------------------------------------------------------------------------------ 
// 
//  Function:  OALIoTransBusAddress 
// 
//  This function translate bus relative address to system address which can 
//  be used for I/O operations. 
// 
BOOL OALIoTransBusAddress( 
    INTERFACE_TYPE ifcType, UINT32 busNumber, UINT64 busAddress, 
    UINT32 *pAddressSpace, UINT64 *pSystemAddress 
); 
//------------------------------------------------------------------------------ 
// 
//  Function:  OALIoTransSystemAddress 
// 
//  This function translate system address to bus-relative address which can 
//  be used for DMA operations. This function isn't reverse to 
//  OALIoTransBusAddress. It maps system RAM address to bus relative RAM 
//  address. 
// 
BOOL OALIoTransSystemAddress( 
    INTERFACE_TYPE ifcType, UINT32 busNumber, UINT64 systemAddress, 
    UINT64 *pBusAddress 
); 
//------------------------------------------------------------------------------ 
// 
//  Function:  OALIoBusPowerOff 
// 
//  This function is called to put bus driver to power off mode. It should 
//  save bus driver state if required and switch power off on bus driver. 
// 
BOOL OALIoBusPowerOff(INTERFACE_TYPE ifcType, UINT32 busId); 
//------------------------------------------------------------------------------ 
// 
//  Function:  OALIoBusPowerOn 
// 
//  This function is called to put bus driver back to power on mode. It should 
//  power on bus driver and restore its state if required. 
// 
BOOL OALIoBusPowerOn(INTERFACE_TYPE ifcType, UINT32 busId); 
//------------------------------------------------------------------------------ 
#if __cplusplus 
} 
#endif 
#endif
반응형