?? zl5011xpla.c
字號:
/*******************************************************************************
*
* File name: zl5011xPla.c
*
* Version: 32
*
* Author: MRC
*
* Date created: 09/04/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 PLA block.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 27/02/2002 MRC Creation
* 2 28/02/2002 MRC Fixed and quick test
* 3 08/03/2002 MRC Updating
* 4 26/03/2002 MRC Teardown clears the update bit if set
* 5 09/04/2002 MRC Clear the valid and first bits when assigning
* a new channel
* 6 17/04/2002 MRC Changed the CHECK_.. macros to ZL5011X_CHECK_..
* 7 18/04/2002 MRC The calculate MPID function used the flow
* rather than the context ID.
* 8 23/04/2002 MRC Allow a context update from the INIT state.
* 9 07/05/2002 MRC Check update and teardown now uses the status
* to indicate when the change completes.
* 10 08/05/2002 MRC Set flow type and payload length used bits and
* mask to ReadModWrite in the wrong order.
* 11 09/05/2002 MRC Updated header.
* 12 06/06/2002 PJE added Enable & DisableInterrupt.
* Updated header & ZL5011X_TRACE.
* 13 13/06/2002 MRC Minor changes
* 14 09/07/2002 MRC TIF connection mode structure entry changed
* 15 12/07/2002 MRC The MPID for set flow type is now a parameter
* rather than calculated.
* 16 12/07/2002 MRC Fixed typo in set flow type fn
* 17 18/07/2002 PJE Added interrupt structure
* 18 29/08/2002 PJE First clear the interrupts before enabling.
* 19 30/09/2002 MRC CheckChan didn't check the active buffer when
* deciding if the channel was free
* 20 03/10/2002 JFE Fixed ZL5011X_TRACE's without : after function name.
* 21 21/10/2002 PJE new PlaEnable/DisableTmiOverflowIntr
* 22 31/10/2002 MRC Added variants + minor fixes
* 23 18/12/2002 MRC Mended bit shifting in context memory issue.
* 24 03/04/2003 MRC Changed interrupt enable to always clear the flags
* even if the mask cannot be changed due to update...
* 25 09/06/2003 MRC Added zl5011xPlaReadModWrite fn
* 26 10/06/2003 MRC Corrected zl5011xPlaReadModWrite fn
* 27 13/06/2003 PJE zl5011xPlaGetError mod to overcome bus data problem
* 28 16/02/2004 APL zl5011xPlaGetError now usable from interrupt context
* 29 23/07/2004 MRC Fixed some compiler warnings
* 30 19/08/2004 MRC Fixed comments
* 31 21/01/2005 MRC Updated first channel function
* 32 14/02/2005 APL Allow use of AUX_CLK stream to generate packets.
*
*******************************************************************************/
/***************** INCLUDE FILES *****************************/
#include "zl5011x.h"
#include "zl5011xPla.h"
#include "zl5011xPlaMap.h"
#include "zl5011xUtilLib.h"
/***************** EXPORTED GLOBAL VARIABLES *****************************/
/***************** STATIC GLOBAL VARIABLES *****************************/
/***************** STATIC FUNCTION DECLARATIONS *****************************/
static zlStatusE zl5011xPlaReadModWrite(zl5011xParamsS *zl5011xParams, AddressT addr,
Uint32T data, Uint32T mask);
/******************************************************************************/
/*******************************************************************************
Function:
zl5011xPlaInit
Description:
This function initialises the PLA data structure. The PLA should have already
been reset. The operation of the device is represented by two device structures.
current - use for tracking modifications
active - the state of the device after the last update.
By tracking both of these, the API has complete history of the PLA.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPlaInit(zl5011xParamsS *zl5011xParams)
{
Uint32T loop;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PLA_FN_ID, "zl5011xPlaInit:", 0, 0, 0, 0, 0, 0);
/* reset the context structures */
for (loop = 0; loop < ZL5011X_MAX_NUMBER_CONTEXTS; loop++)
{
/* reset the current context structure - used to track modifications */
zl5011xParams->wanIf.plaCurrent.context[loop].state = ZL5011X_STATE_NOT_IN_USE;
zl5011xParams->wanIf.plaCurrent.context[loop].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;
zl5011xParams->wanIf.plaCurrent.context[loop].numChannels = 0;
/* reset the active context structure - used to track device operation */
zl5011xParams->wanIf.plaActive.context[loop].state = ZL5011X_STATE_NOT_IN_USE;
zl5011xParams->wanIf.plaActive.context[loop].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;
zl5011xParams->wanIf.plaActive.context[loop].numChannels = 0;
}
/* reset the channel mapping structures */
for (loop = 0; loop < ZL5011X_MAX_NUMBER_CHANNELS; loop++)
{
/* reset the current channel structure - used to track modifications */
zl5011xParams->wanIf.plaCurrent.channel[loop].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
/* reset the active channel structure - used to track device operation */
zl5011xParams->wanIf.plaActive.channel[loop].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
}
status = zl5011xWrite(zl5011xParams, ZL5011X_PLA_BLOCK_ID,
ZL5011X_PLA_SOURCE_BLOCK_ID);
return(status);
}
/*******************************************************************************
Function:
zl5011xPlaAddChan
Description:
Add a channel to the required context. Checks to see that the channel
is not already in use. The first channel is not tracked when adding channels.
The update of the first channel takes place when the context is updated.
This function should only be called once in unstructured mode. With the one
access made when the context is initialised.
Checking for unstructured accesses is a function of the layer above.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to associate the channel with
tdm stream and channel to add.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPlaAddChan(zl5011xParamsS *zl5011xParams,
Uint32T context, zl5011xWanChannelS tdm)
{
Uint32T checkContext, chanIndex;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE_CONTEXT(ZL5011X_PLA_FN_ID, context,
"zl5011xPlaAddChan: ctxt %3d, str %2d, ch %3d",
context, tdm.stream, tdm.channel, 0, 0, 0);
status = zl5011xCheckTdm(zl5011xParams, tdm, &chanIndex);
if (status == ZL5011X_OK)
{
status = zl5011xPlaCheckChan(zl5011xParams, &checkContext, chanIndex);
}
if (status == ZL5011X_OK)
{
if ((checkContext != (Uint32T)ZL5011X_INVALID_CONTEXT) && (checkContext != context))
{
status = ZL5011X_CHANNEL_IN_USE;
}
}
if (status == ZL5011X_OK)
{
if (checkContext != context)
{
/* If in unstructured mode, then only one stream can be associated
with a context */
if (zl5011xParams->wanIf.wanConnectionMode == ZL5011X_WAN_CONNECTION_UNFRAMED)
{
/* unstructured mode, so check that only one channel is attached */
if (zl5011xParams->wanIf.plaCurrent.context[context].numChannels >= 1)
{
status = ZL5011X_CHANNEL_RANGE;
}
}
if (status == ZL5011X_OK)
{
status = zl5011xPlaAssignChan(zl5011xParams, context, chanIndex);
}
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPlaRemoveChan
Description:
Removes a channel from the required context, if is already associated with
this context.The first channel is not tracked when adding channels.
The update of the first channel takes place when the context is updated.
This should not be called in unstructured mode, since only one stream is
allowed. Checking for unstructured accesses is in the layer above.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to remove the channel from
tdm stream and channel to remove.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPlaRemoveChan(zl5011xParamsS *zl5011xParams,
Uint32T context, zl5011xWanChannelS tdm)
{
Uint32T checkContext, chanIndex;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE_CONTEXT(ZL5011X_PLA_FN_ID, context,
"zl5011xPlaRemoveChan: ctxt %3d, str %2d, ch %3d",
context, tdm.stream, tdm.channel, 0, 0, 0);
status = zl5011xCheckTdm(zl5011xParams, tdm, &chanIndex);
if (status == ZL5011X_OK)
{
status = zl5011xPlaCheckChan(zl5011xParams, &checkContext, chanIndex);
}
if (status == ZL5011X_OK)
{
if ((checkContext != context))
{
status = ZL5011X_CHANNEL_NOT_IN_CTXT;
}
else
{
status = zl5011xPlaFreeChan(zl5011xParams, context, chanIndex);
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPlaAssignChan
Description:
Adds the channel to the required context. All checks for validity of
the operation will have been performed outside of this function.
This function accesses the device and maintains the current structures.
The first channel bit is reset when adding a channel, and is not tracked.
The update of the first channel takes place when the context is updated.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to associate the channel with
chanIndex Index used to represent the channel in a linear array.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPlaAssignChan(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T chanIndex)
{
zlStatusE status = ZL5011X_OK;
Uint32T bits;
ZL5011X_TRACE_CONTEXT(ZL5011X_PLA_FN_ID, context,
"zl5011xPlaAssignChan: ctxt %3d, lkup %4X",
context, chanIndex, 0, 0, 0, 0);
zl5011xParams->wanIf.plaCurrent.context[context].numChannels++;
bits = (ZL5011X_1BIT_MASK << ZL5011X_PLA_NEW_VALID_CHAN_BIT) |
(context << ZL5011X_PLA_LKUP_CTXT_ID_BITS);
zl5011xParams->wanIf.plaCurrent.channel[chanIndex].context = context;
status = zl5011xWrite(zl5011xParams,
ZL5011X_PLA_CONTEXT_LOOKUP + (chanIndex * ZL5011X_PLA_LKUP_MEM_SIZE),
bits);
return(status);
}
/*******************************************************************************
Function:
zl5011xPlaFreeChan
Description:
Removes the channel from the required context. Checks that a context has at
least one channel, but all other checks for validity of the operation will
have been performed outside of this function.
This function accesses the device and maintains the current structures.
The first channel and valid channel bits are cleared when removing a channel.
The update of the first channel takes place when the context is updated.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context the context to remove the channel from
chanIndex Index used to represent the channel in a linear array.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPlaFreeChan(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T chanIndex)
{
zlStatusE status = ZL5011X_OK;
Uint32T bits;
Uint32T bitMask;
ZL5011X_TRACE_CONTEXT(ZL5011X_PLA_FN_ID, context,
"zl5011xPlaFreeChan: ctxt %3d, lkup %4X",
context, chanIndex, 0, 0, 0, 0);
if (zl5011xParams->wanIf.plaCurrent.context[context].numChannels <= 1)
{
status = ZL5011X_LAST_CHANNEL_IN_CONTEXT;
}
if (status == ZL5011X_OK)
{
zl5011xParams->wanIf.plaCurrent.context[context].numChannels--;
bits = 0;
bitMask = (ZL5011X_1BIT_MASK << ZL5011X_PLA_NEW_FIRST_CHAN_BIT) |
(ZL5011X_1BIT_MASK << ZL5011X_PLA_NEW_VALID_CHAN_BIT);
zl5011xParams->wanIf.plaCurrent.channel[chanIndex].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
if (zl5011xParams->wanIf.plaCurrent.context[context].firstChannelIndex == chanIndex)
{
zl5011xParams->wanIf.plaCurrent.context[context].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;
}
status = zl5011xPlaReadModWrite(zl5011xParams,
ZL5011X_PLA_CONTEXT_LOOKUP + (chanIndex * ZL5011X_PLA_LKUP_MEM_SIZE),
bits, bitMask);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xPlaUpdateFirstChan
Description:
This called when the context is ready for update. In any add / remove
channel operations that have taken place, the first channel was not tracked.
The current structure is now scanned to find the first channel. If it is
different from the first channel used in the active structure (operating
mode of the device at the moment), then old channel is set to no longer
be the first and the new first channel set up.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context context to update the first channel for.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPlaUpdateFirstChan(zl5011xParamsS *zl5011xParams,
Uint32T context)
{
zlStatusE status = ZL5011X_OK;
zl5011xBooleanE foundFirst = ZL5011X_FALSE;
zl5011xWanChannelS tdm;
Uint32T chanIndex, loop, activeChannels;
ZL5011X_TRACE_CONTEXT(ZL5011X_PLA_FN_ID, context,
"zl5011xPlaUpdateFirstChan: context %3d",
context, 0, 0, 0, 0, 0);
/* the loops are arranged to represent the order in which the device does
the search for the first channel -
i.e. channel 0 stream 0
channel 0 stream 1
channel 0 stream 2 etc. */
for (tdm.channel = 0; ((tdm.channel < zl5011xParams->wanIf.wanNumChannels ) &&
(foundFirst == ZL5011X_FALSE)); tdm.channel++)
{
/* Iterate around all possible streams. This allows non-contiguous stream numbers to be used */
for (tdm.stream = 0; ((tdm.stream < ZL5011X_MAX_NUMBER_STREAMS) &&
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -