?? macutil.c
字號:
#include <string.h>
#include "std.h"
#include "sysconf.h"
#include "snds.h"
#include "isr.h"
#include "mac.h"
//下面是為協(xié)議棧的存在而添加的
#include "netif.h"
#include "eth4510if.h"
#include "OS_CPU.h"
/*
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include "uart.h"
#include "pollio.h"
#include "timer.h"
#include "memory.h"
#include "iic.h"
*/
sFrameDescriptor RxFDBaseAddr[MaxRxFrameDescriptors]; // Tx Frame Descriptor
sMACFrame RxFBABaseAddr[MaxRxFrameData]; // Tx Frame Buffer
sFrameDescriptor TxFDBaseAddr[MaxTxFrameDescriptors]; // Rx Frame Descriptor
sMACFrame TxFBABaseAddr[MaxTxFrameData]; // Rx Frame Buffer
// Global variables used for MAC driver
volatile U32 gMacCon = FullDup ;
volatile U32 gMacTxCon = EnComp ;
volatile U32 gMacRxCon = RxEn | StripCRC ;
volatile U32 gBdmaTxCon = BTxBRST | BTxMSL110 | BTxSTSKO ;
volatile U32 gBdmaRxCon = BRxDIE | BRxEn | BRxLittle | BRxMAINC | BRxBRST | \
BRxNLIE | BRxNOIE | BRxSTSKO ;
volatile U32 gCamCon = CompEn | BroadAcc | GroupAcc;
volatile U32 gDuplexValue = 0 ;
volatile U32 gCTxFDPtr, gWTxFDPtr ;
volatile U32 gCRxFDPtr, gPreviousFdp=0 ;
volatile U32 gCam0_Addr0 = 0 , gCam0_Addr1 = 0 ;
volatile U8 MyMacSrcAddr[6] ;
volatile int WatchDogTime = 0 ;
volatile int gErrorPacketCnt =0 ;
volatile int BdmaRxDoneFlagForLoopBackCheck = 0 ;
volatile int MacTxDoneFlagForLoopBackCheck = 0 ;
// Global variable structure for store status
pMACTxStatus gsMacTxStatus = {0,0,0,0,0,0,0,0,0,0,0} ;
pMACRxStatus gsMacRxStatus = {0,0,0,0,0,0,0,0,0} ;
pBDMATxStatus gsBdmaTxStatus = {0,0,0} ;
pBDMARxStatus gsBdmaRxStatus = {0,0,0,0,0} ;
//網(wǎng)絡(luò)初始化
void LanInitialize(void)
{
//配置物理收發(fā)設(shè)備
ResetPhyChip() ;
//獲取MAC層網(wǎng)卡硬件物理地址
GetMyMacAddr() ;
// Initialize MAC and BDMA controller
MacInitialize() ;
}
/*
* void MacInitialize(void)
* Initialize MAC and BDMA Controller
*/
void MacInitialize(void)
{
/*-----------------------------------------------------------------*
* 1. Disable MAC and BDMA interrupts. *
*-----------------------------------------------------------------*/
Disable_Int(nMAC_RX_INT) ; // Disable MAC Rx Interrupt
Disable_Int(nMAC_TX_INT) ; // Disable MAC Tx Interrupt
Disable_Int(nBDMA_RX_INT) ; // Disable BDMA Rx Interrupt
Disable_Int(nBDMA_TX_INT) ; // Disable BDMA Tx Interrupt
/*-----------------------------------------------------------------*
* 2. BDMA and MAC interrupt vector setup. *
*-----------------------------------------------------------------*/
SysSetInterrupt(nMAC_RX_INT, MAC_Rx_isr) ;
SysSetInterrupt(nMAC_TX_INT, MAC_Tx_isr) ;
SysSetInterrupt(nBDMA_RX_INT, BDMA_Rx_isr) ;
SysSetInterrupt(nBDMA_TX_INT, BDMA_Tx_isr) ;
/*-----------------------------------------------------------------*
* 3. Set the initial condition of the BDMA, and MAC *
*-----------------------------------------------------------------*/
BDMARXCON = BRxRS ; // Reset BDMAC Receiver
BDMATXCON = BTxRS ; // Reset BDMAC Transceiver
MACCON = SwReset ;
BDMARXLSZ = MaxRxFrameSize+40 ; // 1520
MACCON = gMacCon ;
/*-----------------------------------------------------------------*
* 4. Set the BDMA Tx/Rx Frame Descriptor *
*-----------------------------------------------------------------*/
TxFDInitialize() ;
RxFDInitialize() ;
/*-----------------------------------------------------------------*
* 5. Set the CAM Control register and the MAC address value *
*-----------------------------------------------------------------*/
// CAM0 register of CAM registers : 0x9100~0x9103, 0x9104, 0x9105
CAM_Reg(0) = gCam0_Addr0;
CAM_Reg(1) = gCam0_Addr1;
// CAM Enable Register(CAMEN)
CAMEN = 0x0001 ;
CAMCON = gCamCon ;
/*-----------------------------------------------------------------*
* 6. Enable interrupt BDMA Rx and MAC Tx interrupt. *
*-----------------------------------------------------------------*/
Enable_Int(nBDMA_RX_INT);
Enable_Int(nMAC_TX_INT);
//Enable_Int(nMAC_RX_INT);
/*-----------------------------------------------------------------*
* 7. Configure the BDMA and MAC control registers. *
*-----------------------------------------------------------------*/
ReadyMacTx() ;
ReadyMacRx() ;
}
/*
* void TxFDInitialize(void) ;
* Initialize Tx frame descriptor area-buffers.
*/
void TxFDInitialize(void)
{
sFrameDescriptor *pFrameDescriptor;
sFrameDescriptor *pStartFrameDescriptor;
sFrameDescriptor *pLastFrameDescriptor = NULL;
U32 FrameDataAddr;
U32 i;
// Get Frame descriptor's base address.
// +0x4000000 is for setting this area to non-cacheable area.
BDMATXPTR = (U32)TxFDBaseAddr + 0x4000000;
gWTxFDPtr = gCTxFDPtr = BDMATXPTR;
// Get Transmit buffer base address.
FrameDataAddr = (U32)TxFBABaseAddr + 0x4000000;
// Generate linked list.
pFrameDescriptor = (sFrameDescriptor *) gCTxFDPtr;
pStartFrameDescriptor = pFrameDescriptor;
for(i=0; i < MaxTxFrameDescriptors; i++) {
if(pLastFrameDescriptor == NULL)
pLastFrameDescriptor = pFrameDescriptor;
else pLastFrameDescriptor->NextFrameDescriptor = (U32)pFrameDescriptor;
pFrameDescriptor->FrameDataPtr =
(U32)(FrameDataAddr & fOwnership_CPU);
pFrameDescriptor->Reserved = (U32)0x0;
pFrameDescriptor->StatusAndFrameLength = (U32)0x0;
pFrameDescriptor->NextFrameDescriptor = NULL;
pLastFrameDescriptor = pFrameDescriptor;
pFrameDescriptor++;
FrameDataAddr += sizeof(sMACFrame);
} // end for loop
// Make Frame descriptor to ring buffer type.
pFrameDescriptor--;
pFrameDescriptor->NextFrameDescriptor = (U32)pStartFrameDescriptor;
}
/*
* void RxFDInitialize(void) ;
* Initialize Rx frame descriptor area-buffers.
*/
void RxFDInitialize(void)
{
sFrameDescriptor *pFrameDescriptor;
sFrameDescriptor *pStartFrameDescriptor;
sFrameDescriptor *pLastFrameDescriptor = NULL;
U32 FrameDataAddr;
U32 i;
// Get Frame descriptor's base address.
// +0x4000000 is for setting this area to non-cacheable area.
BDMARXPTR = (U32)RxFDBaseAddr + 0x4000000;
gCRxFDPtr = BDMARXPTR;
// Get Transmit buffer base address.
FrameDataAddr = (U32)RxFBABaseAddr + 0x4000000;
// Generate linked list.
pFrameDescriptor = (sFrameDescriptor *) gCRxFDPtr;
pStartFrameDescriptor = pFrameDescriptor;
for(i=0; i < MaxRxFrameDescriptors; i++) {
if(pLastFrameDescriptor == NULL)
pLastFrameDescriptor = pFrameDescriptor;
else pLastFrameDescriptor->NextFrameDescriptor = (U32)pFrameDescriptor;
pFrameDescriptor->FrameDataPtr =
(U32)(FrameDataAddr | fOwnership_BDMA | 0x4000000 );
pFrameDescriptor->Reserved = (U32)0x0;
pFrameDescriptor->StatusAndFrameLength = (U32)0x0;
pFrameDescriptor->NextFrameDescriptor = NULL;
pLastFrameDescriptor = pFrameDescriptor;
pFrameDescriptor++;
FrameDataAddr += sizeof(sMACFrame);
} // end for loop
// Make Frame descriptor to ring buffer type.
pFrameDescriptor--;
pFrameDescriptor->NextFrameDescriptor = (U32)pStartFrameDescriptor;
}
/*
* Function : ReadyMacTx
* Description : set Tx Registers related with BDMA & MAC to transmit
* packet.
*/
void ReadyMacTx(void)
{
BDMATXCON = gBdmaTxCon ;
MACTXCON = gMacTxCon ;
}
/*
* Function : ReadyMacRx
* Description : set Rx Registers related with BDMA & MAC to Receive packet.
*/
void ReadyMacRx(void)
{
BDMARXCON = gBdmaRxCon ;
MACRXCON = gMacRxCon ;
}
/*
* Function : MacTxGo
* Description : MAC Transfer Start for interactive mode
*/
void MacTxGo(void)
{
// Enable MAC and BDMA Transfer
if (!(BDMATXCON & BTxEn)) BDMATXCON |= BTxEn ;
MACTXCON |= TxEn ;
}
/*
* Function : GetMyMacAddr
* Description : Get MAC Address From IIC EEPROM
*/
void GetMyMacAddr(void)
{
U8 MacAddr[MAC_ADDR_SIZE];
U8 TempAddr[MAC_ADDR_SIZE];
int i;
gCam0_Addr0 = gCam0_Addr1 = 0 ;
MacAddr[0] = 0x55 ;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -