فهرست منبع

Few fixes for IPE Camera modification

Suren A. Chilingaryan 13 سال پیش
والد
کامیت
b646194911
5فایلهای تغییر یافته به همراه70 افزوده شده و 33 حذف شده
  1. 3 1
      cli.c
  2. 34 31
      dma/nwl_loopback.c
  3. 5 1
      ipecamera/image.c
  4. 2 0
      ipecamera/model.h
  5. 26 0
      tests/bench3.sh

+ 3 - 1
cli.c

@@ -782,7 +782,9 @@ int WriteData(pcilib_t *handle, ACCESS_MODE mode, pcilib_dma_engine_addr_t dma,
 	if (dmaid == PCILIB_DMA_ENGINE_INVALID) Error("Invalid DMA engine (%lu) is specified", dma);
 	err = pcilib_write_dma(handle, dmaid, addr, size, buf, &ret);
 	if ((err)||(ret != size)) {
-	    if (!ret) Error("No data is written by DMA engine");
+	    if (err == PCILIB_ERROR_TIMEOUT) Error("Timeout writting the data to DMA"); 
+	    else if (err) Error("DMA engine returned a error while writing the data");
+	    else if (!ret) Error("No data is written by DMA engine");
 	    else Error("Only %lu bytes of %lu is written by DMA engine", ret, size);
 	}
       break;

+ 34 - 31
dma/nwl_loopback.c

@@ -1,3 +1,4 @@
+#define _BSD_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -22,17 +23,19 @@ int dma_nwl_start_loopback(nwl_dma_t *ctx,  pcilib_dma_direction_t direction, si
     val = packet_size;
     nwl_write_register(val, ctx, ctx->base_addr, PKT_SIZE_ADDRESS);
 
-    switch (direction) {
-      case PCILIB_DMA_BIDIRECTIONAL:
-	val = LOOPBACK;
-	nwl_write_register(val, ctx, ctx->base_addr, TX_CONFIG_ADDRESS);
-	break;
-      case PCILIB_DMA_TO_DEVICE:
-	return -1;
-      case PCILIB_DMA_FROM_DEVICE:
-        val = PKTGENR;
-	nwl_write_register(val, ctx, ctx->base_addr, RX_CONFIG_ADDRESS);
-	break;
+    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) {
+	switch (direction) {
+          case PCILIB_DMA_BIDIRECTIONAL:
+	    val = LOOPBACK;
+	    nwl_write_register(val, ctx, ctx->base_addr, TX_CONFIG_ADDRESS);
+	    break;
+          case PCILIB_DMA_TO_DEVICE:
+	    return -1;
+	  case PCILIB_DMA_FROM_DEVICE:
+    	    val = PKTGENR;
+	    nwl_write_register(val, ctx, ctx->base_addr, RX_CONFIG_ADDRESS);
+	    break;
+	}
     }
 
     ctx->loopback_started = 1;
@@ -48,15 +51,19 @@ int dma_nwl_stop_loopback(nwl_dma_t *ctx) {
 	/* Stop in any case, otherwise we can have problems in benchmark due to
 	engine initialized in previous run, and benchmark is only actual usage.
 	Otherwise, we should detect current loopback status during initialization */
-    nwl_write_register(val, ctx, ctx->base_addr, TX_CONFIG_ADDRESS);
-    nwl_write_register(val, ctx, ctx->base_addr, RX_CONFIG_ADDRESS);
+
+    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) {
+	nwl_write_register(val, ctx, ctx->base_addr, TX_CONFIG_ADDRESS);
+	nwl_write_register(val, ctx, ctx->base_addr, RX_CONFIG_ADDRESS);
+    }
+    
     ctx->loopback_started = 0;
     
     return 0;
 }
 
 double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dma, uintptr_t addr, size_t size, size_t iterations, pcilib_dma_direction_t direction) {
-    int i;
+    int iter, i;
     int res;
     int err;
     size_t bytes;
@@ -100,10 +107,7 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
     dma_nwl_enable_engine_irq(ctx, writeid);
 #endif /* NWL_GENERATE_DMA_IRQ */
 
-
-    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) {
-	dma_nwl_start_loopback(ctx, direction, size * sizeof(uint32_t));
-    }
+    dma_nwl_start_loopback(ctx, direction, size * sizeof(uint32_t));
 
 	// Allocate memory and prepare data
     buf = malloc(size * sizeof(uint32_t));
@@ -114,23 +118,23 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
 	return -1;
     }
 
-#ifdef DEBUG_HARDWARE	     
+//#ifdef DEBUG_HARDWARE	     
     if (ctx->type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
 	pcilib_write_register(ctx->pcilib, NULL, "control", 0x1e5);
 	usleep(100000);
 	pcilib_write_register(ctx->pcilib, NULL, "control", 0x1e1);
     }
-#endif /* DEBUG_HARDWARE */
+//#endif /* DEBUG_HARDWARE */
 
 	// Benchmark
-    for (i = 0; i < iterations; i++) {
-        memset(cmp, 0x13 + i, size * sizeof(uint32_t));
+    for (iter = 0; iter < iterations; iter++) {
+        memset(cmp, 0x13 + iter, size * sizeof(uint32_t));
 
-#ifdef DEBUG_HARDWARE	     
+//#ifdef DEBUG_HARDWARE	     
 	if (ctx->type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
 	    pcilib_write_register(ctx->pcilib, NULL, "control", 0x1e1);
 	}
-#endif /* DEBUG_HARDWARE */
+//#endif /* DEBUG_HARDWARE */
 
         gettimeofday(&start, NULL);
 	if (direction&PCILIB_DMA_TO_DEVICE) {
@@ -143,14 +147,13 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
 	    }
 	}
 
-#ifdef DEBUG_HARDWARE	     
+//#ifdef DEBUG_HARDWARE	     
 	if (ctx->type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
-	    //usleep(1000000);
 	    pcilib_write_register(ctx->pcilib, NULL, "control", 0x3e1);
 	}
+//#endif /* DEBUG_HARDWARE */
 
 	memset(buf, 0, size * sizeof(uint32_t));
-#endif /* DEBUG_HARDWARE */
         
 	err = pcilib_read_dma(ctx->pcilib, readid, addr, size * sizeof(uint32_t), buf, &bytes);
         gettimeofday(&cur, NULL);
@@ -168,12 +171,12 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
 		    if (buf[i] != cmp[i]) break;
 		
 		bytes = i;
-		printf("Expected: *%lx, Written:", 0x13 + i);
+		printf("Expected: *%lx, Written at position %lu:", 0x13 + iter, bytes);
 		for (; (i < size)&&(i < (bytes + 16)); i++) {
 		    if (((i - bytes)%8)==0) printf("\n");
 		    printf("% 10lx", buf[i]);
 		}
-		printf("\n\n");
+		printf("\n");
 		
 		error = "Written and read values does not match";
 		break;
@@ -216,7 +219,7 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
 #endif /* DEBUG_HARDWARE */
 
     if (error) {
-	pcilib_warning("%s at iteration %i, error: %i, bytes: %zu", error, i, err, bytes);
+	pcilib_warning("%s at iteration %i, error: %i, bytes: %zu", error, iter, err, bytes);
     }
     
 #ifdef NWL_GENERATE_DMA_IRQ
@@ -224,7 +227,7 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
     dma_nwl_disable_engine_irq(ctx, readid);
 #endif /* NWL_GENERATE_DMA_IRQ */
 
-    if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) dma_nwl_stop_loopback(ctx);
+    dma_nwl_stop_loopback(ctx);
 
     __sync_synchronize();
     

+ 5 - 1
ipecamera/image.c

@@ -181,8 +181,12 @@ pcilib_dma_context_t *ipecamera_init_dma(pcilib_context_t *vctx) {
 	pcilib_error("The DMA engine is not configured in model");
 	return NULL;
     }
-    
+
+#ifdef IPECAMERA_DMA_R3
+    return model_info->dma_api->init(ctx->pcilib, PCILIB_NWL_MODIFICATION_IPECAMERA, NULL);
+#else
     return model_info->dma_api->init(ctx->pcilib, PCILIB_DMA_MODIFICATION_DEFAULT, NULL);
+#endif
 }
 
 

+ 2 - 0
ipecamera/model.h

@@ -6,6 +6,8 @@
 #include "pcilib.h"
 #include "image.h"
 
+//#define IPECAMERA_DMA_R3
+
 //#define IPECAMERA_REGISTER_SPACE 0xfeaffc00
 #define IPECAMERA_REGISTER_SPACE 0x9000
 #define IPECAMERA_REGISTER_WRITE (IPECAMERA_REGISTER_SPACE + 0)

+ 26 - 0
tests/bench3.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+
+function pci {
+    PCILIB_PATH="/root/pcitool"
+    LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
+}
+
+size=16
+bytes=`expr $size "*" 4`
+
+pci -w xrawdata_packet_length $bytes
+
+pci --start-dma dma1
+pci -w control 0x1e5
+sleep 1
+pci -w control 0x1e1
+
+for i in `seq 1 10`; do
+    pci -w control 0x1e1
+    pci -w dma1 -s $size "*$i"
+    pci -w control 0x3e1
+    pci -r dma1 -s $size -o bench.out
+done
+
+pci --stop-dma dma1
+