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

📄 zl5011xinit.c

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

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items. See below:

 Structure inputs:
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xRun(zl5011xParamsS *zl5011xParams, zl5011xRunS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
   {
      /* get access to the device */
      status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_INIT_FN_ID, "zl5011xRun: ", 0, 0, 0, 0, 0, 0);

      if (zl5011xParams->running == ZL5011X_TRUE)
      {
         status = ZL5011X_MULTIPLE_INIT_ATTEMPT;
      }
   }

   /* check that all of the necessary initialisations have taken place */
   if (status == ZL5011X_OK)
   {
      if (zl5011xParams->initialised == ZL5011X_FALSE)
      {
         status = ZL5011X_NOT_INIT;
      }
   }

   if (status == ZL5011X_OK)
   {
      if (zl5011xParams->memoryInitialised == ZL5011X_FALSE)
      {
         status = ZL5011X_MEMORY_NOT_INIT;
      }
   }

   if (status == ZL5011X_OK)
   {
      if (zl5011xParams->wanInitialised == ZL5011X_FALSE)
      {
         status = ZL5011X_WAN_NOT_INIT;
      }
   }

   if (status == ZL5011X_OK)
   {
      if (zl5011xParams->lanInitialised == ZL5011X_FALSE)
      {
         status = ZL5011X_LAN_NOT_INIT;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* All blocks have been initialised. Clear the Init Done interrupt bit */
      status = zl5011xAdmClearInterruptSource(zl5011xParams, 1 << ZL5011X_ADM_INIT_DONE_INTERRUPT);
   }

   /* at this point, only the GM block has been run. It is now time to enable the
      rest of the blocks except the TIF, which cannot be enabled until the Wan
      configuration has completed (WanConfigureSync or WanConfigureAsync) */
   if (status == ZL5011X_OK)
   {
      status = zl5011xAdmEnableBlocks(zl5011xParams, ZL5011X_ADM_TFM_BIT |
            ZL5011X_ADM_TFQ_BIT | ZL5011X_ADM_PLA_BIT | ZL5011X_ADM_PAC_BIT |
            ZL5011X_ADM_PKI_BIT | ZL5011X_ADM_PKQ_BIT | ZL5011X_ADM_TM_BIT | ZL5011X_ADM_PRX_BIT |
            ZL5011X_ADM_PKC_BIT | ZL5011X_ADM_RTP_BIT);
   }

   if (status == ZL5011X_OK)
   {
      zl5011xParams->running = ZL5011X_TRUE;
   }

   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         status = zl5011xReleaseDevice(zl5011xParams);
      }
      else
      {
         /* already have an error code, so don't overwrite it */
         (void)zl5011xReleaseDevice(zl5011xParams);
      }
   }

   return status;
}

/*****************   STATIC FUNCTION DEFINTIONS   *****************************/

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

 Function:
    zl5011xInitBlocks

 Description:
    This function sets the required blocks into initialise, and waits for
    completion. The completion is polled, to give a quicker response time if the
    initialisation is fast.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   mask           bit set in mask to initialise a block.

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

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

static zlStatusE zl5011xInitBlocks(zl5011xParamsS *zl5011xParams, Uint32T mask)
{
   Uint32T loop, readValue;
   zlStatusE status = ZL5011X_OK;

   /* set the init bits for the required blocks */
   if (status == ZL5011X_OK)
   {
      status = zl5011xAdmSetInitStatus(zl5011xParams, mask);
   }

   /* use a retry approach, to check whether the blocks have completed
      initialisation, to try and speed up the process */
   for (loop = 0; loop < ZL5011X_BLOCK_INIT_RETRY; loop++)
   {
      if (status != ZL5011X_OK)
         break;

      /* wait for the init to occur */
      OS_TASK_DELAY(ZL5011X_BLOCK_INIT_TIMEOUT_MS);

      status = zl5011xAdmGetInitStatus(zl5011xParams, &readValue);

      if (status == ZL5011X_OK)
      {
         /* if the bits have been reset to 0, then the init has finished */
         if ((readValue & mask) == 0)
            break;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* if the bits have been reset to 0, then the init has finished */
      if (loop == ZL5011X_BLOCK_INIT_RETRY)
      {
         status = ZL5011X_TIMEOUT;
      }
   }

   return status;
}

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

 Function:
    zl5011xPreparePrxGranules

 Description:
   Prepare a granule for each of the GBit Lan ports, for sending, to force
   initialisation.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   grn1           Number of 1st granule to use for PRX init
   grn2           Number of 2nd granule to use for PRX init

 Returns:
   zlStatusE

 Remarks:
    None

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

static zlStatusE zl5011xPreparePrxGranules(zl5011xParamsS *zl5011xParams, Uint32T *grn1, Uint32T *grn2)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T currPtr, address, readValue;
   Uint32T loop;

   currPtr = zl5011xParams->packetMemory.granuleHeadIndex;

   /* find granules near the end of the chain */
   for (loop = 0; loop < zl5011xParams->packetMemory.granuleCount - 3; loop++)
   {
      address = zl5011xParams->packetMemory.granDescBaseAddr +
            (currPtr * ZL5011X_GRANULE_DESCRIPTOR_SIZE);

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

      currPtr = readValue & 0x3ffff;
   }

   if (status == ZL5011X_OK)
   {
      address = zl5011xParams->packetMemory.granDescBaseAddr +
            (currPtr * ZL5011X_GRANULE_DESCRIPTOR_SIZE);

      *grn1 = currPtr;

      /* initialise the granule descriptor for port 0 */
      (void)zl5011xWrite(zl5011xParams, address +  4, (1 << 24) | (128));
      (void)zl5011xWrite(zl5011xParams, address +  8, (64 <<16) | (3 << 6) | 1);
      (void)zl5011xWrite(zl5011xParams, address + 12, 0);

      address = zl5011xParams->packetMemory.granBaseAddr +
            (currPtr * ZL5011X_GRANULE_DATA_SIZE);

      /* initialise the granule data */
      for (loop = 0; loop < ZL5011X_GRANULE_DATA_SIZE; loop = loop + 4)
      {
         (void)zl5011xWrite(zl5011xParams, address + loop, 0);
      }

      status = zl5011xRead(zl5011xParams, zl5011xParams->packetMemory.granDescBaseAddr +
            (currPtr * ZL5011X_GRANULE_DESCRIPTOR_SIZE), &readValue);

      currPtr = readValue & 0x3ffff;
   }


   if (status == ZL5011X_OK)
   {
      address = zl5011xParams->packetMemory.granDescBaseAddr +
            (currPtr * ZL5011X_GRANULE_DESCRIPTOR_SIZE);

      /* initialise the granule descriptor for port 1 */
      (void)zl5011xWrite(zl5011xParams, address +  4, (1 << 24) | (132));
      (void)zl5011xWrite(zl5011xParams, address +  8, (64 <<16) | (3 << 6) | 1);
      (void)zl5011xWrite(zl5011xParams, address + 12, 0);

      address = zl5011xParams->packetMemory.granBaseAddr +
            (currPtr * ZL5011X_GRANULE_DATA_SIZE);

      *grn2 = currPtr;

      /* initialise the granule data */
      for (loop = 0; loop < ZL5011X_GRANULE_DATA_SIZE; loop = loop + 4)
      {
         (void)zl5011xWrite(zl5011xParams, address + loop, 0);
      }
   }

   return status;
}

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

 Function:
    zl5011xSendPrxPackets

 Description:
   Prepare a granule for each of the GBit Lan ports, for sending, to force
   initialisation.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   grn1           Number of 1st granule to use for PRX init
   grn2           Number of 2nd granule to use for PRX init

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

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

static zlStatusE zl5011xSendPrxPackets(zl5011xParamsS *zl5011xParams, Uint32T grn1, Uint32T grn2)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T readValue;

   /* Setup internal loopback for PKI port 0 */
   (void)zl5011xPkiSetPacketFiltering(zl5011xParams, 0, ZL5011X_FALSE, ZL5011X_FALSE, ZL5011X_FALSE);
   (void)zl5011xPkiSetInterfaceType(zl5011xParams, 0, ZL5011X_MAC_TYPE_GMII);
   (void)zl5011xPkiEnablePort(zl5011xParams, 0, ZL5011X_TRUE);

   (void)zl5011xRead(zl5011xParams, ZL5011X_PKI_BASE, &readValue);
   readValue |= 0x00000200;
   (void)zl5011xWrite(zl5011xParams, ZL5011X_PKI_BASE, readValue);

   /* Setup internal loopback for PKI port 1 */
   (void)zl5011xPkiSetPacketFiltering(zl5011xParams, 1, ZL5011X_FALSE, ZL5011X_FALSE, ZL5011X_FALSE);
   (void)zl5011xPkiSetInterfaceType(zl5011xParams, 1, ZL5011X_MAC_TYPE_GMII);
   (void)zl5011xPkiEnablePort(zl5011xParams, 1, ZL5011X_TRUE);

   (void)zl5011xRead(zl5011xParams, ZL5011X_PKI_BASE + 4, &readValue);
   readValue |= 0x00000200;
   (void)zl5011xWrite(zl5011xParams, ZL5011X_PKI_BASE + 4, readValue);

   /* construct TM message */
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x14, (ZL5011X_FLOW_CPU_PKT << 27) | (64 << 16) | (128));
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x18, grn1);
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x1c, (1 << 18) | grn1);
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x20, 0);

   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x24, 1);

   OS_TASK_DELAY(20);

   /* construct TM message */
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x14, (ZL5011X_FLOW_CPU_PKT << 27) | (64 << 16) | (132));
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x18, grn2);
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x1c, (1 << 18) | grn2);
   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x20, 0);

   (void)zl5011xWrite(zl5011xParams, ZL5011X_CPU_BASE + 0x24, 1);

   OS_TASK_DELAY(100);

   return status;
}

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

 Function:
   zl5011xLanLoopbackConfigStructInit

 Description:
   Initialises structure used by zl5011xLanLoopbackConfig function.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items.
                  See main function

 Returns:
  zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xLanLoopbackConfigStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xLanLoopbackConfigS *par)
{
   zlStatusE status = ZL5011X_OK;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if(status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_INIT_FN_ID,
            "zl5011xLanLoopbackConfigStructInit:",
            0, 0, 0, 0, 0, 0);

      par->enable = ZL5011X_TRUE;
      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
   zl5011xLanLoopbackConfig

 Description:
   If Lan loopback was setup during initialisation, then the actual loopback
   can be enabled / disabled using this function.
   Note that the loopback is disabled following initialisation.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

⌨️ 快捷键说明

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