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

📄 zl5011xmisc.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************
*
*  File name:              zl5011xMisc.c
*
*  Version:                16
*
*  Author:                 MRC
*
*  Date created:           12/09/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  This file contains miscellanous high level API functions.
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     12/09/2002  MRC      Creation
*  2     13/09/2002  MRC      Added PHY access functions
*  3     20/09/2002  MRC      Added Release and Revision fn
*  4     25/10/2002  MRC      Added parameter check fns
*  5     30/10/2002  MRC      Added active check to the check context fns
*  6     31/10/2002  MRC      Added variants + minor fixes
*  7     13/11/2002  MRC      Tidied up create, free and reset fns
*  8     10/01/2003  MRC      Changed timeout define used in GetDevice
*  9     21/02/2003  MRC      Added packet checksum functions
*  10    29/07/2003  APL      Added support for devices with no TDM interface
*                             Renamed global wanLimits structure to devLimits
*  11    26/07/2004  MRC      Fixed some compiler warnings
*  12    29/07/2004  MRC      Fixed some compiler warnings
*  13    13/09/2004  APL      Support for Lan-to-Lan contexts added
*  14    21/01/2005  MRC      Revised context checks
*  15    17/03/2005  APL      Allows semaphores to be deleted without taking first
*  16    18/03/2005  APL      Updated comment for zl5011xDeleteSemaphoreEx
*
*******************************************************************************/

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

#include "zl5011xApi.h"
#include "zl5011xMisc.h"
#include "zl5011xApiVersion.h"
#include "zl5011xApiRelease.h"

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

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

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

 Function:
    zl5011xCreateDeviceStructInit

 Description:
   Initialises structure used by zl5011xCreateDevice function.

 Inputs:
   par            Pointer to the structure for configuration items.
                  See main function

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xCreateDeviceStructInit(zl5011xCreateDeviceS *par)
{
   zlStatusE status = ZL5011X_OK;

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xCreateDeviceStructInit:",
            0, 0, 0, 0, 0, 0);

      par->baseAddress = (Uint32T)ZL5011X_INVALID;
   }

   return status;
}

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

 Function:
    zl5011xCreateDevice

 Description:
   Allocates and initialises the memory required for the device structure.

 Inputs:
   par            Pointer to the structure for configuration items. See below:

 Outputs
   zl5011xParams   Pointer to the initialised device structure

 Structure inputs:
   baseAdd        base address of the device

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xCreateDevice(zl5011xParamsS **zl5011xParams, zl5011xCreateDeviceS *par)
{
   zlStatusE status = ZL5011X_OK;

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_MISC_FN_ID,
            "zl5011xCreateDevice: base address %08X",
            par->baseAddress, 0, 0, 0, 0, 0);

      *zl5011xParams = (zl5011xParamsS *)OS_CALLOC(sizeof(zl5011xParamsS), 1);

      if (*zl5011xParams == NULL)
      {
         status = ZL5011X_RTOS_MEMORY_FAIL;
      }
      else
      {
         if (par->baseAddress == (Uint32T)ZL5011X_INVALID)
         {
            status = ZL5011X_PARAMETER_INVALID;
         }
         else
         {
            (*zl5011xParams)->baseAdd = par->baseAddress;
         }
      }
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xCreateSemaphore(*zl5011xParams);
   }

   if (status != ZL5011X_OK)
   {
      if (*zl5011xParams != NULL)
      {
         OS_FREE(*zl5011xParams);
      }
   }

   return status;
}

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

 Function:
    zl5011xResetStructInit

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

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xResetStructInit:",
            0, 0, 0, 0, 0, 0);

      /* Default behaviour is to take the device and phy semaphores before the reset */
      par->takeDeviceBeforeReset = ZL5011X_TRUE;
      par->takePhyBeforeReset = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
    zl5011xReset

 Description:
   Resets the device and initialises the device structure.

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

 Outputs:
   None

 Structure inputs:
   None

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xReset(zl5011xParamsS *zl5011xParams, zl5011xResetS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T baseAdd;
   OS_MUTEX_ID deviceConfigCopy;
   OS_MUTEX_ID lanPhyAccessCopy;
   zl5011xBooleanE takenDevice = ZL5011X_FALSE;
   zl5011xBooleanE takenPhy = ZL5011X_FALSE;

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

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_MISC_FN_ID,
            "zl5011xReset: device %08X",
            (Uint32T)zl5011xParams, 0, 0, 0, 0, 0);

      /* check that any DMA has been disabled on the device */
      if ((zl5011xParams->osExclusion.dmaRxEnabled == ZL5011X_TRUE) ||
         (zl5011xParams->osExclusion.dmaTxEnabled == ZL5011X_TRUE))
      {
         status = ZL5011X_DMA_RUNNING;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* check that the interrupts have been diabled for the device */
      if (zl5011xParams->osExclusion.interruptsEnabled== ZL5011X_TRUE)

      {
         status = ZL5011X_INTERRUPTS_RUNNING;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* make a copy of the config semaphore, so that it can be reistated after
         the reset */
      deviceConfigCopy = zl5011xParams->osExclusion.deviceConfigExclusion;

      if (par->takeDeviceBeforeReset == ZL5011X_TRUE)
      {
         status = zl5011xGetDevice(zl5011xParams, ZL5011X_FALSE);

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

   if (status == ZL5011X_OK)
   {
      /* make a copy of the lan phy semaphore, so that it can be reistated after
         the reset */
      lanPhyAccessCopy = zl5011xParams->osExclusion.lanPhyAccessExclusion;

      if (par->takePhyBeforeReset == ZL5011X_TRUE)
      {
         status = zl5011xGetLanPhy(zl5011xParams, ZL5011X_FALSE);

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


   if (status == ZL5011X_OK)
   {
      status = zl5011xAdmResetDevice(zl5011xParams);
   }

   if (status == ZL5011X_OK)
   {
        /*2004-03-01 modified by ZhengQis, make a copy of slotnum and macAddr*/
        int slot;
        UINT8  macAddr[2][ZL5011X_MAC_SIZE];
        slot = zl5011xParams->slotNum;
        memcpy(macAddr[0], zl5011xParams->macAddress[0], ZL5011X_MAC_SIZE * 2);

      /* clear up the device structure since it has now been reset */
      baseAdd = zl5011xParams->baseAdd;
      (void)memset(zl5011xParams, 0x00, sizeof(zl5011xParamsS));
      zl5011xParams->baseAdd = baseAdd;
      zl5011xParams->slotNum = slot;
      memcpy(zl5011xParams->macAddress[0], macAddr[0], ZL5011X_MAC_SIZE * 2);
      zl5011xParams->osExclusion.deviceConfigExclusion = deviceConfigCopy;
      zl5011xParams->osExclusion.lanPhyAccessExclusion = lanPhyAccessCopy;

      /* wait for the device to complete reset */
      OS_TASK_DELAY(ZL5011X_WAIT_100MS);
   }

   /* give up any semaphores taken - ignore return codes, since they
      all need to be released anyway. */
   if (takenDevice == ZL5011X_TRUE)
   {
      (void)zl5011xReleaseDevice(zl5011xParams);
   }

   if (takenPhy == ZL5011X_TRUE)
   {
      (void)zl5011xReleaseLanPhy(zl5011xParams);
   }

   return status;
}

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

 Function:
    zl5011xFreeDeviceStructInit

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

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_LAN_FN_ID,
            "zl5011xFreeDeviceStructInit:",
            0, 0, 0, 0, 0, 0);

      /* Default behaviour is to take the semaphores before deleting them */
      par->takeDeviceBeforeSemDelete = ZL5011X_TRUE;
      par->takePhyBeforeSemDelete = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
    zl5011xFreeDevice

 Description:
   Free up the memory used for a device instance

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
    None

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

zlStatusE zl5011xFreeDevice(zl5011xParamsS *zl5011xParams, zl5011xFreeDeviceS *par)
{
   zlStatusE status = ZL5011X_OK;

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

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_MISC_FN_ID,
            "zl5011xFreeDevice: struct %08X",
            (Uint32T)zl5011xParams, 0, 0, 0, 0, 0);
   }

   if (status == ZL5011X_OK)
   {
      /* check that any DMA has been disabled on the device */
      if ((zl5011xParams->osExclusion.dmaRxEnabled == ZL5011X_TRUE) ||
         (zl5011xParams->osExclusion.dmaTxEnabled == ZL5011X_TRUE))
      {
         status = ZL5011X_DMA_RUNNING;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* check that the interrupts have been disabled for the device */
      if (zl5011xParams->osExclusion.interruptsEnabled== ZL5011X_TRUE)

      {
         status = ZL5011X_INTERRUPTS_RUNNING;
      }
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xDeleteSemaphoreEx(zl5011xParams, par->takeDeviceBeforeSemDelete,
                                       par->takePhyBeforeSemDelete);
   }

   if (status == ZL5011X_OK)
   {
      OS_FREE(zl5011xParams);
   }

   return status;
}

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

 Function:
    zl5011xEnterFreezeMode

 Description:
   Forces the device into freeze mode.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   None

 Returns:
  zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xEnterFreezeMode(zl5011xParamsS *zl5011xParams)
{
   zlStatusE status = ZL5011X_OK;

⌨️ 快捷键说明

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