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

📄 mac_template.c

📁 zilog z80f91单片机的网络接口函数
💻 C
📖 第 1 页 / 共 2 页
字号:
 *               protocol layers to process the packet.                       *
 *                                                                            *
 * Output:                                                                    *
 * 	EMACDEV_ERR_PEMAC_INIT_DONE	- Initialization was completeled successfully.*
 *                                                                            *
 * Notes:                                                                     *
 * - The upper layers ignore the status returned by this routine.  If an      *
 * error occurs on initialization, a text message can be displayed on the     *
 * console using kprintf.  If the error is fatal, the panic API can be used   *
 * which displays a message on the console and purposely hangs the system.    *
 *	- It is assumed that this routine has a means to determine which eZ80     * 
 * interrupt is connected to the NIC.  (This may simply be a compile time     * 
 * constant).                                                                 *
 ******************************************************************************
 */
DDF_STATUS_t 
EthInitFunc
(			
 INT8 *				ieeeaddr,
 void *				(*rxnotify)( void )
)
{

	/*
	 * Hold on to the Rx callback address so it can be used from the ISR.
	 */
	rxnotifyfunc = rxnotify;

	/*
	 * Program the ieeeaddr into the controller if applicable.
	 * Enable unicast and broadcast reception.
	 */

 	/*
	 * Create an Interrupt Task to process interrupt events.
	 * Once created, this task will be in Suspend state.  When an interrupt
	 * occurs the assembly ISR should disable interrupt generation by the 
     * Ethernet HW controller and then schedule the interrupt task for execution.
	 * Once the interrupt task has finished processing interrupt events, it
	 * should re-enable interrupt generation by the Ethernet HW and self-suspend.
	 */

/* Create Interrupt thread */
	emacInterruptThdHdl = RZKCreateThread((RZK_NAME_t*)"EMAC_TASK",
													(RZK_PTR_t)F91EmacTask, 
													( FNP_THREAD_ENTRY* )NULL, 
													(EMAC_Task_Stack+EMAC_THD_STACK_SIZE), 
													EMAC_TASK_PRIO, 
													2,
													RZK_THREAD_INTERRUPT|RZK_THREAD_PREEMPTION,
													0 ) ;

	/*
	 * Enable interrupt generation on the controller (if applicable).
	 */
	// setup EMAC interrupts
//	RZKInstallInterruptHandler( (RZK_PTR_t)emacisr, IV_ERX) ;
//	RZKInstallInterruptHandler( (RZK_PTR_t)emacisr, IV_ETX) ;
//	RZKInstallInterruptHandler( (RZK_PTR_t)emacisr, IV_ESYS) ;
	
	// program the controller to generate Rx and Tx interrupts

	/*
	 * If an interrupt is not going to be used for event processing this routine
	 * should create a background thread to check for HW events.  This may have
	 * a severe impact on performance.
	 */

	return (EMACDEV_ERR_PEMAC_INIT_DONE);
}



/*
 ******************************************************************************
 *                               EthPktTransmit                               *
 *                                                                            *
 *	Transmit Packet function.                                                 *
 *                                                                            *
 * Description:  The mac library will call this routine when a frame needs to *
 * be transmitted.                                                            *
 *                                                                            *
 * Input:                                                                     *
 * 	pep - Pointer to an Ethernet packet.  This structure contains the         *
 *          Ethernet Header and data that is to be transmitted on the link.   *
 *                                                                            *
 * Output:                                                                    *
 * 	Packet Length			 Indicates the successful completion of a		  *
							 synchronous Tx									  *	
 *  EMACDEV_ERR_TX_WAITING	 Indicates the MAC has accepted the given frame   *
							 for later transmission on the link.  In this case*
							 it will be necessary for your driver to call     *
							 FreePktBuff(pep); when the	frame has been		  *
							 transmitted									  *
 *																			  *
 *	EMACDEV_ERR_PKTTOOBIG	 Indicates that the MAC is unable to transmit     *
				this frame because it exceeds the maximum frame size supported* 
				by the HW or SW driver.                                       *
 *                                                                            *
 * Notes:                                                                     *
 * - The MAC writer is free to define other status codes and add them to	  *
 *	EMACDEV_ERR_NUMS enumerator.  These will be treated as an error by the	  *
	upper layers resulting in the packet being discarded.                     *
 ******************************************************************************
 */

DDF_STATUS_t EthPktTransmit (ETH_PKT_t *	pep )
{
DDF_STATUS_t  status = pep->ethPktLen ;

	return( status );	// return the length of the packet transmitted is tx is successful

}



/*
 ******************************************************************************
 *                               ReceiveEthPkt                                *
 *                                                                            *
 *	HW Packet Reception function.                                             *
 *                                                                            *
 * Description:  The mac library will call this routine when it is ready to   *
 * copy the frame data from HW into an internal MAC buffer.                   *
 *                                                                            *
 * Input:                                                                     *
 * 	databuf - pointer to the MAC structure used to hold received packets.     *
 *                                                                            *
 * Output:                                                                    *
 * 	<none>                                                                    *
 *                                                                            *
 * Notes:                                                                     *
 * - This routine is called by the rxnotifyfunc during processing of an Rx    *
 * packet.                                                                    *
 * - If an error occurs preventing the entire frame from being copied into    *
 * databuff, set the databuff->Length to 0.                                   *
 * - Do not copy frames with errors (e.g. over-run or CRC error) into databuf *
 * since the upper layers assume that the MAC-level data in databuff is       *
 * error free.                                                                *
 ******************************************************************************
 */

void ReceiveEthPkt(EMAC_FRAME_t * databuff)
{

	/*
	 * Copy frame from HW into databuff.  The first byte of the Ethernet 
	 * destination address should be copied into databuff->DstAddr[0].  From
	 * this point, copy the DA,SA, Type and body fields of the Ethernet frame.
	 * Do not copy the received CRC into databuf.
	 */
	// RZKMemCopy( &databuff->DstAddr[0], HW_Rx_Frame_Buffer, length_minus_CRC );

	/*
	 * Update HW registers to indicate that this frame has been processed.
	 */


}




/*
 ******************************************************************************
 *                               F91EmacTask                                  *
 *                                                                            *
 *	Ethernet Interrup Service Routine.                                        *
 *                                                                            *
 * Description:  The routine is called if the Init function claims a system   *
 * interrupt, interupts have been enabled on the controller, and the          *
 * corresponding trigger event has occured.  Otherwise the types of           *
 * operations performed in this routine should be done by a polling thread.   *
 *                                                                            *
 * Input:                                                                     *
 * 	<none>										                              *
 *                                                                            *
 * Output:                                                                    *
 * 	<none>											                          *
 *                                                                            *
 * Notes:                                                                     *
 ******************************************************************************
 */

void F91EmacTask( void )
{
	INT8								bIntStat;
	UINTRMASK intmask ;
	
	while( 1 )
	{
		/*
		 * Consult the HW register set for the controller used in your design to 
		 * determine the source of the interrupt.  Keep looping until all interrupt
		 * events have been processed.
		 */
		//	while( InterruptEvent )
		{
			/*
			 * Decide whether this is an Rx, Tx or Status event.  If this is a receive
			 * interrupt and a valid packet is ready to be processed, call rxnotify().
			 */
			if( rxnotifyfunc )
			{
				rxnotifyfunc();
			}

			/*
			 * If your driver queues Tx packets then when a transmit complete interrupt
			 * occurs, check to see if another packet is available on the transmit queue.
			 */
		}

		/*
		 * Note that rxnotify will place the msg on the IP Message Queue. The receive process *
		 * will recieve the message when it gets scheduled.									  *
	    */


		/*
		 * All interrupt events have been processed.  Disable maskable interrupts while
		 * interrupt generation is re-enabled on the Ethernet controller.  Maskable interrupts
		 * are re-enabled Just after the thread comes out of suspension.
		 */

		intmask = RZKDisableInterrupts() ;
		/*
		 * Re-enable interrupt generation by the emac controller
		 */

		/*
		 * Self suspend the interrupt task.  This task will not run again until the next
		 * Ethernet interrupt event occurs and the emac ISR reschedules this task.
		 */
		RZKSuspendInterruptThread() ;

		RZKEnableInterrupts(intmask) ;

	}
}











⌨️ 快捷键说明

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