/* Add a DMA transfer descriptor to a DMA resource. 
This function will add a DMA transfer descriptor to a DMA resource. If there was a transfer descriptor already allocated to the DMA resource, the descriptor will be linked to the next descriptor address. */
enum status_code dma_add_descriptor(struct dma_resource *resource, DmacDescriptor *descriptor)
/* Add a DMA transfer descriptor to a DMA resource. 
This function will add a DMA transfer descriptor to a DMA resource. If there was a transfer descriptor already allocated to the DMA resource, the descriptor will be linked to the next descriptor address. */
enum status_code dma_add_descriptor(struct dma_resource *resource, DmacDescriptor *descriptor)
{
	DmacDescriptor* desc = resource->descriptor;
	if (resource->job_status == STATUS_BUSY) {
		return STATUS_BUSY;
	}
	if (desc == NULL) {
		resource->descriptor = descriptor;
	} else {
		while(desc->DESCADDR.reg != 0) {
			desc = (DmacDescriptor*)(desc->DESCADDR.reg);
		}
		desc->DESCADDR.reg = (uint32_t)descriptor;
	}
	return STATUS_OK;
}