Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #include <assert.h>
- #include "fpga_pci.h"
- void fail_on(int got, int exp, char *fn)
- {
- printf("%s: expected 0x%x, got %d\n", fn, exp, got);
- }
- #define BRAM_0_ADDRESS 0x0000000
- #define BRAM_1_ADDRESS 0x0010000
- #define MEM_DDRC 0x80000000
- #define TOTAL_MEMORY 3
- const unsigned mem_addr[TOTAL_MEMORY] = {BRAM_0_ADDRESS, BRAM_1_ADDRESS, MEM_DDRC};
- int main(int argc, char *argv[])
- {
- printf("To run this test: ./app_name <n_transfers>\n");
- uint32_t n_transfers = 10;
- uint32_t w_val = 0;
- uint32_t r_val = 0;
- srand(time(NULL));
- if (argc == 2)
- {
- n_transfers = atoi(argv[1]);
- }
- // Initialize the pci library.
- int res = fpga_pci_init();
- fail_on(res, 0, "fpga_pci_init");
- pci_bar_handle_t pcis_handle;
- int pcis_slot_id = 0;
- int pcis_pf_id = FPGA_APP_PF;
- int pcis_bar_id = APP_PF_BAR4;
- uint32_t pcis_flags = 0;
- // Produces same output
- // pci_bar_handle_t ocl_handle;
- // int ocl_slot_id = 0;
- // int ocl_pf_id = FPGA_APP_PF;
- // int ocl_bar_id = APP_PF_BAR0;
- // uint32_t ocl_flags = 0;
- // Attach to an FPGA memory space.
- res = fpga_pci_attach(pcis_slot_id, pcis_pf_id, pcis_bar_id, pcis_flags, &pcis_handle);
- // res = fpga_pci_attach(ocl_slot_id, ocl_pf_id, ocl_bar_id, ocl_flags, &ocl_handle);
- fail_on(res, 0, "fpga_pci_attach");
- for (int i = 0; i < n_transfers; i++)
- {
- w_val = rand() % (int)pow(2, 8);
- int addr_offset = mem_addr[i % TOTAL_MEMORY];
- res = fpga_pci_poke(pcis_handle, addr_offset, w_val);
- fail_on(res, 0, "fpga_pci_poke");
- res = fpga_pci_peek(pcis_handle, addr_offset, &r_val);
- fail_on(res, 0, "fpga_pci_peek");
- assert(w_val == r_val);
- printf("Value %d was w/r to address 0x%x\n", w_val, addr_offset);
- }
- // Detach from an FPGA memory space.
- res = fpga_pci_detach(pcis_handle);
- fail_on(res, 0, "fpga_pci_detach");
- return res;
- }
- /*
- fpga_pci_init: expected 0x0, got 0
- fpga_pci_attach: expected 0x0, got 25
- fpga_pci_poke: expected 0x0, got -22
- fpga_pci_peek: expected 0x0, got -22
- c_pcie_lib_test: c_pcie_lib_test.c:65: main: Assertion `w_val == r_val' failed.
- Aborted
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement