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

📄 io.c

📁 老外的一个开源项目
💻 C
字号:
// Copyright (c) David Vescovi.  All rights reserved.
// Part of Project DrumStix
// Windows Embedded Developers Interest Group (WE-DIG) community project.
// http://www.we-dig.org
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------------------------
//
//  File: io.c
//
//  This file implements input-output routines.
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <Nkintr.h>

UINT16 READ_PORT_USHORT(UINT16 *pAddr)
{
    UINT32 nAlignedAddr = ((UINT32)pAddr & ~0x3);

    if ((UINT32)pAddr & 0x2)    // Is the address an "odd" word within a longword?
    {
        // Yes - read a longword and data is in the upper word.
        return((UINT16) ((*(volatile unsigned long *)nAlignedAddr) >> 16));
    }
    else
    {
        // No - read single word.
        return(*(volatile unsigned short *)nAlignedAddr);
    }
}


void WRITE_PORT_USHORT(UINT16 *pAddr, UINT16 Data)
{
    UINT32 nAlignedAddr = ((UINT32)pAddr & ~0x3);

    if ((UINT32)pAddr & 0x2)    // Is the address an "odd" word within a longword?
    {
        // Yes - write a longword with data in the upper word.
        *(volatile UINT32 *)nAlignedAddr = (READ_PORT_USHORT(pAddr) | (Data << 16));
    }
    else
    {
        // No - write single word.
        *(volatile UINT16 *)pAddr = Data;
    }
}



UCHAR
READ_PORT_UCHAR(
    PUCHAR  Port
    )
{
    return *(volatile UCHAR * const)Port;
}

VOID
WRITE_PORT_UCHAR(
    PUCHAR  Port,
    UCHAR   Value
    )
{
    *(volatile UCHAR * const)Port = Value;
}

VOID
WRITE_REGISTER_USHORT(
    PUSHORT Register,
    USHORT  Value
    )
{
    *(volatile USHORT * const)Register = Value;
}


VOID
WRITE_REGISTER_ULONG(
    PULONG  Register,
    ULONG   Value
    )
{
    *(volatile ULONG * const)Register = Value;
}

USHORT
READ_REGISTER_USHORT(
    PUSHORT Register
    )
{
    return (*(volatile USHORT * const)Register);
}


ULONG
READ_REGISTER_ULONG(
    PULONG  Register
    )
{
    return (*(volatile ULONG * const)Register);
}

UCHAR
READ_REGISTER_UCHAR(
    PUCHAR  Register
    )
{
    return *(volatile UCHAR * const)Register;
}

VOID
WRITE_REGISTER_UCHAR(
    PUCHAR  Register,
    UCHAR   Value
    )
{
    *(volatile UCHAR * const)Register = Value;
}

⌨️ 快捷键说明

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