Configure the DMA for Capture TCC Channel 1
Configure the DMAC module to obtain captured value from TCC channel 1.
- Create a DMA resource instance.
struct
dma_resource capture_dma_resource;
Note: This should never go out of scope as long as the resource is in use. In most cases, this should be global. - Create a DMA resource configuration struct.
struct
dma_resource_config config;
- Initialize the DMA resource configuration struct with default values.
dma_get_config_defaults(&config);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Adjust the DMA resource configurations.
config.trigger_action = DMA_TRIGGER_ACTON_BEAT;
config.peripheral_trigger = CONF_CAPTURE_TRIGGER;
- Allocate a DMA resource with the configurations.
dma_allocate(&capture_dma_resource, &config);
- Prepare DMA transfer descriptor.
- Create a DMA transfer descriptor.
COMPILER_ALIGNED(16) DmacDescriptor capture_dma_descriptor;
Note: When multiple descriptors are linked, the linked item should never go out of scope before it is loaded (to DMA Write-Back memory section). In most cases, if more than one descriptors are used, they should be global except the very first one. Create a DMA transfer descriptor struct.
- Create a DMA transfer descriptor configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
struct
dma_descriptor_config descriptor_config;
- Initialize the DMA transfer descriptor configuration struct with default values.
dma_descriptor_get_config_defaults(&descriptor_config);
Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings. - Adjust the DMA transfer descriptor configurations.
descriptor_config.block_transfer_count = 3;
descriptor_config.beat_size = DMA_BEAT_SIZE_HWORD;
descriptor_config.step_selection = DMA_STEPSEL_SRC;
descriptor_config.src_increment_enable =
false
;
descriptor_config.source_address =
(uint32_t)&CONF_PWM_MODULE->CC[CONF_TCC_CAPTURE_CHANNEL];
descriptor_config.destination_address =
(uint32_t)capture_values +
sizeof
(capture_values);
- Create the DMA transfer descriptor with the given configuration.
dma_descriptor_create(&capture_dma_descriptor, &descriptor_config);
- Start DMA transfer job with prepared descriptor.
- Add the DMA transfer descriptor to the allocated DMA resource.
dma_add_descriptor(&capture_dma_resource, &capture_dma_descriptor);
dma_add_descriptor(&capture_dma_resource, &capture_dma_descriptor);
Note: When adding multiple descriptors, the last added one is linked at the end of descriptor queue. If ringed list is needed, just add the first descriptor again to build the circle. - Start the DMA transfer job with the allocated DMA resource and transfer descriptor.
dma_start_transfer_job(&capture_dma_resource);