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

📄 txc_envoy_spi3_valid.c

📁 TranSwitch Envoy CE2 & Envoy CE4 设备驱动及编程指南
💻 C
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------

  *******                           ****
     *     *****     **    *    *  *       *    *   *  *****   ****   *    *
     *     *    *   *  *   **   *  *       *    *   *    *    *    *  *    *
     *     *    *  *    *  * *  *   ****   *    *   *    *    *       ******
     *     *****   ******  *  * *       *  * ** *   *    *    *       *    *
     *     *   *   *    *  *   **  *    *  **  **   *    *    *    *  *    *
     *     *    *  *    *  *    *   ****   *    *   *    *     ****   *    *

                        Proprietary and Confidential 

    This program is made available only to customers and prospective customers 
of TranSwitch Corporation under license and may be used only with TranSwitch 
semi-conductor products.

                      Copyright(c) 2004 TranSwitch Inc.

 --------------------------------------------------------------------------

             *******  **      **  **        **   ********   **      **
             *******  ***     **  **        **  **********  **      **
             **       ** *    **  **        **  **      **   **    **
             *****    **  *   **   **      **   **      **     *  *
             *****    **   *  **    **    **    **      **      **
             **       **    * **     **  **     **      **      **
             *******  **     ***      ****      **********      **
             *******  **      **       **        ********       **

 --------------------------------------------------------------------------
                           TranSwitch Envoy-CE2/CE4
                                Device Driver
 --------------------------------------------------------------------------

   Workfile:  txc_envoy_spi3_valid.c

   Description: Validation of SPI3 API calls.

  --------------------------------------------------------------------------
                               Revision History
  --------------------------------------------------------------------------
    Rev #     Date          Author                Description
   -----    -------      ------------         ----------------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/


/****************************************************************************
 **                             Include Files                              **
 ****************************************************************************/

#include "txc_envoy_api.h"
#include "txc_envoy_spi3_support.h"
#include "txc_envoy_database.h"
#include <string.h>


/****************************************************************************
 **                            Static Functions                            **
 ****************************************************************************/


static TXC_U16BIT ENVOY_VerifySpi3HandleIfaceIdAndSinglePort(TXC_U16BIT handle, 
                  TXC_U8BIT interfaceId, TXC_U16BIT port);
static TXC_U16BIT ENVOY_VerifySpi3HandleIfaceIdAndMultiPort(TXC_U16BIT handle, 
                  TXC_U8BIT interfaceId, TXC_U16BIT port);
static TXC_U16BIT ENVOY_VerifySpi3HandleAndIfaceId(TXC_U16BIT handle,TXC_U8BIT interfaceId);



/****************************************************************************
 **                        Static/Global Variables                         **
 ****************************************************************************/



/****************************************************************************
 **                           STATIC FUNCTIONS                             **
 ****************************************************************************/

/* check port,and then handle, in that order for valid range. 
    ON THE SET FUNCTIONS. Set function allow the port == 0xFFFF.
    Overwrite the last error, so the hierarchy is correctly followed. */

static TXC_U16BIT ENVOY_VerifySpi3HandleIfaceIdAndSinglePort(TXC_U16BIT handle, 
                  TXC_U8BIT interfaceId, TXC_U16BIT port)
{
    TXC_U16BIT maxPorts, error;

    /* first, check the handle. This may return invalid handle or driver not created */
    error = ENVOY_DbVerifyHandle (handle);

    /* if NO handle error, make sure the port value is correct, 
        allow for the all ports (0xFFFF) */
    if (error == TXC_NO_ERR)
    {
        /* Verify interfaceId */
        if (interfaceId != 0)
        {
            error = TXC_INVALID_IFACE_ID_ERR;
        }
        if (error == TXC_NO_ERR)
        {
            maxPorts = ENVOY_DbGetMaxSpi3Ports (handle);
            if (port >= maxPorts)
            {
                error = TXC_INVALID_CHANNEL_ERR;
            }
        }
    }
    /* return the error */
    return error;
}


static TXC_U16BIT ENVOY_VerifySpi3HandleIfaceIdAndMultiPort(TXC_U16BIT handle, 
                  TXC_U8BIT interfaceId, TXC_U16BIT port)
{
    TXC_U16BIT maxPorts, error;

    /* first, check the handle. This may return invalid handle or driver not created */
    error = ENVOY_DbVerifyHandle (handle);

    /* if NO handle error, make sure the port value is correct, 
        allow for the all ports (0xFFFF) */
    if (error == TXC_NO_ERR)
    {
        /* Verify interfaceId */
        if (interfaceId != 0)
        {
            error = TXC_INVALID_IFACE_ID_ERR;
        }
        if (error == TXC_NO_ERR)
        {
            maxPorts = ENVOY_DbGetMaxSpi3Ports (handle);
            if (port >= maxPorts)
            {
                if (port != ENVOY_MAC_ALL_PORTS)
                error = TXC_INVALID_CHANNEL_ERR;
            }
        }
    }
    /* return the error */
    return error;
}



static TXC_U16BIT ENVOY_VerifySpi3HandleAndIfaceId(TXC_U16BIT handle,
                  TXC_U8BIT interfaceId)
{
    TXC_U16BIT error;

    /* first, check the handle. This may return invalid handle or driver not created */
    error = ENVOY_DbVerifyHandle (handle);

    /* if NO handle error, make sure the port value is correct, 
        allow for the all ports (0xFFFF) */
    if (error == TXC_NO_ERR)
    {
        /* Verify interfaceId */
        if (interfaceId != 0)
        {
            error = TXC_INVALID_IFACE_ID_ERR;
        }
    }
    /* return the error */
    return error;
}







/****************************************************************************
 **                                  CODE                                  **
 ****************************************************************************/


/************************************************************************************/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/************************************************************************************

   FUNCTION:  ENVOY_SetSpi3InputIfaceValid

   DESCRIPTION: This function validates the TXC_IfSPI3_InputIfaceSet

   INPUTS:  Same as TXC_IfSPI3_InputIfaceSet

   RETURNS:  TXC_NO_ERR or an appropriate specific error code listed in
   appendix.

   CAVEATS: None.

   REVISION HISTORY:

    Rev #     Date          Author                Description
   -----    -------      ------------         ----------------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
 *--------------------------------------------------------------------------*/

TXC_U16BIT ENVOY_SetSpi3InputIfaceValid ( TXC_U16BIT handle, TXC_U8BIT interfaceId,
                                      TXC_IfSPI3_INPUT_STRUCT *spi3InputIfaceDataPtr)
{
    TXC_U16BIT error;
    ENVOY_DEV_EXT_PIN_STRUCT pinData;

    /* fill the structure with 0 */
    memset ((void *) &pinData, 0, sizeof (pinData));

    /* first, check the handle and the interfaceId */
    error = ENVOY_VerifySpi3HandleAndIfaceId (handle, interfaceId);

    /* now range check the data */
    if (error == TXC_NO_ERR)
    {
        if (spi3InputIfaceDataPtr->inputMode >= TXC_IfSPI3_END_OF_MODE_ENUM)
        {
            spi3InputIfaceDataPtr->inputMode = TXC_IfSPI3_MODE_ENUM_ERR;
            error = TXC_INVALID_PARM_ERR;
        }
        else
        {
            /* checking of the inputMode */
            error = TXC_ENVOY_DeviceExPinRtrv (handle, &pinData);
            if (error != TXC_NO_ERR)
            {
                return error;
            }
            else
            {
                switch (spi3InputIfaceDataPtr->inputMode)
                {
                    case TXC_IfSPI3_PHY_LAYER_SINGLE_PHY:
                        /* check if in PHY mode, otherwise return an error */
                        if (pinData.spi3InputMode == ENVOY_DEV_PIN_SPI3_LINK_MODE)
                        {
                            spi3InputIfaceDataPtr->inputMode = TXC_IfSPI3_MODE_ENUM_ERR;
                            error = TXC_INVALID_PARM_ERR; /* the CLI will take place */
                        }
                        break;

                    case TXC_IfSPI3_PHY_LAYER_MULTI_PHY:
                        /* check if in PHY LAYER mode, otherwise return an error */
                        if (pinData.spi3InputMode == ENVOY_DEV_PIN_SPI3_LINK_MODE)
                        {
                            spi3InputIfaceDataPtr->inputMode = TXC_IfSPI3_MODE_ENUM_ERR;
                            error = TXC_INVALID_PARM_ERR; /* the CLI will take place */
                        }
                        break;

                    case TXC_IfSPI3_LINK_LAYER_SINGLE_PHY:
                        /* check if in PHY mode, otherwise return an error */
                        if (pinData.spi3InputMode == ENVOY_DEV_PIN_SPI3_PHY_MODE)
                        {
                            spi3InputIfaceDataPtr->inputMode = TXC_IfSPI3_MODE_ENUM_ERR;
                            error = TXC_INVALID_PARM_ERR; /* the CLI will take place */
                        }
                        break;

                    case TXC_IfSPI3_LINK_LAYER_MULTI_PHY:
                        /* check if in PHY LAYER mode, otherwise return an error */
                        if (pinData.spi3InputMode == ENVOY_DEV_PIN_SPI3_PHY_MODE)
                        {
                            spi3InputIfaceDataPtr->inputMode = TXC_IfSPI3_MODE_ENUM_ERR;
                            error = TXC_INVALID_PARM_ERR; /* the CLI will take place */
                        }
                        break;

                    default:
                        spi3InputIfaceDataPtr->inputMode = TXC_IfSPI3_MODE_ENUM_ERR;
                        error = TXC_INVALID_PARM_ERR; /* it should never get here */
                        break;
                }
            }
        }

        /* Note: the Bus width is pin-configurable in Envoy-CE2/CE4 */
        if (spi3InputIfaceDataPtr->inputBusWidth > TXC_IfSPI3_BUS_WIDTH_NONE)
        {
            error = TXC_INVALID_PARM_ERR;
            spi3InputIfaceDataPtr->inputBusWidth = TXC_IfSPI3_BUS_WIDTH_ENUM_ERR;
        }

        if (spi3InputIfaceDataPtr->inputParityCheckingMode >= TXC_IfSPI3_END_OF_PARITY_ENUM)
        {
            error = TXC_INVALID_PARM_ERR;
            spi3InputIfaceDataPtr->inputParityCheckingMode = TXC_IfSPI3_PARITY_ENUM_ERR;
        }

        if (spi3InputIfaceDataPtr->inputDeviceExtension.envoyCe2Ce4InputAttr.inputAggregationMode >= TXC_IfSPI3_END_OF_INPUT_AGGR_ENUM)
        {
            error = TXC_INVALID_PARM_ERR;
            spi3InputIfaceDataPtr->inputDeviceExtension.envoyCe2Ce4InputAttr.inputAggregationMode = TXC_IfSPI3_INPUT_AGGR_ENUM_ERR;
        }

        if ((spi3InputIfaceDataPtr->inputDeviceExtension.envoyCe2Ce4InputAttr.inputStpaViolationDiscardEnable != TXC_FALSE)  &&
            (spi3InputIfaceDataPtr->inputDeviceExtension.envoyCe2Ce4InputAttr.inputStpaViolationDiscardEnable != TXC_TRUE))
        {
            spi3InputIfaceDataPtr->inputDeviceExtension.envoyCe2Ce4InputAttr.inputStpaViolationDiscardEnable = TXC_BOOL_INVALID;
            error = TXC_INVALID_PARM_ERR;
        }
    }
    /* return the error code */
    return error;
}


/************************************************************************************/
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/************************************************************************************

   FUNCTION:  ENVOY_GetSpi3InputIfaceValid

   DESCRIPTION: This function validates the TXC_IfSPI3_InputIfaceGet

   INPUTS:   handle: Instance of the Envoy device to configure

             interfaceId: SPI-3 Bus Interface identifier

   RETURNS:  TXC_NO_ERR or an appropriate specific error code listed in appendix.

   CAVEATS:  None.

   REVISION HISTORY:

    Rev #     Date          Author                Description
   -----    -------      ------------         ----------------------
   0.5.0    6/03/04      F. Giannella         Initial release (beta)
-----------------------------------------------------------------------------------*/
TXC_U16BIT ENVOY_GetSpi3InputIfaceValid(TXC_U16BIT handle, TXC_U8BIT interfaceId)
{
    TXC_U16BIT error;
    
    /* Check the handle and the interfaceId */
    error = ENVOY_VerifySpi3HandleAndIfaceId (handle, interfaceId);

    /* return the error code */
    return error;
}


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

⌨️ 快捷键说明

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