📄 le1veconfig.c
字号:
/* le1veConfig.c - LE1VE interface config resoure file
*
* Copyright 2004-2007 ZTE, Inc.
* author: ZhengQishan
* date: 2004.03
*
* modification history
*------------------------------
* 2004-06-01 ZhengQishan 增加对TDM接口配置的宏定义
* 2004-06-02 ZhengQishan 增加pktTxHeaderCfg和pktRxHeaderCfg函数
* 2004-07-10 ZhengQiShan 当context一个包都没有收到时,是不能成功deleted
* 2004-07-15 ZhengQiShan 增加一个PM4354外环的函数
*
*/
#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 "zl5011xPkcMap.h"
#include "zl5011xCet.h"
#include "zl5011xPrintError.h"
#include "zl5011xLanLanLink.h"
#include "le1veLib.h"
#include "le1veConfig.h"
#include "mux_ex.h"
/*add by shf */
#include "driver/lce1f/include/lce1flib.h"
#ifdef INSTALL_INTERFACE_STATISTICS
#include "protocol/attache/interface/statis/include/if_stat.h"
#endif
/*end*/
extern zl5011xParamsS *le1ve_Zl5011xParams[];
extern CONTEXT_ATTRIB_T *g_contextAttribTbl[];
extern UINT8 udpPortAndSlotTbl[];
/*lce1f_frame_unframe变量表示4354某一个端口是否成帧,引入此变量是为了
实现T1透传TDM功能,实现T1透传TDM数据时,将端口配置成UNFRAME模式,从而可以
使F bit透传实现。在添加tdm-channel时,当该端口为UNFRAME模式,需要额外
添加F bit所在时隙,此处只引用,不修改*/
extern char lce1f_frame_unframe[];
/*shf add 2005.9.8 20:25
*le1veCetInited[i]记录i+1号e1ve板是否被初始化
*le1veCetRefCnt[i]记录i+1号e1ve板上配置adaptive clock 的context数目
*/
static UINT8 le1veCetDevAdded[8]={0};
static UINT8 le1veCetRefCnt[8]={0};
static zlStatusE cetInitFirstTime = ZL5011X_OK;
/*static zlStatusE isrInitFirstTime = ZL5011X_OK;*/
/*end*/
extern STATUS pm4354LinecodeCfg(UINT32 gPort, int linecode);
/*shf add*/
extern STATUS pm4354FrameModeCfg(UINT32 gPort, int FrameMode);
extern STATUS lce1f_pm4354_frame_config(UINT32 gPort, char mode);
zlStatusE drv_Le1veAdaptiveClock(zl5011xParamsS *zl5011xParams, UINT32 gport, ADAPTIVE_CLOCK_ATTRIB attrib);
/*end*/
LOCAL zlStatusE pktTxHeaderDefaultCfg(UINT32 gPort);
LOCAL zlStatusE pktRxHeaderDefaultCfg(UINT32 gPort);
LOCAL zlStatusE le1veContextUpdate(zl5011xParamsS *pZl5011xParams, int context, int dir);
LOCAL zlStatusE wanRxPayloadCfg(zl5011xParamsS *pZl5011xParams, int contextNum, int frameNum);
LOCAL zlStatusE wanTxQueueCfg(zl5011xParamsS *pZl5011xParams, int contextNum, int jitterBufferSize);
LOCAL zlStatusE le1veRxContextAddChan(UINT32 gPort, UINT32 *pTimeSlot);
LOCAL zlStatusE le1veTxContextAddChan(UINT32 gPort, UINT32 *pTimeSlot);
LOCAL zlStatusE modifyPktHeader(int slot, int port, int contextNum, int dir);
LOCAL void le1ve_defaultHeader(Uint32T context, UINT8 *macAddress, Uint8T *header);
zlStatusE drv_Le1veAdaptiveClock(zl5011xParamsS *zl5011xParams, UINT32 gport, ADAPTIVE_CLOCK_ATTRIB attrib);
LOCAL int getContextTimeSlotNum(UINT32 *pTimeSlot)
{
int portLoop,channelLoop;
int timeSlotNum = 0;
UINT32 timeSlot;
for (portLoop = 0; portLoop < 4; portLoop ++)
{
timeSlot = pTimeSlot[portLoop];
for (channelLoop = 0 ; channelLoop < 32; channelLoop++)
{
if (1 != ((timeSlot >> channelLoop) & 1))
continue;
else
timeSlotNum ++;
}
}
return (timeSlotNum);
}
/*****************************
drv_le1veCPLDCetEnable----enable cet in cpld
*Description :
* Enable the Cet Clock pin connect
*Parameters :
* IN:
* slot -- slot number
* OUT:
* OK or ERROR
*------------------------------
*History:
*------------------------------
*2005.9.9 8:53 shf created
*******************************/
zlStatusE drv_le1veCPLDCetEnable(int slot)
{
UINT32 value;
volatile UINT32 *pBaseAddr;
pBaseAddr = (volatile UINT32 *)(IF_CARD_CPU_REG_BASE(slot) + CPLD_CET_CONTROL_REG);
value = Drv_Swap32(*pBaseAddr);
*pBaseAddr = Drv_Swap32(value | 0xFF);
return ZL5011X_OK;
}
zlStatusE drv_le1veCPLDCetDisable(int slot)
{
UINT32 value;
volatile UINT32 *pBaseAddr;
pBaseAddr = (volatile UINT32 *)(IF_CARD_CPU_REG_BASE(slot) + CPLD_CET_CONTROL_REG);
value = Drv_Swap32(*pBaseAddr);
/*写入任何非0xFF都可以disable CET*/
*pBaseAddr = Drv_Swap32(value & 0x0);
return ZL5011X_OK;
}
/*****************************
drv_Le1veWanSyncCetInit---init wan sync
*Description :
* init the wan sync mode to use Cet clock
*Parameters :
* IN:
* zl5011xParamsS* --pointer to a e1ve device struct
* OUT:
* none
*Return :
* OK or ERROR
*----------------------------
*history:
*----------------------------
*2005.9.8 FM 17:14 shf created
*****************************/
zlStatusE drv_Le1veWanSyncCetInit(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
zl5011xWanConfigureSyncS wanConfigureSync;
if(NULL == zl5011xParams)
return ZL5011X_ERROR;
/* setup the TDM interface - in this example sync clocks */
if (status == ZL5011X_OK)
{
status = zl5011xWanConfigureSyncStructInit(zl5011xParams, &wanConfigureSync);
if (status == ZL5011X_OK)
{
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;
/* For default values for structure wanConfigureSync, see the function
zl5011xWanConfigureSyncStructInit() in file zl5011xTdm.c */
status = zl5011xWanConfigureSync(zl5011xParams, &wanConfigureSync);
}
}
/*修改Warning*/
return status;
}
/*****************************
drv_Le1veCetInit---init cet for clock recovery
*Description :
* init the cet mode for zl5011x
*Parameters :
* IN:
* gPort --global port
* zl5011xParamsS* --pointer to a e1ve device struct
* OUT:
* none
*Return :
* OK or ERROR
*----------------------------
*history:
*----------------------------
*2005.9.8 FM 17:14 shf created
*****************************/
zlStatusE drv_Le1veCetInit(zl5011xParamsS *zl5011xParams, UINT32 slotNum)
{
int slot;
zlStatusE status = ZL5011X_OK;
zl5011xCetInitS cetInit;
zl5011xCetAddDeviceS cetAddDevice;
#if 0
zl5011xIsrInitialiseS isrInitialise;
zl5011xIsrAddDeviceS isrAddDevice;
#endif
slot = slotNum;
/*参数检查*/
status =ZL5011X_CHECK_SLOTNUM(slot, zl5011xParams);
printf("cet init start slot %x\n",slot);
/*是否已初始化*/
if(le1veCetDevAdded[slot-1] == 1)
return ZL5011X_ERROR;
#if 0
if(ZL5011X_OK == status)
status = drv_Le1veWanSyncCetInit(zl5011xParams);
#endif
/*写CPLD,改变时钟为zl5011x环回*/
if(ZL5011X_OK == status)
{
status = drv_le1veCPLDCetEnable(slot);
}
/*Init ISR Module*/
/*GAR中目前只有在使用CET时才使用中断,所以把中断放在CET初始化过程中
*如果有新的需求可以将中断初始化提出
*使用adaptive clock Recovery时不需要中断支持。使用Diff Clock Recovery
*时,需要中断支持。
*如果仅仅使用Adaptive Clock,可以不初始化中断,并且不处理api中断
*/
#if 0
if(ZL5011X_OK == isrInitFirstTime)
{
/* initialise the ISR's */
if (status == ZL5011X_OK)
{
status = zl5011xIsrInitialiseStructInit(zl5011xParams, &isrInitialise);
/*使用我们自己的中断,只打开api中断,*/
isrInitialise.apiPhysIntr = FAKE_INT;/*不真正的连接中断*/
if (status == ZL5011X_OK)
{
/*中断初始化过程被修改,用假中断号,并未真正连接*/
status = zl5011xIsrInitialise(zl5011xParams, &isrInitialise);
printf("le1vezl5011xIntInit %d\n",status);
}
}
if(status == ZL5011X_OK)
isrInitFirstTime = ZL5011X_ERROR;
}
/*中断添加设备*/
/* initialise the interrupt handler and add the device to the ISR */
if (status == ZL5011X_OK)
{
status = zl5011xIsrAddDeviceStructInit(zl5011xParams, &isrAddDevice);
if (status == ZL5011X_OK)
{
status = zl5011xIsrAddDevice(zl5011xParams, &isrAddDevice);
printf("zl5011xIsrAddDevice %d\n",status);
}
}
#endif
/*本E1VE板CET初始化,CET初始化和中断初始化都只能进行一次*/
/*************************************************************************/
/* Initialise CET */
/*************************************************************************/
if(ZL5011X_OK == cetInitFirstTime)
{
if (status == ZL5011X_OK)
{
status = zl5011xCetInitStructInit(zl5011xParams, &cetInit);
if (status == ZL5011X_OK)
{
/* only need the interrupt to be running for differential modes of
clock recovery, so don't try and use it */
cetInit.clockRecoveryInterruptEnable = ZL5011X_FALSE;
status = zl5011xCetInit(zl5011xParams, &cetInit);
printf("Cet init status %d\n",status);
}
}
if (status == ZL5011X_OK)
cetInitFirstTime = ZL5011X_ERROR;
}
if (status == ZL5011X_OK)
{
status = zl5011xCetAddDeviceStructInit(zl5011xParams, &cetAddDevice);
if (status == ZL5011X_OK)
{
status = zl5011xCetAddDevice(zl5011xParams, &cetAddDevice);
printf("Cet add device status %d\n",status);
}
}
if(ZL5011X_OK == status)
{
/*初始化完成*/
le1veCetDevAdded[slot-1] = 1;
}
return status;
}
/*****************************
drv_Le1veCheckCet()---check if cet running
*Description :
* check if cet running
*Parameters :
* IN:
* void
* OUT:
* void
*Return :
* int 0 represent no need Cet module
* >0 means Cet modue in using
*
*----------------------------
*history:
*----------------------------
*2005.9.8 FM 17:14 shf created
*****************************/
int drv_Le1veCheckCet()
{
int i;
int garCetRuning = 0;
/*检查全部TDMoIP板是否都不再使用CET*/
for(i=0;i<8;i++)
{
garCetRuning += le1veCetDevAdded[i];
}
return garCetRuning;
}
/*****************************
drv_Le1veCetDelete---Delete cet for clock recovery
*Description :
* Delete the cet mode for zl5011x
*Parameters :
* IN:
* zl5011xParamsS* --pointer to a e1ve device struct
* OUT:
* none
*Return :
* OK or ERROR
*----------------------------
*history:
*----------------------------
*2005.9.8 FM 17:14 shf created
*****************************/
zlStatusE drv_Le1veCetDelete(zl5011xParamsS *zl5011xParams, int slotNum)
{
/*
zl5011xCetDeleteS cetDelete;
zl5011xIsrDeleteS isrDelete;
zl5011xCetRemoveDeviceS CetRemoveDevice;
int i;
*/
zl5011xCetRemoveDeviceS CetRemoveDevice;
zlStatusE status = ZL5011X_OK;
/*参数检查*/
if(NULL == zl5011xParams)
return ZL5011X_ERROR;
if(0 == le1veCetDevAdded[(slotNum)-1])
{
/*未初始化*/
return ZL5011X_ERROR;
}
/*自适应时钟恢复引用计数是否为零*/
if(le1veCetRefCnt[(slotNum)-1] > 0)\
{
/*该TDMoIP板上还有Context使用adaptive clock*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -