?? zl5011xinit.c
字號:
par Pointer to the structure for configuration items. See below:
Structure inputs:
enable ZL5011X_TRUE to enable loopback
Outputs:
None
Returns:
zlStatusE
Remarks:
*******************************************************************************/
zlStatusE zl5011xLanLoopbackConfig(zl5011xParamsS *zl5011xParams,
zl5011xLanLoopbackConfigS *par)
{
zlStatusE status = ZL5011X_OK;
Uint32T matchNum;
zl5011xBooleanE gotDevice = ZL5011X_FALSE;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
{
/* get access to the device */
status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);
if (status == ZL5011X_OK)
{
gotDevice = ZL5011X_TRUE;
}
}
/* main function code starts */
if(status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_INIT_FN_ID,
"zl5011xLanLoopbackConfig: enable %d",
par->enable, 0, 0, 0, 0, 0);
if (zl5011xParams->packetIf.unmatchedProtocolLoopback != ZL5011X_TRUE)
{
status = ZL5011X_PARAMETER_INVALID;
}
}
if (status == ZL5011X_OK)
{
/* enable the classification entry for the last protocol match */
matchNum = ZL5011X_PKC_NUM_CLASSIFY_ENTRIES - 1;
if (par->enable == ZL5011X_TRUE)
{
status = zl5011xPkcClassifyEnableEntry(zl5011xParams, matchNum);
}
else
{
status = zl5011xPkcClassifyDisableEntry(zl5011xParams, matchNum);
}
}
if (gotDevice == ZL5011X_TRUE)
{
if (status == ZL5011X_OK)
{
status = zl5011xReleaseDevice(zl5011xParams);
}
else
{
/* already have an error code, so don't overwrite it */
(void)zl5011xReleaseDevice(zl5011xParams);
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xCheckAPICompatibility
Description:
Verifies that the requested device is supported by this release of the API
Inputs:
zl5011xParams Pointer to the structure for this device instance
Structure inputs:
deviceType The device type requested
Outputs:
None
Returns:
zlStatusE
Remarks:
*******************************************************************************/
static zlStatusE zl5011xCheckAPICompatibility(zlDeviceTypeE deviceType)
{
zlStatusE status = ZL5011X_OK;
switch (deviceType)
{
case ZL_DEVICE_ZL50110:
case ZL_DEVICE_ZL50111:
case ZL_DEVICE_ZL50114:
case ZL_DEVICE_ZL50115:
case ZL_DEVICE_ZL50116:
case ZL_DEVICE_ZL50117:
case ZL_DEVICE_ZL50118:
case ZL_DEVICE_ZL50119:
case ZL_DEVICE_ZL50120:
case ZL_DEVICE_ZL80041:
case ZL_DEVICE_ZL30300:
case ZL_DEVICE_ZL30301:
case ZL_DEVICE_ZL30302:
/* Device is fully supported by this API */
break;
case ZL_DEVICE_ZL50130:
/* Device not supported by this API */
status = ZL5011X_API_AND_DEVICE_MISMATCH;
break;
default:
/* Device unknown */
status = ZL5011X_UNKNOWN_DEVICE_ID;
break;
}
return status;
}
/*******************************************************************************
Function:
zl5011xMemoryCalcAddrGranulesMax
Description:
Verifies that the requested device is supported by this release of the API
Inputs:
zl5011xParams Pointer to the structure for this device instance
Structure inputs:
deviceType The device type requested
Outputs:
None
Returns:
zlStatusE
Remarks:
*******************************************************************************/
static zlStatusE zl5011xMemoryCalcAddrGranulesMax(zl5011xParamsS *zl5011xParams, zl5011xConfigureMemoryS *par,
Uint32T *descBase, Uint32T *dataBase, Uint32T *heapStartAddress, Uint32T *heapEndAddress, Uint32T *numGranules)
{
Uint32T freeIntMemory;
Uint32T freeExtMemory;
Uint32T temp, temp1, temp2;
zl5011xBooleanE descInternal = ZL5011X_TRUE;
zlStatusE status = ZL5011X_OK;
*dataBase = 0;
/* work out the best configuration for the memory */
if (status == ZL5011X_OK)
{
freeIntMemory = ZL5011X_INT_MEMORY_SIZE_IN_BYTES;
freeExtMemory = zl5011xParams->packetMemory.extMemSizeBytes;
temp = par->maxWanQueueSizeInkBytes * 1024;
/* reserve internal memory space for the Wan queues */
if (temp <= freeIntMemory)
{
freeIntMemory -= temp;
*heapStartAddress = ZL5011X_INT_MEM_BASE + ZL5011X_INT_MEMORY_SIZE_IN_BYTES - temp;
*heapEndAddress = ZL5011X_INT_MEM_BASE + ZL5011X_INT_MEMORY_SIZE_IN_BYTES - 1;
}
else
{
status = ZL5011X_PARAMETER_INVALID;
}
}
if (status == ZL5011X_OK)
{
/* calculate whether more granules could be used by putting the descriptors into
external memory */
temp1 = freeIntMemory / ZL5011X_GRANULE_DESCRIPTOR_SIZE;
temp2 = freeExtMemory / (ZL5011X_GRANULE_DATA_SIZE + ZL5011X_GRANULE_DESCRIPTOR_SIZE);
if (temp1 < temp2)
{
/* put the descriptors in external memory */
descInternal = ZL5011X_FALSE;
}
}
if (status == ZL5011X_OK)
{
if (((freeExtMemory > 0) && (descInternal == ZL5011X_FALSE)) || (freeExtMemory == 0))
{
/* descriptors and granules are in the same memory area */
Uint32T memSize;
if (freeExtMemory > 0)
{
memSize = freeExtMemory;
/* set the base address for the granules and descriptors */
*dataBase = 0;
*descBase = 0;
}
else
{
memSize = freeIntMemory;
/* set the base address for the granules and descriptors */
*dataBase = ZL5011X_INT_MEM_BASE;
*descBase = ZL5011X_INT_MEM_BASE;
}
temp = memSize / (ZL5011X_GRANULE_DATA_SIZE + ZL5011X_GRANULE_DESCRIPTOR_SIZE);
*numGranules = temp;
/* round down the number of granules to match the alignment boundary */
temp1 = *numGranules * ZL5011X_GRANULE_DATA_SIZE;
temp1 &= ~ZL5011X_MEMORY_GRANULARITY_MASK;
/* add in the offset for the descriptors, which are placed after the granules */
*descBase += temp1;
/* recalculate the number of granules based on the rounded down memory size */
*numGranules = temp1 / ZL5011X_GRANULE_DATA_SIZE;
if (descInternal == ZL5011X_TRUE)
{
/* recalculate the heap start address - this allows for any wasted space
to potentially be put to use */
*heapStartAddress = *descBase + (*numGranules * ZL5011X_GRANULE_DESCRIPTOR_SIZE);
}
}
else
{
/* descriptors and granules are in different memory areas */
*dataBase = 0;
*descBase = ZL5011X_INT_MEM_BASE;
/* calculate how many granules and descriptors can be supported in the available memory */
temp1 = freeIntMemory / ZL5011X_GRANULE_DESCRIPTOR_SIZE;
temp2 = freeExtMemory / ZL5011X_GRANULE_DATA_SIZE;
/* set the number of granules to the least of these calculations */
if (temp1 > temp2)
{
*numGranules = temp2;
}
else
{
*numGranules = temp1;
}
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xMemoryCalcAddrGranules
Description:
Verifies that the requested device is supported by this release of the API
Inputs:
zl5011xParams Pointer to the structure for this device instance
Structure inputs:
deviceType The device type requested
Outputs:
None
Returns:
zlStatusE
Remarks:
*******************************************************************************/
static zlStatusE zl5011xMemoryCalcAddrGranules(zl5011xParamsS *zl5011xParams, zl5011xConfigureMemoryS *par,
Uint32T *descBase, Uint32T *dataBase, Uint32T *heapStartAddress, Uint32T *heapEndAddress)
{
Uint32T freeIntMemory;
Uint32T freeExtMemory;
Uint32T temp;
zl5011xBooleanE descInternal = ZL5011X_TRUE;
zlStatusE status = ZL5011X_OK;
/* work out the best configuration for the memory */
if (status == ZL5011X_OK)
{
freeIntMemory = ZL5011X_INT_MEMORY_SIZE_IN_BYTES;
freeExtMemory = zl5011xParams->packetMemory.extMemSizeBytes;
/* check whether the granule descriptors can fit in the internal memory */
if ((par->numberGranules * ZL5011X_GRANULE_DESCRIPTOR_SIZE) <= freeIntMemory)
{
descInternal = ZL5011X_TRUE;
freeIntMemory -= par->numberGranules * ZL5011X_GRANULE_DESCRIPTOR_SIZE;
*descBase = ZL5011X_INT_MEM_BASE;
}
else
{
if ((par->numberGranules * ZL5011X_GRANULE_DESCRIPTOR_SIZE) <= freeExtMemory)
{
descInternal = ZL5011X_FALSE;
freeExtMemory -= par->numberGranules * ZL5011X_GRANULE_DESCRIPTOR_SIZE;
descBase = ZL5011X_EXT_MEM_BASE;
}
else
{
status = ZL5011X_PARAMETER_INVALID;
}
}
}
if (status == ZL5011X_OK)
{
temp = par->maxWanQueueSizeInkBytes * 1024;
/* check whether the Wan queues can fit in the internal memory */
if (temp <= freeIntMemory)
{
freeIntMemory -= temp;
*heapStartAddress = ZL5011X_INT_MEM_BASE + ZL5011X_INT_MEMORY_SIZE_IN_BYTES - temp;
*heapEndAddress = ZL5011X_INT_MEM_BASE + ZL5011X_INT_MEMORY_SIZE_IN_BYTES - 1;
}
else
{
if (temp <= freeExtMemory)
{
freeExtMemory -= temp;
*heapStartAddress = ZL5011X_EXT_MEM_BASE + zl5011xParams->packetMemory.extMemSizeBytes - temp;
*heapEndAddress = ZL5011X_EXT_MEM_BASE + zl5011xParams->packetMemory.extMemSizeBytes - 1;
}
else
{
status = ZL5011X_PARAMETER_INVALID;
}
}
}
if (status == ZL5011X_OK)
{
temp = par->numberGranules * ZL5011X_GRANULE_DATA_SIZE;
if ((temp & ZL5011X_MEMORY_GRANULARITY_MASK) != 0)
{
temp = (temp & ~ZL5011X_MEMORY_GRANULARITY_MASK) +
ZL5011X_MEMORY_GRANULARITY_MASK + 1;
}
/* check whether the granules can fit in the internal memory */
if (temp <= freeIntMemory)
{
freeIntMemory -= par->numberGranules * ZL5011X_GRANULE_DATA_SIZE;
*dataBase = ZL5011X_INT_MEM_BASE;
*descBase += temp;
}
else
{
if (((descInternal == ZL5011X_TRUE) && ((par->numberGranules * ZL5011X_GRANULE_DATA_SIZE) <= freeExtMemory)) ||
((descInternal == ZL5011X_FALSE) && (temp <= freeExtMemory)))
{
*dataBase = ZL5011X_EXT_MEM_BASE;
freeExtMemory -= par->numberGranules * ZL5011X_GRANULE_DATA_SIZE;
if (descInternal == ZL5011X_FALSE)
{
*descBase += temp;
}
}
else
{
status = ZL5011X_PARAMETER_INVALID;
}
}
}
return status;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -