📄 txc_envoy_drv_mgmt_api.c
字号:
/*--------------------------------------------------------------------------
******* ****
* ***** ** * * * * * * ***** **** * *
* * * * * ** * * * * * * * * * *
* * * * * * * * **** * * * * * ******
* ***** ****** * * * * * ** * * * * * *
* * * * * * ** * * ** ** * * * * * *
* * * * * * * **** * * * * **** * *
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_lmgmt_api.c
Description: The layer management functions support the driver but do
not affect the device. The layer management will not affect traffic
(except for device reset).
--------------------------------------------------------------------------
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_database.h"
#include "txc_envoy_drv_mgmt_real.h"
#include <string.h>
#include "txc_os_sem.h"
/****************************************************************************
** Static Functions **
****************************************************************************/
static TXC_U16BIT ENVOY_DeviceResetValid
(TXC_U16BIT handle, ENVOY_DEV_RESET_STRUCT * deviceResetTypePtr);
/****************************************************************************
** Static/Global Variables **
****************************************************************************/
extern ENVOY_DRIVER_DATABASE envoyDatabase;
const char * semName = ENVOY_SEM_NAME;
/****************************************************************************
** Code **
****************************************************************************/
/*--------------------------------------------------------------------------*
FUNCTION: TXC_ENVOY_StartDriver
DESCRIPTION: This creates specific device driver infrastructure for the
Envoy device. It clears out the driver database and acquires the needed
semaphores. The input parameter is a NULL pointers that allows for future
enhancements. This function will not affect any live traffic already
passing in the device.
INPUTS: startdriverDataPtr: a pointer to type ENVOY_START_DRIVER_STRUCT.
The structure is defined in section 4.2.1.1.
RETURNS: TXC_NO_ERR or an appropriate specific error code listed in the
appendix. This function will return a TXC_WARNING if the driver was
already created.
REVISION HISTORY:
Rev Date Author Description
----- ------- ------------ -----------------
0.5.0 6/03/04 F. Giannella Initial release (beta)
*--------------------------------------------------------------------------*/
TXC_U16BIT TXC_ENVOY_StartDriver(ENVOY_START_DRIVER_STRUCT * startDriverDataPtr)
{
TXC_U16BIT error;
/* set the error code to no error */
error = TXC_NO_ERR;
/* first, check if the driver is already created; if so, return warning */
if (envoyDatabase.driverActive != TXC_FALSE)
return TXC_WARNING;
/* clear out the database */
memset (&envoyDatabase, 0, sizeof (ENVOY_DRIVER_DATABASE) );
/* create the semaphore, with adjustments for no-semaphore mode */
if (ENVOY_SEM_NAME == TXC_NULL)
error = TXC_SemOpen (ENVOY_SEM_NAME, &envoyDatabase.semId);
else
error = TXC_SemOpen (semName, &envoyDatabase.semId);
if (error == TXC_NO_ERR)
envoyDatabase.driverActive = TXC_TRUE;
/* return the error code */
return error;
}
/*--------------------------------------------------------------------------*
FUNCTION: TXC_ENVOY_TerminateDriver
DESCRIPTION: This function is the complement of TXC_ENVOY_StartDriver; it
releases all resources acquired with the create function.
This function will not affect any live traffic already passing in the
device.
INPUTS: None
RETURNS: TXC_NO_ERR or an appropriate specific error code listed in
appendix. This function will return a TXC_WARNING if the driver was never created
or created and deleted.
REVISION HISTORY:
Rev Date Author Description
----- ------- ------------ -----------------
0.5.0 6/03/04 F. Giannella Initial release (beta)
*--------------------------------------------------------------------------*/
TXC_U16BIT TXC_ENVOY_TerminateDriver (void)
{
TXC_U16BIT error, handle;
/* check if the driver is deleted */
if (envoyDatabase.driverActive == TXC_FALSE)
return TXC_WARNING;
/* check if all device are deleted */
error = TXC_NO_ERR;
for (handle = 0; handle < ENVOY_MAX_DEVICES; handle ++)
{
if (envoyDatabase.envoyDeviceData[handle].deviceActive != TXC_FALSE)
error = TXC_DRIVER_BUSY_ERR;
}
/* if all is well, then delete the RTOS functions */
if (error == TXC_NO_ERR)
{
/* delete the semaphore */
TXC_SemDelete (envoyDatabase.semId);
/* clear out the database */
memset (&envoyDatabase, 0, sizeof (ENVOY_DRIVER_DATABASE) );
}
/* return the error code */
return error;
}
/*--------------------------------------------------------------------------*
FUNCTION: TXC_ENVOY_RegisterDevice
DESCRIPTION: This function initializes an individual device.
The device create function assigns a logical handle for all future device
references and registers the device with the driver. This function will
not affect any live traffic already passing in the device.
INPUTS: registerDeviceDataPtr: a pointer to type ENVOY_REGISTER_DEVICE_STRUCT.
The structure is defined in section 4.2.1.1.
RETURNS: TXC_NO_ERR or an appropriate specific error code listed in
appendix. This function will return a TXC_WARNING if the device was
already created at the base address. In addition to the error codes,
this function will return the device handle number in the
ENVOY_REGISTER_DEVICE_STRUCT structure. The handle returned will be in the
range of 0 to ENVOY_MAX_DEVICES - 1.
REVISION HISTORY:
Rev Date Author Description
----- ------- ------------ -----------------
0.5.0 6/03/04 F. Giannella Initial release (beta)
*--------------------------------------------------------------------------*/
TXC_U16BIT TXC_ENVOY_RegisterDevice (ENVOY_REGISTER_DEVICE_STRUCT * registerDeviceDataPtr )
{
TXC_BOOL foundAvailHandle;
TXC_U16BIT i, error;
ENVOY_DEVICE_VERSION_STRUCT deviceVersionData;
/* first, test if the driver is activate */
if (envoyDatabase.driverActive == TXC_FALSE)
return TXC_DRIVER_NOT_CREATED_ERR;
/* loop thru the database and check if the base addr is used */
error = TXC_NO_ERR;
for (i = 0; i < ENVOY_MAX_DEVICES; i ++)
{
/* check if the base address is already found */
if (envoyDatabase.envoyDeviceData[i].baseAddr == registerDeviceDataPtr->baseAddr)
{
error = TXC_WARNING;
break; /* found fatal error */
}
}
/* if the base addr was not found, then find the first handle and use it */
if (error == TXC_NO_ERR)
{
/* loop thru and find first valid handle */
foundAvailHandle = TXC_FALSE;
error = TXC_DEVICE_INIT_ERR;
for (i = 0; i < ENVOY_MAX_DEVICES; i ++)
{
/* check if the handle is NOT active */
if (envoyDatabase.envoyDeviceData[i].deviceActive == TXC_FALSE)
{
/* found a potential handle */
foundAvailHandle = TXC_TRUE;
/* clear out the database */
memset (&envoyDatabase.envoyDeviceData[i], 0, sizeof (ENVOY_DEVICE_DATABASE) );
/* initialize it to the proper values */
envoyDatabase.envoyDeviceData[i].deviceActive = TXC_TRUE;
envoyDatabase.envoyDeviceData[i].baseAddr = registerDeviceDataPtr->baseAddr;
/* get the device type */
TXC_ENVOY_DeviceVersion (i, &deviceVersionData);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -