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

📄 io.c

📁 Windows CE 6.0 BSP for VOIPAC Board (PXA270) Version 2b.
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File: io.c
//
//  This file implements Mainstone II input-output routines.
//
#include <windows.h>

/***NOTE: This function is specific to the SMSC LAN91C111 Ethernet controller
    registers 16-bit access as the chip is wired very differently on mainstoneii.
    Use READ_PORT_USHORT16 & WRITE_PORT_USHORT16 for 16-bit accesses to other peripherals.
****/
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);
    }
}

/***NOTE: This function is specific to the SMSC LAN91C111 Ethernet controller
    registers 16-bit access as the chip is wired very differently on mainstoneii.
    Use READ_PORT_USHORT16 & WRITE_PORT_USHORT16 for 16-bit accesses to other peripherals.
****/
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;
    }
}


UINT16 READ_PORT_USHORT16(UINT16 *pAddr)
{
    return(*(volatile unsigned short *)pAddr);
}

void WRITE_PORT_USHORT16(UINT16 *pAddr, UINT16 Data)
{
    *(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);
}

⌨️ 快捷键说明

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