📄 zl5011xptx.c
字号:
Inputs:
zl5011xParams Pointer to the structure for this device instance
entry entry in the ctrl header table to get the address of.
Outputs:
address returns the address for the header
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPtxGetTableAddress(zl5011xParamsS *zl5011xParams,
Uint32T entry, Uint32T *address)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PTX_FN_ID,
"zl5011xPtxGetTableAddress: entry %3d",
entry, 0, 0, 0, 0, 0);
*address = ZL5011X_PTX_CTRL_HEADER_BASE_ADDRESS +
(entry * ZL5011X_PTX_CTRL_HEADER_SIZE);
ZL5011X_TRACE(ZL5011X_PTX_FN_ID,
"zl5011xPtxGetTableAddress: entry %3d, addr %08X",
entry, *address, 0, 0, 0, 0);
return status;
}
/*******************************************************************************
Function:
zl5011xPtxGetHeaderAddress
Description:
Returns the base address of the header for the required context.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context context ID
Outputs:
address returns the address for the header
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xPtxGetHeaderAddress(zl5011xParamsS *zl5011xParams,
Uint32T context, Uint32T *address)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PTX_FN_ID,
"zl5011xPtxGetHeaderAddress: ctxt %3d",
context, 0, 0, 0, 0, 0);
*address = ZL5011X_PTX_HEADER_BASE_ADDRESS +
(context * ZL5011X_PTX_HEADER_SIZE);
ZL5011X_TRACE(ZL5011X_PTX_FN_ID,
"zl5011xPtxGetHeaderAddress: ctxt %3d, addr %08X",
context, *address, 0, 0, 0, 0);
return status;
}
/*******************************************************************************
Function:
zl5011xPtxSetHeader
Description:
Write the information in the header structure to the device.
Inputs:
zl5011xParams Pointer to the structure for this device instance
context context ID
header pointer to a structure that holds the header to be programmed.
This structure gives the positions of the length and checksum
fields in the header.
Outputs:
none
Returns:
zlStatusE
Remarks:
This function should only be called when a context is being initialised.
The PTX header cannot be modified during operation.
*******************************************************************************/
zlStatusE zl5011xPtxSetHeader(zl5011xParamsS *zl5011xParams,
Uint32T context, zl5011xPacketTxLowHeaderS *header)
{
Uint32T address;
Uint32T loop, loopAddress, data = 0;
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PTX_FN_ID,
"zl5011xPtxSetHeader: context %3d",
context, 0, 0, 0, 0, 0);
status = zl5011xPtxGetHeaderAddress(zl5011xParams, context,
&address);
if (status == ZL5011X_OK)
{
if (header->txLowLength > ZL5011X_PTX_HEADER_SIZE)
{
status = ZL5011X_PKT_HEADER_SIZE_ERROR;
}
}
/* write the header to the device */
loop = 0;
loopAddress = address;
while ((loop < header->txLowLength) && (status == ZL5011X_OK))
{
if (status != ZL5011X_OK)
break;
data = header->txLowData[loop++];
if (loop < header->txLowLength)
{
data |= header->txLowData[loop++] << 8;
}
if (loop < header->txLowLength)
{
data |= header->txLowData[loop++] << 16;
}
if (loop < header->txLowLength)
{
data |= header->txLowData[loop++] << 24;
}
status = zl5011xWrite(zl5011xParams,
loopAddress, data);
loopAddress += sizeof(Uint32T);
}
/* get the base address for the control header */
if (status == ZL5011X_OK)
{
status = zl5011xPtxGetTableAddress(zl5011xParams, context,
&address);
}
/* set up the first of the two 32 bit fields in the header */
/* set the bit to enable header insertion */
if (status == ZL5011X_OK)
{
data = ZL5011X_1BIT_MASK << ZL5011X_PTX_ENABLE_HEADER_BIT;
/* control whether the MAC should insert the ethernet source address
or should it come from the header */
if (header->ethernetSrcAddressFromMac == ZL5011X_TRUE)
{
data |= ZL5011X_1BIT_MASK << ZL5011X_PTX_SRC_ADDR_FROM_MAC_BIT;
}
}
/* overrall header length field */
if (status == ZL5011X_OK)
{
data |= header->txLowLength << ZL5011X_PTX_HEADER_LENGTH_BITS;
}
/* layer 2 header enable */
if (status == ZL5011X_OK)
{
if (header->layer2LengthEnable == ZL5011X_TRUE)
{
data |= ZL5011X_1BIT_MASK << ZL5011X_PTX_L2_LENGTH_ENABLE_BIT;
/* since enabling the length, must set up the value and position
fields. Do the position field first. */
if (header->layer2LengthPos >= (header->txLowLength - 1))
{
/* the length field is 16 bits, so must not be further than the last
byte in the header */
status = ZL5011X_PARAMETER_INVALID;
}
else
{
data |= header->layer2LengthPos << ZL5011X_PTX_L2_LENGTH_POS_BITS;
}
if (status == ZL5011X_OK)
{
/* set up the initial value for the length - that is with
a 0 byte payload */
if ((header->layer2LengthValue & ~ZL5011X_PTX_L2_LENGTH_VALUE_MASK) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
else
{
data |= header->layer2LengthValue << ZL5011X_PTX_L2_LENGTH_VALUE_BITS;
}
}
}
}
/* set up the header checksum (IPv4) */
if (status == ZL5011X_OK)
{
if (header->layer3ChecksumEnable == ZL5011X_TRUE)
{
data |= ZL5011X_1BIT_MASK << ZL5011X_PTX_L3_CHECKSUM_ENABLE_BIT;
/* since enabling the checksum, must set up the position */
if (header->layer3ChecksumPos >= (header->txLowLength - 1))
{
status = ZL5011X_PARAMETER_INVALID;
}
else
{
data |= header->layer3ChecksumPos << ZL5011X_PTX_L3_CHECKSUM_POS_BITS;
}
}
}
/* write the first of the two 32 bit fields to the header */
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, address, data);
}
/* set up the second of the two 32 bit fields in the header */
/* layer 3 header enable */
data = 0;
if (status == ZL5011X_OK)
{
if (header->layer3LengthEnable == ZL5011X_TRUE)
{
data |= ZL5011X_1BIT_MASK << ZL5011X_PTX_L3_LENGTH_ENABLE_BIT;
/* since enabling the length, must set up the value and position
fields. Do the position field first. */
if (header->layer3LengthPos >= (header->txLowLength - 1))
{
status = ZL5011X_PARAMETER_INVALID;
}
else
{
data |= header->layer3LengthPos << ZL5011X_PTX_L3_LENGTH_POS_BITS;
}
if (status == ZL5011X_OK)
{
/* set up the initial value for the length - that is with
a 0 byte payload */
if ((header->layer3LengthValue & ~ZL5011X_PTX_L3_LENGTH_VALUE_MASK) != 0)
{
status = ZL5011X_PARAMETER_INVALID;
}
else
{
data |= header->layer3LengthValue << ZL5011X_PTX_L3_LENGTH_VALUE_BITS;
}
}
}
}
/* write the second of the two 32 bit fields to the header */
if (status == ZL5011X_OK)
{
status = zl5011xWrite(zl5011xParams, address + sizeof(Uint32T), data);
}
if (status == ZL5011X_OK)
{
/* since succesfully setup the header, copy the contents across to
the device structure */
memcpy(&(zl5011xParams->packetIf.packetTx.txHeader[context].lowHeader),
header, sizeof(zl5011xPacketTxLowHeaderS));
}
return(status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -