From c65e64cb859ec840d1c53eca471ff43e51b8bf65 Mon Sep 17 00:00:00 2001
From: ROBBE Patrick <robbe@lal.in2p3.fr>
Date: Tue, 27 Aug 2019 04:21:29 +0200
Subject: [PATCH] Add DMA test softwrae

---
 .gitignore                           |  1 +
 Pcie40Applications/Makefile          |  7 +++++
 Pcie40Applications/main_pcie40_dma.c | 44 ++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)
 create mode 100644 Pcie40Applications/main_pcie40_dma.c

diff --git a/.gitignore b/.gitignore
index a73c303..4ad60e4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,5 +27,6 @@ modules.order
 Pcie40Applications/pcie40_ecs
 Pcie40Applications/pcie40_reload
 Pcie40Applications/pcie40_b2slc
+Pcie40Applications/pcie40_dma
 *.d
 **/pcie40_reload.out
diff --git a/Pcie40Applications/Makefile b/Pcie40Applications/Makefile
index bd1ae46..7847c78 100644
--- a/Pcie40Applications/Makefile
+++ b/Pcie40Applications/Makefile
@@ -27,6 +27,12 @@ PCIE40_SLC_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Libraries
 PCIE40_SLC_INSTALL =$(PREFIX)/bin
 PCIE40_SLC_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
 
+PCIE40_DMA :=pcie40_dma
+PCIE40_DMA_OBJS =main_pcie40_dma.o
+PCIE40_DMA_CFLAGS =$(CFLAGS) -I$(TOP) -I$(TOP)/../Pcie40Driver
+PCIE40_DMA_INSTALL =$(PREFIX)/bin
+PCIE40_DMA_LDFLAGS = -L../Pcie40Libraries/lib -lpcie40 -L../Pcie40DriverLibraries/ -lpcie40driver_ecs
+
 VPATH :=$(TOP)
 
 include $(TOP)/rules.mk
@@ -34,6 +40,7 @@ include $(TOP)/rules.mk
 ifeq ($(ENABLE_PCIE40), true)
 $(eval $(call ODIR_template,PCIE40_ECS))
 $(eval $(call ODIR_template,PCIE40_SLC))
+$(eval $(call ODIR_template,PCIE40_DMA))
 $(eval $(call COPY_template,SCRIPTS,755))
 $(eval $(call LINK_template,PCIE40_RELOAD))
 $(eval $(call ODIR_template,PCIE40_RELOAD_SUID))
diff --git a/Pcie40Applications/main_pcie40_dma.c b/Pcie40Applications/main_pcie40_dma.c
new file mode 100644
index 0000000..dceaf2e
--- /dev/null
+++ b/Pcie40Applications/main_pcie40_dma.c
@@ -0,0 +1,44 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "altera_dma_cmd.h"
+#include "altera_dma_regs.h"
+#define BUFFER_LENGTH 40
+
+unsigned int* pDmaUser;
+
+int main (int argc ,char** argv) {
+  int i;
+  int rc= 0;
+  int on_chip_size = ( DMASIZE * 4 )*ALTERA_DMA_DESCRIPTOR_NUM ; 
+  ssize_t f;
+  
+  f = open ("/dev/pcie40_0_altdma", O_RDWR);
+  if (f == -1) {
+    printf ("Couldn't open the device.\n");
+    return 0;
+  } else {
+    printf ("Opened the device: file handle #%lu!\n", (long unsigned int)f);
+  }
+  pDmaUser= (unsigned int *) mmap( NULL , 
+				   on_chip_size , 
+				   PROT_READ|PROT_WRITE , 
+				   MAP_SHARED , 
+				   f , 
+				   0x000);
+  rc = ioctl(f, ALTERA_IOCX_START);
+    
+  if (( pDmaUser!= NULL)&(rc >0) ) {
+    for (i= 0 ;i < DMASIZE;i++) printf("0X%08x\n",pDmaUser[i]);
+  } else {
+    printf (" No data available  :\n");
+    if (rc == -1) printf( "DMA too longs\n ");
+    if (rc == -2) printf( "FIFO is empty \n ");
+  }  
+  close (f);
+  return 0 ;
+}
-- 
GitLab