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

📄 stoe.c

📁 台湾亚信电子ASIX11015以太网驱动.AX系列单片机带TCP/IP协议栈,和适合网络应用.希望和大家一起探讨
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 ******************************************************************************
 *     Copyright (c) 2006	ASIX Electronic Corporation      All rights reserved.
 *
 *     This is unpublished proprietary source code of ASIX Electronic Corporation
 *
 *     The copyright notice above does not evidence any actual or intended
 *     publication of such source code.
 ******************************************************************************
 */
/*=============================================================================
 * Module Name: stoe.c
 * Purpose:
 * Author:
 * Date:
 * Notes:
 * $Log: stoe.c,v $
 * Revision 1.1.1.1  2006/02/23 00:55:10  borbin
 * no message
 *
 *=============================================================================
 */

/* INCLUDE FILE DECLARATIONS */
#include "reg80390.h"
#include "stoe.h"
#include "dma.h"
#include "delay.h"
#include "interrupt.h"


/* GLOBAL VARIABLES DECLARATIONS */
LOCAL_STATION XDATA* PNetStation = {0};
BUF_DESC_PAGE XDATA* PBDP = 0;
void (*STOE_RcvCallback)(U8_T XDATA*, U16_T, U8_T); /* call eth layer rcv process
														function. */

/* LOCAL VARIABLES DECLARATIONS */
static U8_T XDATA stoe_BufferSize[STOE_SOCKET_BUFFER_SIZE] _at_ STOE_BDP_START_ADDR;
static U8_T XDATA stoe_InterruptStatus = 0;

/* LOCAL SUBPROGRAM DECLARATIONS */
static void stoe_BdpInit(void);
#if (STOE_GET_INTSTATUS_MODE == STOE_INTERRUPT_MODE)
  static void stoe_InterruptEnable(void);
#endif
static void stoe_StartOperate(void);
static void stoe_RcvHandle(void);

/*
 * ----------------------------------------------------------------------------
 * Function Name: stoe_ReadReg
 * Purpose:
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_ReadReg(U8_T regaddr, U8_T XDATA* pbuf, U8_T length)
{
	U8_T	isr;

	isr = EA;
	EA = 0;
	TCIR = regaddr;
	while (length--)
		pbuf[length] = TDR;
	EA = isr;

} /* End of stoe_ReadReg */

/*
 * ----------------------------------------------------------------------------
 * Function Name: stoe_WriteReg
 * Purpose:
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_WriteReg(U8_T regaddr, U8_T XDATA* pbuf, U8_T length)
{
	U8_T	isr;

	isr = EA;
	EA = 0;
	while (length--)
		TDR = pbuf[length];
	TCIR = regaddr;
	EA = isr;

} /* End of stoe_WriteReg */

/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_Init
 * Purpose: to initial all registers and variables of STOE. 
 * Params: network_type -0: auto- negotiation
 *						-1: fixed 100 full speed.
 *						-2: fixed 100 half speed.
 *						-3: fixed 10 full speed.
 *						-4: fixed 10 half speed.
 * Returns: none
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_Init(U8_T network_type)
{
	U8_T XDATA	temp[2];
	U8_T XDATA	value[6] = {0,0,0,0,0,0};
	U8_T		index, count;

	/* set xmit & rcv memory. */
	stoe_BdpInit();

	PNetStation = &PBDP->NetStation;

	/* source IP */
	stoe_ReadReg(STOE_IP_ADDR_REG, (U8_T XDATA*)&PNetStation->DefaultIP, 4);
	PNetStation->StationIP = PNetStation->DefaultIP;

	/* subnet mask */
	stoe_ReadReg(STOE_SUBNET_MASK_REG, (U8_T XDATA*)&PNetStation->DefaultMask, 4);
	PNetStation->SubnetMask = PNetStation->DefaultMask;

	/* gateway */
	stoe_ReadReg(STOE_GATEWAY_IP_REG, (U8_T XDATA*)&PNetStation->DefaultGateway, 4);
	PNetStation->Gateway = PNetStation->DefaultGateway;

	/* set L2 control register */
#if (STOE_TRANSPARENT == STOE_TRANSPARENT_MODE)
	temp[0] = (RX_TRANSPARENT | TX_TRANSPARENT);
#else
	temp[0] = 0;
#endif
//#if (STOE_ADD_SNAP_HEADER)
//	temp[0] |= TX_SNAP_ENABLE;
//#endif
	stoe_WriteReg(STOE_L2_CTL_REG, temp, 1);

	/* set ARP table timeout register */
	temp[0] = STOE_ARP_TIMEOUT;
	stoe_WriteReg(STOE_ARP_TIMEOUT_REG, temp, 1);

	/* set L4 control register */
#if (STOE_CHECKSUM_OFFLOAD)
	temp[0] = (DROP_CHKSUMERR_PKT | ENABLE_XMIT_CHKSUM | ENABLE_XMIT_CROSS);
#else
	temp[0] = ENABLE_XMIT_CROSS;
#endif
	stoe_WriteReg(STOE_L4_CTL_REG, temp, 1);

	/* set BDP point */
	temp[0] = (STOE_BDP_START_ADDR >> 16);
	temp[1] = (STOE_BDP_START_ADDR >> 8);
	stoe_WriteReg(STOE_L4_BDP_PNT_REG, temp, 2);

	/* receive callback function initialize to null point. */
	STOE_RcvCallback = 0;

	DMA_Init();
	DELAY_Init();
	MAC_Init(network_type);

	/* clear arp table */
	for (index = 0; index < 128 ; index++)
	{
		count = index * 2;
		stoe_WriteReg(STOE_ARP_ADDR_REG, &count, 1);
		stoe_WriteReg(STOE_ARP_DATA_REG, value, 6);
		count = ARP_CACHE_CMD_GO;
		stoe_WriteReg(STOE_ARP_CMD_REG, &count, 1);
		while (count & ARP_CACHE_CMD_GO)
			stoe_ReadReg(STOE_ARP_CMD_REG, &count, 1);
	}

} /* End of STOE_Init */

/*
* -----------------------------------------------------------------------------
 * Function Name: stoe_BdpInit
 * Purpose: initial Buffer Descriptor Page.
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_BdpInit(void)
{
	U16_T	page = (STOE_BDP_START_ADDR >> 8);

	PBDP = STOE_BDP_START_ADDR;

	// set BDP number
	PBDP->BDP_ID = 0;

	// set rcv buffer.
	PBDP->RSPP = page + 1;
	PBDP->REPP = page + PAGES_OF_RCV;
	PBDP->RHPR = PBDP->RSPP;
	PBDP->RTPR = PBDP->RSPP;
	PBDP->RFP = PAGES_OF_RCV;

	// set xmit buffer.
	PBDP->TSPP = page + 1 + PAGES_OF_RCV;
	PBDP->TEPP = page + PAGES_OF_RCV + PAGES_OF_XMIT;
	PBDP->THPR = PBDP->TSPP;
	PBDP->TTPR = PBDP->TSPP;
	PBDP->TFP = PAGES_OF_XMIT;

	// set rcv and xmit start/end buffer address.
	PBDP->RcvStartAddr = STOE_BDP_START_ADDR + 256;
	PBDP->XmtStartAddr = PBDP->RcvStartAddr + STOE_RCV_BUF_SIZE;
	PBDP->RcvEndAddr = PBDP->XmtStartAddr - 1;
	PBDP->XmtEndAddr = PBDP->XmtStartAddr + STOE_XMIT_BUF_SIZE - 1;

} /* End of stoe_BdpInit */

//#if (STOE_GET_IPADDR_TYPE == STOE_INITIAL_ASSIGN_IP)
/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_SetIPAddr
 * Purpose:
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_SetIPAddr(U32_T ip)
{
	if (ip != PNetStation->StationIP)
	{
		PNetStation->StationIP = ip;
		stoe_WriteReg(STOE_IP_ADDR_REG, (U8_T XDATA*)&PNetStation->StationIP, 4);
	}

} /* End of STOE_SetIPAddr*/

/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_SetSubnetMask
 * Purpose:
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_SetSubnetMask(U32_T subnet)
{
	if (subnet != PNetStation->SubnetMask)
	{
		PNetStation->SubnetMask = subnet;
		stoe_WriteReg(STOE_SUBNET_MASK_REG, (U8_T XDATA*)&PNetStation->SubnetMask, 4);
	}

} /* End of STOE_SetSubnetMask */

/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_Gateway
 * Purpose:
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_SetGateway(U32_T gateway)
{
	if (gateway != PNetStation->Gateway)
	{
		PNetStation->Gateway = gateway;
		stoe_WriteReg(STOE_GATEWAY_IP_REG, (U8_T XDATA*)&PNetStation->Gateway, 4);
	}

} /* End of STOE_SetGateway */ 
//#endif

/*
 * ----------------------------------------------------------------------------
 * Function Name: STOE_Start
 * Purpose: enable all used interrupts and set some register to start
 *			timer, software-dma and processing received packets.
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void STOE_Start(void)
{
	U8_T XDATA	temp;

	/* clear interrupt status */
	stoe_ReadReg(STOE_INT_STATUS_REG, &temp, 1);

#if (STOE_GET_INTSTATUS_MODE == STOE_INTERRUPT_MODE)
	/* enable STOE interrupt */
	stoe_InterruptEnable();
#endif

	/* start STOE L2/L3/L4 engines*/
	stoe_StartOperate();

	/* start DMA module */
	DMA_Start();

	/* start MAC module */
	MAC_Start();

	EXTINT4(1);	/* Enable INT4 interrupt for stoe & mac modules. */

} /* End of STOE_Start */

#if (STOE_GET_INTSTATUS_MODE == STOE_INTERRUPT_MODE)
/*
 * ----------------------------------------------------------------------------
 * Function Name: stoe_InterruptEnable
 * Purpose: enable STOE used interrupt
 * Params:
 * Returns:
 * Note:
 * ----------------------------------------------------------------------------
 */
void stoe_InterruptEnable(void)
{
	U8_T XDATA	temp;

	temp = STOE_DEFAULT_INT_MASK;
	stoe_WriteReg(STOE_INT_MASK_REG, &temp, 1);

} /* End of stoe_InterruptEnable */

/*
 * ----------------------------------------------------------------------------
 * Function Name: stoe_InterruptDisable
 * Purpose: disable STOE used interrupt
 * Params:

⌨️ 快捷键说明

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