|
@@ -0,0 +1,100 @@
|
|
|
+#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 <pcilib/bar.h>
|
|
|
+
|
|
|
+#include <kiro/kiro-client.h>
|
|
|
+#include <kiro/kiro-server.h>
|
|
|
+
|
|
|
+#define DEVICE "/dev/fpga0"
|
|
|
+
|
|
|
+#define BAR PCILIB_BAR0
|
|
|
+
|
|
|
+#include "test.h"
|
|
|
+
|
|
|
+
|
|
|
+int main(int argc, char *argv[]) {
|
|
|
+
|
|
|
+
|
|
|
+ pcilib_t *pci;
|
|
|
+ void* volatile bar;
|
|
|
+ const pcilib_bar_info_t *bar_info;
|
|
|
+
|
|
|
+ pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT);
|
|
|
+ if (!pci) {
|
|
|
+ printf("pcilib_open\n");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ bar = pcilib_resolve_bar_address(pci, BAR, 0);
|
|
|
+ if (!bar) {
|
|
|
+ pcilib_close(pci);
|
|
|
+ printf("map bar\n");
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+ printf("BAR mapped to: %p\n", bar);
|
|
|
+
|
|
|
+ bar_info = pcilib_get_bar_info(pci, BAR);
|
|
|
+ printf("%p (Phys: 0x%lx, Size: 0x%x)\n", bar_info[BAR].virt_addr, bar_info[BAR].phys_addr, bar_info[BAR].size);
|
|
|
+
|
|
|
+ //Clear debugging
|
|
|
+ /*
|
|
|
+ volatile int *reset_enable = ((int *)(((unsigned long)bar)+0x9040));
|
|
|
+ volatile int *reset = ((int *)(((unsigned long)bar)+0x93a4));
|
|
|
+ volatile int *reset_slave_tx = ((int *)(((unsigned long)bar)+0x92e4));
|
|
|
+ *reset_enable = 4; //bit 2
|
|
|
+ *reset_slave_tx = 1;
|
|
|
+ *reset_slave_tx = 0;
|
|
|
+ *reset = 1; //bit 0
|
|
|
+ *reset = 0;
|
|
|
+ *reset_enable = 0;
|
|
|
+ */
|
|
|
+
|
|
|
+ sleep (1);
|
|
|
+
|
|
|
+
|
|
|
+ //write some test data to the BAR
|
|
|
+ int *test = ((int *)(((unsigned long)bar)+0x10000));
|
|
|
+ //int *test = (int *)malloc(4);
|
|
|
+ //int *test = bar;
|
|
|
+ //printf ("Pointing to: %lx\n",test);
|
|
|
+ *test = 0xdeadbeef;
|
|
|
+ //test[1] = 0xdeadbeef;
|
|
|
+ //printf ("Set BAR to: 0x%x\n", test);
|
|
|
+
|
|
|
+ KiroClient *client = kiro_client_new ();
|
|
|
+
|
|
|
+ kiro_client_set_prealloc (client, test, 1024);
|
|
|
+ kiro_client_connect (client, "192.168.11.71", "60010");
|
|
|
+ kiro_client_sync (client);
|
|
|
+
|
|
|
+
|
|
|
+ unsigned long length = kiro_client_get_memory_size (client);
|
|
|
+ printf ("Transferred %lu bytes from server.\n", length);
|
|
|
+ KiroServer *server = kiro_server_new ();
|
|
|
+ kiro_server_start (server, NULL, "60011", test, length);
|
|
|
+
|
|
|
+ while (0)
|
|
|
+ {
|
|
|
+ sleep (1);
|
|
|
+ kiro_client_sync (client);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ printf ("BAR now reads: 0x%x\n", *test);
|
|
|
+ //printf("Read '%s' from the server\n", (char *)kiro_client_get_memory (client));
|
|
|
+ /* free (mem); */
|
|
|
+
|
|
|
+
|
|
|
+end:
|
|
|
+ kiro_server_free (server);
|
|
|
+ kiro_client_free (client);
|
|
|
+ pcilib_close(pci);
|
|
|
+ printf("PCI closed\n");
|
|
|
+}
|