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

📄 zl5011xdpr.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
      /* Delete the 'isr' task */
      if (zl5011xIsrTaskId != (OS_TASK_ID)NULL)
      {
          if( OS_TASK_DELETE(zl5011xIsrTaskId) == OS_ERROR)
          {
             status = ZL5011X_RTOS_TASK_DELETE_FAIL;
          }
          else
          {
             zl5011xIsrTaskId = (OS_TASK_ID)NULL;
          }
      }
   }

   if (status == ZL5011X_OK)
   {
      /* Delete the 'Dpr' task */
      if (zl5011xDprTaskId != (OS_TASK_ID)NULL)
      {
          if( OS_TASK_DELETE(zl5011xDprTaskId) == OS_ERROR)
          {
             status = ZL5011X_RTOS_TASK_DELETE_FAIL;
          }
          else
          {
             zl5011xDprTaskId = (OS_TASK_ID)NULL;
          }
      }
   }

   if (status == ZL5011X_OK)
   {
      /* Delete the PW task */
      if (zl5011xIsrPwTaskId != (OS_TASK_ID)NULL)
      {
          if( OS_TASK_DELETE(zl5011xIsrPwTaskId) == OS_ERROR)
          {
             status = ZL5011X_RTOS_TASK_DELETE_FAIL;
          }
          else
          {
             zl5011xIsrPwTaskId = (OS_TASK_ID)NULL;
          }
      }
   }

   if (status == ZL5011X_OK)
   {
      /* Delete the 'zl5011xIsrMsgQId' message Queue if present */
      if (zl5011xIsrMsgQId != OS_MSG_Q_INVALID)
      {
          if( OS_MSG_Q_DELETE(zl5011xIsrMsgQId) == OS_ERROR)
          {
             status = ZL5011X_RTOS_MSGQ_DELETE_FAIL;
          }
          else
          {
             zl5011xIsrMsgQId = OS_MSG_Q_INVALID;
          }
      }
   }

   if (status == ZL5011X_OK)
   {
      /* Delete the 'zl5011xIsrSemId' semaphore if present */
      if (zl5011xIsrSemId != OS_SEM_INVALID)
      {
          if (OS_SEMA4_DELETE(zl5011xIsrSemId)== OS_ERROR)
          {
             status = ZL5011X_RTOS_SEMA4_DELETE_FAIL;
          }
          else
          {
            zl5011xIsrSemId = OS_SEM_INVALID;
          }
      }
   }

   if (status == ZL5011X_OK)
   {
      if (zl5011xIsrApiIntNum != (Uint32T)ZL5011X_INVALID)
      {
        #if 0
         if (OS_INTERRUPT_DISABLE(zl5011xIsrApiIntNum) == OS_ERROR)
         {
            status = ZL5011X_RTOS_FAIL;
         }
         else
        #endif
         {
            zl5011xIsrApiIntNum = (Uint32T)ZL5011X_INVALID;
         }
      }
   }

   if (status == ZL5011X_OK)
   {
      if (zl5011xIsrAppIntNum != (Uint32T)ZL5011X_INVALID)
      {
        #if 0
         if (OS_INTERRUPT_DISABLE(zl5011xIsrAppIntNum) == OS_ERROR)
         {
            status = ZL5011X_RTOS_FAIL;
         }
         else
        #endif
         {
            zl5011xIsrAppIntNum = (Uint32T)ZL5011X_INVALID;
         }
      }
   }

   return status;
}

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

 Function:
    zl5011xIsrInitialisePwOnlyStructInit

 Description:
   Initialise the structure used in function zl5011xIsrInitialisePwOnly

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance
   par               Pointer to parameter structure

 Structure Inputs:
   None

 Outputs:

 Returns:
    zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xIsrInitialisePwOnlyStructInit(zl5011xParamsS *zl5011xParams, zl5011xIsrInitialisePwOnlyS *par)
{
   zlStatusE status = ZL5011X_OK;

   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_ISR_FN_ID,
            "zl5011xIsrInitialisePwOnlyStructInit: ",
            0, 0, 0, 0, 0, 0);
   }

   return (status);
}

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

 Function:
    zl5011xIsrInitialisePwOnly

 Description:
   This function is provided for systems where PW status byte monitoring is
   required without enabling the full interrupt functionality.

   This function creates a message queue used to send PW status byte changes
   to the application - refer to zl5011xDprTask for example of message handling.

   The PW status byte is checked when the application makes a call to function
   zl5011xPwStatusCheck(zl5011xParams).

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to parameter structure containing:

  Structure Inputs:
   None

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   OS facilities created using this function can be cleaned up using function
   zl5011xIsrDelete.

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

zlStatusE zl5011xIsrInitialisePwOnly(zl5011xParamsS *zl5011xParams, zl5011xIsrInitialisePwOnlyS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T index;

   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_ISR_FN_ID, "zl5011xIsrInitialisePwOnly: ",
            0, 0, 0, 0, 0, 0);

      if ((zl5011xIsrAppIntNum != (Uint32T)ZL5011X_INVALID) || (zl5011xIsrApiIntNum != (Uint32T)ZL5011X_INVALID))
      {
         /* if either interrupt has already been enabled then bomb out */
         status = ZL5011X_INTERRUPTS_RUNNING;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* clear out the device table before setting up the interrupts */
      for (index = 0; index < ZL5011X_ISR_MAX_NUMBER_DEVICES; index++)
      {
         zl5011xIsrDeviceTable[index]= NULL;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* Create the 'zl5011xIsrMsgQId' message queue if it does not already exist */
      if (zl5011xIsrMsgQId == OS_MSG_Q_INVALID)
      {
         zl5011xIsrMsgQId = OS_MSG_Q_CREATE(ZL5011X_DPR_MESSAGES, sizeof(zl5011xInterruptQueueDataS), OS_MSG_Q_PRIORITY);
      }
      else
      {
          ZL5011X_TRACE(ZL5011X_ISR_FN_ID, "zl5011xIsrInitialise: message queue already exists", 0,0,0,0,0,0);
      }

      if (zl5011xIsrMsgQId == OS_MSG_Q_INVALID)
      {
         status = ZL5011X_RTOS_MSGQ_CREATE_FAIL;
      }
   }

   if (status == ZL5011X_OK)
   {
      zl5011xIsrPwReportEnable(ZL5011X_TRUE);
   }

   return (status);
}

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

 Function:
    zl5011xIsrConnect

 Description:
   This is the interrupt service routine for the application
   interrupts - it simply 'gives' a semaphore to the Isr task.

 Inputs:
   None

 Outputs:
   None

 Returns:
   None

 Remarks:

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

void zl5011xIsrConnect(void)
{
   Uint32T loop;
   Uint32T reg;

   /* The interrupt is not going to be serviced in the ISR, but is being deferred
      to a task.
      To allow the ISR to return without having cleared the interrupt
      source, the interrupt from the device has to be cleared. This can be
      achieved without changing the mask settings etc. by gating off the interrupt
      as it leaves the device.
      Clear the int0 request for any device registered with the interrupt handler */

   reg = ZL5011X_ADM_MOD_CONSTAT;

   for (loop = 0; loop < ZL5011X_ISR_MAX_NUMBER_DEVICES; loop++)
   {
      if (zl5011xIsrDeviceTable[loop] != NULL)
      {
         *(Uint32T *)(reg + zl5011xIsrDeviceTable[loop]->baseAdd) &= ~ZL5011X_ENABLE_INT_0;
      }
   }

   if (OS_SEMA4_GIVE(zl5011xIsrSemId) == OS_ERROR)
   {
      /* Inform the user if the semaphore giving has failed */
      ZL5011X_TRACE(ZL5011X_ISR_FN_ID, "zl5011xIsrConnect:  *** Error : can't give Semaphore",
            0,0,0,0,0,0);
   }
}

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

 Function:
    zl5011xIsrTask

 Description:
   This is the Isr Task for the application interrupts -
   it sits here waiting for a semaphore and then proceeds with the
   task.

 Inputs:
   None

 Outputs:
   None

 Returns:
   None

 Remarks:

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

void zl5011xIsrTask(void)
{
   ZL5011X_TRACE(ZL5011X_ISR_FN_ID, "zl5011xIsrTask: task started", 0,0,0,0,0,0);

   while (ZL5011X_TRUE) /* loop forever */
   {
       /* Block the task here waiting for the 'zl5011xIsrSemId' sema4 to become available */
       (void)OS_SEMA4_TAKE(zl5011xIsrSemId,OS_WAIT_FOREVER);

       /* Got the sema4, let's do some processing... */
       (void)zl5011xIsrHandler();
   }
}

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

 Function:
   zl5011xDprHandler

 Description:
   This provides an example of how to handle the messages that are passed via
   the ISR Task and the message queue from the interrupt service routine. From the
   queue msg it has a specific device and a set of high level (ADM) interrupts.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance
   par               Pointer to function structure containing

 Structure Inputs:
   interruptSource   One of zl5011xIsrSourcesE
   activeInterrupts  The relevant intr reg.

 Returns:
   zlStatusE

 Remarks:

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

zlStatusE zl5011xDprHandler(zl5011xParamsS *zl5011xParams,
      zl5011xInterruptQueueDataS *par)
{
   zlStatusE status = ZL5011X_OK;
   char *intStr;
   Uint32T loop;

   /* Service any packet Rx PW interrupts using a dedicated routine */
   if ((par->interruptSource == ZL5011X_PACKET_RX_INTERRUPT) &&
      ((par->activeInterrupts & (ZL5011X_1BIT_MASK << ZL5011X_PACKET_RX_PW_INT)) != 0))
   {
      /* detected a PW event */
      ZL5011X_TRACE(ZL5011X_ISR_FN_ID,
            "zl5011xDprHandler: PW event for context %3d, byte changed to %02X",
            par->context, (Uint8T)par->misc, 0, 0, 0, 0);
   }
   else
   {
      intStr = zl5011xDprInterruptStr[0].text;

      for (loop = 0; loop < (sizeof(zl5011xDprInterruptStr) / sizeof(zl5011xDprInterruptStrS)); loop++)
      {
         if (zl5011xDprInterruptStr[loop].intSrc == par->interruptSource)
         {
            intStr = zl5011xDprInterruptStr[loop].text;
            break;
         }
      }

      ZL5011X_TRACE(ZL5011X_ISR_FN_ID,
            "zl5011xDprHandler: device %08X, src %s, ctxt %d, int %08lX, misc %08X",
            (Uint32T)(par->zl5011xParams), (Uint32T)intStr,
            par->context, par->activeInterrupts, par->misc, 0);
   }

   return (status);
}

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

 Function:
   zl5011xDprTask

 Description:
   This function checks the message queue (without timeout) and calls the
   deferred interrupt handler in response to interrupts present.

 Inputs:
   None

 Outputs:
   None

 Returns:
    zlStatusE

 Remarks:

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

void zl5011xDprTask(void)
{
   OS_STATUS osStatus;
   zl5011xInterruptQueueDataS intr;

   ZL5011X_TRACE(ZL5011X_ISR_FN_ID, "zl5011xDprTask: task started", 0,0,0,0,0,0);

   while( ZL5011X_TRUE) /* loop forever */
   {
      /* Look for a received message */
      osStatus = OS_MSG_Q_RECEIVE( zl5011xIsrMsgQId,
            (char*)&intr,
            sizeof(zl5011xInterruptQueueDataS),
            OS_WAIT_FOREVER);

      if (osStatus == OS_ERROR)
      {
         ZL5011X_TRACE(ZL5011X_ISR_FN_ID,
               "zl5011xDprTask: Rx on message queue (%X) failed, error = %d",
               (Uint32T)zl5011xIsrMsgQId, osStatus, 0, 0, 0, 0);

         /* the task is about to exit, so clear the taskId that was stored
            when it was created */
         zl5011xDprTaskId = (OS_TASK_ID)NULL;
         return;
      }

      /* call the user's function -  zl5011xDprHandler */
      (void)zl5011xDprHandler( intr.zl5011xParams, &intr);
   }
}

/*****************   END   ****************************************************/

⌨️ 快捷键说明

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