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

📄 zl5011xadm.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
*
*  File name:              zl5011xAdm.c
*
*  Version:                49
*
*  Author:                 LCW
*
*  Date created:           22/03/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  This module contains all the functions that are to control the ADM block.
*  The main responsibilites of the ADM block are
*  Interrupt handling
*  System reset
*  Initiate debug/freeze mode
*  Monitor internal modules
*  Provide initialisation signals
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     22/03/2002  LCW      Creation.
*  2     26/03/2002  LCW      Minor Mods.
*  3     27/03/2002  LCW      Minor Mods.
*  4     28/03/2002  LCW      Minor Mods.
*  5     03/04/2002  LCW      Minor Mods.
*  6     03/04/2002  LCW      Minor Mods.
*  7     03/04/2002  LCW      Minor Mods.
*  8     11/04/2002  LCW      Minor Mods.
*  9     15/04/2002  LCW      Prepared for code review.
*  10    17/04/2002  LCW      Code review actions.
*  11    18/04/2002  LCW      Code review actions.
*  12    18/04/2002  LCW      Changed interrupt & enable constants and
*                                  registers.
*  13    18/04/2002  LCW      Changed comments.
*  14    19/04/2002  LCW      Minor Mods.
*  15    19/04/2002  LCW      Changed zl5011xAdmClearInterruptSource
*  16    19/04/2002  LCW      Minor mods.
*  17    23/04/2002  LCW      Code review actions.
*  18    24/04/2002  LCW      Code review actions.
*  19    26/04/2002  LCW      Added function zl5011xAdmSetInitStatus
*  20    29/04/2002  LCW      Code review actions
*  21    29/04/2002  LCW      Minor mods.
*  22    29/04/2002  LCW      Minor mods.
*  23    29/04/2002  LCW      Minor mods.
*  24    31/05/2002  MRC      Tidied up and fixed uninitialised status
*                                 problem in function zl5011xAdmSetInitStatus
*  25    07/06/2002  LCW      Added zl5011xAdmGetInterruptStatus
*  26    19/06/2002  PJE      modified interruptMasks in structure
*  27    12/07/2002  MRC      Changed function headers due to ADM block change
*  28    05/08/2002  MRC      Used inconsistent error codes
*  29    28/08/2002  PJE      First clear the interrupts before enabling.
*  30    26/09/2002  DJA      zl5011xGetBootStrapMode renamed to
*                             zl5011xAdmGetBootStrapMode
*  31    09/10/2002  PJE      mod for debugging with no device
*  32    29/10/2002  DJA      mod to function zl5011xAdmGetFreezeState, return true
*                             if either bit in the freeze register is set.
*  33    30/10/2002  MRC      Added in variant initialisation to the init fn
*  34    31/10/2002  MRC      Added variants + minor fixes
*  35    05/11/2002  MRC      Added more variants
*  36    06/11/2002  MRC      Added enum to store variant type
*  37    03/12/2002  MRC      Updated variant information
*  38    07/03/2003  MRC      Fixed register error in zl5011xAdmGpioWrite
*  39    03/04/2003  MRC      Initialises the interrupts to off at start, and
*                             added protection around changing the interrupt
*                             masks
*  40    09/06/2003  DJA      Performed pre-audit actions
*  41    29/07/2003  APL      Renamed global wanLimits structure to devLimits
*  42    04/08/2003  APL      Return an error if the API type mismatches device type
*  43    05/08/2003  APL      Applications written with ZL50130 API can execute on ZL5011x devices
*  44    23/07/2004  MRC      Fixed some compiler warnings
*  45    29/07/2004  MRC      Fixed some compiler warnings
*  46    06/09/2004  APL      Device variant support now moved to zl5011xInit.c
*  47    28/01/2005  MRC      Added mask for the GPIO write functions
*  48    15/07/2005  APL      Changed comment for zl5011xAdmGpioRead
*  49    15/07/2005  APL      Changed parameter name zl5011xAdmGpioRead
*
*******************************************************************************/


/*****************   INCLUDE FILES   ******************************************/
#include "zl5011x.h"
#include "zl5011xAdmMap.h"
#include "zl5011xAdm.h"
#include "zl5011xRdWr.h"
#include "zl5011xUtilLib.h"

/*******************************************************************************
 Function:
    zl5011xAdmInit

 Description:
   Returns chip ID and state of the 16 bootstrap pins.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   None

 Returns:
  zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE  zl5011xAdmInit(zl5011xParamsS *zl5011xParams)
{

   zlStatusE status = ZL5011X_OK;
   Uint16T bootStrapMode;

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

   /* Return state of GPIO pins to device structure */
   status = zl5011xAdmGetBootStrapMode(zl5011xParams, &bootStrapMode);

   zl5011xParams->bootStrapMode = bootStrapMode;

   if(status == ZL5011X_OK)
   {
      /* disable the interrupts from the device - can be re-instated later
         when the device is attached to the interrupt handler */
      status = zl5011xAdmDisableInterrupt(zl5011xParams, ZL5011X_ENABLE_INT_0_1);
   }

   return status;
}

/*******************************************************************************
 Function:
    zl5011xAdmSetInitStatus

 Description:
   Each block is represented by a bit in the initialsation status register.
   These bits are defined as the following constants:
   ZL5011X_ADM_TFM_BIT
   ZL5011X_ADM_TFQ_BIT
   ZL5011X_ADM_PLA_BIT
   ZL5011X_ADM_RTP_BIT
   ZL5011X_ADM_TIF_BIT
   ZL5011X_ADM_PAC_BIT
   ZL5011X_ADM_PKI_BIT
   ZL5011X_ADM_PKQ_BIT
   ZL5011X_ADM_PKC_BIT
   ZL5011X_ADM_PRX_BIT
   ZL5011X_ADM_GM_BIT
   ZL5011X_ADM_INIT_ALL_BLOCKS

 Inputs:
    zl5011xParams  Pointer to the structure for this device instance.
   blockMask      Blocks to be initialise.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE  zl5011xAdmSetInitStatus(zl5011xParamsS *zl5011xParams,
                  Uint32T blockMask)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmSetInitStatus: %08X",
         blockMask, 0, 0, 0, 0, 0);

   if ((blockMask & ~ZL5011X_ADM_INIT_CHECK_MASK) != 0)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if(status == ZL5011X_OK)
   {
      status = zl5011xWrite(zl5011xParams, ZL5011X_ADM_MOD_INIT_START, blockMask);
   }

   return status;
}


/*******************************************************************************
 Function:
    zl5011xAdmGetInitStatus

 Description:
   Gets the initialisation status of each block.
   The initalisation status of each block is represented by a particular bit. A
   set bit represents an initialised block. The bits associated with each block
   are listed as the following constants:
   ZL5011X_ADM_TFM_BIT
   ZL5011X_ADM_TFQ_BIT
   ZL5011X_ADM_PLA_BIT
   ZL5011X_ADM_RTP_BIT
   ZL5011X_ADM_TIF_BIT
   ZL5011X_ADM_PAC_BIT
   ZL5011X_ADM_PKI_BIT
   ZL5011X_ADM_PKQ_BIT
   ZL5011X_ADM_PKC_BIT
   ZL5011X_ADM_PRX_BIT
   ZL5011X_ADM_GM_BIT
   ZL5011X_ADM_INIT_ALL_BLOCKS

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

 Outputs:
   blockInitStatus   Parameter used to return the initialisation status of
                     blocks.
 Returns:
   zlStatusE

 Remarks:
   None
*******************************************************************************/
zlStatusE  zl5011xAdmGetInitStatus(zl5011xParamsS *zl5011xParams,
                  Uint32T *blockInitStatus)
{
   zlStatusE status = ZL5011X_OK;

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

   /* Read initialisation status of blocks and record in device structure */
   status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_INIT_START, blockInitStatus);

   /* Used to mask out unused bits to prevent illegal value being returned */
   *blockInitStatus &= ZL5011X_ADM_INIT_CHECK_MASK;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGetInitStatus: %08X",
         *blockInitStatus, 0, 0, 0, 0, 0);

   return(status);
}

/*******************************************************************************
 Function:
   zl5011xAdmEnableBlocks

 Description:
   Writes a mask to the run register to enable the block/s.

 Inputs:
   zl5011xParams  Pointer to the structure for this device instance.
   enableBlocks  The blocks to be enabled.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
  Each block is enabled by writing to a particular bit in the ADM run register.
  The bits associated with each block are listed as follows:

   ZL5011X_ADM_TFM_BIT
   ZL5011X_ADM_TFQ_BIT
   ZL5011X_ADM_PLA_BIT
   ZL5011X_ADM_RTP_BIT
   ZL5011X_ADM_TIF_BIT
   ZL5011X_ADM_PAC_BIT
   ZL5011X_ADM_PKI_BIT
   ZL5011X_ADM_PKQ_BIT
   ZL5011X_ADM_PKC_BIT
   ZL5011X_ADM_PTX_BIT
   ZL5011X_ADM_PRX_BIT
   ZL5011X_ADM_GM_BIT
   ZL5011X_ADM_ENABLE_ALL_BLOCKS

*******************************************************************************/
zlStatusE zl5011xAdmEnableBlocks(zl5011xParamsS *zl5011xParams,
                 Uint32T enableBlocks)
{

   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmEnableBlocks: %08X", enableBlocks, 0, 0,
   0, 0, 0);

   if ((enableBlocks & ~ZL5011X_ADM_ENABLE_CHECK_MASK) != 0)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }


   if(status == ZL5011X_OK)
   {
      /* "or" in the blocks to be initialised */
      status =  zl5011xReadModWrite(zl5011xParams, ZL5011X_ADM_MOD_RUN, enableBlocks,
                  enableBlocks);
   }

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmResetDevice

 Description:
   Writes to the reset register to force an internal reset.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
    None
 *******************************************************************************/
zlStatusE zl5011xAdmResetDevice(zl5011xParamsS *zl5011xParams)
{

   zlStatusE status = ZL5011X_OK;

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

   status = zl5011xWrite(zl5011xParams, ZL5011X_ADM_MOD_RESET, ZL5011X_ADM_RESET_KEY);

   return status;
}
/*******************************************************************************
 Function:
   zl5011xAdmInitiateFreeze

 Description:
   This function generates a global freeze signal (debug_freeze), connected to
   all blocks which require it.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   This function will only have any effect when the device is in debug mode.
   This is achieved by setting x_debug_enable pin active active.  This pin can
   be changed at any time to switch into or out of debug mode.
*******************************************************************************/
zlStatusE zl5011xAdmInitiateFreeze(zl5011xParamsS *zl5011xParams)
{

   zlStatusE status = ZL5011X_OK;

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

   /* Write to freeze register to initiate freeze (sets bit 0) */
   status = zl5011xWrite(zl5011xParams, ZL5011X_ADM_MOD_FREEZE,
         ZL5011X_1BIT_MASK << ZL5011X_ADM_SET_FREEZE_BIT);

   return status;

}
/*******************************************************************************
 Function:
   zl5011xAdmGetFreezeState

 Description:
   Reads the Freeze register and returns TRUE if either the hardware or software
   status bits are set.  If both bits are reset then it returns FALSE.

 Inputs:
   zl5011xParams  Pointer to the structure for this device instance
   freezeState   Return parameter - gives freeze state

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   This function does nothing with the hardware debug enable pin.  Therefore
   it will not inform the user whether the device is actually in a freeze state.

*******************************************************************************/
zlStatusE zl5011xAdmGetFreezeState(zl5011xParamsS *zl5011xParams,
                 zl5011xBooleanE *freezeState)
{

   zlStatusE status = ZL5011X_OK;
   Uint32T   registerValue;

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

   /* Check enumerated parameters are within range */
   status = ZL5011X_CHECK_BOOLEAN(*freezeState);

   /* Get freeze state register */
   if(status == ZL5011X_OK)
   {
      status = zl5011xRead(zl5011xParams, ZL5011X_ADM_MOD_FREEZE, &registerValue);
   }

   if (status == ZL5011X_OK)
   {
      if ((registerValue & (ZL5011X_1BIT_MASK  << ZL5011X_ADM_FREEZE_STATUS_BIT |
                            ZL5011X_1BIT_MASK  << ZL5011X_ADM_SET_FREEZE_BIT )) != 0)
      {
         *freezeState = ZL5011X_TRUE;
      }
      else
      {
         *freezeState = ZL5011X_FALSE;
      }
   }

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmGetFreezeState: %d",
         *freezeState, 0, 0, 0, 0, 0);

   return status;
}

/*******************************************************************************
 Function:
   zl5011xAdmEnableInterruptSource

 Description:
   Enables the source of the interrupt to be directed to the selected interrupt.
   First clear the interrupts before enabling.

 Inputs:
   zl5011xParams          Pointer to the structure for this device instance
   interrupt             Which interrupt to enable (IE0, IE1 or freeze)
   interruptSourceMask   Defines the interrupt source (see remarks below)

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   The possible sources of the interrupts are contained in the file
   zl5011x.h

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

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

   ZL5011X_TRACE(ZL5011X_ADM_FN_ID, "zl5011xAdmEnableInterruptSource: 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();

⌨️ 快捷键说明

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