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

📄 zl5011xinit.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*******************************************************************************
*
*  File name:              zl5011xInit.c
*
*  Version:                55
*
*  Author:                 MRC
*
*  Date created:           01/05/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  This file contains the functions required to initialise the device.
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     01/05/2002  MRC      Creation
*  2     02/05/2002  MRC      Update
*  3     03/05/2002  MRC      Changed the test harness prefix to hrn_
*  4     07/05/2002  MRC      Changed enum to use uppercase
*                             P(acketTxHeaderModeE).
*  5     09/05/2002  MRC      Added VerInit structure init fn
*  6     14/05/2002  MRC      Tidied up if statements.
*  7     21/05/2002  MRC      Initialise the PKQ to avoid sim warnings
*  8     28/05/2002  MRC      Added in PKC initialisation
*  9     28/05/2002  MRC      Mods following seminar
*  10    31/05/2002  MRC      Added in real admin block functions
*  11    06/06/2002  MRC      Added in PKQ and RTP init functions
*  12    14/06/2002  MRC      Brought more options out to the verInit fn
*  13    19/06/2002  MRC      PTX block changed
*  14    20/06/2002  MRC      moved run for PTX block to Lan int fn
*  15    20/06/2002  MRC      added in PTX memory initialisation for the system
*                             verification
*  16    09/07/2002  MRC      Wan init now includes the liu frequency
*  17    11/07/2002  WD       Changed default granule address.
*  18    18/07/2002  MRC      Changed memory configuration
*  19    01/08/2002  MRC      Added RTP statistics interrupt config to LanInit
*  20    16/08/2002  MRC      RTP headers and stats no longer use external mem
*  21    09/09/2002  MRC      Tidied up ready for review
*  22    10/09/2002  MRC      Updated following review
*  23    19/09/2002  MRC      Added Wan Tx max granule usage to WanInit
*  24    23/09/2002  MRC      Added SysInit function
*  25    11/10/2002  MRC      Changed RTP interrupt period - due to the way the
*                             RTP statistics operate
*  26    22/10/2002  MRC      Added Lan port initialisation
*  27    29/10/2002  MRC      Added parameter checking
*  28    31/10/2002  MRC      Added variants + minor fixes
*  29    19/11/2002  MRC      Fixed gotDevice checks
*  30    09/12/2002  MRC      Now sets the run bit for the TM block
*  31    29/01/2003  MRC      Added control for external memory parity
*  32    31/01/2003  MRC      Added extra initialisation functions for PRX
*  33    17/02/2003  MRC      Fixed granule problem in PRX initialisation
*  34    26/02/2003  MRC      Added packet loopback function
*  35    27/05/2003  MRC      Delayed run on TIF block until Wan configuration
*                             is completed (WanConfigureSync/WanConfigureAsync)
*  36    05/06/2003  MRC      Fixed packet loopback function
*  37    11/06/2003  MRC      Increased the default number of granules for the
*                             TDM queues
*  38    03/07/2003  MRC      Updated structure comments
*  39    10/07/2003  APL      Fixed compiler warning about unused static functions
*  40    10/07/2003  APL      Corrected revision number on last version
*  41    17/07/2003  APL      Trace flag was incorrect in ...StructInit function
*  42    04/08/2003  APL      Removed unused variable for some device variants
*  43    07/08/2003  APL      Don't enable run bits which are unused for the ZL50130
*  44    08/09/2003  APL      Added comment
*  45    26/07/2004  MRC      Fixed some compiler warnings
*  46    19/08/2004  MRC      Added user defined LIU frequency setting
*  47    06/09/2004  APL      Added support for different device variants
*  48    04/10/2004  APL      Additional comment for device type field
*  49    09/12/2004  MRC      Added extra device variants
*  50    03/02/2005  APL      Added ZL30301 and ZL30302 device variants
*  51    03/02/2005  APL      Renamed device ID's to allow new family members
*  52    03/02/2005  APL      Added further device variant code
*  53    14/02/2005  APL      Removed spurious comment character
*  54    11/04/2005  APL      Clear initialisation interrupt when complete
*  55    08/06/2005  MRC      Configure memory now calculates number of granules
*
*******************************************************************************/

/*****************   INCLUDE FILES                *****************************/

#include "zl5011xApi.h"
#include "zl5011xAdmMap.h"
#include "zl5011xMisc.h"
#include "zl5011xInit.h"
#include "zl5011xRtpMap.h"
#include "zl5011xLan.h"
#include "zl5011xPacketLoopback.h"
#include "zl5011xVariant.h"

/*****************   STATIC FUNCTION DECLARATIONS   ***************************/

static zlStatusE zl5011xCheckAPICompatibility(zlDeviceTypeE deviceType);
static zlStatusE zl5011xInitBlocks(zl5011xParamsS *zl5011xParams, Uint32T blocks);
static zlStatusE zl5011xSendPrxPackets(zl5011xParamsS *zl5011xParams, Uint32T grn1, Uint32T grn2);
static zlStatusE zl5011xPreparePrxGranules(zl5011xParamsS *zl5011xParams, Uint32T *grn1, Uint32T *grn2);
static zlStatusE zl5011xMemoryCalcAddrGranulesMax(zl5011xParamsS *zl5011xParams, zl5011xConfigureMemoryS *par,
      Uint32T *descBase, Uint32T *dataBase, Uint32T *heapStartAddress, Uint32T *heapEndAddress, Uint32T *numGranules);
static zlStatusE zl5011xMemoryCalcAddrGranules(zl5011xParamsS *zl5011xParams, zl5011xConfigureMemoryS *par,
      Uint32T *descBase, Uint32T *dataBase, Uint32T *heapStartAddress, Uint32T *heapEndAddress);

/*****************   EXPORTED FUNCTION DEFINTIONS   ***************************/

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

 Function:
    zl5011xSysInitStructInit

 Description:
   Initialises structure used by zl5011xSysInit 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 zl5011xSysInitStructInit(zl5011xParamsS *zl5011xParams, zl5011xSysInitS *par)
{
   zlStatusE status = ZL5011X_OK;

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

      par->osExclusionEnable = ZL5011X_TRUE;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xInitStructInit(zl5011xParams, &(par->init));
      par->init.osExclusionEnable = ZL5011X_FALSE;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xConfigureMemoryStructInit(zl5011xParams, &(par->configureMemory));
      par->configureMemory.osExclusionEnable = ZL5011X_FALSE;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xWanInitStructInit(zl5011xParams, &(par->wanInit));
      par->wanInit.osExclusionEnable = ZL5011X_FALSE;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xLanInitStructInit(zl5011xParams, &(par->lanInit));
      par->lanInit.osExclusionEnable = ZL5011X_FALSE;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRunStructInit(zl5011xParams, &(par->run));
      par->run.osExclusionEnable = ZL5011X_FALSE;
   }

   return status;
}

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

 Function:
    zl5011xSysInit

 Description:
   This performs a complete initialisation of the device, and provides a
   convenient way of initialising each of the functional areas in the device
   from a single function call.

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

 Structure inputs:
   init           settings for the general init function
   configureMemory   settings for the memory initialisation function
   wanInit        settings for the WAN init function
   lanInit        settings for the LAN init function
   run            settings for the run function
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

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

      Uint32T grn1, grn2;
      zl5011xResetS reset;

   /* 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,
            "zl5011xSysInit: ",
            0, 0, 0, 0, 0, 0);
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xInit(zl5011xParams, &(par->init));
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xConfigureMemory(zl5011xParams, &(par->configureMemory));
   }

      if (status == ZL5011X_OK)
      {
         if (zl5011xParams->doneInit == ZL5011X_FALSE)
         {
            status = zl5011xPreparePrxGranules(zl5011xParams, &grn1, &grn2);
         }
      }

   if (status == ZL5011X_OK)
   {
      status = zl5011xWanInit(zl5011xParams, &(par->wanInit));
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xLanInit(zl5011xParams, &(par->lanInit));
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xRun(zl5011xParams, &(par->run));
   }

   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);
      }
   }

      if (zl5011xParams->doneInit == ZL5011X_FALSE)
      {
         if (status == ZL5011X_OK)
         {
            status = zl5011xSendPrxPackets(zl5011xParams, grn1, grn2);
         }

         if (status == ZL5011X_OK)
         {
            status = zl5011xResetStructInit(zl5011xParams, &reset);
         }

         if (status == ZL5011X_OK)
         {
            status = zl5011xReset(zl5011xParams, &reset);
         }

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

            status = zl5011xSysInit(zl5011xParams, par);
         }
      }

   return status;
}

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

 Function:
    zl5011xInitStructInit

 Description:
   Initialises structure used by zl5011xInit 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 zl5011xInitStructInit(zl5011xParamsS *zl5011xParams, zl5011xInitS *par)
{
   zlStatusE status = ZL5011X_OK;

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

      par->deviceType = (zlDeviceTypeE)ZL5011X_NOT_INITIALISED; /* This MUST be set by the calling application */
      par->systemClockFreq = 100000000;
      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
    zl5011xInit

 Description:
   This function sets up the more general functional blocks within the device.

   There are several functions used to configure the device from reset. They
   are shown below, and must be called in this sequence, in order to enable the
   device.
      zl5011xInit
      zl5011xConfigureMemory
      zl5011xWanInit
      zl5011xLanInit
      zl5011xRun

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

 Structure inputs:
   deviceType        The particular type of device we are running on.
                     This MUST be specified or an error will be generated.
   systemClockFreq   frequency the device is being clocked at.
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xInit(zl5011xParamsS *zl5011xParams, zl5011xInitS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T loop;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

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

   if (status == ZL5011X_OK)
   {  /* Check that a valid device type has been specified */
      status = ZL5011X_CHECK_DEVICE_TYPE(par->deviceType);
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xCheckAPICompatibility(par->deviceType);
   }

   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)
      {

⌨️ 快捷键说明

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