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

📄 zl5011xtm.c

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

 Remarks:
   Using magic numbers for the bit positions in the TM buffer, since the bit
   positions are unique to this function.

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

zlStatusE zl5011xTmDecodeTraceSource(zl5011xParamsS *zl5011xParams,
      Uint32T *buffer, zl5011xTmTraceMessageS *msg)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TM_FN_ID, "zl5011xTmDecodeTraceSource:", 0, 0, 0, 0, 0, 0);

   /* decode the first 32 bit word of the message */
   msg->headGranule = (buffer[0] >> 0) & 0x3ffff;
   msg->sourceBlock = (Uint8T)((buffer[0] >> 22) & 0x1f);
   msg->flowType = (zl5011xFlowTypeE)((buffer[0] >> 27) & 0x1f);

   /* any fields not populated are set to invalid */
   msg->timestamp = (Uint16T)ZL5011X_INVALID;
   msg->headerOffset = (Uint8T)ZL5011X_INVALID;
   msg->mpid = (Uint16T)ZL5011X_INVALID;
   msg->pktLen = (Uint16T)ZL5011X_INVALID;
   msg->tailGranule = (Uint32T)ZL5011X_INVALID;
   msg->granuleNum = (Uint8T)ZL5011X_INVALID;
   msg->miscField1 = (Uint16T)ZL5011X_INVALID;
   msg->miscField2 = (Uint32T)ZL5011X_INVALID;

   return(status);
}

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

 Function:
   zl5011xTmGetTraceMessage

 Description:
   Reads the contents of the trace buffer identified by index. The trace message
   structure is populated depending on the trace mode in use.

   For SHORT trace modes, only one 32 bit word is used for each message in the
   trace buffer, so the number of buffers available is equal to the size of the
   trace buffer.

   For PARTIAL trace, two 32 bit words are used for each message in the
   trace buffer, so the number of buffers available is half the size of the
   trace buffer.

   For FULL trace, four 32 bit words are used for each message in the
   trace buffer, so the number of buffers available is a quarter the size of the
   trace buffer.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   index          which entry in the trace buffer to fetch

 Outputs:
    msg           structure populated with the trace message - fields populated
                  will depend on the trace mode in operation. Unused fields will
                  be set to all 1's

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xTmGetTraceMessage(zl5011xParamsS *zl5011xParams,
      Uint32T index, zl5011xTmTraceMessageS *msg)
{
   Uint32T readValue[4], loop, offset = 0;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TM_FN_ID, "zl5011xTmGetTraceMessage: index %4d",
         index, 0, 0, 0, 0, 0);

   if (msg == NULL)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      if (index > (ZL5011X_TM_TRACE_BUFFER_SIZE / zl5011xParams->taskManager.tmBufferSize))
      {
         status = ZL5011X_PARAMETER_INVALID;
      }
      else
      {
         offset = index * zl5011xParams->taskManager.tmBufferSize * sizeof(Uint32T);
      }
   }

   /* read the 32 bit words from the trace buffer that make up the
      message */
   for (loop = 0; loop < zl5011xParams->taskManager.tmBufferSize; loop++)
   {
      if (status != ZL5011X_OK)
      {
         break;
      }

      status = zl5011xRead(zl5011xParams,
            ZL5011X_TM_TRACE_BUFFER + offset + (loop * sizeof(Uint32T)),
            readValue + loop);
   }

   if (status == ZL5011X_OK)
   {
      /* populate the statistics structure using the values read from the
         device */
      switch (zl5011xParams->taskManager.tmTraceMode)
      {
         case ZL5011X_TM_TRACE_FULL :
            status = zl5011xTmDecodeTraceFull(zl5011xParams, readValue, msg);
            break;

         case ZL5011X_TM_TRACE_PARTIAL :
            status = zl5011xTmDecodeTracePartial(zl5011xParams, readValue, msg);
            break;

         case ZL5011X_TM_TRACE_SHORT_TIME :
            status = zl5011xTmDecodeTraceTime(zl5011xParams, readValue, msg);
            break;

         case ZL5011X_TM_TRACE_SHORT_SOURCE :
            status = zl5011xTmDecodeTraceSource(zl5011xParams, readValue, msg);
            break;

         default :
            status = ZL5011X_PARAMETER_INVALID;
            break;
      }
   }

   return(status);
}

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

 Function:
   zl5011xTmDumpTraceMessage

 Description:
   Displays the contents of the trace buffer identified by index using the OS
   log message function.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   index          which entry in the trace buffer to display

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xTmDumpTraceMessage(zl5011xParamsS *zl5011xParams,
      Uint32T index)
{
   zl5011xTmTraceMessageS msg;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TM_FN_ID, "zl5011xTmDumpTraceMessage: index %4d", index, 0, 0, 0, 0, 0);

   status = zl5011xTmGetTraceMessage(zl5011xParams, index, &msg);

   if (status == ZL5011X_OK)
   {
      OS_LOG_MSG("TM buffer %4d" ZL5011X_NEWLINE
            "flow   %02X,       length        %04X, mpid         %04X" ZL5011X_NEWLINE,
            index, msg.flowType, msg.pktLen, msg.mpid, 0, 0);

      OS_LOG_MSG("block  %02X,       header offset %02X,   head granule %08X" ZL5011X_NEWLINE,
            msg.sourceBlock, msg.headerOffset, msg.headGranule, 0, 0, 0);

      OS_LOG_MSG("misc 1 %04X,     granule count %02X,   tail granule %08X" ZL5011X_NEWLINE,
            msg.miscField1, msg.granuleNum, msg.tailGranule, 0, 0, 0);

      OS_LOG_MSG("misc 2 %08X, timestamp     %04X" ZL5011X_NEWLINE,
            msg.miscField2, msg.timestamp, 0, 0, 0, 0);
   }

   return(status);
}

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

 Function:
   zl5011xTmEnableInterrupts

 Description:

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   interruptBits  a ONE to enable the interrupt

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

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

   ZL5011X_TRACE(ZL5011X_TM_FN_ID, "zl5011xTmEnableInterrupts: index %4d",
               interruptBits, 0, 0, 0, 0, 0);

   status = zl5011xTmClearInterrupts(zl5011xParams, interruptBits);

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

   /* write ONES to the mask reg  */
   if( status== ZL5011X_OK)
   {
      regBits |= interruptBits;
      status = zl5011xWrite(zl5011xParams, ZL5011X_TM_INTERRUPT_MASK, regBits);
   }

   /* store value in the structure  */
   if( status== ZL5011X_OK)
   {
      zl5011xParams->interruptMasks.tmInterruptsEnabled= regBits;
   }

   return(status);
}

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

 Function:
   zl5011xTmDisableInterrupts

 Description:
   writes to the the TM intr mask reg  to disable interrupts
 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   interruptBits  a ONE to disable the interrupt

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

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

   ZL5011X_TRACE(ZL5011X_TM_FN_ID, "zl5011xTmDisableInterrupts: index %4d",
               interruptBits, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams, ZL5011X_TM_INTERRUPT_MASK, &regBits);

   /* write ZEROS to the mask reg (0 = Mask on (disable interrupt)) */
   if( status== ZL5011X_OK)
   {
      regBits &= ~interruptBits;
      status = zl5011xWrite(zl5011xParams, ZL5011X_TM_INTERRUPT_MASK, regBits);
   }

   /* store value in the structure  */
   if( status== ZL5011X_OK)
   {
      zl5011xParams->interruptMasks.tmInterruptsEnabled= regBits;
   }


   return(status);
}

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

 Function:
    zl5011xTmGetInterruptStatus

 Description:
   This function reads back the  interrupt status register

 Inputs:
    zl5011xParams      Pointer to the structure for this device instance

 Outputs:
    pIntrStatus      the state of the interrupt register

 Returns:
    zlStatusE

 Remarks:

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

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

   ZL5011X_TRACE(ZL5011X_TM_FN_ID, "zl5011xTmGetInterruptStatus:",0, 0, 0, 0, 0, 0);

   if (status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_TM_INTERRUPT_STATUS, pIntrStatus);

      ZL5011X_TRACE(ZL5011X_TM_FN_ID, "zl5011xTmGetInterruptStatus: %08X",
            *pIntrStatus, 0, 0, 0, 0, 0);
   }

   return status;
}

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

 Function:
    zl5011xTmClearInterrupts

 Description:
    Set a bit to 1 to clear the interrupt.

 Inputs:
    zl5011xParams     Pointer to the structure for this device instance
    interruptBits    interrupts to clear

 Outputs:

 Returns:
    zlStatusE

 Remarks:

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

zlStatusE zl5011xTmClearInterrupts(zl5011xParamsS *zl5011xParams, Uint32T interruptBits)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TM_FN_ID,
          "zl5011xTmClearInterrupts: bits %08X",
          interruptBits, 0, 0, 0, 0, 0);

   /* write a 1 to the interrupt source to clear the interrupt */
   if( status== ZL5011X_OK)
   {
      status = zl5011xWrite(zl5011xParams, ZL5011X_TM_INTERRUPT_CLEAR, interruptBits);
   }

   return(status);
}

⌨️ 快捷键说明

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