?? zl5011xdma.c
字號:
/* enable the DMA interrupt */
status = zl5011xIsrEnableInterruptSourceStructInit(zl5011xParams, &isrSource);
isrSource.interruptSource = ZL5011X_HOST_DMA_RX_INTERRUPT;
if (status == ZL5011X_OK)
{
status = zl5011xIsrEnableInterruptSource(zl5011xParams, &isrSource);
}
}
return status;
}
/*******************************************************************************
Function:
zl5011xHostTxInitialiseStructInit
Description:
Set up default parameters for the HostTxInitialise function
Inputs:
zl5011xParams Pointer to the structure for this device instance.
(Unused in this function)
par Pointer to the structure for configuration items.
Outputs:
None
Returns:
zlStatusE
Remarks:
*******************************************************************************/
zlStatusE zl5011xHostTxInitialiseStructInit(zl5011xParamsS *zl5011xParams, zl5011xHostTxInitialiseS *par)
{
zlStatusE status = ZL5011X_OK;
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_DMA_FN_ID,
"zl5011xHostTxInitialiseStructInit:", 0, 0, 0, 0, 0, 0);
par->dmaChannel = 0; /* ZARLINK evaluation board uses DMA channel 0 for
packet transmission from CPU, and 1 for reception */
par->numberOfBuffers = 128;/* Default number of buffers to use */
par->bufferSize = ZL5011X_MAXIMUM_PACKET_SIZE;
par->ethernetSrcAddressFromMac = ZL5011X_TRUE; /* Overwrite the packet source MAC address by default */
}
return status;
}
/*******************************************************************************
Function:
zl5011xHostTxInitialise
Description:
Configures a DMA channel for transmission and initialises the device to
provide the required handshaking
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items. See below:
Structure inputs:
dmaChannel DMA channel to configure
numberOfBuffers Size of buffer chain
bufferSize Size of data buffer to create for each descriptor
Structure outputs:
None
Returns:
zlStatusE
Remarks:
*******************************************************************************/
zlStatusE zl5011xHostTxInitialise(zl5011xParamsS *zl5011xParams, zl5011xHostTxInitialiseS *par)
{
zlStatusE status = ZL5011X_OK;
Uint32T loop;
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_DMA_FN_ID,"zl5011xHostTxInitialise:", 0, 0, 0, 0, 0, 0);
}
/* Check DMA channel is in range for the micro */
ZL5011X_CHECK_PARAMETER_RANGE(par->dmaChannel,0,
zl5011xDmaProps.maxNumberOfChannels,ZL5011X_PARAMETER_INVALID)
/* Now check the number of descriptors is in range for micro */
if (status == ZL5011X_OK)
{
if (par->numberOfBuffers > zl5011xDmaProps.maxDescriptorChainSize)
{
status = ZL5011X_PARAMETER_INVALID;
}
}
/* Check the value of the ethernetSrcAddressFromMac flag */
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_BOOLEAN(par->ethernetSrcAddressFromMac);
}
/* Check DMA Tx not already initialised */
if ((status == ZL5011X_OK) && (txQParams != NULL))
{
status = ZL5011X_DMA_QUEUE_ALREADY_INIT;
}
/* Set the ethernet src address overwrite state for all host headers */
for (loop = 0; (loop < ZL5011X_PKT_TX_NUM_HOST_HEADERS) && (status == ZL5011X_OK); loop++)
{
status = zl5011xPtxEnableSrcMacOverwrite(zl5011xParams,
ZL5011X_PKT_TX_NUM_CONTEXT_HEADERS + loop, par->ethernetSrcAddressFromMac);
}
/* Now initialise DMA channel and build chain of descriptors */
if (status == ZL5011X_OK)
{
/* Allocate memory for tx structure. Function also sets polarity of DREQ
and DACK signals */
status = zl5011xDmaAllocateStructure(zl5011xParams,ZL5011X_DMA_TRANSMIT);
if (status == ZL5011X_OK)
{
txQParams->dmaChannel.numberOfBuffers = par->numberOfBuffers;
txQParams->dmaChannel.channelNumber = par->dmaChannel;
/* Specify the buffer size as a whole number of words (including the
PTH), and as a whole number of buffers transfer sizes */
txQParams->dmaChannel.bufferSize = (((par->bufferSize
+ZL5011X_PTH_BYTESIZE -1)/ zl5011xDmaProps.transferBufferSize)+1)
*ZL5011X_WORDS_PER_TRANSFER;
txQParams->dmaChannel.devParams = zl5011xParams;
txQParams->dmaChannel.dmaDirection = ZL5011X_DMA_TRANSMIT;
/* Initialise the DMA channel */
status = zl5011xDmaInitialise(&txQParams->dmaChannel);
}
}
if (status == ZL5011X_OK)
{
/* Put the DMA into a known state */
status = zl5011xDmaIssueCommand(&txQParams->dmaChannel,
ZL5011X_DMA_STOP_COMMAND);
}
if (status == ZL5011X_OK)
{
/* Initialise device DMA Tx handshaking */
status = zl5011xCpuDmaSetTxControl(zl5011xParams,ZL5011X_DMA_ENABLED);
}
if (status == ZL5011X_OK)
{
txQParams->packetsSent = 0;
txQParams->packetsSentFail = 0;
txQParams->cpucpuPackets = 0;
/* Create the semaphore used for controlling access to txQParams
structure and also to the tx dma channel */
txQParams->mutex = OS_MUTEX_CREATE(OS_SEM_FULL);
if (txQParams->mutex == OS_SEM_INVALID)
{
status = ZL5011X_RTOS_SEMA4_CREATE_FAIL;
}
}
/* Send a dummy packet into the DMA and check that it is transferred
correctly */
if (status == ZL5011X_OK)
{
status = zl5011xHostTxSendDMAStartPacket(zl5011xParams);
}
if (status == ZL5011X_OK)
{
zl5011xParams->osExclusion.dmaTxEnabled = ZL5011X_TRUE;
}
return status;
}
/*******************************************************************************
Function:
zl5011xHostTxDisableStructInit
Description:
This function will set default parameters for zl5011xHostTxDisable
Inputs:
zl5011xParams Pointer to the structure for this device instance.
(Unused in this function)
par Pointer to the structure for configuration item.
(Unused in this function)
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xHostTxDisableStructInit(zl5011xParamsS *zl5011xParams, zl5011xHostTxDisableS *par)
{
zlStatusE status = ZL5011X_OK;
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_DMA_FN_ID,"zl5011xHostTxDisableStructInit:",0,0,0,0,0,0);
}
return(status);
}
/*******************************************************************************
Function:
zl5011xHostTxDisable
Description:
This function will stop the transmit DMA channel (if active), and disable
the device from receiving any more packets
Inputs:
zl5011xParams Pointer to the structure for this device instance.
(Unused in this function)
par Pointer to the structure for configuration items. See below:
Structure inputs:
unused Reserved for future use
Structure outputs:
None
None
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xHostTxDisable(zl5011xParamsS *zl5011xParams, zl5011xHostTxDisableS *par)
{
zlStatusE status = ZL5011X_OK;
zl5011xDmaControlModeE txMode;
Uint32T timeout;
zl5011xBooleanE unused;
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_DMA_FN_ID,"zl5011xHostTxDisable:", 0, 0, 0, 0, 0, 0);
ZL5011X_CHECK_FOR_INVALID_VALUE(txQParams,NULL,ZL5011X_DMA_QUEUE_NOT_INIT)
}
/* Take the semaphore before deleting memory to prevent other tasks from
accessing a structure that is about to be deleted! */
ZL5011X_MUTEX_TAKE(txQParams->mutex)
if (status == ZL5011X_OK)
{
status = zl5011xCpuDmaSetTxControl(txQParams->dmaChannel.devParams,
ZL5011X_DMA_DISABLED);
}
/* Wait for device to complete last packet */
for (timeout=0;timeout<zl5011xDmaProps.deviceStopTimeout;timeout++)
{
status = zl5011xCpuDmaGetTxStatus(txQParams->dmaChannel.devParams,
&txMode, &unused);
if ((status != ZL5011X_OK) || (txMode == ZL5011X_DMA_DISABLED))
{
break;
}
OS_TICK_DELAY(1); /* Wait 1 RTOS tick before checking again */
}
if (status == ZL5011X_OK)
{
if (timeout == zl5011xDmaProps.deviceStopTimeout)
{
status = ZL5011X_DMA_QUEUE_FAIL;
}
else
{
/* Stop the DMA if still active (shouldn't be necessary) */
(void)zl5011xDmaIssueCommand(&txQParams->dmaChannel,
ZL5011X_DMA_STOP_COMMAND);
}
}
/* Free memory acquired */
if (status == ZL5011X_OK)
{
zl5011xDmaDisable(&txQParams->dmaChannel);
/* Delete the access semaphore */
if (OS_MUTEX_DELETE(txQParams->mutex) != OS_OK)
{
status = ZL5011X_RTOS_SEMA4_DELETE_FAIL;
}
txQParams->mutex = OS_SEM_INVALID;
OS_FREE(txQParams);
txQParams = NULL;
}
if (status == ZL5011X_OK)
{
zl5011xParams->osExclusion.dmaTxEnabled = ZL5011X_FALSE;
}
return status;
}
/*******************************************************************************
Function:
zl5011xHostTxSendPacketStructInit
Description:
Initialise the structure used in function HostTxSendPacket
Inputs:
zl5011xParams Pointer to the structure for this device instance.
(Unused in this function)
par Pointer to the structure for configuration items.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
*******************************************************************************/
zlStatusE zl5011xHostTxSendPacketStructInit(zl5011xParamsS *zl5011xParams, zl5011xHostTxSendPacketS *par)
{
zlStatusE status = ZL5011X_OK;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -