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

📄 cs8900.c

📁 2440的又一BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
#pragma NDIS_PAGEABLE_FUNCTION(CS8900Initialize)

BOOLEAN
CS8900Initialize(
    IN PCS8900_ADAPTER Adapter
    )

/*++

Routine Description:

    Initializes the card into a running state.

Arguments:

    Adapter - pointer to the adapter block.

Return Value:

    TRUE, if all goes well, else FALSE.

--*/

{

	DWORD rdata;
	

	EthCommand = (unsigned char *)ioPacketPage;

    v_pIOPRegs = (volatile S3C2440A_IOPORT_REG*)VirtualAlloc(0, sizeof(S3C2440A_IOPORT_REG), MEM_RESERVE, PAGE_NOACCESS);
	if (v_pIOPRegs==NULL)
	{
		DEBUGMSG (1,(TEXT("[CS8900] v_pIOPRegs is not allocated\n\r")));
		return FALSE;
	}
	if (!VirtualCopy((PVOID)v_pIOPRegs, (PVOID)(S3C2440A_BASE_REG_PA_IOPORT >> 8), sizeof(S3C2440A_IOPORT_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
	{
		DEBUGMSG (1,(TEXT("[CS8900] v_pIOPRegs is not mapped\n\r")));
		goto cs8900_fail;
	}
	DEBUGMSG (1,(TEXT("[CS8900] v_pIOPRegs is mapped to %x\n\r"), v_pIOPRegs));

      v_pINTRegs = (volatile S3C2440A_INTR_REG*)VirtualAlloc(0, sizeof(S3C2440A_INTR_REG), MEM_RESERVE, PAGE_NOACCESS);
	if (v_pINTRegs== NULL)
	{
	    DEBUGMSG (1,(TEXT("[CS8900] v_pINTRegs is not allocated\n\r")));
	    goto cs8900_fail;
	}
	if (!VirtualCopy((PVOID)v_pINTRegs, (PVOID)(S3C2440A_BASE_REG_PA_INTR >> 8), sizeof(S3C2440A_INTR_REG), PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
	{
	   DEBUGMSG (1,(TEXT("[CS8900] v_pINTRegs is not mapped\n\r")));
	   goto cs8900_fail;
	}
       DEBUGMSG (1,(TEXT("[CS8900] v_pINTRegs is mapped to %x\n\r"), v_pINTRegs));
       
	v_pMEMRegs = (S3C2440A_MEMCTRL_REG*)VirtualAlloc(0,sizeof(S3C2440A_MEMCTRL_REG), MEM_RESERVE,PAGE_NOACCESS);
	if(v_pMEMRegs == NULL) 
	{
	    DEBUGMSG (1,(TEXT("[CS8900] v_pMEMRegs is not allocated\n\r")));
		goto cs8900_fail;
	}
	if(!VirtualCopy((PVOID)v_pMEMRegs,(PVOID)(S3C2440A_BASE_REG_PA_MEMCTRL >> 8),sizeof(S3C2440A_MEMCTRL_REG),PAGE_PHYSICAL | PAGE_READWRITE|PAGE_NOCACHE)) {
	    DEBUGMSG (1,(TEXT("[CS8900] v_pMEMRegs is not mapped\n\r")));
	    goto cs8900_fail;
	}    
	DEBUGMSG (1,(TEXT("[CS8900] v_pMEMRegs is mapped to %x\n\r"), v_pMEMRegs));


    // nGCS3=nUB/nLB(nSBHE),nWAIT,16-bit
    v_pMEMRegs->BWSCON = (v_pMEMRegs->BWSCON&~(0xf<<12))|(0xd<<12);	

    // BANK3 access timing
	v_pMEMRegs->BANKCON3=((CS8900_Tacs<<13)+(CS8900_Tcos<<11)+(CS8900_Tacc<<8)+(CS8900_Tcoh<<6)\
		+(CS8900_Tah<<4)+(CS8900_Tacp<<2)+(CS8900_PMC));

	rdata  = v_pIOPRegs->GPGCON;
	rdata &= ~(3 << 2);
	rdata |=  (2 << 2);
	v_pIOPRegs->GPGCON = rdata;			/* External Interrupt #9 Enable			*/

#if 1
	rdata  = v_pIOPRegs->EXTINT1;
	rdata &= ~(7 << 4);
	rdata |=  (4 << 4);
	v_pIOPRegs->EXTINT1 = rdata;			/* High Level Triggered Mode				*/
#else
	rdata  = v_pIOPRegs->EXTINT1;
	rdata &= ~(7 << 4);
	rdata |=  (1 << 4);
	v_pIOPRegs->EXTINT1 = rdata;			/* Rising Edge Detect Mode				*/
#endif

	DEBUGMSG(1, (TEXT("[CS8900] rGPGCON = %x\r\n"),	v_pIOPRegs->GPGCON));
	DEBUGMSG(1, (TEXT("[CS8900] rEXTINT1 = %x\r\n"), v_pIOPRegs->EXTINT1));


	if (CSInit() == FALSE)
	    {
	    	RETAILMSG(1, (TEXT("CS8900:CSInit failure!!\r\n")));
		return FALSE;
             } 
             
	return TRUE;

cs8900_fail:
    if (v_pIOPRegs) {
        VirtualFree((PVOID)v_pIOPRegs, 0, MEM_RELEASE);
    }
    if (v_pINTRegs) {
        VirtualFree((PVOID)v_pINTRegs, 0, MEM_RELEASE);
    }
    if (v_pMEMRegs) {
        VirtualFree((PVOID)v_pMEMRegs, 0, MEM_RELEASE);
    }
	return FALSE;
}

#pragma NDIS_PAGEABLE_FUNCTION(CS8900ReadEthernetAddress)

BOOLEAN CS8900ReadEthernetAddress(
    IN PCS8900_ADAPTER Adapter
)

/*++

Routine Description:

    Reads in the Ethernet address from the CS8900 Chip...

Arguments:

    Adapter - pointer to the adapter block.

Return Value:

    The address is stored in Adapter->PermanentAddress, and StationAddress if it
    is currently zero.

--*/

{
	HKEY hKey;
    DWORD dwSize, dwAngle1,dwAngle2,dwAngle3, dwType;

    if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Drivers\\CS8900"), 0, 0, &hKey))
    {
        dwSize = sizeof(DWORD);
        if (ERROR_SUCCESS == RegQueryValueEx(hKey,
                                             TEXT("MACAddress1"),
                                             NULL,
                                             &dwType,
                                             (LPBYTE)&dwAngle1,
                                             &dwSize))
        {
            RETAILMSG(0,(TEXT("MACAddress1[ %02x-%02x ]\r\n"),(dwAngle1>>8)&0Xff,dwAngle1&0xff));
        }
		if (ERROR_SUCCESS == RegQueryValueEx(hKey,
                                             TEXT("MACAddress2"),
                                             NULL,
                                             &dwType,
                                             (LPBYTE)&dwAngle2,
                                             &dwSize))
        {
            RETAILMSG(0,(TEXT("MACAddress2:[ %02x-%02x ]\r\n"),(dwAngle2>>8)&0Xff,dwAngle2&0xff));
        }
		if (ERROR_SUCCESS == RegQueryValueEx(hKey,
                                             TEXT("MACAddress3"),
                                             NULL,
                                             &dwType,
                                             (LPBYTE)&dwAngle3,
                                             &dwSize))
        {
            RETAILMSG(0,(TEXT("MACAddress3:[ %02x-%02x ]\r\n"),(dwAngle3>>8)&0Xff,dwAngle3&0xff));
        }

        RegCloseKey(hKey);
    }

	Adapter->PermanentAddress[0] = (dwAngle1>>8)&0Xff;
	Adapter->PermanentAddress[1] = dwAngle1&0xff;
	Adapter->PermanentAddress[2] = (dwAngle2>>8)&0Xff;
	Adapter->PermanentAddress[3] = dwAngle2&0xff;
	Adapter->PermanentAddress[4] = (dwAngle3>>8)&0Xff;
	Adapter->PermanentAddress[5] = dwAngle3&0xff;

	RETAILMSG(1,
		(TEXT("\n\nCS8900: MAC Address [ %02x-%02x-%02x-%02x-%02x-%02x ]\r\n\n"),
            Adapter->PermanentAddress[0],
            Adapter->PermanentAddress[1],
            Adapter->PermanentAddress[2],
            Adapter->PermanentAddress[3],
            Adapter->PermanentAddress[4],
            Adapter->PermanentAddress[5]));
    //
    // Use the burned in address as the station address, unless the
    // registry specified an override value.
    //
    if ((Adapter->StationAddress[0] == 0x00) &&
        (Adapter->StationAddress[1] == 0x00) &&
        (Adapter->StationAddress[2] == 0x00) &&
        (Adapter->StationAddress[3] == 0x00) &&
        (Adapter->StationAddress[4] == 0x00) &&
        (Adapter->StationAddress[5] == 0x00)
	    )
    {
    	DEBUGMSG(1, (TEXT("CS8900: StationAddress Modified!...\r\n")));
        Adapter->StationAddress[0] = Adapter->PermanentAddress[0];
        Adapter->StationAddress[1] = Adapter->PermanentAddress[1];
        Adapter->StationAddress[2] = Adapter->PermanentAddress[2];
        Adapter->StationAddress[3] = Adapter->PermanentAddress[3];
        Adapter->StationAddress[4] = Adapter->PermanentAddress[4];
        Adapter->StationAddress[5] = Adapter->PermanentAddress[5];
    }

    return(TRUE);
}

unsigned short CS8900RequestTransmit
(
	UINT PacketLength
	)
{
	// Request that the transmit be started after all data has been copied
	writeIoPort(IO_TX_CMD, TX_CMD_START_ALL);
	writeIoPort(IO_TX_LENGTH, (unsigned short)PacketLength);

	// Return the BusStatus register which indicates success of the request
	return CS8900ReadRegister(PKTPG_BUS_ST);
}

void CS8900CopyTxFrame
(
	PCHAR pPacket,
	UINT PacketLength
    )
{
	UINT 	i;
	PWORD	pMsg;
	WORD	PacketType, PacketOper;

	pMsg = (PWORD)pPacket;

	PacketType = *(pMsg + 6);
	PacketOper = *(pMsg + 10);

	if (PacketType == 0x0608)
	{
		if (PacketOper == 0x0100)
			DEBUGMSG(1, (TEXT("[CS8900] Send ARP Request Packet\r\n")));
		else if (PacketOper == 0x0200)
			DEBUGMSG(1, (TEXT("[CS8900] Send ARP Response Packet\r\n")));
		else if (PacketOper == 0x0300)
			DEBUGMSG(1, (TEXT("[CS8900] Send RARP Request Packet\r\n")));
		else if (PacketOper == 0x0400)
			DEBUGMSG(1, (TEXT("[CS8900] Send RARP Response Packet\r\n")));
		else
			DEBUGMSG(1, (TEXT("[CS8900] Send Unknown ARP Packet\r\n")));
	}
	else if (PacketType == 0x0008)
		DEBUGMSG(1, (TEXT("[CS8900] Send IP Packet\r\n")));
	
	for (i = 0 ; i < (PacketLength + 1) / 2; i++)
	{
		writeIoPort(IO_RX_TX_DATA_0, *pMsg);
		pMsg++;
	}
}

⌨️ 快捷键说明

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