/* Initiates a DMA, allocating the descriptors as required. */
int dma_transfer(DMA_Handle_t handle, dmacHw_TRANSFER_TYPE_e transferType, dma_addr_t srcData, dma_addr_t dstData, size_t numBytes)
/* Initiates a DMA, allocating the descriptors as required. */
int dma_transfer(DMA_Handle_t handle, dmacHw_TRANSFER_TYPE_e transferType, dma_addr_t srcData, dma_addr_t dstData, size_t numBytes)
{
	DMA_Channel_t *channel;
	DMA_DeviceAttribute_t *devAttr;
	int rc = 0;
	channel = HandleToChannel(handle);
	if (channel == NULL) {
		return -ENODEV;
	}
	devAttr = &DMA_gDeviceAttribute[channel->devType];
	if (devAttr->config.transferType != transferType) {
		return -EINVAL;
	}
	{
		rc =
		     dma_alloc_descriptors(handle, transferType, srcData,
					   dstData, numBytes);
		if (rc != 0) {
			return rc;
		}
	}
	devAttr->numBytes = numBytes;
	devAttr->transferStartTime = timer_get_tick_count();
	dmacHw_initiateTransfer(channel->dmacHwHandle, &devAttr->config,
				devAttr->ring.virtAddr);
	return 0;
}