?? zl5011xpac.c
字號:
/*******************************************************************************
*
* File name: zl5011xPac.c
*
* Version: 53
*
* Author: MRC
*
* Date created: 27/03/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
*
* This file contains all the functions that will initialise and control
* the PAC block.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 27/03/2002 MRC Creation
* 2 28/03/2002 MRC Added async functions
* 3 03/04/2002 MRC Added more async functions
* 4 17/04/2002 MRC Changed the CHECK_.. macros to ZL5011X_CHECK_..
* 5 22/04/2002 MRC Changed the interrupt functions to use the read
* modify write function. Also streamNum changed
* to 8 bit from 32 bit in a few places.
* 6 26/04/2002 MRC Added typedef's for 64 bit numbers
* 7 23/05/2002 MRC Async reference and RTP had changed in the PAC
* 8 28/05/2002 MRC Number of frames setting is no longer used for
* RTP timestamp
* 9 17/06/2002 LCW Minor mods.
* 10 17/06/2002 LCW Minor mods.
* 11 19/06/2002 MRC PAC block changed - mostly updated. Need to
* add support for PLL bandwidth, lock detect etc.
* 12 19/06/2002 PJE modified interruptMasks in structure
* 13 02/07/2002 MRC Changed DPLL centre freq calculation to use 64 bit
* numbers
* 14 09/07/2002 MRC TIF interface structure changed and DPLL modified
* 15 10/07/2002 MRC DPLL block changed frame pulse options
* 16 12/07/2002 MRC Missed out break in DPLL initialise function
* 17 15/07/2002 MRC DCO registers changed
* 18 17/07/2002 MRC Temporary fix for DCO setting
* 19 18/07/2002 MRC DCO is initialised to 0 to disable output clocks
* 20 16/09/2002 MRC Added in fns for setting inverse DCO value
* 21 19/09/2002 MRC Added extra dpll control fns
* 22 20/09/2002 MRC Fixed dpll 2M / 8M selection
* 23 01/10/2002 DJA ZL5011X_TRACE messages fixed up
* 24 02/10/2002 DJA ZL5011X_TRACE messages fixed up - part 2 !
* 25 03/10/2002 PJE info from verification: intr mask polarities were wrong
* changed to ONE to enable (zl5011xPacEnableInterrupts)
* 26 11/10/2002 MRC Added fix for Async interrupt reference when
* using stream input
* 27 24/10/2002 PJE API tidy up
* 28 31/10/2002 MRC Added variants + minor fixes
* 29 11/11/2002 MRC Added zl5011xPacDpllRefEnableLimits, to enable
* the DPLL engine when the limits have been set.
* 30 11/11/2002 MRC Fixed fn header
* 31 13/11/2002 MRC Fixed async interrupt mask problem
* 32 28/01/2003 MRC Added functions for CET data collection
* 33 06/02/2003 MRC Added DPLL output enable function
* 34 24/03/2003 MRC Stream DCO calculation had wrapped and dpll lock
* range changed
* 35 10/04/2003 MRC Differential sequence numbers were not returned
* 36 06/05/2003 MRC Only enable the DCO TDL's if a fast LIU freq.
* Reference freq's can be user defined
* 37 22/05/2003 NJF PAC changes
* 38 27/05/2003 MRC Tidied up PAC changes and enable TDL's
* 39 11/06/2003 MRC Disables DPLL when in async mode
* 40 11/08/2003 MRC Added limit check for user reference freq
* 41 15/04/2004 MRC Updated SetDcoOffset function to more precision
* 42 23/07/2004 MRC Fixed some compiler warnings
* 43 29/07/2004 MRC Fixed some compiler warnings
* 44 19/08/2004 MRC DCO calculation didn't work for slow LIU freqs
* 45 08/09/2004 MRC Added option to call library fn for 64 bit calcs
* 46 20/10/2004 MRC Added PRS variable to async configure function
* 47 16/11/2004 MRC Added individual stream frequency control
* 48 18/11/2004 MRC Added fix to DcoInit functionality for low
* stream count variants
* 49 16/12/2004 MRC Added clock reference mux functions
* 50 03/03/2005 MRC ConfigureAsync always configures ref source
* 51 01/04/2005 MRC Amended parameter check in zl5011xPacDpllRefSetSingleLimit
* 52 04/07/2005 MRC Added support for clock only streams
* 53 21/07/2005 MRC Fixed PLL status and configuration functions
*
*******************************************************************************/
/***************** INCLUDE FILES *****************************/
#include "zl5011x.h"
#include "zl5011xPac.h"
#include "zl5011xPacMap.h"
#include "zl5011xUtilLib.h"
/***************** EXPORTED GLOBAL VARIABLES *****************************/
/***************** STATIC GLOBAL VARIABLES *****************************/
/***************** STATIC FUNCTION DECLARATIONS *****************************/
/******************************************************************************/
/* define types for 64 bit numbers. This is being done locally to this file
and its usage should be minimised. */
#ifdef _ZL5011X_DISABLE_64_BIT_OPERATIONS
#include "gmp.h"
#include "gmp-impl.h"
typedef mpz_t Uint64T;
typedef mpz_t Sint64T;
#else
typedef unsigned OS_INT64 Uint64T;
typedef OS_INT64 Sint64T;
#endif
/*******************************************************************************
Function:
zl5011xPacInit
Description:
This function initialises the PAC block and data structure.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPacInit(zl5011xParamsS *zl5011xParams)
{
Uint32T loop;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacInit:", 0, 0, 0, 0, 0, 0);
/* reset the context structures */
for (loop = 0; loop < ZL5011X_MAX_NUMBER_STREAMS; loop++)
{
zl5011xParams->wanIf.clock.async.stream[loop].dataMode = ZL5011X_WAN_ASYNC_DISABLED;
zl5011xParams->wanIf.clock.async.stream[loop].wanRtpJitterCalcEnable = ZL5011X_FALSE;
zl5011xParams->wanIf.clock.async.stream[loop].txClockMode = ZL5011X_WAN_ASYNC_CLOCK_DCO_NORMAL;
zl5011xParams->wanIf.clock.async.stream[loop].streamFrequency = 0;
}
/* disable all of the interrupts */
if (status == ZL5011X_OK)
{
status = zl5011xPacDisableInterrupts(zl5011xParams, ZL5011X_PAC_INT_MASK);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPacCheckRef
Description:
Checks that the external frequency is valid and returns the numeric value
for the enum passed in.
Inputs:
zl5011xParams Pointer to the structure for this device instance
ref structure to select the external ref source / freq
Outputs:
refFreqHz number that represents the ref freq in Hz
Returns:
zlStatusE
Remarks:
*******************************************************************************/
zlStatusE zl5011xPacCheckRef(zl5011xParamsS *zl5011xParams,
zl5011xRefClkConfigS *ref, Uint32T *refFreqHz)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PAC_FN_ID,
"zl5011xPacCheckRef: src %d, ref %d, stream %2d",
ref->source, ref->refFreq, ref->stream, 0, 0, 0);
if (ref->source == ZL5011X_WAN_STREAM_REF)
{
status = zl5011xCheckClockRange(zl5011xParams, ref->stream);
if (status == ZL5011X_OK)
{
*refFreqHz = zl5011xParams->wanIf.clock.async.stream[ref->stream].streamFrequency;
}
}
else
{
switch (ref->refFreq)
{
case ZL5011X_WAN_REF_FREQ_8K :
*refFreqHz = 8000;
break;
case ZL5011X_WAN_REF_FREQ_64K :
*refFreqHz = 64000;
break;
case ZL5011X_WAN_REF_FREQ_1_544M :
*refFreqHz = 1544000;
break;
case ZL5011X_WAN_REF_FREQ_2_048M :
*refFreqHz = 2048000;
break;
case ZL5011X_WAN_REF_FREQ_4_096M :
*refFreqHz = 4096000;
break;
case ZL5011X_WAN_REF_FREQ_6_312M :
*refFreqHz = 6312000;
break;
case ZL5011X_WAN_REF_FREQ_8_192M :
*refFreqHz = 8192000;
break;
case ZL5011X_WAN_REF_FREQ_16_384M :
*refFreqHz = 16384000;
break;
case ZL5011X_WAN_REF_FREQ_34_368M :
*refFreqHz = 34368000;
break;
case ZL5011X_WAN_REF_FREQ_USER_DEFINED :
/* check that the user frequency is not too fast. The fastest
input allowed for a reference is the E3 clock at 34.368MHz */
if (ref->userDefinedFreqHz <= 34368000)
{
*refFreqHz = ref->userDefinedFreqHz;
}
else
{
status = ZL5011X_PARAMETER_INVALID;
}
break;
default :
status = ZL5011X_PARAMETER_INVALID;
break;
}
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_PAC_FN_ID,
"zl5011xPacCheckRef: src %d, ref %d, stream %2d, ref Hz %d",
ref->source, ref->refFreq, ref->stream, *refFreqHz, 0, 0);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPacCheckDpllRef
Description:
Checks that the dpll reference frequency is valid and returns the numeric
value for the enum passed in.
Inputs:
zl5011xParams Pointer to the structure for this device instance
refFreq enum to select the frequency of the external ref
Outputs:
refFreqHz number that represents the ref freq in Hz
Returns:
zlStatusE
Remarks:
*******************************************************************************/
zlStatusE zl5011xPacCheckDpllRef(zl5011xParamsS *zl5011xParams,
zl5011xDpllRefInputFreqE refFreq, Uint32T *refFreqHz)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacCheckDpllRef: ref %d", refFreq, 0, 0, 0, 0, 0);
switch (refFreq)
{
case ZL5011X_DPLL_8K_REF :
*refFreqHz = 8000;
break;
case ZL5011X_DPLL_64K_REF :
*refFreqHz = 64000;
break;
case ZL5011X_DPLL_1_544M_REF :
*refFreqHz = 1544000;
break;
case ZL5011X_DPLL_2_048M_REF :
*refFreqHz = 2048000;
break;
case ZL5011X_DPLL_4_096M_REF :
*refFreqHz = 4096000;
break;
case ZL5011X_DPLL_6_312M_REF :
*refFreqHz = 6312000;
break;
case ZL5011X_DPLL_8_192M_REF :
*refFreqHz = 8192000;
break;
case ZL5011X_DPLL_16_384M_REF :
*refFreqHz = 16384000;
break;
default :
status = ZL5011X_PARAMETER_INVALID;
break;
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacCheckDpllRef: ref %d, ref Hz %d",
refFreq, *refFreqHz, 0, 0, 0, 0);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPacConfigureSync
Description:
This function initialises configures the DPLL - used in for synchronous mode.
The DPLL is initialised, with default values for lock range and slew rate.
Inputs:
zl5011xParams Pointer to the structure for this device instance
config connection mode for the DPLL :-
slave - the internal DPLL is by-passed - clock / frm are
sourced externally
master - references are divided down for the DPLL. Clock / frm
signals are sourced internally and output.
external - references are divided down for the DPLL and output
on PLL_PRI and PLL_SEC. Otherwise the same as slave.
masterOutputEnable ZL5011X_TRUE to enable the PLL_PRI and PLL_SEC outputs
primaryRef source for the primary reference - stream or ext ref
secondaryRef source for the primary reference - stream or ext ref
priority priority mode for the reference sources.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPacConfigureSync(zl5011xParamsS *zl5011xParams,
zl5011xDpllConnectionE config, zl5011xBooleanE masterOutputEnable,
zl5011xRefClkConfigS primaryRefConfig, zl5011xRefClkConfigS secondaryRefConfig,
zl5011xDpllRefPriorityE priority)
{
zlStatusE status = ZL5011X_OK;
zl5011xDpllRefInputFreqE dpllRefFreq = 0;
zl5011xBooleanE outputEnable = ZL5011X_FALSE;
Uint32T primaryFreq = 0;
Uint32T secondaryFreq = 0;
Uint32T dpllFreq = 0;
ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacConfigureSync: mode %d, priority %d",
config, priority, 0, 0, 0, 0);
/* work out the frequency of the primary reference input to the device,
or 0 if it is not in use */
if (status == ZL5011X_OK)
{
if (priority != ZL5011X_DPLL_SECONDARY_ONLY)
{
status = zl5011xPacCheckRef(zl5011xParams, &primaryRefConfig, &primaryFreq);
}
}
/* work out the frequency of the secondary reference input to the device,
or 0 if it is not in use */
if (status == ZL5011X_OK)
{
if (priority != ZL5011X_DPLL_PRIMARY_ONLY)
{
status = zl5011xPacCheckRef(zl5011xParams, &secondaryRefConfig, &secondaryFreq);
}
}
/* work out what is the highest common frequency for the DPLL reference */
if (status == ZL5011X_OK)
{
for (dpllRefFreq = ZL5011X_DPLL_6_312M_REF; (Sint8T)dpllRefFreq >= 0; dpllRefFreq = (zl5011xDpllRefInputFreqE)((Uint32T)dpllRefFreq - 1))
{
status = zl5011xPacCheckDpllRef(zl5011xParams, dpllRefFreq, &dpllFreq);
if (status == ZL5011X_OK)
{
if (((primaryFreq % dpllFreq) == 0) && ((secondaryFreq % dpllFreq) == 0))
{
/* the references are direct multiples of the dpll i/p freq */
break;
}
}
}
}
if (status == ZL5011X_OK)
{
if ((Sint8T)dpllRefFreq < 0)
{
/* didn't find a DPLL frequency that worked */
status = ZL5011X_PARAMETER_INVALID;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -