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

📄 zl5011xtfm.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************

Function:
   zl5011xTfmUpdateContext

Description:
   Sets the update bit for the context.

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

Outputs:
   None

Returns:
   zlStatusE

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

zlStatusE zl5011xTfmUpdateContext(zl5011xParamsS *zl5011xParams, Uint32T context)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T temp;

   ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmUpdateContext: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   /* the context can be updated from the INIT or TAKEN state. The error code is
      to show that the context needs to be taken before it can be updated */
   if ((zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_TAKEN) &&
      (zl5011xParams->wanIf.tfmCurrent.context[context].state != ZL5011X_STATE_INIT))
   {
      status = ZL5011X_CONTEXT_NOT_TAKEN;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams,
            ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
            &temp);
   }

   if (status == ZL5011X_OK)
   {
         /* cannot request an update and a teardown at the same time */
      if ((temp & (ZL5011X_1BIT_MASK << ZL5011X_TFM_TEARDOWN_BIT)) != 0)
      {
         status = ZL5011X_CONTEXT_IN_TEARDOWN;
      }
   }

   /* if the update bit is being set for the first time for this context, then need
      to reset the cache state for the context to force it into action */
   if (status == ZL5011X_OK)
   {
      if (zl5011xParams->wanIf.tfmCurrent.context[context].state == ZL5011X_STATE_INIT)
      {
         status = zl5011xTfmInitContextCache(zl5011xParams, context);
      }
   }

   if (status == ZL5011X_OK)
   {
      /* set the update bit */
      temp |= ZL5011X_1BIT_MASK << ZL5011X_TFM_UPDATE_BIT;

      /* if we are updating a context from the INIT state, then this context
         is not currently in use, so must also set the first frame bit. This
         allows the jitter buffer to be built up, and the context switch bit
         to be determined by the 1st packet received. */
      if (zl5011xParams->wanIf.tfmCurrent.context[context].state == ZL5011X_STATE_INIT)
      {
         temp |= ZL5011X_1BIT_MASK << ZL5011X_TFM_FIRST_FRAME_BIT;
      }

      status = zl5011xWrite(zl5011xParams,
            ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
            temp);
   }

   if (status == ZL5011X_OK)
   {
      zl5011xParams->wanIf.tfmCurrent.context[context].state = ZL5011X_STATE_UPDATING;
   }

   return(status);
}

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

Function:
   zl5011xTfmGetCurrentHeader

Description:
   This function is called to get the state of the current ctxt_sw bit.
   This bit is used to select the header that is in use in the packet
   classifier block.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        which context to get the ctct sw for

Outputs:
   ctxtSw         which header is currently in use.

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xTfmGetCurrentHeader(zl5011xParamsS *zl5011xParams,
          Uint32T context, Uint8T *ctxtSw)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T readValue;

   ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
         "zl5011xTfmGetCurrentHeader: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams,
         ZL5011X_TFM_CACHE5_FILL + (context * ZL5011X_TFM_CACHE5_FILL_SIZE),
         &readValue);

   if (status == ZL5011X_OK)
   {
      *ctxtSw = (Uint8T)((readValue >> ZL5011X_TFM_CTXT_SW_BIT) & ZL5011X_1BIT_MASK);

      ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
            "zl5011xTfmGetCurrentHeader: ctxt %3d, ctxt sw %d",
            context, *ctxtSw, 0, 0, 0, 0);
   }

   return(status);
}

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

Function:
   zl5011xTfmInitContextCache

Description:
   Initialises the cache for a given context. This must be called every time
   the context is updated (after the update bit is set).

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

Outputs:
   None

Returns:
   zlStatusE

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

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

   ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
         "zl5011xTfmInitContextCache:",
         0, 0, 0, 0, 0, 0);

   /* reset the cache fill 2 register, to clear any previous history */
   status = zl5011xWrite(zl5011xParams,
         ZL5011X_TFM_CACHE2_FILL + (context * ZL5011X_TFM_CACHE2_FILL_SIZE),
         0);

   if (status == ZL5011X_OK)
   {
      /* reset the byte offsets etc, to clear any previous history */
      status = zl5011xWrite(zl5011xParams,
            ZL5011X_TFM_CACHE1_FILL + (context * ZL5011X_TFM_CACHE1_FILL_SIZE),
            0);
   }

   if (status == ZL5011X_OK)
   {
      /* setup the cache control register, to restart the context */
      status = zl5011xWrite(zl5011xParams,
            ZL5011X_TFM_CACHE_CTRL + (context * ZL5011X_TFM_CACHE_CTRL_SIZE),
            ZL5011X_TFM_CACHE_INIT_VALUE);
   }

   return(status);
}

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

Function:
   zl5011xTfmGetContextValidBit

Description:
   Gets the state of the valid bit for the context.

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

Outputs:
   valid       boolean - if the valid bit is set then TRUE and  FALSE if clear

Returns:
   zlStatusE

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

zlStatusE zl5011xTfmGetContextValidBit(zl5011xParamsS *zl5011xParams, Uint32T context,
      zl5011xBooleanE *valid)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T readValue;

   ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
         "zl5011xTfmGetContextValidBit: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams,
         ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
         &readValue);

   if ((readValue & (ZL5011X_1BIT_MASK << ZL5011X_TFM_VALID_CTXT_BIT)) == 0)
   {
      *valid = ZL5011X_FALSE;
   }
   else
   {
      *valid = ZL5011X_TRUE;
   }

   ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context,
         "zl5011xTfmGetContextValidBit: ctxt %3d, valid %d",
         context, *valid, 0, 0, 0, 0);

   return(status);
}

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

Function:
   zl5011xTfmGetPayloadLength

Description:
   Reads from the device to find the length of the current packet.
   In a CES application, the length should be a constant and not changing
   from packet to packet.

Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        which context to get the length for.

Outputs:
   None

Returns:
   zlStatusE

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

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

   ZL5011X_TRACE_CONTEXT(ZL5011X_TFM_FN_ID, context, "zl5011xTfmGetPayloadLength: ctxt %3d",
         context, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams,
         ZL5011X_TFM_CACHE2_FILL + (context * ZL5011X_TFM_CACHE2_FILL_SIZE),
         &readValue);

   if (status == ZL5011X_OK)
   {
      *length = (readValue >> ZL5011X_TFM_PKT_LENGTH_BITS) &
            ZL5011X_TFM_PKT_LENGTH_MASK;
   }

   return(status);
}

/*******************************************************************************
 Function:
    zl5011xTfmDisableInterrupts

 Description:
   This function disables the interrupt sources.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        which context
   intBits        if a bit is set in this parameter the interrupt is disabled.

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
   The interrupt disable cannot be changed if an update or teardown is pending.

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

zlStatusE zl5011xTfmDisableInterrupts(zl5011xParamsS *zl5011xParams, Uint32T context,
      Uint32T intBits)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bitMask, temp;

   ZL5011X_TRACE(ZL5011X_TFM_FN_ID, "zl5011xTfmDisableInterrupts: ctxt %3d, mask %08X",
         context, intBits, 0, 0, 0, 0);

   bitMask = (ZL5011X_1BIT_MASK << ZL5011X_TFM_UNDERRUN_INT) |
         (ZL5011X_1BIT_MASK << ZL5011X_TFM_FRAME_INT) |
         (ZL5011X_1BIT_MASK << ZL5011X_TFM_LUT_INT) |
         (ZL5011X_1BIT_MASK << ZL5011X_TFM_UPDATE_INT) |
         (ZL5011X_1BIT_MASK << ZL5011X_TFM_TEARDOWN_INT);

   if ((intBits & ~bitMask) != 0)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams,
            ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
            &temp);
   }

   if (status == ZL5011X_OK)
   {
      if ((temp & intBits) != intBits)
      {
         /* the interrupt bits are to be changed, so check that neither
            update or teardown are pending */
         if ((temp & (ZL5011X_1BIT_MASK << ZL5011X_TFM_UPDATE_BIT)) != 0)
         {
            status = ZL5011X_CONTEXT_IN_UPDATE;
         }

         if ((temp & (ZL5011X_1BIT_MASK << ZL5011X_TFM_TEARDOWN_BIT)) != 0)
         {
            status = ZL5011X_CONTEXT_IN_TEARDOWN;
         }

         /* only set the interrupt bits if no update or teardown is pending.
            It is not safe to write to the register in these instances, since
            the device will autonomously do a write to clear the bits at
            some point */
         if (status == ZL5011X_OK)
         {
            status = zl5011xWrite(zl5011xParams,
                  ZL5011X_TFM_CONTEXT_MEMORY + (context * ZL5011X_TFM_CTXT_MEM_SIZE),
                  temp | intBits);

            /* record the state in the device structure */
            zl5011xParams->interruptMasks.tfmMask[context] = temp | intBits;
         }
      }
   }

   return(status);
}

/*******************************************************************************
 Function:
    zl5011xTfmEnableInterrupts

 Description:
   This function enables the interrupt sources
   It also clears the corresponding actual interrupt by writing ONE to it.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   context        which context
   intBits        if a bit is set here the interrupt is enabled.

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
   The interrupt enable cannot be changed if an update or teardown is pending.
   It is not safe to write to the register in these instances, since
   the device will autonomously do a write to clear the bits at some point

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

⌨️ 快捷键说明

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