tests: dma: update dma loop transfer app
Update the dma loop transfer sample app to use the new dma api interfaces. This change is based on the api change and the updated dma driver. A RFC was posted recently on this. Jira: ZEP-873 Change-Id: I289e2e08d4c775a833bf3d585d2706a903edd0bc Signed-off-by: Baohong Liu <baohong.liu@intel.com>
This commit is contained in:
parent
110df98619
commit
59b8af5395
1 changed files with 34 additions and 32 deletions
|
@ -25,40 +25,47 @@ static char rx_data[TRANSFER_LOOPS][RX_BUFF_SIZE] = {{ 0 } };
|
|||
#define DMA_DEVICE_NAME "DMA_0"
|
||||
|
||||
volatile uint8_t transfer_count;
|
||||
static struct dma_config dma_cfg = {0};
|
||||
static struct dma_block_config dma_block_cfg = {0};
|
||||
|
||||
static void test_transfer(struct device *dev, void *data)
|
||||
static void test_transfer(struct device *dev, uint32_t id)
|
||||
{
|
||||
int ret;
|
||||
struct dma_transfer_config dma_trans = {0};
|
||||
uint32_t *chan_id = data;
|
||||
|
||||
transfer_count++;
|
||||
if (transfer_count < TRANSFER_LOOPS) {
|
||||
dma_trans.block_size = strlen(tx_data);
|
||||
dma_trans.source_address = (uint32_t *)tx_data;
|
||||
dma_trans.destination_address =
|
||||
(uint32_t *)rx_data[transfer_count];
|
||||
dma_block_cfg.block_size = strlen(tx_data);
|
||||
dma_block_cfg.source_address = (uint32_t)tx_data;
|
||||
dma_block_cfg.dest_address = (uint32_t)rx_data[transfer_count];
|
||||
|
||||
ret = dma_transfer_config(dev, *chan_id, &dma_trans);
|
||||
ret = dma_config(dev, id, &dma_cfg);
|
||||
if (ret == 0) {
|
||||
dma_transfer_start(dev, *chan_id);
|
||||
dma_start(dev, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_error(struct device *dev, void *data)
|
||||
static void test_error(void)
|
||||
{
|
||||
printk("DMA could not proceed, an error occurred\n");
|
||||
}
|
||||
|
||||
static void dma_user_callback(struct device *dev, uint32_t id, int error_code)
|
||||
{
|
||||
if (error_code == 0) {
|
||||
test_transfer(dev, id);
|
||||
} else {
|
||||
test_error();
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
struct device *dma;
|
||||
static uint32_t chan_id;
|
||||
struct dma_channel_config dma_chan_cfg = {0};
|
||||
struct dma_transfer_config dma_trans = {0};
|
||||
|
||||
printk("DMA memory to memory transfer started on %s\n", DMA_DEVICE_NAME);
|
||||
printk("DMA memory to memory transfer started on %s\n",
|
||||
DMA_DEVICE_NAME);
|
||||
printk("Preparing DMA Controller\n");
|
||||
|
||||
dma = device_get_binding(DMA_DEVICE_NAME);
|
||||
|
@ -67,33 +74,28 @@ void main(void)
|
|||
return;
|
||||
}
|
||||
|
||||
dma_chan_cfg.channel_direction = MEMORY_TO_MEMORY;
|
||||
dma_chan_cfg.source_transfer_width = TRANS_WIDTH_8;
|
||||
dma_chan_cfg.destination_transfer_width = TRANS_WIDTH_8;
|
||||
dma_chan_cfg.source_burst_length = BURST_TRANS_LENGTH_1;
|
||||
dma_chan_cfg.destination_burst_length = BURST_TRANS_LENGTH_1;
|
||||
dma_chan_cfg.dma_transfer = test_transfer;
|
||||
dma_chan_cfg.dma_error = test_error;
|
||||
dma_cfg.channel_direction = MEMORY_TO_MEMORY;
|
||||
dma_cfg.source_data_size = 1;
|
||||
dma_cfg.dest_data_size = 1;
|
||||
dma_cfg.source_burst_length = 1;
|
||||
dma_cfg.dest_burst_length = 1;
|
||||
dma_cfg.dma_callback = dma_user_callback;
|
||||
dma_cfg.block_count = 1;
|
||||
dma_cfg.head_block = &dma_block_cfg;
|
||||
|
||||
chan_id = 0;
|
||||
dma_chan_cfg.callback_data = (void *)&chan_id;
|
||||
|
||||
if (dma_channel_config(dma, chan_id, &dma_chan_cfg)) {
|
||||
printk("Error: configuration\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Starting the transfer and waiting for 1 second\n");
|
||||
dma_trans.block_size = strlen(tx_data);
|
||||
dma_trans.source_address = (uint32_t *)tx_data;
|
||||
dma_trans.destination_address = (uint32_t *)rx_data[transfer_count];
|
||||
dma_block_cfg.block_size = strlen(tx_data);
|
||||
dma_block_cfg.source_address = (uint32_t)tx_data;
|
||||
dma_block_cfg.dest_address = (uint32_t)rx_data[transfer_count];
|
||||
|
||||
if (dma_transfer_config(dma, chan_id, &dma_trans)) {
|
||||
if (dma_config(dma, chan_id, &dma_cfg)) {
|
||||
printk("ERROR: transfer config\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (dma_transfer_start(dma, chan_id)) {
|
||||
if (dma_start(dma, chan_id)) {
|
||||
printk("ERROR: transfer start\n");
|
||||
return;
|
||||
}
|
||||
|
@ -103,7 +105,7 @@ void main(void)
|
|||
if (transfer_count < TRANSFER_LOOPS) {
|
||||
transfer_count = TRANSFER_LOOPS;
|
||||
printk("ERROR: unfinished transfer\n");
|
||||
if (dma_transfer_stop(dma, chan_id)) {
|
||||
if (dma_stop(dma, chan_id)) {
|
||||
printk("ERROR: transfer stop\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue