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

📄 le1velib.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
字号:
/* le1veLib.c - LE1VE (TDMoIP) soure libary file
*
* Copyright     2004-2007 ZTE, Inc.
* author:       ZhengQishan
* date:         2004.02
*
* modification history
*------------------------------
*
*/
#include "zl5011x.h"
#include "le1veLib.h"
#include "le1veApp.h"
#include "zl5011xError.h"
#include "le1veConfig.h"

UINT8  udpPortAndSlotTbl[LE1VE_UDP_MAX_LEN];
SEM_ID drv_ReadRegSemaphore[LE1VE_MAX_NUM] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
CONTEXT_ATTRIB_T  *g_contextAttribTbl[LE1VE_MAX_NUM] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};

extern int diag_prjDrvCtrlRegist();
extern int diag_prjIntfcardParamParse();
extern int drv_le1veDiag();
extern void le1veIntConnect(int slot);
extern STATUS le1veFpgaPciDevSend(UINT32 gPort, char *pBuf, int size, char *pData);
extern STATUS le1veFpgaPciDevInit(int slot);
extern STATUS b_Lce1fLineStatusGet(UINT8 slotNum, UINT32 *lineStatus);
extern void le1veFeiPhyLineStatus(int slot, UINT8 *pStatus);
extern int drv_le1veRegister(int slotNum);


char packetarp[]={0x00, 0x11, 0x5b, 0xbc, 0xf3, 0x99, /*dest mac*/ 
				      0x00, 0xd0, 0xd0, 0xc4, 0xff, 0xe0, /*source mac*/
				      0x08, 0x06, /*arp*/ 
				      0x00, 0x01, /*eth type*/
				      0x08, 0x00, /*protocol type*/
				      0x06,         /*hardware addr length*/
				      0x04,         /*protocol addr length*/
				      0x00, 0x02, /*arp op code*/
				      0x00, 0xd0, 0xd0, 0xc4, 0xff, 0xe0,  /*sender mac*/
				      0x64, 0x00, 0x00, 0x02, /*sender ip*/
				      0x00, 0x11, 0x5b, 0xbc, 0xf3, 0x99,  /*dest mac (current unkown)*/
				      0x64, 0x00, 0x00, 0x01, /*dest ip*/ 
				      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
				      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /*padding*/};
char packeticmp[]={0x00, 0x11, 0x5b, 0xbc, 0xf3, 0x99, /*dest mac*/ 
				     0x00, 0xd0, 0xd0, 0xc4, 0xff, 0xe0, /*source mac*/
				     0x08, 0x00,
				     0x45,/*ver*/
				     0x00,/*tos*/
				     0x00, 0x3c,/*head length*/
				     0x00, 0x01,/*flag*/
				     0x00, 0x00, /*fragment*/
				     0xff,/*time to live*/
				     0x01,/*protocol*/
				     0xf3,0xbc,/*check sum*/
				     0x64, 0x00, 0x00, 0x02,/*source ip*/
				     0x64, 0x00, 0x00, 0x01,/*dest ip*/
				     0x00,/*icmp type echo reply*/
				     0x00,/*icmp code*/
				     0x3f, 0x5c, /*icmp check sum*/
				     0x02, 0x00, /*indentifier*/
				     0x14, 0x00,/*seq num*/
				     0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 
				     0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
				     0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x61, 
				     0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69
				   };
STATUS drv_le1ve_init(int slot)
{
    int loop;
    UINT32 baseAddr;
    STATUS result = OK;
    static STATUS firstTime = OK;
    if (OK == firstTime)
    {
        bzero(udpPortAndSlotTbl, LE1VE_UDP_MAX_LEN);
        firstTime = ERROR;
    }
    if (slot > LE1VE_MAX_NUM || slot <= 0)
        return ERROR;
    /*shf added  2006.2.24 . if router is 18 28 38 .the 16m clock should be selected */
    #if INSTALL_ON_PPC8241
	*(UINT8 *)(b_infBaseAddrGet(slot)+ CPLD_HMVIP_CLOCK_SEL_REG) = 0x1;
	#endif

	#if INSTALL_ON_PPC8349
    EPLD_OUT_BYTE(b_infBaseAddrGet(slot)+ CPLD_HMVIP_CLOCK_SEL_REG, 0x1);
	#endif

	#if INSTALL_ON_PPC8347
    EPLD_OUT_BYTE(b_infBaseAddrGet(slot)+ CPLD_HMVIP_CLOCK_SEL_REG, 0x1);
	#endif
	
	#if INSTALL_ON_PPC8541
	EPLD_OUT_BYTE(b_infBaseAddrGet(slot)+ CPLD_HMVIP_CLOCK_SEL_REG, 0x1);
	#endif
    /*end*/
    if (NULL == g_contextAttribTbl[slot - 1])
    {
        drv_ReadRegSemaphore[slot - 1] = semBCreate (SEM_Q_FIFO, SEM_FULL);
		if (drv_ReadRegSemaphore[slot - 1] == NULL)
		    taskSuspend(0);

        if (NULL == (g_contextAttribTbl[slot - 1] = malloc(ZL5011X_MAX_NUMBER_CONTEXTS * sizeof(CONTEXT_ATTRIB_T) + 4)))
        {
            printf("Cannot malloc memory for LE1VE %d\n",slot);
            taskSuspend(0);
        }
        bzero((char *)g_contextAttribTbl[slot - 1], ZL5011X_MAX_NUMBER_CONTEXTS * sizeof(CONTEXT_ATTRIB_T) + 4);
        for (loop = 0; loop < ZL5011X_MAX_NUMBER_CONTEXTS; loop ++)
        {
            g_contextAttribTbl[slot - 1][loop].jiterBufLen = LE1VE_DEFAULT_JITTER_BUFFER;
            g_contextAttribTbl[slot - 1][loop].frameNumPerPkt = LE1VE_DEFAULT_FRAMES_PER_PKT;
            g_contextAttribTbl[slot - 1][loop].adaptiveClock = LE1VE_ADAPTIVE_CLOCK_NOT_USED;
        }
    }

    /*reset LE1VE card*/
    baseAddr = b_infBaseAddrGet(slot);
    *((UINT8*)(baseAddr  + 4 * 0x4)) = 0xff;
    taskDelay(20);
    *((UINT8*)(baseAddr  + 4 * 0x4)) = 0x0;
        
    /*初始化PM4354*/
    lce1f_pm4354_init(slot, 1, lce1f_getFrameMode(slot));

    /*初始化MT89L86
    le1veMt8986Init(slot);*/
#if 1
    /*初始化ZL50114*/
	if (ZL5011X_OK != zl5011xModuleInit(slot))
         return ERROR;
    le1veIntConnect(slot);
#if INSTALL_ON_IXP1200
    if ((slot % 2) != 0)
        le1veFpgaPciDevInit(slot);
#else
    le1veFpgaPciDevInit(slot);
#endif

#if 0
    le1veCreatRxContext(slot);
    le1veCreatTxContext(slot);
#endif
#endif
    /*注册诊断测试*/
    drv_le1veRegister(slot);
    return result;
}

/*调试时可以关闭此接口的收发包*/
int drv_le1veSndPktFlag = 1;
STATUS drv_le1ve_send(LE1VE_SND_PKT_MSG *pMsg)
{
    int slot;
    UINT32 gPort;

    /*checkout the slot number through the UDP port Number*/
    /*for arp icmp the udpport = slot add by shf to packet forward 2005.7.29 FM 20:36*/
    if(pMsg->udp_port <TDMOIP_UDP_PORT_START)
	  slot =pMsg->udp_port;
    else 
    slot  = udpPortAndSlotTbl[pMsg->udp_port - TDMOIP_UDP_PORT_START];
    if ((slot > 0) && (drv_le1veSndPktFlag != 0))
    {
        gPort = Ros_GlobalPort(slot, 1,1);
        #if INSTALL_ON_IXP1200
        if ((slot % 2) != 0)
        {
            if (OK != le1veFpgaPciDevSend(gPort, pMsg->pbuf, pMsg->size, pMsg->pData))
                endPktFree(pMsg->pData);
        }
        else
            ;
        #else
             if (OK != le1veFpgaPciDevSend(gPort, pMsg->pbuf, pMsg->size, pMsg->pData))
                endPktFree(pMsg->pData);
        #endif
    }
    else
        endPktFree(pMsg->pData);

    return OK;
}

STATUS b_Le1veLineStatusGet(UINT8 slotNum, UINT32 *lineStatus)
{
    UINT8 feiLineStatus = 0;

    b_Lce1fLineStatusGet(slotNum, lineStatus);
    le1veFeiPhyLineStatus(slotNum, &feiLineStatus);
    
    *lineStatus |= feiLineStatus;
    return OK;
}
/*-----------------test code------------------*/
STATUS test_replypacket(UINT8 protocol, UINT16 length)/*1 for arp 2 for icmp*/
{
	LE1VE_SND_PKT_MSG packet;
	UINT32 gPort;
	gPort = Ros_GlobalPort(1, 1,1);
	if(protocol == 1)
	{
		packet.pbuf = packetarp;
		packet.size = sizeof(packetarp);
		packet.pData = NULL;
		packet.udp_port = 0;
	}
	if(protocol == 2)
	{
		*((UINT16 *)(packeticmp+40))= length;
		packet.pbuf = packeticmp;
		packet.size = sizeof(packeticmp);
		packet.pData = NULL;
		packet.udp_port = 0;
	}
 	le1veFpgaPciDevSend(gPort, packet.pbuf,packet.size , packet.pData);
	return OK;
}

STATUS test_sendpacket(UINT8 protocol, UINT count, UINT length )
{
	int i=0;
	for(i=0;i<count;i++)
		test_replypacket(protocol,0);
    return OK;
}

⌨️ 快捷键说明

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