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

📄 zl5011xpla.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 4 页
字号:
            (foundFirst == ZL5011X_FALSE)); tdm.stream++)
      {
         if (status != ZL5011X_OK)
         {
            break;
         }

         /* Check that this stream is valid for this device. */
         if (zl5011xCheckStreamRange(zl5011xParams, tdm.stream)  == ZL5011X_OK)
         {
            status = zl5011xCalcChanIndex(zl5011xParams, tdm, &chanIndex);

            if (status == ZL5011X_OK)
            {
               if (zl5011xParams->wanIf.plaCurrent.channel[chanIndex].context == context)
               {
                  foundFirst = ZL5011X_TRUE;
               }
            }
         }
      }
   }

   if (status == ZL5011X_OK)
   {
      /* if we have not found any channels, then something has gone seriously wrong */
      if (foundFirst != ZL5011X_TRUE)
      {
         status = ZL5011X_CTXT_NO_CHANNELS;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* check that the number of channels is not being exceeded */
      activeChannels = 0;

      /* count the number of channels used by other contexts */
      for (loop = 0; loop < ZL5011X_MAX_NUMBER_CHANNELS; loop++)
      {
         Uint32T tempContext;

         /* check if a valid context number is specified in the active device copy */
         tempContext = zl5011xParams->wanIf.plaActive.channel[loop].context;

         if (tempContext == (Uint32T)ZL5011X_INVALID_CONTEXT)
         {
            /* active context for this channel, so check in the modification copy */
            tempContext = zl5011xParams->wanIf.plaCurrent.channel[loop].context;
         }

         if ((tempContext != (Uint32T)ZL5011X_INVALID_CONTEXT) && (tempContext != context))
         {
            /* got a context for this channel and it's not the one we are updating */
            switch (zl5011xParams->wanIf.plaCurrent.context[tempContext].state)
            {
               case ZL5011X_STATE_TAKEN :
               case ZL5011X_STATE_ACTIVE :
                  if (zl5011xParams->wanIf.plaActive.channel[loop].context != (Uint32T)ZL5011X_INVALID_CONTEXT)
                  {
                     /* the device usage for the state is represented in the active device copy */
                     activeChannels++;
                  }
                  break;

               case ZL5011X_STATE_UPDATING :
                  if (zl5011xParams->wanIf.plaCurrent.channel[loop].context != (Uint32T)ZL5011X_INVALID_CONTEXT)
                  {
                     /* the device usage for the state is represented in the current device copy, that is
                        a change has been requested and the device is in the process of switching */
                     activeChannels++;
                  }
                  break;

               case ZL5011X_STATE_NOT_IN_USE :
               case ZL5011X_STATE_INIT :
               case ZL5011X_STATE_TEARING_DOWN :
               default :
                  /* channel not active */
                  break;
            }
         }
      }

      activeChannels += zl5011xParams->wanIf.plaCurrent.context[context].numChannels;

      if (activeChannels > zl5011xParams->devLimits.numChannels)
      {
         status = ZL5011X_CHANNEL_CAPACITY;
      }
   }

   if (status == ZL5011X_OK)
   {
      if (zl5011xParams->wanIf.plaCurrent.context[context].firstChannelIndex !=
            chanIndex)
      {
         /* we have a new first channel, so reset the first bit in the old one */
         status = zl5011xPlaClearFirstChan(zl5011xParams, context);

         /* and set the first bit in the new one */
         if (status == ZL5011X_OK)
         {
            status = zl5011xPlaSetFirstChan(zl5011xParams, context, chanIndex);
         }
      }
   }

   return status;
}

/*******************************************************************************

 Function:
    zl5011xPlaClearFirstChan

 Description:
   Clears the first channel for the context. Clears the bit in the channel mapping
   for the device and sets the first channel in the context structure to invalid.
   If the previous value was valid, then checks that it was in bounds.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     context to reset the first channel for.

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPlaClearFirstChan(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T tempFirstIndex;

   tempFirstIndex = zl5011xParams->wanIf.plaCurrent.context[context].firstChannelIndex;

   /* if there wasn't a valid first channel, then just exit with OK, since
      this is to be expected */
   if (tempFirstIndex != (Uint32T)ZL5011X_INVALID_CHANNEL)
   {
      ZL5011X_TRACE_CONTEXT(ZL5011X_PLA_FN_ID, context,
            "zl5011xPlaClearFirstChan: context %3d, lkup %4X",
            context, tempFirstIndex, 0, 0, 0, 0);

      if (tempFirstIndex >= ZL5011X_MAX_NUMBER_CHANNELS)
      {
         status = ZL5011X_WAN_INVALID_FIRST_CHANNEL;
      }
      else
      {
         zl5011xParams->wanIf.plaCurrent.context[context].firstChannelIndex = (Uint32T)ZL5011X_INVALID_CHANNEL;

         status = zl5011xPlaReadModWrite(zl5011xParams,
               ZL5011X_PLA_CONTEXT_LOOKUP + (tempFirstIndex * ZL5011X_PLA_LKUP_MEM_SIZE),
               0,
               ZL5011X_1BIT_MASK << ZL5011X_PLA_NEW_FIRST_CHAN_BIT);
      }
   }

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPlaSetFirstChan

 Description:
   Sets the first channel for the context. Sets the bit in the channel mapping
   for the device and sets the first channel in the context structure to
   the context.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     context to reset the first channel for.

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPlaSetFirstChan(zl5011xParamsS *zl5011xParams,
      Uint32T context, Uint32T chanIndex)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PLA_FN_ID, "zl5011xPlaSetFirstChan: lkup %4X",
         chanIndex, 0, 0, 0, 0, 0);

   zl5011xParams->wanIf.plaCurrent.context[context].firstChannelIndex = chanIndex;

   status = zl5011xPlaReadModWrite(zl5011xParams,
         ZL5011X_PLA_CONTEXT_LOOKUP + (chanIndex * ZL5011X_PLA_LKUP_MEM_SIZE),
         ZL5011X_1BIT_MASK << ZL5011X_PLA_NEW_FIRST_CHAN_BIT,
         ZL5011X_1BIT_MASK << ZL5011X_PLA_NEW_FIRST_CHAN_BIT);

   return(status);
}

/*****************************************************************************
Function:
   zl5011xPlaCheckChan

Description:
   Checks whether the channel is in use and retruns the context if it is.
   If the context is in update or teardown, then a check is made to see if
   the operation has finished. If it has, then the active and current structures
   are updated.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   chanIndex   Index used to represent the channel in a linear array.

Outputs:
   context     Use to pass back the context associated with the channel.
               Can be either a channel or invalid if the channel is free.

 Returns:
   zlStatusE

 Remarks:
    None

*****************************************************************************/

zlStatusE zl5011xPlaCheckChan(zl5011xParamsS *zl5011xParams,
      Uint32T *context, Uint32T chanIndex)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T tempContext;

   ZL5011X_TRACE(ZL5011X_PLA_FN_ID, "zl5011xPlaCheckChan: lkup %4X",
         chanIndex, 0, 0, 0, 0, 0);

   /* determine if the channel is associated with a context */
   tempContext = zl5011xParams->wanIf.plaActive.channel[chanIndex].context;

   /* check the modification buffer if active is unused */
   if (tempContext == (Uint32T)ZL5011X_INVALID_CONTEXT)
   {
      tempContext = zl5011xParams->wanIf.plaCurrent.channel[chanIndex].context;
   }

   /* if the channel is associated with a context, then check if it is still in use */
   if (tempContext != (Uint32T)ZL5011X_INVALID_CONTEXT)
   {
      if (zl5011xParams->wanIf.plaCurrent.context[tempContext].state == ZL5011X_STATE_TEARING_DOWN)
      {
         status = zl5011xPlaCheckContextTeardown(zl5011xParams, tempContext);

         /* if the return code indicates that the teardown completed, then this is not
            an error, so don't proliferate it */
         if (status == ZL5011X_CONTEXT_TEARDOWN_COMPLETE)
         {
            status = ZL5011X_OK;
         }
      }
      else
      {
         if (zl5011xParams->wanIf.plaCurrent.context[tempContext].state == ZL5011X_STATE_UPDATING)
         {
            status = zl5011xPlaCheckContextUpdate(zl5011xParams, tempContext);

            /* if the return code indicates that the update completed, then this is not
               an error, so don't proliferate it */
            if (status == ZL5011X_CONTEXT_UPDATE_COMPLETE)
            {
               status = ZL5011X_OK;
            }
         }
      }

      /* the current and active structures will have been updated if any change
         had completed, so just check the structures */
      if (status == ZL5011X_OK)
      {
         *context = zl5011xParams->wanIf.plaActive.channel[chanIndex].context;

         /* check the modification buffer if active is unused */
         if (*context == (Uint32T)ZL5011X_INVALID_CONTEXT)
         {
            *context = zl5011xParams->wanIf.plaCurrent.channel[chanIndex].context;
         }
      }
   }
   else
   {
      *context = (Uint32T)ZL5011X_INVALID_CONTEXT;
   }

   return(status);
}

/*****************************************************************************
Function:
   zl5011xPlaCheckContextTeardown

Description:
   Reads from the device to see if the teardown has completed. If it has
   then the routine to clean up the structures is called.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context to check

Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
    None

*****************************************************************************/

zlStatusE zl5011xPlaCheckContextTeardown(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T readValue;

   ZL5011X_TRACE(ZL5011X_PLA_FN_ID, "zl5011xPlaCheckContextTeardown: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   if (zl5011xParams->wanIf.plaCurrent.context[context].state != ZL5011X_STATE_TEARING_DOWN)
   {
      status = ZL5011X_CONTEXT_NOT_IN_TEARDOWN;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams,
            ZL5011X_PLA_CONTEXT_MEMORY1 + (context * ZL5011X_PLA_CTXT_MEM1_SIZE),
            &readValue);
   }

   if (status == ZL5011X_OK)
   {
      if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_PLA_TEARDOWN_BIT)) == 0)
      {
         /* the teardown bit is now clear, so update the current and active PLA
            structures */
         status = zl5011xPlaTearoutContext(zl5011xParams, context);

         if (status == ZL5011X_OK)
         {
            status = ZL5011X_CONTEXT_TEARDOWN_COMPLETE;
         }
      }
   }

   return(status);
}

/*****************************************************************************
Function:
   zl5011xPlaCheckContextUpdate

Description:
   Reads from the device to see if the update has completed. If it has
   then the routine to clean up the structures is called.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context to check

Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
    None

*****************************************************************************/

zlStatusE zl5011xPlaCheckContextUpdate(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T readValue;

   ZL5011X_TRACE(ZL5011X_PLA_FN_ID, "zl5011xPlaCheckContextUpdate: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   if (zl5011xParams->wanIf.plaCurrent.context[context].state != ZL5011X_STATE_UPDATING)
      status = ZL5011X_CONTEXT_NOT_IN_UPDATE;

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams,
            ZL5011X_PLA_CONTEXT_MEMORY1 + (context * ZL5011X_PLA_CTXT_MEM1_SIZE),
            &readValue);
   }

   if (status == ZL5011X_OK)
   {
      if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_PLA_UPDATE_BIT)) == 0)
      {
         /* the update bit is now clear, so update the current and active PLA
            structures */
         status = zl5011xPlaUpdateActiveContext(zl5011xParams, context);

         if (status == ZL5011X_OK)
         {
            status = ZL5011X_CONTEXT_UPDATE_COMPLETE;
         }
      }
   }

   return(status);
}

/*****************************************************************************
Function:
   zl5011xPlaTearoutContext

Description:
   Removes all references to a context from both the active and current channel
   structures. Then resets the entries in the active and current context
   structures. Sets the state for the context to be not in use.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context     which context to clear up

Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
    None

*****************************************************************************/

zlStatusE zl5011xPlaTearoutContext(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T loop;

   ZL5011X_TRACE(ZL5011X_PLA_FN_ID, "zl5011xPlaTearoutContext: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   /* copy the channel information from current to active structure */
   for (loop = 0; loop < ZL5011X_MAX_NUMBER_CHANNELS; loop++)
   {

⌨️ 快捷键说明

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