示例#1
0
int main(void)
{
	//! [sample_resource]
	struct dma_resource example_resource;
	//! [sample_resource]

	system_init();

	//! [setup_init]
	//! [setup_dma_resource]
	configure_dma_resource(&example_resource);
	//! [setup_dma_resource]

	//! [setup_transfer_descriptor]
	setup_transfer_descriptor(&example_descriptor);
	//! [setup_transfer_descriptor]

	//! [add_descriptor_to_dma_resource]
	dma_add_descriptor(&example_resource, &example_descriptor);
	//! [add_descriptor_to_dma_resource]

	//! [setup_callback_register]
	dma_register_callback(&example_resource, transfer_done,
			DMA_CALLBACK_TRANSFER_DONE);
	//! [setup_callback_register]

	//! [setup_enable_callback]
	dma_enable_callback(&example_resource, DMA_CALLBACK_TRANSFER_DONE);
	//! [setup_enable_callback]

	//! [setup_source_memory_content]
	for (uint32_t i = 0; i < DATA_LENGTH; i++) {
		source_memory[i] = i;
	}
	//! [setup_source_memory_content]

	//! [setup_init]

	//! [main]
	//! [main_1]
	dma_start_transfer_job(&example_resource);
	//! [main_1]

	//! [main_1_1]
	dma_trigger_transfer(&example_resource);
	//! [main_1_1]

	//! [main_2]
	while (!transfer_is_done) {
		/* Wait for transfer done */
	}
	//! [main_2]

	while (true) {
		/* Nothing to do */
	}

	//! [main]
}
示例#2
0
文件: main.c 项目: thegeek82000/asf
/**
* \brief Config DMA to make peripheral-to-memory transfer scrolling string to
* SLCD memory.
*/
static void configure_dma(void)
{
    configure_dma_resource(&example_resource);
    setup_transfer_descriptor(&example_descriptor);

    if (STATUS_OK != dma_add_descriptor(&example_resource,
                                        &example_descriptor)) {
        printf("Descriptor status error\n\n\r");
    }

    dma_register_callback(&example_resource, dma_callback,
                          DMA_CALLBACK_TRANSFER_DONE);
    dma_enable_callback(&example_resource, DMA_CALLBACK_TRANSFER_DONE);
}
示例#3
0
/**
 * \brief configure and enable DMA multiple channel (in this case it is 3)
 */
void configure_dma(void)
{
	/* Configure DMA channel 0 */
	configure_dma_resource(&dmac_adc_channel0, DMAC_CHANNEL0_ID);

	/* Configure descriptor for channel 1 */
	setup_transfer_descriptor(&dmac_adc_descriptor1, DMAC_DESCRIPTOR1_ID);

	/* Assign descriptor 1 to DMA channel 0 */
	dma_add_descriptor(&dmac_adc_channel0, &dmac_adc_descriptor1);
	/*
	 * Register call back for DMA channel 0 transfer complete interrupt
	 * which will get triggered for every block transfer (I.e. 1024 beats 
	 * in this case 
	 */
	dma_register_callback(&dmac_adc_channel0, dmac_calback_channel0,
		DMA_CALLBACK_TRANSFER_DONE);
	/* Enable Call back for channel 0 */
	dma_enable_callback(&dmac_adc_channel0, DMA_CALLBACK_TRANSFER_DONE);
	/* Enable DMA channel 0 and its interrupt */
	dma_start_transfer_job(&dmac_adc_channel0);

}