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

📄 zl5011xpkc.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    TM to control the routing.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   flow           the flow type that should be used for messages forwarded to
                  the host.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xPkcSetHostFlowType(zl5011xParamsS *zl5011xParams,
      zl5011xFlowTypeE flow)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcSetHostFlowType: flow %d",
         flow, 0, 0, 0, 0, 0);

   status = ZL5011X_CHECK_FLOW_TYPE(flow);

   if (status == ZL5011X_OK)
   {
      status = zl5011xWrite(zl5011xParams, ZL5011X_PKC_HOST_FLOW_TYPE,
            flow  << ZL5011X_PKC_NO_MATCH_FLOW_BITS);
   }

   return (status);
}

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

 Function:
    zl5011xAssembleBitFields

 Description:
    This function is used to assemble bit fields into 32 bit words.
    An array of input words is provided, and the new data field is written into
    the array, using the current index and the bit position within the word as
    the starting point

 Inputs:
   newField       the data bits that are to be copied into the output word
   newFieldSize   how many bits are to be copied to the output word

 Outputs:
   word           the base address of the word array used to store the fields
   index          current word to use in the array
   wordPos        the bit position for data to be added to the word. This is input,
                  and updated when bits are added.

 Returns:
   zlStatusE

 Remarks:
   If the bit field size is greater than 32 bits, then the remaining bits will
   be padded with 0.

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

zlStatusE zl5011xAssembleBitFields(Uint32T *word, Uint8T *index, Uint8T *wordPos,
      Uint32T newField, Uint8T newFieldSize)
{
   Uint32T loop;
   Uint32T bit;
   zlStatusE status = ZL5011X_OK;

   loop = 0;
   while (loop < newFieldSize)
   {
      /* get the bit from the new field */
      if (loop >= 32)
      {
         bit = 0;
      }
      else
      {
         bit = (newField >> loop) & ZL5011X_1BIT_MASK;
      }

      /* shift the new bit into the right place in the current word */
      word[*index] = (word[*index] & ~(ZL5011X_1BIT_MASK << *wordPos)) | bit << *wordPos;

      (*wordPos)++;

      /* if we have reached the end of the word then change over to start
         working on the second one */
      if (*wordPos >= 32)
      {
         (*index)++;
         *wordPos = 0;
      }

      loop++;
   }

   return (status);
}

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

 Function:
    zl5011xWriteAssembledBitFields

 Description:
   This function is used to write data to the device that has been assembled
   into an array. The device must be accessed in reverse order, due to a
   latching mechanism in the PKC - that is the highest address first.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   word           array of words to write to the device
   numWords       How many words to write to the device
   wordPos        The word position is needed to determine whether the word is
                  empty or not.
   address        the base address for the access. The last write will be to this
                  address (i.e. the address is decremented after each write).

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xWriteAssembledBitFields(zl5011xParamsS *zl5011xParams,
      Uint32T *word, Uint8T numWords, Uint8T wordPos, Uint32T address)
{
   zlStatusE status = ZL5011X_OK;
   Sint32T  loop;

   /* if no bits have been added to this word, then subtract one from the
      length count */
   if (wordPos == 0)
   {
      loop = (Sint32T)numWords - 1;
   }
   else
   {
      loop = (Sint32T)numWords;
   }

   do
   {
      status = zl5011xWrite(zl5011xParams, address + (loop * sizeof(Uint32T)),
            word[loop]);

      loop--;
   } while ((loop >= 0) && (status == ZL5011X_OK));

   return (status);
}

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

 Function:
    zl5011xPkcGetStats

 Description:
   Collects various statistics for packet matching

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   stats          Structure to hold stats

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xPkcGetStats(zl5011xParamsS *zl5011xParams, zl5011xPkcStatsS *stats)
{
   Uint32T loop;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
         "zl5011xPkcGetStats:",
         0, 0, 0, 0, 0, 0);

   for (loop = 0; loop < ZL5011X_PKC_NUM_PROTOCOL_ENTRIES; loop++)
   {
      if (status != ZL5011X_OK)
      {
         break;
      }

      status = zl5011xRead(zl5011xParams,
            ZL5011X_PKC_PROTOCOL_COUNT + (loop * 2 * sizeof(Uint32T)),
            &(stats->protocolCount[loop]));
   }

   if(status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_PKC_PROTOCOL_NO_MATCH_COUNT,
            &(stats->protocolNoMatchCount));
   }

   if(status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_PKC_CLASSIFY_NO_MATCH_COUNT,
            &(stats->classifyNoMatchCount));
   }

   if(status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_PKC_VERIFY_FAIL_COUNT,
            &(stats->verifyFailCount));
   }

   if(status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_PKC_IPV4_CHECKSUM_COUNT,
            &(stats->ipv4ChecksumFailCount));
   }

   if(status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_PKC_UDP_CHECKSUM_COUNT,
            &(stats->udpChecksumFailCount));
   }

   return (status);
}

/*******************************************************************************
 Function:
    zl5011xPkcGetInterruptStatus

 Description:
   This function reads back the  interrupt status ( poll) register

 Inputs:
    zl5011xParams      Pointer to the structure for this device instance

 Outputs:
    ptr to intrStatus value returned

 Returns:
    zlStatusE

 Remarks:

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

zlStatusE zl5011xPkcGetInterruptStatus(zl5011xParamsS *zl5011xParams, Uint32T *pIntrStatus)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID, "zl5011xPkcGetInterruptStatus:",0, 0, 0, 0, 0, 0);

   if( pIntrStatus== NULL)
   {
      status= ZL5011X_PARAMETER_INVALID;
   }
   if( status== ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_PKC_INT_POLL, pIntrStatus);
   }
   if( status== ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_PKC_FN_ID, "zl5011xPkcGetInterruptStatus: status 0x%.08lx",*pIntrStatus,
                     0, 0, 0, 0, 0);
   }
   return (status);

}

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

 Function:
    zl5011xPkcEnableInterrupts

 Description:
    Set enabling bits for the interrupt register. A ONE  indicates
    that interrupt is enabled. Leaves other bits unchanged.

 Inputs:
    zl5011xParams     Pointer to the structure for this device instance
    interruptBits    Set bit position to 1 to enable corresponding interrupt

 Outputs:

 Returns:
    zlStatusE

 Remarks:

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

zlStatusE zl5011xPkcEnableInterrupts(zl5011xParamsS *zl5011xParams, Uint32T interruptBits)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T regBits=0;

   ZL5011X_TRACE(ZL5011X_PKC_FN_ID,
          "zl5011xPkcEnableInterrupts: bits %08X",
          interruptBits, 0, 0, 0, 0, 0);

   if(status == ZL5011X_OK)
   {
      /* clear the interrupt before enabling it. The assumption being that if the
         interrupt was disabled, then there is no interest in any prior events.
         Do not clear the PW status interrupt though - queue MUST be read
         before clearing the bit!!! */
      regBits = interruptBits & ~(ZL5011X_1BIT_MASK << ZL5011X_PACKET_RX_PW_INT);

      status = zl5011xPkcClearInterrupts(zl5011xParams, regBits);
   }

   if(status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_PKC_INT_MASK, &regBits);
   }

   /* write ZEROS to the mask reg (A 

⌨️ 快捷键说明

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