📄 zl5011xmisc.c
字号:
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_MISC_FN_ID,
"zl5011xEnterFreezeMode: device %08X",
(Uint32T)zl5011xParams, 0, 0, 0, 0, 0);
/* Device enters freeze mode */
status = zl5011xAdmInitiateFreeze(zl5011xParams);
}
return status;
}
/*******************************************************************************
Function:
zl5011xCreateSemaphore
Description:
Creates semaphores used to access the device
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xCreateSemaphore(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_MISC_FN_ID, "zl5011xCreateSemaphore:", 0, 0, 0, 0, 0, 0);
/* Create device configuration semaphore */
if (zl5011xParams->osExclusion.deviceConfigExclusion == OS_SEM_INVALID)
{
zl5011xParams->osExclusion.deviceConfigExclusion = OS_MUTEX_CREATE(OS_SEM_FULL);
if(zl5011xParams->osExclusion.deviceConfigExclusion == OS_SEM_INVALID)
{
status = ZL5011X_RTOS_SEMA4_CREATE_FAIL;
}
}
}
if (status == ZL5011X_OK)
{
/* Create Lan PHY access semaphore */
if (zl5011xParams->osExclusion.lanPhyAccessExclusion == OS_SEM_INVALID)
{
zl5011xParams->osExclusion.lanPhyAccessExclusion = OS_MUTEX_CREATE(OS_SEM_FULL);
if(zl5011xParams->osExclusion.lanPhyAccessExclusion == OS_SEM_INVALID)
{
status = ZL5011X_RTOS_SEMA4_CREATE_FAIL;
}
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xGetDevice
Description:
Used to provide exclusive access for device configuration, using a binary
semaphore.
Inputs:
zl5011xParams Pointer to the structure for this device instance
waitForever ZL5011X_TRUE to wait forever, or ZL5011X_FALSE to set a timeout
when taking the semaphore
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGetDevice(zl5011xParamsS *zl5011xParams, zl5011xBooleanE waitForever)
{
OS_STATUS osStatus;
zlStatusE status = ZL5011X_OK;
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_MISC_FN_ID,
"zl5011xGetDevice: wait forever %d",
waitForever, 0, 0, 0, 0, 0);
if (zl5011xParams->osExclusion.deviceConfigExclusion == OS_SEM_INVALID)
{
status = ZL5011X_RTOS_SEMA4_NOT_CREATED;
}
}
if (status == ZL5011X_OK)
{
if (waitForever == ZL5011X_TRUE)
{
osStatus = OS_MUTEX_TAKE(zl5011xParams->osExclusion.deviceConfigExclusion);
}
else
{
osStatus = OS_MUTEX_TAKE_T(zl5011xParams->osExclusion.deviceConfigExclusion,
ZL5011X_MUTEX_TIMEOUT_MS);
}
if (osStatus != OS_OK)
{
status = ZL5011X_RTOS_SEMA4_TAKE_FAIL;
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xGetLanPhy
Description:
Used to provide exclusive access to the Lan PHYs, using a binary semaphore.
Inputs:
zl5011xParams Pointer to the structure for this device instance
waitForever ZL5011X_TRUE to wait forever, or ZL5011X_FALSE to set a timeout
when taking the semaphore
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGetLanPhy(zl5011xParamsS *zl5011xParams, zl5011xBooleanE waitForever)
{
OS_STATUS osStatus;
zlStatusE status = ZL5011X_OK;
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_MISC_FN_ID,
"zl5011xGetLanPhy: wait forever %d",
waitForever, 0, 0, 0, 0, 0);
if (zl5011xParams->osExclusion.lanPhyAccessExclusion == OS_SEM_INVALID)
{
status = ZL5011X_RTOS_SEMA4_NOT_CREATED;
}
}
if (status == ZL5011X_OK)
{
if (waitForever == ZL5011X_TRUE)
{
osStatus = OS_MUTEX_TAKE(zl5011xParams->osExclusion.lanPhyAccessExclusion);
}
else
{
osStatus = OS_MUTEX_TAKE_T(zl5011xParams->osExclusion.lanPhyAccessExclusion,
ZL5011X_PHY_MUTEX_TIMEOUT_MS);
}
/* Take semaphore */
if (osStatus != OS_OK)
{
status = ZL5011X_RTOS_SEMA4_TAKE_FAIL;
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xReleaseDevice
Description:
Used to indicate that configuration has completed, and allow another task to
access the device.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xReleaseDevice(zl5011xParamsS *zl5011xParams)
{
OS_STATUS osStatus;
zlStatusE status = ZL5011X_OK;
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_MISC_FN_ID, "zl5011xReleaseDevice:", 0, 0, 0, 0, 0, 0);
/* Give up semaphore */
osStatus = OS_MUTEX_GIVE(zl5011xParams->osExclusion.deviceConfigExclusion);
if (osStatus != OS_OK)
{
status = ZL5011X_RTOS_SEMA4_GIVE_FAIL;
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xReleaseLanPhy
Description:
Used to indicate that configuration has completed, and allow another task to
access the PHYs.
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xReleaseLanPhy(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
OS_STATUS osStatus;
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_MISC_FN_ID, "zl5011xReleaseLanPhy:", 0, 0, 0, 0, 0, 0);
/* Give up semaphore */
osStatus = OS_MUTEX_GIVE(zl5011xParams->osExclusion.lanPhyAccessExclusion);
/* Convert the return value */
if (osStatus != OS_OK)
{
status = ZL5011X_RTOS_SEMA4_GIVE_FAIL;
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xDeleteSemaphore
Description:
Deletes the semaphores created during device initialisation
Inputs:
zl5011xParams Pointer to the structure for this device instance
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xDeleteSemaphore(zl5011xParamsS *zl5011xParams)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_MISC_FN_ID, "zl5011xDeleteSemaphore:", 0, 0, 0, 0, 0, 0);
status = zl5011xDeleteSemaphoreEx(zl5011xParams, ZL5011X_TRUE, ZL5011X_TRUE);
return status;
}
/*******************************************************************************
Function:
zl5011xDeleteSemaphoreEx
Description:
Deletes the semaphores created during device initialisation. Allows option
to specify whether to take the semaphores before deleting them. This passes
responsibility for ensuring mutual exclusion on to the caller.
Inputs:
zl5011xParams Pointer to the structure for this device instance
takeDeviceBeforeDelete If ZL5011X_TRUE this function will attempt to
take the device mutex before deleting it
takePhyBeforeDelete If ZL5011X_TRUE this function will attempt to
take the PHY mutex before deleting it
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xDeleteSemaphoreEx(zl5011xParamsS *zl5011xParams,
zl5011xBooleanE takeDeviceBeforeDelete, zl5011xBooleanE takePhyBeforeDelete)
{
zlStatusE status = ZL5011X_OK;
OS_STATUS osStatus = OS_OK;
zl5011xBooleanE takenDevice = ZL5011X_FALSE;
zl5011xBooleanE takenPhy = ZL5011X_FALSE;
ZL5011X_TRACE(ZL5011X_MISC_FN_ID, "zl5011xDeleteSemaphore:", 0, 0, 0, 0, 0, 0);
/* get the device, to check that no other processes are using it */
if(zl5011xParams->osExclusion.deviceConfigExclusion != OS_SEM_INVALID)
{
if (takeDeviceBeforeDelete == ZL5011X_TRUE)
{
if (status == ZL5011X_OK)
{
status = zl5011xGetDevice(zl5011xParams, ZL5011X_FALSE);
if (status == ZL5011X_OK)
{
takenDevice = ZL5011X_TRUE;
}
}
}
else
{ /* Don't need to take the semaphore but pretend that we took it */
takenDevice = ZL5011X_TRUE;
}
}
if (zl5011xParams->osExclusion.lanPhyAccessExclusion != OS_SEM_INVALID)
{
if (takePhyBeforeDelete == ZL5011X_TRUE)
{
/* get the device, to check that no other processes are using it */
if (status == ZL5011X_OK)
{
status = zl5011xGetLanPhy(zl5011xParams, ZL5011X_FALSE);
if (status == ZL5011X_OK)
{
takenPhy = ZL5011X_TRUE;
}
}
}
else
{ /* Don't need to take the semaphore but pretend that we took it */
takenPhy = ZL5011X_TRUE;
}
}
if (status == ZL5011X_OK)
{
/* delete the semaphores that have been taken */
if (takenDevice == ZL5011X_TRUE)
{
osStatus = OS_MUTEX_DELETE(zl5011xParams->osExclusion.deviceConfigExclusion);
if(osStatus != OS_OK)
{
status = ZL5011X_RTOS_SEMA4_DELETE_FAIL;
}
else
{
zl5011xParams->osExclusion.deviceConfigExclusion = OS_SEM_INVALID;
}
}
if (takenPhy == ZL5011X_TRUE)
{
osStatus = OS_MUTEX_DELETE(zl5011xParams->osExclusion.lanPhyAccessExclusion);
/* if an error code is already set, then ignore the return code */
if (status == ZL5011X_OK)
{
if(osStatus != OS_OK)
{
status = ZL5011X_RTOS_SEMA4_DELETE_FAIL;
}
else
{
zl5011xParams->osExclusion.lanPhyAccessExclusion = OS_SEM_INVALID;
}
}
}
}
return(status);
}
/*******************************************************************************
Function:
zl5011xGetApiVersion
Description:
Returns the revision and date / time of the API.
Inputs:
None
Outputs:
info structure holding the revision info
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xGetApiVersion(zl5011xGetApiVersionS *par)
{
zlStatusE status = ZL5011X_OK;
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_MISC_FN_ID, "zl5011xGetApiVersion:", 0, 0, 0, 0, 0, 0);
par->revisionNumberMajor = zl5011xRevisionNumberMajor;
par->revisionNumberMinor = zl5011xRevisionNumberMinor;
par->revisionNumberMicro = zl5011xRevisionNumberMicro;
(void)strcpy((char *)par->releaseDate, (char *)zl5011xApiReleaseDate);
(void)strcpy((char *)par->releaseTime, (char *)zl5011xApiReleaseTime);
}
return status;
}
/*******************************************************************************
Function:
zl5011xContextCheckRx
Description:
Used to check that a Wan Rx context number is valid. Can also check that
the context is in a valid state for modification - i.e. taken or init
Inputs:
zl5011xParams Pointer to the structure for this device instance
check which check to perform on the context
Outputs:
None
Returns:
zlStatusE
Remarks:
None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -