test_with_kiro.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <stdarg.h>
  5. #include <time.h>
  6. #include <sched.h>
  7. #include <sys/time.h>
  8. #include <pcilib.h>
  9. #include <pcilib/bar.h>
  10. #include <kiro/kiro-client.h>
  11. #include <kiro/kiro-server.h>
  12. #define DEVICE "/dev/fpga0"
  13. #define BAR PCILIB_BAR0
  14. #include "test.h"
  15. int main(int argc, char *argv[]) {
  16. pcilib_t *pci;
  17. void* volatile bar;
  18. const pcilib_bar_info_t *bar_info;
  19. pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT);
  20. if (!pci) {
  21. printf("pcilib_open\n");
  22. exit(1);
  23. }
  24. bar = pcilib_resolve_bar_address(pci, BAR, 0);
  25. if (!bar) {
  26. pcilib_close(pci);
  27. printf("map bar\n");
  28. exit(1);
  29. }
  30. printf("BAR mapped to: %p\n", bar);
  31. bar_info = pcilib_get_bar_info(pci, BAR);
  32. printf("%p (Phys: 0x%lx, Size: 0x%x)\n", bar_info[BAR].virt_addr, bar_info[BAR].phys_addr, bar_info[BAR].size);
  33. //Clear debugging
  34. /*
  35. volatile int *reset_enable = ((int *)(((unsigned long)bar)+0x9040));
  36. volatile int *reset = ((int *)(((unsigned long)bar)+0x93a4));
  37. volatile int *reset_slave_tx = ((int *)(((unsigned long)bar)+0x92e4));
  38. *reset_enable = 4; //bit 2
  39. *reset_slave_tx = 1;
  40. *reset_slave_tx = 0;
  41. *reset = 1; //bit 0
  42. *reset = 0;
  43. *reset_enable = 0;
  44. */
  45. sleep (1);
  46. //write some test data to the BAR
  47. int *test = ((int *)(((unsigned long)bar)+0x10000));
  48. //int *test = (int *)malloc(4);
  49. //int *test = bar;
  50. //printf ("Pointing to: %lx\n",test);
  51. *test = 0xdeadbeef;
  52. //test[1] = 0xdeadbeef;
  53. //printf ("Set BAR to: 0x%x\n", test);
  54. KiroClient *client = kiro_client_new ();
  55. kiro_client_set_prealloc (client, test, 1024);
  56. kiro_client_connect (client, "192.168.11.71", "60010");
  57. kiro_client_sync (client);
  58. unsigned long length = kiro_client_get_memory_size (client);
  59. printf ("Transferred %lu bytes from server.\n", length);
  60. KiroServer *server = kiro_server_new ();
  61. kiro_server_start (server, NULL, "60011", test, length);
  62. while (0)
  63. {
  64. sleep (1);
  65. kiro_client_sync (client);
  66. }
  67. printf ("BAR now reads: 0x%x\n", *test);
  68. //printf("Read '%s' from the server\n", (char *)kiro_client_get_memory (client));
  69. /* free (mem); */
  70. end:
  71. kiro_server_free (server);
  72. kiro_client_free (client);
  73. pcilib_close(pci);
  74. printf("PCI closed\n");
  75. }