diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2013-11-25 21:13:53 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2013-11-25 21:13:53 +0100 |
commit | ba90c7c942f39b83986e4ed899def33ce79e2f1d (patch) | |
tree | 155b0762262642f8caa83019efd6fc1f8d7f36f9 /apps | |
parent | ba1ef9d055cbb94cd06c92709546174047f02a15 (diff) | |
download | ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.tar.gz ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.tar.bz2 ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.tar.xz ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.zip |
Some tests are added
Diffstat (limited to 'apps')
-rw-r--r-- | apps/CMakeLists.txt | 5 | ||||
-rw-r--r-- | apps/compare_to_value.c | 65 | ||||
-rw-r--r-- | apps/pio_test.c | 96 |
3 files changed, 166 insertions, 0 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 2f882a3..b3ce318 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -6,3 +6,8 @@ link_directories(${UFODECODE_LIBRARY_DIRS}) add_executable(xilinx xilinx.c) target_link_libraries(xilinx pcilib rt) + +add_executable(pio_test pio_test.c) +target_link_libraries(pio_test pcilib rt) + +add_executable(compare_to_value compare_to_value.c) diff --git a/apps/compare_to_value.c b/apps/compare_to_value.c new file mode 100644 index 0000000..b6df9c0 --- /dev/null +++ b/apps/compare_to_value.c @@ -0,0 +1,65 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +int main(int argc, char *argv[]) { + long i, j, size, num; + size_t count = 0, total = 0; + int offset = 0, toread = 1, toskip = 0; + uint32_t value; + uint32_t *buf; + + if ((argc != 4)&&(argc != 7)) { + printf("Usage: %s <file> <dwords> <value> [offset_dwords read_dwords skip_dwords] \n", argv[0]); + exit(0); + } + + FILE *f = fopen(argv[1], "r"); + if (!f) { + printf("Can't open %s\n", argv[1]); + exit(1); + } + + size = atol(argv[2]); + if (size <= 0) { + printf("Can't parse size %s\n", argv[2]); + exit(1); + } + + if (sscanf(argv[3], "%x", &value) != 1) { + printf("Can't parse register %s\n", argv[3]); + exit(1); + } + + buf = malloc(size * sizeof(uint32_t)); + if (!buf) { + printf("Can't allocate %lu bytes of memory\n", size * sizeof(uint32_t)); + exit(1); + } + + if (argc == 7) { + offset = atoi(argv[4]); + toread = atoi(argv[5]); + toskip = atoi(argv[6]); + } + + + num = fread(buf, 4, size, f); + if (num != size) { + printf("Only %lu of %lu dwords in the file\n", num, size); + } + fclose(f); + + for (i = offset; i < size; i += toskip) { + for (j = 0; j < toread; j++, i++) { + total++; + if (buf[i] != value) { + count++; + } + } + } + free(buf); + + printf("%lu of %lu is wrong\n", count, total); + +} diff --git a/apps/pio_test.c b/apps/pio_test.c new file mode 100644 index 0000000..7eca362 --- /dev/null +++ b/apps/pio_test.c @@ -0,0 +1,96 @@ +#define _BSD_SOURCE +#define _POSIX_C_SOURCE 199309L +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdarg.h> +#include <time.h> +#include <sched.h> +#include <sys/time.h> + +#include "pcilib.h" +#include "irq.h" +#include "kmem.h" + +#define DEVICE "/dev/fpga0" +//#define REALTIME + +#define BAR PCILIB_BAR0 +#define BITS 16 +#define MASK ((1ll << BITS) - 1) + + +#define WR(addr, value) { *(uint32_t*)(bar + addr) = value; } +#define RD(addr, value) { value = *(uint32_t*)(bar + addr); } + +unsigned long long bits[BITS]; + +int main(int argc, char *argv[]) { + uint32_t i, j; + pcilib_t *pci; + uint32_t reg, value, diff, errors; + void* volatile bar; + + unsigned long long attempts = 0, failures = 0; + + if (argc < 2) { + printf("Usage: %s <register>\n", argv[0]); + exit(0); + } + + if (sscanf(argv[1], "%x", ®) != 1) { + printf("Can't parse register %s\n", argv[1]); + exit(1); + } + +#ifdef REALTIME + pid_t pid; + struct sched_param sched = {0}; + + pid = getpid(); + sched.sched_priority = sched_get_priority_min(SCHED_FIFO); + if (sched_setscheduler(pid, SCHED_FIFO, &sched)) + printf("Warning: not able to get real-time priority\n"); +#endif /* REALTIME */ + + pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT); + if (!pci) { + printf("pcilib_open\n"); + exit(1); + } + + bar = pcilib_map_bar(pci, BAR); + if (!bar) { + pcilib_close(pci); + printf("map bar\n"); + exit(1); + } + + for (i = 0; 1; i++) { + WR(reg, (i%MASK)); + RD(reg, value); + + attempts++; + if (value != (i%MASK)) { + failures++; + + diff = value ^ (i%MASK); + for (errors = 0, j = 0; j < BITS; j++) + if (diff&(1<<j)) errors++; + bits[errors]++; + + //printf("written: %x, read: %x\n", i, value); + } + + if ((i % 1048576 ) == 0) { + printf("Attempts %llu, failures %llu (", attempts, failures); + for (j = 1; j < BITS; j++) + printf("%llu ", bits[j]); + printf(")\n"); + } + + } + + pcilib_unmap_bar(pci, BAR, bar); + pcilib_close(pci); +} |