?? le1veapp.c
字號:
/* le1veApp.c - LE1VE card application resoure file
*
* Copyright 2004-2007 ZTE, Inc.
* author: ZhengQishan
* date: 2004.02
*
* modification history
*------------------------------
*
*/
#include "zl5011x.h"
#include "zl5011xRdWr.h"
#include "zl5011xDpr.h"
#include "zl5011xInterrupts.h"
#include "zl5011xApi.h"
#include "zl5011xInit.h"
#include "zl5011xTdm.h"
#include "zl5011xLan.h"
#include "zl5011xMisc.h"
#include "zl5011xPacket.h"
#include "zl5011xError.h"
#include "le1veLib.h"
#include "le1veApp.h"
zl5011xParamsS *le1ve_Zl5011xParams[MAX_IF_CARD_NUM] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
LOCAL zlStatusE initLe1veCard(zl5011xSysInitS *sysInit);
#if 0
LOCAL void populateHeader(Uint32T context, UINT8 *macAddress, Uint8T *header, Uint8T *headerLength, zl5011xProtocolTypeE *protocol);
#endif
/*-----------------------------
* zl5011xModuleInit - init Zl5011X data structure
*
*Argument: void
*
*Return: zlStatusE - the status of init
*/
zlStatusE zl5011xModuleInit(int slot)
{
int loop;
zl5011xCreateDeviceS createDevice;
zl5011xSysInitS sysInit;
zl5011xWanConfigureSyncS wanConfigureSync;
zl5011xLanConfigureS lanConfigure;
zl5011xLanQueueConfigureS lanQueueConfigure;
zlStatusE result = ZL5011X_OK;
UINT8 *pMacAddress;
zl5011xParamsS *pZl5011xParams;
if (slot > 8 || slot < 1)
{
printf("Error slot number !\n");
return(ZL5011X_ERROR_SLOT_NUM);
}
if (le1ve_Zl5011xParams[slot - 1] != NULL)
{
printf("slot %d zl5011xModuleInit have been called!\n", slot);
return(ZL5011X_DEVICE_HAVE_BEEN_INIT);
}
/* create the device structure and OS objects */
result = zl5011xCreateDeviceStructInit(&createDevice);
if (result == ZL5011X_OK)
{
createDevice.baseAddress = IF_CARD_CPU_REG_BASE(slot);
result = zl5011xCreateDevice(&pZl5011xParams, &createDevice);
if (result != ZL5011X_OK)
{
printf("Init (slot %d) Zl50114 failed!\n", slot );
return(result);
}
le1ve_Zl5011xParams[slot - 1] = pZl5011xParams;
le1ve_Zl5011xParams[slot - 1]->slotNum = slot;
}
/* get ready to initialise the device. Default the structure entries to default
values and then set up any required values */
if (result == ZL5011X_OK)
{
result = zl5011xSysInitStructInit(pZl5011xParams, &sysInit);
/*指定所用芯片類型,新添加*/
sysInit.init.deviceType = ZL_DEVICE_ZL50114;
/*TDM接口的時鐘由硬件決定*/
sysInit.wanInit.ifType = ZL5011X_WAN_HMVIP_8M; /*ZL5011X_WAN_STBUS_2M_X2_CLOCK;*/
/*2倍默認值大小*/
sysInit.wanInit.txQueueMaxNumberOfGranules = 10000;
#if 0 /*默認2.048M 恢復時鐘涉及*/
/*add by shf 2005.7.13 */
if( b_physIfType(slot) == CARD_TMD_OVER_IP_4_1_T1)
{
sysInit.wanInit.liuFreq= ZL5011X_WAN_LIU_FREQ_1_544M;
}
/*end*/
#endif
/*LE1VE 有8Mbyte 的extern memory*/
sysInit.configureMemory.extMemChipSize= ZL5011X_EXT_MEM_SIZE_4MB;
/*顆粒的多少主要取決于內(nèi)存的多少,? 每一個顆粒由于64字節(jié)的數(shù)據(jù)區(qū)和16字節(jié)的描述區(qū)組成。
顆粒的大小暫定為20000*/
/*sysInit.configureMemory.numberGranules= 40000;讓芯片自己選擇*/
}
/*用sysInit參數(shù)初始化Le1ve單板*/
if (result == ZL5011X_OK)
{
result = initLe1veCard(&sysInit);
}
/* Initialise the device */
if (result == ZL5011X_OK)
{
printf("ZL50114 Device Initialise\n");
result = zl5011xSysInit(pZl5011xParams, &sysInit);
}
/* setup the TDM interface - in this example sync clocks */
if (result == ZL5011X_OK)
{
result = zl5011xWanConfigureSyncStructInit(pZl5011xParams, &wanConfigureSync);
if (result == ZL5011X_OK)
{
/*add by shf 2005.7.13 */
if( b_physIfType(slot) == CARD_TMD_OVER_IP_4_1)
{
wanConfigureSync.primaryRef.refFreq = ZL5011X_WAN_REF_FREQ_2_048M;
wanConfigureSync.secondaryRef.refFreq = ZL5011X_WAN_REF_FREQ_2_048M;
}
else
{
wanConfigureSync.primaryRef.refFreq = ZL5011X_WAN_REF_FREQ_1_544M;
wanConfigureSync.secondaryRef.refFreq = ZL5011X_WAN_REF_FREQ_1_544M;
}
#if 0
/*end*/
wanConfigureSync.dpllConnection = ZL5011X_DPLL_SLAVE_CONNECTION;/*ZL5011X_DPLL_MASTER_CONNECTION;*/
wanConfigureSync.dpllMasterOutputEnable = ZL5011X_FALSE; /*ZL5011X_TRUE;*/
wanConfigureSync.framePulsePolarity = ZL5011X_NEGATIVE ; /*ZL5011X_POSITIVE;*/
wanConfigureSync.framePulseWidth = ZL5011X_WAN_FRAME_2_BITS_CENTRED;/*ZL5011X_WAN_FRAME_FULL_BIT_CENTRED;*/
#endif
#if 0
/*slave or master*/
wanConfigureSync.dpllConnection = ZL5011X_DPLL_MASTER_CONNECTION; /* enableDPLL, drive TDM_CLKo and TDM_FRMo outputs */
wanConfigureSync.dpllMasterOutputEnable = ZL5011X_TRUE; /* enable the PLL_PRI and PLL_SEC outputs */
wanConfigureSync.primaryRef.source = ZL5011X_WAN_STREAM_REF; /* Take CLKi0 (connected to CLKo0) as DPLL reference input */
wanConfigureSync.primaryRef.stream = (Uint8T)0x00;
wanConfigureSync.primaryRef.refFreq = ZL5011X_WAN_REF_FREQ_2_048M;
wanConfigureSync.secondaryRef.source = ZL5011X_WAN_STREAM_REF; /*secondary input, for backup only. */
wanConfigureSync.secondaryRef.stream = (Uint8T)0x01;
wanConfigureSync.secondaryRef.refFreq = ZL5011X_WAN_REF_FREQ_2_048M;
wanConfigureSync.refPriority = ZL5011X_DPLL_PRIMARY_PRIORITY;
wanConfigureSync.refPolarity = ZL5011X_POSITIVE;
#endif
/* For default values for structure wanConfigureSync, see the function
zl5011xWanConfigureSyncStructInit() in file zl5011xTdm.c */
result = zl5011xWanConfigureSync(pZl5011xParams, &wanConfigureSync);
/*ZL50114 */
#if 0
zl5011xTifReverseBitOrder(pZl5011xParams, ZL5011X_TRUE);
#endif
}
}
/* Configure the LAN interface - Packet Tx, Packet Rx and MAC */
if (result == ZL5011X_OK)
{
pMacAddress = pZl5011xParams->macAddress[0];
Ros_GetMacBase(b_FetchSerial(),pMacAddress);
pMacAddress = pZl5011xParams->macAddress[1];
Ros_GetMacBase(b_FetchSerial(),pMacAddress);
/*兩以太接口的MAC地址不一樣*/
pZl5011xParams->macAddress[1][ZL5011X_MAC_SIZE - 1] += 0x40;
result = zl5011xLanConfigureStructInit(pZl5011xParams, &lanConfigure);
lanConfigure.macType = ZL5011X_MAC_TYPE_MII; /* alternatively ZL5011X_MAC_TYPE_GMII */
}
if (result == ZL5011X_OK)
{
result = zl5011xLanQueueConfigureStructInit(pZl5011xParams, &lanQueueConfigure);
}
/* set up 2 LAN ports */
for (loop = 0; loop < 2; loop++)
{
lanQueueConfigure.portNum = loop;
if (result == ZL5011X_OK)
{
/* set up the LAN queues */
result = zl5011xLanQueueConfigure(pZl5011xParams, &lanQueueConfigure);
}
if (result == ZL5011X_OK)
{
/* set up the LAN ports. Set the low byte of the MAC address to be the
port number itself. That is port 1 becomes xx:xx:xx:xx:xx:01 */
lanConfigure.portNum = loop;
/* set the ethernet MAC address */
bcopy (pZl5011xParams->macAddress[loop], lanConfigure.macAddress, ZL5011X_MAC_SIZE);
result = zl5011xLanConfigure(pZl5011xParams, &lanConfigure);
}
}
#if 0
if (firstTime == OK)
{
/* Interrupts are required for the differential mode of operation. So, must
initialise the interrupts before CET */
if (result == ZL5011X_OK)
{
result = zl5011xIsrInitialiseStructInit(pZl5011xParams, &isrInit);
isrInit.apiPhysIntr = 0;
isrInit.appPhysIntr = 0;
if (result == ZL5011X_OK)
{
result = zl5011xIsrInitialise(pZl5011xParams, &isrInit);
}
}
firstTime = ERROR;
}
/* The interrupt is now initialised, so add the device to the list to be serviced */
if (result == ZL5011X_OK)
{
result = zl5011xIsrAddDeviceStructInit(pZl5011xParams, &isrAddDevice);
if (result == ZL5011X_OK)
{
result = zl5011xIsrAddDevice(pZl5011xParams, &isrAddDevice);
}
}
#endif
return(result);
}
LOCAL zlStatusE initLe1veCard(zl5011xSysInitS *sysInit)
{
zlStatusE result = ZL5011X_OK;
return (result);
}
#if 0
/*-----------------------------
* le1veCreatContext - create context
*
*Argument:
* UINT32 gPort - global port
* UINT32 timeSlot - 該通道所占的時隙數(shù),每一位表示一個時隙
*
* 說明:LE1VE最多只創(chuàng)建兩個context,而且context創(chuàng)建后,不為其分配通道(時隙)也不會工作,LE1VE的驅(qū)動
* 在初始化時直接先創(chuàng)建兩個context,在使用時再為其動態(tài)分配通道及配置接口屬性。
*
*Return:
* OK or ERROR if something is wrong
*/
zlStatusE le1veCreatRxContext(int slot)
{
int contextLoop, context, stream, channelLoop;
zl5011xParamsS *pZl5011xParams;
zl5011xContextCreateS contextCreate;
zl5011xContextAddChannelRxS addChannelRx;
zl5011xWanRxPayloadConfigS wanRxPayload;
zl5011xPacketTxSetHeaderS packetTxHeader;
zl5011xContextS contextInfo;
zl5011xWanRxGetPayloadLengthS payloadLength;
Uint8T *packetHeader;
zlStatusE result = ZL5011X_OK;
pZl5011xParams = le1ve_Zl5011xParams[slot - 1];
/*Create the TDM input contexts (WAN Rx contexts)*/
for (contextLoop = FIRST_CONTEXT;
(contextLoop < (FIRST_CONTEXT + NUM_CONTEXTS)) && (result == ZL5011X_OK);
contextLoop++)
{
printf("context %3d: TDM input create\n", contextLoop);
result = zl5011xContextCreateStructInit(pZl5011xParams, &contextCreate);
/* For default values for structure contextCreate, see the function
zl5011xContextCreateStructInit() in file zl5011xTdm.c */
if (NULL == (packetHeader = (Uint8T*)malloc(100)))
result = ZL5011X_ERROR;
else
{
pZl5011xParams->pPktTxHeader[contextLoop] = packetHeader;
}
if (result == ZL5011X_OK)
{
contextCreate.context = contextLoop;
contextCreate.flow = ZL5011X_FLOW_WAN_PE_PKT;
result = zl5011xContextCreateRx(pZl5011xParams, &contextCreate);
}
}
#if 1 /*正式版本中將刪除這段代碼,要求實現(xiàn)通道的動態(tài)增加/刪除*/
/* Add channels to the TDM input contexts (structured mode only) */
for (contextLoop = FIRST_CONTEXT;
(contextLoop < FIRST_CONTEXT + NUM_CONTEXTS) && (result == ZL5011X_OK);
contextLoop++)
{
context = contextLoop;
for (channelLoop = 1 ; (channelLoop < 32) && (result == ZL5011X_OK); channelLoop++)
{
/* simply assign 32 channels to each context. */
stream = context;
result = zl5011xContextAddChannelRxStructInit(pZl5011xParams, &addChannelRx);
/* the structure addChannelRx is used to associate with the context
stream & channel numbers and some other properties For default
values for structure addChannelRx, see the function
zl5011xContextAddChannelRxStructInit() in file zl5011xTdm.c */
if (result == ZL5011X_OK)
{
addChannelRx.context = context;
addChannelRx.tdm.stream = 0;
addChannelRx.tdm.channel = channelLoop * 4 + stream;
result = zl5011xContextAddChannelRx(pZl5011xParams, &addChannelRx);
}
}
}
#endif /*1*/
/* Setup the packet size for the TDM Input contexts (WAN Rx contexts) */
for (contextLoop = FIRST_CONTEXT;
(contextLoop < FIRST_CONTEXT + NUM_CONTEXTS) && (result == ZL5011X_OK);
contextLoop++)
{
context = contextLoop;
printf("context %3d: TDM input configure payload\n", context);
result = zl5011xWanRxPayloadConfigStructInit(pZl5011xParams, &wanRxPayload);
if (result == ZL5011X_OK)
{
wanRxPayload.context = context;
wanRxPayload.numberOfFrames = 8;
result = zl5011xWanRxPayloadConfig(pZl5011xParams, &wanRxPayload);
}
}
/* Configure the Packet Transmit header */
for (contextLoop = FIRST_CONTEXT;
(contextLoop < FIRST_CONTEXT + NUM_CONTEXTS) && (result == ZL5011X_OK);
contextLoop++)
{
printf("context %3d: TDM input setup header\n", contextLoop);
/* Using a ETHERNET->IPv4->UDP->RTP->PW header */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -