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

📄 isapnp.c

📁 威盛 wince5.0 bsp 包 for x86 系统, 支持 VT8601 等北桥
💻 C
📖 第 1 页 / 共 2 页
字号:

            pPnPResources->DMADescriptors[0] = PnPReadRegister(PNP_ISA_IO_BASE, 0x74);

            pPnPResources->DMADescriptors[1] = PnPReadRegister(PNP_ISA_IO_BASE, 0x75);

            for ( i = 0; i < 4; i++ ) {
                pPnPResources->Memory32Descriptors[i].MemoryBase =
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x76 + i * 16)) << 24;
                pPnPResources->Memory32Descriptors[i].MemoryBase |=
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x77 + i * 16)) << 16;
                pPnPResources->Memory32Descriptors[i].MemoryBase |=
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x78 + i * 16)) << 8;
                pPnPResources->Memory32Descriptors[i].MemoryBase |=
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x79 + i * 16));

                pPnPResources->Memory32Descriptors[i].MemoryControl =
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x7A + i * 16));

                pPnPResources->Memory32Descriptors[i].MemoryUpperLimit =
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x7B + i * 16)) << 24;
                pPnPResources->Memory32Descriptors[i].MemoryUpperLimit |=
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x7C + i * 16)) << 16;
                pPnPResources->Memory32Descriptors[i].MemoryUpperLimit |=
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x7D + i * 16)) << 8;
                pPnPResources->Memory32Descriptors[i].MemoryUpperLimit |=
                PnPReadRegister(PNP_ISA_IO_BASE, (UCHAR)(0x7E + i * 16));
            }

        } else {
            pPnPResources->Flags = 0;
        }

        ulReturn = sizeof(ISA_PNP_RESOURCES);
    }

    PnPSetWaitForKey(PNP_ISA_IO_BASE);

    LeaveCriticalSection(&g_csISAConfig);

    return (ulReturn);
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
ULONG
ISASetBusDataByOffset(
                     IN ULONG BusNumber,
                     IN ULONG SlotNumber,
                     IN PVOID Buffer,
                     IN ULONG Offset,
                     IN ULONG Length
                     )
{
    UCHAR               ucCSNumber, ucLogicalDevice;
    PISA_PNP_RESOURCES  pPnPResources = (PISA_PNP_RESOURCES)Buffer;
    int                 i;


    if ( g_bISAInitialized == FALSE )
        ISAInitBusInfo();

    if ( g_ucISANumberCSNs == 0 || g_ucISANumberCSNs == ~0U ) {
        return (0);
    }

    ucCSNumber = (UCHAR)(SlotNumber >> 8);
    ucLogicalDevice = (UCHAR)SlotNumber;

    if ( ucCSNumber > g_ucISANumberCSNs || ucCSNumber == 0 ||
         Offset != 1 || Length != sizeof(ISA_PNP_RESOURCES) ) {
        return (0);
    }

    EnterCriticalSection(&g_csISAConfig);

    PnPSendInitiationKey(PNP_ISA_IO_BASE);

    PnPWake(PNP_ISA_IO_BASE, ucCSNumber);

    PnPWriteRegister(PNP_ISA_IO_BASE, 0x07, ucLogicalDevice);

    if ( pPnPResources->Flags & ISA_PNP_RESOURCE_FLAG_ACTIVE ) {
        for ( i = 0; i < 4; i++ ) {
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x40 + i * 8),
                            (UCHAR)(pPnPResources->Memory24Descriptors[i].MemoryBase >> 8));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x41 + i * 8),
                            (UCHAR)(pPnPResources->Memory24Descriptors[i].MemoryBase));

            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x42 + i * 8),
                            pPnPResources->Memory24Descriptors[i].MemoryControl);

            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x43 + i * 8),
                            (UCHAR)(pPnPResources->Memory24Descriptors[i].MemoryUpperLimit >> 8));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x44 + i * 8),
                            (UCHAR)(pPnPResources->Memory24Descriptors[i].MemoryUpperLimit));
        }

        for ( i = 0; i < 8; i++ ) {
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x60 + i * 2),
                            (UCHAR)(pPnPResources->IoPortDescriptors[i] >> 8));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x61 + i * 2),
                            (UCHAR)(pPnPResources->IoPortDescriptors[i]));
        }

        PnPWriteRegister(PNP_ISA_IO_BASE, 0x70, pPnPResources->IRQDescriptors[0].IRQLevel);
        PnPWriteRegister(PNP_ISA_IO_BASE, 0x71, pPnPResources->IRQDescriptors[0].IRQType);
        PnPWriteRegister(PNP_ISA_IO_BASE, 0x72, pPnPResources->IRQDescriptors[1].IRQLevel);
        PnPWriteRegister(PNP_ISA_IO_BASE, 0x73, pPnPResources->IRQDescriptors[1].IRQType);

        PnPWriteRegister(PNP_ISA_IO_BASE, 0x74, pPnPResources->DMADescriptors[0]);
        PnPWriteRegister(PNP_ISA_IO_BASE, 0x75, pPnPResources->DMADescriptors[1]);

        for ( i = 0; i < 4; i++ ) {
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x76 + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryBase >> 24));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x77 + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryBase >> 16));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x78 + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryBase >> 8));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x79 + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryBase));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x7A + i * 16),
                            pPnPResources->Memory32Descriptors[i].MemoryControl);
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x7B + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryUpperLimit >> 24));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x7C + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryUpperLimit >> 16));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x7D + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryUpperLimit >> 8));
            PnPWriteRegister(
                            PNP_ISA_IO_BASE, (UCHAR)(0x7E + i * 16),
                            (UCHAR)(pPnPResources->Memory32Descriptors[i].MemoryUpperLimit));
        }

        PnPWriteRegister(PNP_ISA_IO_BASE, 0x30, 1);
    } else {
        PnPWriteRegister(PNP_ISA_IO_BASE, 0x30, 0);
    }


    PnPSetWaitForKey(PNP_ISA_IO_BASE);

    LeaveCriticalSection(&g_csISAConfig);

    return (sizeof(ISA_PNP_RESOURCES));
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
UCHAR
PnPReadRegister(
               PUCHAR pIOSpace, 
               UCHAR ucRegNo
               )
{
    _outp((USHORT) (pIOSpace + PNP_ADDRESS_PORT), (int) ucRegNo);
    return (_inp((USHORT) (pIOSpace + g_usISAReadPort)));
}    



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
PnPWriteRegister(
                PUCHAR pIOSpace, 
                UCHAR ucRegNo, 
                UCHAR ucValue
                )
{
    _outp((USHORT) (pIOSpace + PNP_ADDRESS_PORT), (int) ucRegNo);
    _outp((USHORT) (pIOSpace + PNP_WRITE_DATA_PORT), (int) ucValue);
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
PnPSendInitiationKey(
                    PUCHAR pIOSpace
                    )
{
    int             i;
    static  UCHAR   ucInitKey[] =
    {
        0x00, 0x00,
        0x6A, 0xB5, 0xDA, 0xED, 0xF6, 0xFB, 0x7D, 0xBE,
        0xDF, 0x6F, 0x37, 0x1B, 0x0D, 0x86, 0xC3, 0x61,
        0xB0, 0x58, 0x2C, 0x16, 0x8B, 0x45, 0xA2, 0xD1,
        0xE8, 0x74, 0x3A, 0x9D, 0xCE, 0xE7, 0x73, 0x39
    };


    for ( i = 0; i < sizeof(ucInitKey); i++ ) {
        _outp((USHORT) (pIOSpace + PNP_ADDRESS_PORT), (int) ucInitKey[i]);
    }
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
PnPWake(PUCHAR pIOSpace, UCHAR ucCSN)
{
    PnPWriteRegister(pIOSpace, 0x03, ucCSN);
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
PnPReadSerialId(PUCHAR pIOSpace, PUCHAR ucSerialId)
{
    int     i;

    for ( i = 0; i < 9; i++ ) {
        _outp((USHORT) (pIOSpace + PNP_ADDRESS_PORT), (int) 0x05);

        while ( !(_inp((USHORT) (pIOSpace + g_usISAReadPort)) & 0x01) )
            ;

        _outp((USHORT) (pIOSpace + PNP_ADDRESS_PORT), (int) 0x04);
        ucSerialId[i] = _inp((USHORT) (pIOSpace + g_usISAReadPort));
    }
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int
PnPReadResourceData(PUCHAR pIOSpace, PUCHAR ucResourceData, int iDataSize)
{
    int     i;
    int     bSawEndTag = FALSE;
    UCHAR   ucChecksum = 0;

    for ( i = 0; i < iDataSize; i++ ) {
        _outp((USHORT) (pIOSpace + PNP_ADDRESS_PORT), (int) 0x05);

        while ( !(_inp((USHORT) (pIOSpace + g_usISAReadPort)) & 0x01) )
            ;

        _outp((USHORT) (pIOSpace + PNP_ADDRESS_PORT), (int) 0x04);
        ucResourceData[i] = _inp((USHORT) (pIOSpace + g_usISAReadPort));

        ucChecksum += ucResourceData[i];

        if ( bSawEndTag ) {
            if ( ucResourceData[i] != 0 && ucChecksum != 0 ) {
                DEBUGMSG(1, (TEXT("PnPReadResourceData : Bad resource checksum\n")));
            }

            i++;
            break;
        }

        if ( ucResourceData[i] == 0x79 ) {
            bSawEndTag = 1;
        }
    }

    return (i);
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int
PnPGetLogicalDeviceInfo(
                       PUCHAR ucResourceData, int iDataSize, 
                       PISA_PNP_LOGICAL_DEVICE_INFO pDeviceInfo)
{
    PUCHAR  pCurrent;
    int     iLength, iName;
    int     i;
    int     nDevices = 0, nCompatibleIDs = 0;

    pCurrent = ucResourceData;

    memset(pDeviceInfo, 0, sizeof(ISA_PNP_LOGICAL_DEVICE_INFO) * 8);

    for ( i = 0; i < iDataSize; i++ ) {
        if ( (*pCurrent & 0x80) == 0 ) {
            //
            // Small TAG
            //

            iName = (*pCurrent >> 3) & 0x0F;
            iLength = (*pCurrent & 0x07) + 1;

            switch ( iName ) {
            case 2:     // Logical Device ID
                if ( nDevices <= 8 ) {
                    nDevices++;
                    nCompatibleIDs = 0;
                    pDeviceInfo[nDevices - 1].LogicalDeviceID =
                    pCurrent[1] << 24 | pCurrent[2] << 16 | pCurrent[3] << 8 |
                    pCurrent[4];
                }
                break;

            case 3:     // Compatible Device ID
                if ( nDevices <= 8 ) {
                    nCompatibleIDs++;
                    pDeviceInfo[nDevices - 1].CompatibleIDs[nCompatibleIDs - 1] =
                    pCurrent[1] << 24 | pCurrent[2] << 16 | pCurrent[3] << 8 |
                    pCurrent[4];
                }
                break;
            }
        } else {
            //
            // Large TAG
            //

            iName = *pCurrent & 0x7F;
            iLength = ((pCurrent[2] << 8) | pCurrent[1]) + 3;
        }

        pCurrent += iLength;
        i += iLength - 1;
    }

    return (nDevices);
}



//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void
PnPSetWaitForKey(PUCHAR pIOSpace)
{
    PnPWriteRegister(pIOSpace, 0x02, 0x02);
}

⌨️ 快捷键说明

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