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

📄 ethernet.c

📁 网口收发程序
💻 C
📖 第 1 页 / 共 3 页
字号:
   /* Issue Init RX & TX Parameters Command for SCC1. This command to */
   /* the CP lets it know to reinitialize SCC1 with the new parameter */
   /* RAM values. When the ENT/ENR bits are set below Hunt Mode will  */
   /* begin automatically.                                            */
   /*-----------------------------------------------------------------*/

   while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD); 

	IMM->cpm_cpcr = CPCR_INIT_TX_RX_PARAMS |
		   SCC1_PAGE_SUBBLOCK | 
		   CPCR_FLG;              /* ISSUE COMMAND */

   while ((IMM->cpm_cpcr & CPCR_FLG) != READY_TO_RX_CMD); 

   /*-------------------------------------------------------------*/
   /* Set the ENT/ENR bits in the GSMR -- Enable Transmit/Receive */
   /*-------------------------------------------------------------*/

   IMM->scc_regs[SCC1].gsmr_l |= GSMR_L1_ENT | GSMR_L1_ENR;

} /* end SCC1EtherInit() */


/*--------------------------------------------------------------------------
*
* FUNCTION NAME: InterruptInit
*
*
* DESCRIPTION:
*
*     Copy Interrupt Handler code from its current address to the 
*     specified PowerPC Interrupt Vector.
*
* EXTERNAL EFFECTS:
*
* PARAMETERS:  
*
*     interrupt_vector -- address to which interrupt code should be copied
*     interrupt_code   -- current address of interrupt code
*
* RETURNS: NONE
*
*--------------------------------------------------------------------------*/

void InterruptInit(UWORD *interrupt_vector,
		   UWORD interrupt_code[])

{

   UHWORD index;
   UWORD *instruction;
   UWORD *next_vector;
   
   /*-------------------*/
   /* next vector entry */
   /*-------------------*/
   
   next_vector = (interrupt_vector + VECTOR_BLOCK_LEN); 

   for(instruction = interrupt_vector, index = 0; instruction < next_vector;
       instruction++, index++)
      
      *instruction = interrupt_code[index];

} /* end InterruptInit */


/*--------------------------------------------------------------------------
*
* 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: ExtIntHandler
*
* DESCRIPTION:
*
*     Process External Interrupt (assumes only interrupts from SCC1)
*
*
* EXTERNAL EFFECTS:  interrupt related registers
*
* PARAMETERS:
*
*     vector - interrupt vector (address)
*
* RETURNS: NONE
*
*-------------------------------------------------------------------------*/

void ExtIntHandler(UWORD vector)

{

   UWORD    sivec_ic;
   UWORD    scce;
   UHWORD  ethernet_bd_status;

   /*------------------------------------*/
   /* Shift the byte wide interrupt code */
   /* down to the least significant byte */
   /*------------------------------------*/

   sivec_ic = IMM->ic_sivec >> 26;   /* sivec interrupt code */


   /*-----------------------------*/
   /* Grab the SCC event register */
   /*-----------------------------*/

   scce = IMM->scc_regs[SCC1].scce; /* Save off scce */


   /*------------------------------------*/
   /* Match input vector against Exteral */
   /* Interrupt Vector -- 0x500 on PPC   */
   /*------------------------------------*/

   if (vector != EXT_INT_VECTOR) 

   {
   
      while (1) 
      
		FlashLed();   /* spin here if error is flagged */
	 
   };
   
   /*-----------------------------------------------*/
   /* Test CPM Interrupt Vector against SCC1 Vector */
   /* Flash red GP1 LED is not vector for SCC1      */
   /*-----------------------------------------------*/

   if (sivec_ic !=  SCC1_VECTOR) 
   
    {
       while (1)

	 	FlashLed();

    };
    
    
   /*-----------------------------*/
   /* Process SIU Interrupt Event */
   /*-----------------------------*/
    
   if (IMM->ic_sipnr_l != 0x00800000)
   
   {
      while (1)

		FlashLed();
	
   }


   /*-------------------------------------------*/
   /* Clear SCC1 Event Register (by writing 1s) */
   /*-------------------------------------------*/

   IMM->scc_regs[SCC1].scce = 0xFFFF;

   /*-------------------------------------------------------------*/
   /* Process SCC Ethernet Event if the event flag for RXF is set */
   /*-------------------------------------------------------------*/

   if (scce & ENET_SCCM_RXF) 
   
   {
      
	/*-------------------------------------------------------------------*/
	/* Traverse from last processed Rx buffer descriptor and process all */
	/* all subsequent buffers that have the empty bit cleared.           */
	/*-------------------------------------------------------------------*/
     
	for (;(RxProcIndex < NUM_RXBDS)&&
	      (!BDEmpty(RxTxBD->RxBD[RxProcIndex].bd_cstatus));
	      RxProcIndex++)
       
	     
	{
	     /*--------------------------------------*/
	     /* Copy Status of Rx Buffer Descriptors */
	     /*--------------------------------------*/

	     ethernet_bd_status = RxTxBD->RxBD[RxProcIndex].bd_cstatus;

	    /*-------------------------------------*/
	    /* Compare the receive buffer with its */                  
	    /* corresponding transmit buffer.      */
	    /* (exclude the 4 CRC bytes for this)  */                                               
	    /*-------------------------------------*/

	    if (memcmp(&RxBufferPool[RxProcIndex],
		       &TxBufferPool[RxProcIndex],
		       (TX_BUFFER_SIZE-4)))
	    {
	       RxGood=FALSE; /* they didn't compare */
	    }

	    else

	       RxGood=TRUE;  /* they did compare */

	    /*-------------------------------------*/
	    /* checking all status bits for errors */
	    /*-------------------------------------*/

	    if (BDRxError(ethernet_bd_status)) 
	    
		RxGood = FALSE;
	     
	
       }                                

   }    

   else 
	
	
      RxGood = FALSE; /* Expected to see RXF event in SCCE */

   /*-------------------------------------*/
   /* Here's our error loop. Spin here    */
   /* indefinitely if there was an error. */
   /*-------------------------------------*/

   if (RxGood == FALSE) 
   
   {
      while (1) 
      
		Led(GREEN);  /* spin here if error is flagged */
   } 


   /*--------------------------------------------------------------------*/
   /* If we've processed all 8 frames, enter into the next while loop in */
   /* main() to light General Purpose Signalling LED #0 green. We also   */
   /* need to clear the event register again which will also clear the   */
   /* SIU Interrupt Pending Register High (SIPNR_H) so that another      */
   /* interrupt doesn't occur when we just finished processing the last  */
   /* one.                                                               */
   /*--------------------------------------------------------------------*/

   if (RxProcIndex == 8)  

   {
      NotDone=FALSE;
      IMM->scc_regs[SCC1].scce = 0xFFFF;
   }

 
} /* end ExtIntHandler */



/*--------------------------------------------------------------------------
*
* FUNCTION NAME: Led
*
* DESCRIPTION:
*
*     Turn On/Off either the Green or Red LED on ADS 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:
             CSR->bcsr0 |= (GP_LED1 | GP_LED2); 
             break;

        /* Turn green LED on */
        case GREEN:
             CSR->bcsr0 &= ~GP_LED1;
             break;

        /* Turn red LED on */
        case RED:
             CSR->bcsr0 &= ~GP_LED2;
             break;

        /* Turn red LED on to indicate an error */
        default:
             CSR->bcsr0 &= ~GP_LED2;        
     }

} /* end Led */

/*--------------------------------------------------------------------------
*
* FUNCTION NAME:  FlashLed
*
* DESCRIPTION:  This function flashes the Red LED on the ADS 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 */





⌨️ 快捷键说明

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