📄 fenetpq2.c
字号:
/*-----------------------------------------------------------*/
/* In this architecture, every frame encompasses a buffer */
/* descriptor's worth of data. This a very simple example. */
/* Normally there could be several BD's in a frame, and once */
/* a data buffer was processed, it could be released for */
/* use. */
/* */
/* Although not invoked in this example, lines to that */
/* are included here for the user's benefit, and to */
/* represent where BD handling could occur in a more */
/* complete handler. */
/* */
/* In this example, EVERY BD is the first and last BD in */
/* frame, so the following IF will not test true in this */
/* example. */
/*-----------------------------------------------------------*/
if(!LastBD(RxTxBD->RxBD[index].bd_cstatus ))
{
RxTxBD->RxBD[index].bd_cstatus |= 0x8000; /* set empty flag */
/*-------------------------------------*/
/* checking all status bits for errors */
/*-------------------------------------*/
if (BDRxError(RxTxBD->RxBD[index].bd_cstatus ))
RxGood = FALSE;
}
/*------------------------------------------*/
/* Again, the following line is included */
/* merely as an example. */
/* */
/* This is the last BD in the chain. Clear */
/* all bits but the Ready bit and Wrap bit. */
/*------------------------------------------*/
/* if (index == (NUM_RXBDS-1))
RxTxBD->RxBD[index].bd_cstatus = 0xA000; */
/*------------------------------------*/
/* Set RX process index to start next */
/* BD scan from the BD after this one */
/*------------------------------------*/
RxProcIndex = index+ 1;
if (RxProcIndex == 8)
NotDone=FALSE;
index++;
}
}
else
RxGood = FALSE; /* Expected to see RXF event in FCCE */
/*-------------------------------------*/
/* Here's our error loop. Spin here */
/* indefinitely if there was an error. */
/*-------------------------------------*/
if (RxGood == FALSE)
{
Led(GREEN);
while (1); /* spin here if error is flagged */
};
} /* end ExtIntHandler */
/*--------------------------------------------------------------------------
*
* FUNCTION NAME: BDRxError
*
* DESCRIPTION:
*
* Return TRUE if Buffer Descriptor Status bd_cstatus indicates Receive
* Error; Return FALSE otherwise note Receive Errors are as follows:
*
* 0x80: DPLL Error (DE)
* 0x20: Length Violation (LG)
* 0x10: Non-Octet Aligned (NO)
* 0x8: Rx Abort Sequence (AB)
* 0x4: Rx CRC Error (CR)
* 0x2: Overrun (OV)
* 0x1: Carrier Detect Lost (CD)
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS:
*
* bd_cstatus
*
* RETURNS: TRUE if there was an error and FALSE if there wasn't
*
*-------------------------------------------------------------------------*/
UHWORD BDRxError(UHWORD bd_cstatus)
{
if (bd_cstatus & BD_RX_ERROR)
return TRUE;
else
return FALSE;
} /* end BDRxError */
/*--------------------------------------------------------------------------
*
* FUNCTION NAME: LastBD
*
* DESCRIPTION: Return TRUE if Buffer Descriptor with status and
* control register bd_cstatus is last in frame; Return
* FALSE otherwise.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS:
*
* bd_cstatus -
*
* RETURNS:
*
*-------------------------------------------------------------------------*/
UHWORD LastBD(UHWORD bd_cstatus)
{
if (bd_cstatus & 0x0800)
return TRUE;
else
return FALSE;
} /* end LastBD */
/*--------------------------------------------------------------------------
*
* FUNCTION NAME: BDEmpty
*
* DESCRIPTION:
*
* Return TRUE if Buffer Descriptor Status bd_cstatus is empty. Return
* FALSE otherwise.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS:
*
* bd_cstatus
*
* RETURNS: TRUE if empty and FALSE if it isn't
*
*-------------------------------------------------------------------------*/
UHWORD BDEmpty(UHWORD bd_cstatus)
{
if (bd_cstatus & 0x8000)
return TRUE;
else
return FALSE;
} /* end BDEmpty */
/*--------------------------------------------------------------------------
*
* FUNCTION NAME: Led
*
* DESCRIPTION:
*
* Turn On/Off either the Green or Red LED on 8260 VADS board.
*
* EXTERNAL EFFECTS:
*
* PARAMETERS:
*
* setting - 0 turns off LED; otherwise turn on LED.
*
* RETURNS: NONE
*
*--------------------------------------------------------------------------*/
void Led(UHWORD setting)
{
switch(setting)
{
/* Turn red and green LEDs off */
case OFF:
if (Revision == 1)
CSR->bcsr0 |= (GP_LED0_PIL | GP_LED1_PIL);
else
CSR->bcsr0 |= (GP_LED0_ENG | GP_LED1_ENG);
break;
/* Turn green LED on */
case GREEN:
if (Revision == 1)
CSR->bcsr0 &= ~GP_LED0_PIL;
else
CSR->bcsr0 &= ~GP_LED0_ENG;
break;
/* Turn red LED on */
case RED:
if (Revision == 1)
CSR->bcsr0 &= ~GP_LED1_PIL;
else
CSR->bcsr0 &= ~GP_LED1_ENG;
break;
/* Turn red LED on to indicate an error */
default:
if (Revision == 1)
CSR->bcsr0 &= ~GP_LED1_PIL;
else
CSR->bcsr0 &= ~GP_LED1_ENG;
}
} /* end Led */
/*--------------------------------------------------------------------------
*
* FUNCTION NAME: FlashLed
*
* DESCRIPTION: This function flashes the Red LED on the 8260 Board.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: none
*
* RETURNS: None
*
*--------------------------------------------------------------------------*/
void FlashLed()
{
UBYTE ii;
UWORD jj;
for (ii = 0; ii<20; ii++)
{
Led(ii%2); /* Turn on every other time through the loop */
for (jj=0; jj < 100000; jj++); /* Wait */
}
Led(OFF); /* LED off */
} /* end FlashLed */
/*--------------------------------------------------------------------------
*
* FUNCTION NAME: SetEEinMSR
*
* DESCRIPTION:
*
* Enables external interrupts in the core by setting EE bit (bit 16)
* in MSR.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: none
*
* RETURNS: none
*-------------------------------------------------------------------------*/
void SetEEinMSR(void)
{
/* NOTE: This is syntax for the DIAB compiler. You may need to alter it
for other compilers */
asm(" mfmsr r3 ");
asm(" ori r3,r3,0x8000 ");
asm(" mtmsr r3 ");
} /* end SetEEinMSR */
/*----------------------------------------------------------------------------
*
* FUNCTION NAME: InitLxt970Transceiver
*
* DESCRIPTION:
*
* Initializes the Lxt970 transceiver. Test frames to make sure data is
* being written correctly.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: None
*
* RETURNS: -1 if frames are not being written correctly, 0 if they are
*
*---------------------------------------------------------------------------*/
int InitLxt970Transceiver()
{
int i;
MdioFrame(WRITE,0,16,0xdead); /* send test frame */
i = MdioFrame(READ,0,16,0); /* read test frame */
if (i != 0xdead) /* Check to see that test frame was written correctly */
return -1; /* test frame is not written correctly */
MdioFrame(WRITE,0,4, 0x0101); //100 Mbps Full Duplex and 802.3
MdioFrame(WRITE,0,19,0x5000); //0x5008); //0x1008); //0x5000);
MdioFrame(WRITE,0,17,0x0002);
MdioFrame(WRITE,0,0, 0x2100); // 0x3300
return 0;
} /* end InitLxt970Transceiver */
/*----------------------------------------------------------------------------
*
* FUNCTION NAME: MdioFrame
*
* DESCRIPTION:
*
* Sends frames to the Lxt970 transceiver.
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: None
*
* RETURNS: Data
*
*---------------------------------------------------------------------------*/
int MdioFrame(int R_W, int PhyAddr, int RegAddr, int PutData)
{
unsigned int GetData;
IMM->io_regs[PORTC].pdir |= MDIO_PIN_MASK; //set to output mode
MdioSend(0xFFFFFFFF,32); //PreAmble
MdioSend(0x1,2); /* Start Frame Delimiter */
if (R_W)
MdioSend(0x2,2); /* Read OpCode */
else
MdioSend(0x1,2); /* Write OpCode */
MdioSend(PhyAddr,5); /* Send PHY transciever Address */
MdioSend(RegAddr,5); /* Send Register Address */
if (R_W)
{ /* if read */
IMM->io_regs[PORTC].pdir &= ~MDIO_PIN_MASK; /* set to input mode */
GetData = MdioReceive(17); /* Drive TurnAround and Data */
MdioReceive(2);
}
else
{ /* if write */
MdioSend(0x2,2); /* Drive TurnAround */
MdioSend(PutData, 16); /* Send Data */
GetData = 0;
IMM->io_regs[PORTC].pdir &= ~MDIO_PIN_MASK; /* set to input mode */
}
return GetData;
} /* end MdioFrame */
/*----------------------------------------------------------------------------
*
* FUNCTION NAME: MdioSend
*
* DESCRIPTION:
*
* Shift out bits of data
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: None
*
* RETURNS: Data
*
*---------------------------------------------------------------------------*/
void MdioSend( UWORD txF, int size)
{
UWORD dmask;
int i,j; /* index */
dmask = 1 << (size-1); /* msbit out first */
for ( i = 0; i < size; i++ )
{ /* for "size" bits */
if ( txF & dmask )
{ /* output data bit high */
IMM->io_regs[PORTC].pdat |= MDIO_PIN_MASK;
}
else
{ /* output data bit low, >400ns */
IMM->io_regs[PORTC].pdat &= ~MDIO_PIN_MASK;
}
/* >10ns */
IMM->io_regs[PORTC].pdat |= MDC_PIN_MASK; /* clock rise */
txF = (UWORD)(txF << 1); /* >160ns */
for (j=0; j<40; j++);
IMM->io_regs[PORTC].pdat &= ~MDC_PIN_MASK; /* clock fall */
for (j=0; j<40; j++);
}
} /* end MdioSend */
/*----------------------------------------------------------------------------
*
* FUNCTION NAME: MdioReceive
*
* DESCRIPTION:
*
* Shift out bits of data
*
* EXTERNAL EFFECTS: None
*
* PARAMETERS: None
*
* RETURNS: Data
*
*---------------------------------------------------------------------------*/
UWORD MdioReceive(int size)
{
int i,j,rxF; /* index */
rxF = 0x0;
for ( i = 0; i < size; i++ )
{ /* 16 bits */
IMM->io_regs[PORTC].pdat |= MDC_PIN_MASK; /* clock rise */
if ( IMM->io_regs[PORTC].pdat & MDIO_PIN_MASK )
{
/* if read in a high bit */
rxF = ( (UHWORD)(rxF << 1) | 1 ); /* shift in a one */
}
else
{ /* if read in a low bit */
rxF = ( (UHWORD)(rxF << 1) & ~(UHWORD)1 ); /* shift in a zero */
}
for (j=0; j<40; j++);
IMM->io_regs[PORTC].pdat &= ~MDC_PIN_MASK; /* clock fall */
for (j=0; j<40; j++);
} /* end of for loop */
return rxF;
} /* end MdioReceive */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -