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

📄 zl5011xadm.c

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

      status = zl5011xAdmClearInterruptSource(zl5011xParams, interruptSourceMask);

      /* Enable the chosen intr */
      if(status == ZL5011X_OK)
      {
         status = zl5011xRead(zl5011xParams, temp, &readValue);

         /* force the non-valid interrupt bits to a safe state */
         readValue = (readValue | interruptSourceMask) & ZL5011X_ADM_INTERRUPT_CHECK_MASK;

         zl5011xParams->interruptMasks.admMasks[interrupt] = readValue;

         status = zl5011xWrite(zl5011xParams, temp, readValue);
      }

      (void)zl5011xHostInterruptEnable();
   }

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmDisableInterruptSource

 Description:
   If a bit is set in the mask, then the interrupt is disabled.
   The state of the interrupt mask is maintained in the device structure.

 Inputs:
   zl5011xParams            Pointer to the structure for this device instance
   interrupt               0, 1 or freeze
   interruptSourceMask     Inverse used to disable interrupt source

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/

zlStatusE zl5011xAdmDisableInterruptSource(zl5011xParamsS *zl5011xParams,
      zl5011xInterruptValueE interrupt, Uint32T interruptSourceMask)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T temp, readValue;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmDisableInterruptSource: interrupt %d, mask %08X",
         interrupt, interruptSourceMask, 0, 0, 0, 0);

   if(status == ZL5011X_OK)
   {
      /* Check interrupt has valid value */
      status = ZL5011X_CHECK_INTERRUPT_VALUE(interrupt);
   }

   if(status == ZL5011X_OK)
   {
      switch(interrupt)
      {
         case(ZL5011X_INTERRUPT_ZERO):
            temp = ZL5011X_ADM_MOD_IE0;
            break;

         case(ZL5011X_INTERRUPT_ONE):
            temp = ZL5011X_ADM_MOD_IE1;
            break;

         case(ZL5011X_INTERRUPT_FROZEN):
            temp = ZL5011X_ADM_MOD_FREEZE;
            break;

         default:
            temp = 0;
            status = ZL5011X_PARAMETER_INVALID; /* Do nothing */
            break;
      }
   }

   if(status == ZL5011X_OK)
   {
      (void)zl5011xHostInterruptDisable();

      status = zl5011xAdmClearInterruptSource(zl5011xParams, interruptSourceMask);

      /* Enable the chosen intr */
      if(status == ZL5011X_OK)
      {
         status = zl5011xRead(zl5011xParams, temp, &readValue);

         /* force the non-valid interrupt bits to a safe state */
         readValue = (readValue & ~interruptSourceMask) & ZL5011X_ADM_INTERRUPT_CHECK_MASK;

         zl5011xParams->interruptMasks.admMasks[interrupt] = readValue;

         status = zl5011xWrite(zl5011xParams, temp, readValue);
      }

      (void)zl5011xHostInterruptEnable();
   }

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmClearInterruptSource

 Description:
   If a bit is set in the mask, then the interrupt source is cleared.

 Inputs:
   zl5011xParams               Pointer to the structure for this device instance
   interruptClearMask         Used to clear interrupts that have been serviced

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   Not dependent on the interrupt destination, int0, int1 or freeze,
   since it is a common latch.
*******************************************************************************/
zlStatusE zl5011xAdmClearInterruptSource(zl5011xParamsS *zl5011xParams,
                 Uint32T interruptClearMask)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bitMask;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmClearInterruptSource: %08x",
         interruptClearMask, 0, 0, 0, 0, 0);

   if(status == ZL5011X_OK)
   {
      /* force the non-valid interrupt bits to a safe state */
      bitMask = interruptClearMask | ~ZL5011X_ADM_INTERRUPT_CHECK_MASK;

#ifdef _NO_DEVICE
      status = zl5011xReadModWrite(zl5011xParams, ZL5011X_ADM_MOD_ISTAT, 0, bitMask);
#else
      status = zl5011xWrite(zl5011xParams, ZL5011X_ADM_MOD_ICR, bitMask);
#endif
   }

   return status;
}

/*******************************************************************************
 Function: zl5011xAdmEnableInterrupt


 Description:
   Enables interrupts, namely IE0, IE1, or both

 Inputs:
   zl5011xParams          Pointer to the structure for this device instance
   enableInterruptMask   Set bit 0 to enable interrupt 0, and bit 1 to enable
                         interrupt 1.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmEnableInterrupt(zl5011xParamsS *zl5011xParams,
                 zl5011xEnableInterruptE enableInterruptMask)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T gpBuffer;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmEnableInterrupt: %08X",
         enableInterruptMask, 0, 0, 0, 0, 0);

   status = ZL5011X_CHECK_ENABLE_INTERRUPT(enableInterruptMask);

   if(status == ZL5011X_OK)
   {
      /* Writes to the control/status register to enable interrupts */
      status = zl5011xReadModWrite(zl5011xParams, ZL5011X_ADM_MOD_CONSTAT,
               enableInterruptMask, enableInterruptMask);
   }

   if(status == ZL5011X_OK)
   {
      /* Read value of control/status register */
      status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_CONSTAT, &gpBuffer);
   }

   if(status == ZL5011X_OK)
   {
         /* Record enabled state of interrupts in device structure */
      zl5011xParams -> cpuIf.constat = gpBuffer & ZL5011X_ADM_CONSTAT_MASK;
   }

   return status;

}

/*******************************************************************************
 Function:
   zl5011xAdmDisableInterrupt

 Description:
   Clears the bit in the CONSTAT register for the associated interrupt.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance
   interrupt         Reset bit 0 to disable interrupt 0 and reset
                     bit 1 to disable interrupt 1.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmDisableInterrupt(zl5011xParamsS *zl5011xParams,
                 zl5011xEnableInterruptE interrupt)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T gpBuffer;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmDisableInterrupt: %08X",
         interrupt, 0, 0, 0, 0, 0);

   /* Actually disabling interrupt but using the same check as enable */
   status = ZL5011X_CHECK_ENABLE_INTERRUPT(interrupt);

   if(status == ZL5011X_OK)
   {
      /* Writes to the control/status register to enable interrupts */
      status = zl5011xReadModWrite(zl5011xParams, ZL5011X_ADM_MOD_CONSTAT,
               ~interrupt, interrupt);
   }

   if(status == ZL5011X_OK)
   {
      /* Read value of control/status register */
      status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_CONSTAT, &gpBuffer);
   }

   if(status == ZL5011X_OK)
   {
         /* Record enabled state of interrupts in device structure */
      zl5011xParams -> cpuIf.constat = gpBuffer & ZL5011X_ADM_CONSTAT_MASK;
   }

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmGetInterruptStatus

 Description:
   Reads the interrupt status bits from the device.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   interruptStatusBits   interrupt status bits - if a bit is set, then that
                         interrupt is pending

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmGetInterruptStatus(zl5011xParamsS *zl5011xParams,
          Uint32T *interruptStatusBits)
{
   zlStatusE status;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGetInterruptStatus:", 0, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_ISTAT, interruptStatusBits);

   return status;

}
/*******************************************************************************
 Function:
   zl5011xAdmGetDeviceId

 Description:
   Gets the value from the chip ID register

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   ChipId   Return parameter, used to return chip ID

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmGetDeviceId(zl5011xParamsS *zl5011xParams,
      Uint32T *chipId, Uint32T *version)
{
   Uint32T readValue;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGetDeviceId:", 0, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_CHIP_ID, &readValue);

   /* Mask out unused bits of ChipId */
   *chipId = (readValue >> ZL5011X_ADM_CHIP_ID_BITS) & ZL5011X_ADM_CHIP_ID_MASK;
   *version = (readValue >> ZL5011X_ADM_CHIP_VERSION_BITS) & ZL5011X_ADM_CHIP_VERSION_MASK;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGetDeviceId: ID %08X, version %d",
         *chipId, *version, 0, 0, 0, 0);

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmGpioRead

 Description:
   Gets the state of the GPIO pins

 Inputs:
   zl5011xParams  Pointer to the structure for this device instance
   gpioReadValue Return parameter which holds the state of the 16 GPIO pins

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmGpioRead(zl5011xParamsS *zl5011xParams,
                 Uint32T *gpioReadValue)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T   GpBuffer;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGpioRead:", 0, 0, 0, 0, 0, 0);

   /* Read GPIO pins state */
   status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_GPIO_IN, &GpBuffer);

   /* Mask resets upper unused bits */
   *gpioReadValue = GpBuffer & ZL5011X_ADM_GPIO_MASK;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGpioRead: %d", *gpioReadValue, 0, 0, 0, 0, 0);

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmGpioWrite

 Description:
   Writes a value to the GPIO pins.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance.
   gpioWriteValue    Value to be written to the GPIO pins.
   mask              bits set to a 1 are to be changed

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmGpioWrite(zl5011xParamsS *zl5011xParams,
                 Uint16T gpioWriteValue, Uint16T mask)
{

   zlStatusE   status;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGpioWrite: %04X",
         gpioWriteValue, 0, 0, 0, 0, 0);

   /* Write to output register */
   status =  zl5011xReadModWrite(zl5011xParams, ZL5011X_ADM_MOD_OP_REG,
         (Uint32T)gpioWriteValue, (Uint32T)mask);

   return status;

}

/*******************************************************************************
 Function:
   zl5011xAdmGpioMode

 Description:
   Controls which bits are in/out

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance.
   gpioPins          Bit mask - Setting a bit causes the corresponding GPIO pin
                     to be an output.
   mask              bits set to a 1 are to be changed

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmGpioMode(zl5011xParamsS *zl5011xParams,
                 Uint16T gpioPins, Uint16T mask)
{
   zlStatusE   status;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGpioMode: %04x", gpioPins, 0, 0, 0, 0, 0);

   /* Enable GPIO pins */
   status =  zl5011xReadModWrite(zl5011xParams, ZL5011X_ADM_MOD_GPIO_EN,
         (Uint32T)gpioPins, (Uint32T)mask);

   zl5011xParams->gpioMode = (zl5011xParams->gpioMode & (~mask)) | (gpioPins & mask);

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmGetBootStrapMode

 Description:
   Reads the state of the 16 bootstrap pins at startup and stores it in the
   device structure.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance.

 Outputs:
   bootStrapMode     General purpose pins recorded at reset.

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE zl5011xAdmGetBootStrapMode(zl5011xParamsS *zl5011xParams,
                 Uint16T *bootStrapMode)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T   gpBuffer;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGetBootStrapMode:",
         0, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_CONFIG, &gpBuffer);

   /* Mask out unused bits */
   gpBuffer = gpBuffer & ZL5011X_ADM_BOOTSTRAP_MASK;

   *bootStrapMode = (Uint16T)gpBuffer;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGetBootStrapMode: %04X",
         *bootStrapMode, 0, 0, 0, 0, 0);

   return status;
}

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

⌨️ 快捷键说明

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