?? cs8900a.c
字號:
/****************************************************************************/
/* */
/* FILENAME VERSION */
/* */
/* CS8900A.C 2001年6月30日 0.91 */
/* */
/* DESCRIPTION */
/* */
/* 該文件包括所有與CS8900A網絡芯片的接口程序,處理初始化、傳輸數據和 */
/* 錯誤處理。 */
/* */
/* DATA STRUCTURES */
/* */
/* Check in file 'CS8900A.h' */
/* */
/* FUNCTIONS */
/* */
/* CS8900A_Init */
/* CS8900A_Get_Address */
/* CS8900A_Set_Address */
/* CS8900A_Open */
/* CS8900A_Recv_Packet */
/* CS8900A_Xmit_Packet */
/* CS8900A_Transmit */
/* CS8900A_LISR */
/* CS8900A_Recv_HISR */
/* CS8900A_Chip_Write */
/* CS8900A_Chip_Read */
/* CS8900A_Reset */
/* CS8900A_Delay */
/* */
/****************************************************************************/
#include "nucleus.h"
#include "externs.h"
//#include "net/inc/protocol.h"
#include "net/inc/tcp_errs.h"
#include "target.h"
#include "driver.h"
#include "xdrvdev.h"
//#include "2410slib.h"
//#if SNMP_INCLUDED
#if INCLUDE_SNMP // == NU_TRUE)
#include "snmp.h"
#endif
//#include "data.h"
#include "CS8900A.h"
#include "net.h"
#include "mem_defs.h"
/* Receive and Transmit HISR Control Blocks. */
NU_HISR CS8900A_Ether_inter_Control;
NU_HISR CS8900A_inter_Trans;
NU_HISR CS8900A_inter_BufferE;
#define ioread16(addr) (*((volatile unsigned short *)addr))
#define MAX_CS8900A_DEVICES 5
DV_DEVICE_ENTRY *CS8900A_RBuffer[MAX_CS8900A_DEVICES];
DV_DEVICE_ENTRY *CS8900A_THOSTBuffer[MAX_CS8900A_DEVICES];
int CS8900A_Read;
int CS8900A_Write;
int Host_Data_Read;
int Host_Data_Write;
int *INT_cont = 0;
void *pXDATA,*pHISR_IRQ,*pHISR_Tx,*pHISR_IBuff;
unsigned short CS8900AReadPacketPage( unsigned short Offset );
void CS8900AWritePacketPage( unsigned short Offset, unsigned short Value );
unsigned short CS8900ARequestTransmit(unsigned short Length);
void *normalize_ptr(void *ptr);
/****************************************************************************/
/* FUNCTION */
/* */
/* CS8900A_Init */
/* */
/* DESCRIPTION */
/* */
/* 初始化設備結構并調用設備打開程序。 */
/* */
/* CALLED BY */
/* */
/* DEV_Init_Devices */
/* */
/* CALLS */
/* */
/* The device open function */
/* */
/* INPUTS */
/* */
/* DV_DEVICE_ENTRY *: Pointer to the device */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS or a negative value on failure. */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/****************************************************************************/
STATUS CS8900A_Init(DV_DEVICE_ENTRY *device)
{
void *pointer;
/* Initialize the various function pointers. */
device->dev_open = CS8900A_Open;
device->dev_start = CS8900A_Xmit_Packet;
device->dev_output = NET_Ether_Send;
device->dev_input = NET_Ether_Input;
device->dev_ioctl = CS8900A_Ioctl;
device->dev_type = DVT_ETHER;
device->dev_addrlen = 6;
device->dev_hdrlen = 14; /* Size of an ethernet header. */
device->dev_mtu = 1500; /* MTU excludes the size of the MAC
layer header. */
/* The CS8900A is a simplex controller. Broadcasts are allowed. */
device->dev_flags |= (DV_BROADCAST | DV_SIMPLEX | DV_MULTICAST);
/* Allocate the memory required for the CS8900A data. */
if ( NU_Allocate_Memory ( &System_Memory, &pointer, sizeof(CS8900A_XDATA),
NU_NO_SUSPEND ) != NU_SUCCESS)
{
NU_Tcp_Log_Error (TCP_SESS_MEM, TCP_FATAL, __FILE__, __LINE__);
return (-1);
}
/* Clear the data. */
UTL_Zero (pointer, sizeof(CS8900A_XDATA));
/* The device structure includes 4 fields that are unused. Two are reserved
for system use, and two are for reserved for users. We are going to use
one of the fields reserved for users to store a pointer to the data for
this CS8900A device. */
device->user_defined_1 = (uint32)pointer;
Xos_Lisr_Driver[XDRV_NET_RVECTOR] = (XHANDLE *)device;
/* Initialize the device. */
return ( (*(device->dev_open)) (device->dev_mac_addr, device) );
} /* CS8900A_Init */
STATUS CS8900A_Close(NU_DEVICE *device)
{
STATUS status;
//將EINT9腳設置為輸入
rGPGCON &= 0XFFFFFFF3;
//子中斷屏蔽寄存器將EINT9屏蔽
rEINTMASK |= 0X200;
//中斷屏蔽寄存器中將EINT8~23屏蔽
rINTMSK |= BIT_EINT8_23;
if((status = NU_Deallocate_Memory(pXDATA)) != NU_SUCCESS)
{
return status;
}
if((status = NU_Deallocate_Memory(pHISR_IRQ)) != NU_SUCCESS)
{
return status;
}
if((status = NU_Deallocate_Memory(pHISR_Tx)) != NU_SUCCESS)
{
return status;
}
if((status = NU_Deallocate_Memory(pHISR_IBuff)) != NU_SUCCESS)
{
return status;
}
return NU_SUCCESS;
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CS8900A_Get_Address */
/* */
/* DESCRIPTION */
/* */
/* 該函數從芯片內部寄存器讀取芯片的物理地址。 */
/* */
/* CALLED BY */
/* */
/* */
/* */
/* CALLS */
/* */
/* */
/* */
/* INPUTS */
/* */
/* */
/* */
/* OUTPUTS */
/* */
/* */
/* */
/****************************************************************************/
STATUS CS8900A_Get_Address (uint8 *ether_addr)
{
/* cs8900a IA :{0x08, 0x00, 0x20, 0x74, 0x80, 0xa7} */
/*從芯片內部寄存器讀取物理地址,或用戶自己設置物理地址,并寫入參數
ether_addr中。 */
ether_addr[0]=0x00;//0xa7;
ether_addr[1]=0x00;//0x80;
ether_addr[2]=0x74;
ether_addr[3]=0x20;
ether_addr[4]=0x00;
ether_addr[5]=0x08;
return NU_SUCCESS;
} /* end CS8900A_Get_Address */
/****************************************************************************/
/* FUNCTION */
/* */
/* CS8900A_Set_Address */
/* */
/* DESCRIPTION */
/* */
/* 將芯片的物理地址寫入芯片的物理地址寄存器中。 */
/* */
/* CALLED BY */
/* */
/* CS8900A_Open */
/* */
/* CALLS */
/* */
/* */
/* INPUTS */
/* */
/* */
/* OUTPUTS */
/* */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/****************************************************************************/
void CS8900A_Set_Address (uint8 *ether_addr, DV_DEVICE_ENTRY *device)
{
union
{
unsigned short word;
unsigned char byte[2];
} Value;
/*將物理地址寫入芯片寄存器*/
/* Put hardware address into the Individual Address register */
Value.byte[0]=ether_addr[0];
Value.byte[1]=ether_addr[1];
CS8900AWritePacketPage( PKTPG_IND_ADDR, Value.word);
Value.byte[0]=ether_addr[2];
Value.byte[1]=ether_addr[3];
CS8900AWritePacketPage( PKTPG_IND_ADDR+2, Value.word);
Value.byte[0]=ether_addr[4];
Value.byte[1]=ether_addr[5];
CS8900AWritePacketPage( PKTPG_IND_ADDR+4, Value.word);
/* Initialize the Physical address in the MIB. */
SNMP_ifPhysAddress(device->dev_unit + 1, ether_addr);
} /* end CS8900A_Set_Address */
/****************************************************************************/
/* FUNCTION */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -