2016-06-14 01:19:17 +02:00
|
|
|
/** Test procedures for VILLASfpga
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, Steffen Vogel
|
2016-06-14 01:19:17 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
2017-03-03 20:21:33 -04:00
|
|
|
#include <unistd.h>
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
#include <criterion/options.h>
|
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
#include <xilinx/xtmrctr.h>
|
|
|
|
|
2017-03-12 23:16:33 -03:00
|
|
|
#include <villas/super_node.h>
|
2016-06-14 01:19:17 +02:00
|
|
|
#include <villas/utils.h>
|
2016-06-19 19:23:19 +02:00
|
|
|
#include <villas/nodes/fpga.h>
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
#include <villas/fpga/ip.h>
|
2017-03-03 20:21:33 -04:00
|
|
|
#include <villas/fpga/card.h>
|
2017-03-07 06:36:23 -04:00
|
|
|
#include <villas/fpga/vlnv.h>
|
|
|
|
|
2017-03-03 20:21:33 -04:00
|
|
|
#include <villas/fpga/ips/intc.h>
|
|
|
|
#include <villas/fpga/ips/timer.h>
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2016-06-14 01:19:17 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
#define TEST_CONFIG "/villas/etc/fpga.conf"
|
2016-06-14 01:19:17 +02:00
|
|
|
#define TEST_LEN 0x1000
|
|
|
|
|
|
|
|
#define CPU_HZ 3392389000
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
static struct fpga_card *card;
|
2017-03-12 23:16:33 -03:00
|
|
|
static struct super_node sn;
|
2017-03-03 20:21:33 -04:00
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
static void init()
|
2016-06-15 20:05:09 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2016-12-23 17:24:53 +01:00
|
|
|
int argc = 1;
|
|
|
|
char *argv[] = { "tests" };
|
|
|
|
config_setting_t *cfg_root;
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2017-03-12 23:16:33 -03:00
|
|
|
super_node_parse_uri(&sn, TEST_CONFIG);
|
2016-12-23 17:24:53 +01:00
|
|
|
|
2017-03-12 23:16:33 -03:00
|
|
|
cfg_root = config_root_setting(&sn.cfg);
|
2016-12-23 17:24:53 +01:00
|
|
|
|
|
|
|
ret = fpga_init(argc, argv, cfg_root);
|
|
|
|
cr_assert_eq(ret, 0, "Failed to initilize FPGA");
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
card = fpga_lookup_card("vc707");
|
2016-12-23 17:24:53 +01:00
|
|
|
|
|
|
|
if (criterion_options.logging_threshold < CRITERION_IMPORTANT)
|
2017-03-07 06:36:23 -04:00
|
|
|
fpga_card_dump(card);
|
2016-12-23 17:24:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void fini()
|
|
|
|
{
|
|
|
|
int ret;
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = fpga_card_destroy(card);
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert_eq(ret, 0, "Failed to de-initilize FPGA");
|
|
|
|
|
2017-03-12 23:16:33 -03:00
|
|
|
super_node_destroy(&sn);
|
2016-06-15 20:05:09 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
TestSuite(fpga,
|
|
|
|
.init = init,
|
|
|
|
.fini = fini,
|
|
|
|
.description = "VILLASfpga");
|
|
|
|
|
|
|
|
Test(fpga, intc, .description = "Interrupt Controller")
|
2016-06-14 01:19:17 +02:00
|
|
|
{
|
2016-06-26 15:33:19 +02:00
|
|
|
int ret;
|
2016-06-19 19:23:19 +02:00
|
|
|
uint32_t isr;
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
cr_assert(card->intc);
|
2016-06-19 19:23:19 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_enable(card->intc, 0xFF00, 0);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to enable interrupt");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
/* Fake IRQs in software by writing to ISR */
|
2017-03-07 06:36:23 -04:00
|
|
|
XIntc_Out32((uintptr_t) card->map + card->intc->baseaddr + XIN_ISR_OFFSET, 0xFF00);
|
2016-06-19 19:23:19 +02:00
|
|
|
|
|
|
|
/* Wait for 8 SW triggered IRQs */
|
2016-06-14 01:19:17 +02:00
|
|
|
for (int i = 0; i < 8; i++)
|
2017-03-07 06:36:23 -04:00
|
|
|
intc_wait(card->intc, i+8);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
/* Check ISR if all SW IRQs have been deliverd */
|
2017-03-07 06:36:23 -04:00
|
|
|
isr = XIntc_In32((uintptr_t) card->map + card->intc->baseaddr + XIN_ISR_OFFSET);
|
2016-06-19 19:23:19 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_disable(card->intc, 0xFF00);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to disable interrupt");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert_eq(isr & 0xFF00, 0); /* ISR should get cleared by MSI_Grant_signal */
|
2016-06-14 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
Test(fpga, xsg, .description = "XSG: multiply_add")
|
2016-06-14 01:19:17 +02:00
|
|
|
{
|
2016-06-19 19:23:19 +02:00
|
|
|
int ret;
|
|
|
|
double factor, err = 0;
|
|
|
|
|
2017-02-18 10:43:58 -05:00
|
|
|
struct fpga_ip *xsg, *dma;
|
2016-07-08 13:31:46 +02:00
|
|
|
struct model_param *p;
|
|
|
|
struct dma_mem mem;
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
xsg = fpga_vlnv_lookup(&card->ips, &(struct fpga_vlnv) { NULL, "sysgen", "xsg_multiply", NULL });
|
|
|
|
dma = fpga_vlnv_lookup(&card->ips, &(struct fpga_vlnv) { "xilinx.com", "ip", "axi_dma", NULL });
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
/* Check if required IP is available on FPGA */
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert_neq(!dma || !xsg || !dma, 0);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
p = list_lookup(&xsg->model.parameters, "factor");
|
|
|
|
if (!p)
|
|
|
|
error("Missing parameter 'factor' for model '%s'", xsg->name);
|
|
|
|
|
|
|
|
ret = model_param_read(p, &factor);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to read parameter 'factor' from model '%s'", xsg->name);
|
|
|
|
|
|
|
|
info("Model param: factor = %f", factor);
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, dma, xsg);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, xsg, dma);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
ret = dma_alloc(dma, &mem, 0x1000, 0);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to allocate DMA memory");
|
|
|
|
|
|
|
|
float *src = (float *) mem.base_virt;
|
|
|
|
float *dst = (float *) mem.base_virt + 0x800;
|
2016-06-19 19:23:19 +02:00
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
src[i] = 1.1 * (i+1);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
ret = dma_ping_pong(dma, (char *) src, (char *) dst, 6 * sizeof(float));
|
|
|
|
if (ret)
|
|
|
|
error("Failed to to ping pong DMA transfer: %d", ret);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-15 20:05:09 +02:00
|
|
|
for (int i = 0; i < 6; i++)
|
2016-06-19 19:23:19 +02:00
|
|
|
err += abs(factor * src[i] - dst[i]);
|
2016-06-26 15:33:19 +02:00
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
info("Error after FPGA operation: err = %f", err);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_disconnect(card->sw, dma, xsg);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_disconnect(card->sw, xsg, dma);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
ret = dma_free(dma, &mem);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to release DMA memory");
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert(err < 1e-3);
|
2016-06-14 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
Test(fpga, hls_dft, .description = "HLS: hls_dft")
|
2016-06-15 20:05:09 +02:00
|
|
|
{
|
2016-06-26 15:33:19 +02:00
|
|
|
int ret;
|
2017-02-18 10:43:58 -05:00
|
|
|
struct fpga_ip *hls, *rtds;
|
2016-06-26 15:33:19 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
rtds = fpga_vlnv_lookup(&card->ips, &(struct fpga_vlnv) { "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL });
|
|
|
|
hls = fpga_vlnv_lookup(&card->ips, &(struct fpga_vlnv) { NULL, "hls", "hls_dft", NULL });
|
2016-06-15 20:05:09 +02:00
|
|
|
|
|
|
|
/* Check if required IP is available on FPGA */
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert(hls && rtds);
|
2016-06-26 15:33:19 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_enable(card->intc, (1 << rtds->irq), 0);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to enable interrupt");
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, rtds, hls);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, hls, rtds);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
/* Dump RTDS AXI Stream state */
|
|
|
|
rtds_axis_dump(rtds);
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
int len = 2000;
|
|
|
|
int NSAMPLES = 400;
|
|
|
|
float src[len], dst[len];
|
|
|
|
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
src[i] = 4 + 5.0 * sin(2.0 * M_PI * 1 * i / NSAMPLES) +
|
|
|
|
2.0 * sin(2.0 * M_PI * 2 * i / NSAMPLES) +
|
|
|
|
1.0 * sin(2.0 * M_PI * 5 * i / NSAMPLES) +
|
|
|
|
0.5 * sin(2.0 * M_PI * 9 * i / NSAMPLES) +
|
|
|
|
0.2 * sin(2.0 * M_PI * 15 * i / NSAMPLES);
|
|
|
|
|
|
|
|
fifo_write()
|
|
|
|
}
|
2016-06-19 19:23:19 +02:00
|
|
|
#endif
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_disconnect(card->sw, rtds, hls);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_disconnect(card->sw, hls, rtds);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2016-06-15 20:05:09 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
Test(fpga, fifo, .description = "FIFO")
|
2016-06-14 01:19:17 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ssize_t len;
|
|
|
|
char src[255], dst[255];
|
2017-02-18 10:43:58 -05:00
|
|
|
struct fpga_ip *fifo;
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
fifo = fpga_vlnv_lookup(&card->ips, &(struct fpga_vlnv) { "xilinx.com", "ip", "axi_fifo_mm_s", NULL });
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert(fifo);
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_enable(card->intc, (1 << fifo->irq), 0);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to enable interrupt");
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, fifo, fifo);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
|
|
|
/* Get some random data to compare */
|
|
|
|
memset(dst, 0, sizeof(dst));
|
2017-02-12 14:36:44 -03:00
|
|
|
len = read_random((char *) src, sizeof(src));
|
|
|
|
if (len != sizeof(src))
|
2016-06-14 01:19:17 +02:00
|
|
|
error("Failed to get random data");
|
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
len = fifo_write(fifo, (char *) src, sizeof(src));
|
2016-06-14 01:19:17 +02:00
|
|
|
if (len != sizeof(src))
|
|
|
|
error("Failed to send to FIFO");
|
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
len = fifo_read(fifo, (char *) dst, sizeof(dst));
|
2016-06-14 01:19:17 +02:00
|
|
|
if (len != sizeof(dst))
|
|
|
|
error("Failed to read from FIFO");
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_disable(card->intc, (1 << fifo->irq));
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to disable interrupt");
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_disconnect(card->sw, fifo, fifo);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
|
|
|
/* Compare data */
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert_eq(memcmp(src, dst, sizeof(src)), 0);
|
2016-06-14 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
Test(fpga, dma, .description = "DMA")
|
2016-06-14 01:19:17 +02:00
|
|
|
{
|
2016-07-26 15:42:11 +02:00
|
|
|
int ret = -1;
|
2016-07-08 13:31:46 +02:00
|
|
|
struct dma_mem mem, src, dst;
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
list_foreach(struct fpga_ip *dma, &card->ips) { INDENT
|
|
|
|
if (fpga_vlnv_cmp(&dma->vlnv, &(struct fpga_vlnv) { "xilinx.com", "ip", "axi_dma", NULL }))
|
2016-06-19 19:23:19 +02:00
|
|
|
continue; /* skip non DMA IP cores */
|
2016-07-08 13:31:46 +02:00
|
|
|
|
|
|
|
/* Simple DMA can only transfer up to 4 kb due to
|
|
|
|
* PCIe page size burst limitation */
|
2017-02-12 14:36:44 -03:00
|
|
|
ssize_t len2, len = dma->dma.inst.HasSg ? 64 << 20 : 1 << 2;
|
2016-07-08 13:31:46 +02:00
|
|
|
|
|
|
|
ret = dma_alloc(dma, &mem, 2 * len, 0);
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert_eq(ret, 0);
|
2016-07-08 13:31:46 +02:00
|
|
|
|
|
|
|
ret = dma_mem_split(&mem, &src, &dst);
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert_eq(ret, 0);
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2016-06-26 15:33:19 +02:00
|
|
|
/* Get new random data */
|
2017-02-12 14:36:44 -03:00
|
|
|
len2 = read_random(src.base_virt, len);
|
|
|
|
if (len2 != len)
|
2016-07-08 13:31:46 +02:00
|
|
|
serror("Failed to get random data");
|
2016-06-26 15:33:19 +02:00
|
|
|
|
2016-06-19 19:23:19 +02:00
|
|
|
int irq_mm2s = dma->irq;
|
|
|
|
int irq_s2mm = dma->irq + 1;
|
2017-03-03 20:30:45 -04:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_enable(card->intc, (1 << irq_mm2s) | (1 << irq_s2mm), 0);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to enable interrupt");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, dma, dma);
|
2016-06-19 19:23:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
|
|
|
|
|
|
|
/* Start transfer */
|
2016-07-08 13:31:46 +02:00
|
|
|
ret = dma_ping_pong(dma, src.base_phys, dst.base_phys, dst.len);
|
2016-06-19 19:23:19 +02:00
|
|
|
if (ret)
|
2016-07-08 13:31:46 +02:00
|
|
|
error("DMA ping pong failed");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
ret = memcmp(src.base_virt, dst.base_virt, src.len);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-26 15:33:19 +02:00
|
|
|
info("DMA %s (%s): %s", dma->name, dma->dma.inst.HasSg ? "scatter-gather" : "simple", ret ? RED("failed") : GRN("passed"));
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_disconnect(card->sw, dma, dma);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_disable(card->intc, (1 << irq_mm2s) | (1 << irq_s2mm));
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to disable interrupt");
|
2016-07-08 13:31:46 +02:00
|
|
|
|
|
|
|
ret = dma_free(dma, &mem);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to release DMA memory");
|
2016-06-19 19:23:19 +02:00
|
|
|
}
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert_eq(ret, 0);
|
2016-06-14 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
Test(fpga, timer, .description = "Timer Counter")
|
2016-06-14 01:19:17 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2017-02-18 10:43:58 -05:00
|
|
|
struct fpga_ip *tmr;
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
tmr = fpga_vlnv_lookup(&card->ips, &(struct fpga_vlnv) { "xilinx.com", "ip", "axi_timer", NULL });
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert(tmr);
|
2016-06-26 15:33:19 +02:00
|
|
|
|
|
|
|
XTmrCtr *xtmr = &tmr->timer.inst;
|
2016-06-15 20:05:09 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = intc_enable(card->intc, (1 << tmr->irq), 0);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to enable interrupt");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-26 15:33:19 +02:00
|
|
|
XTmrCtr_SetOptions(xtmr, 0, XTC_EXT_COMPARE_OPTION | XTC_DOWN_COUNT_OPTION);
|
2016-07-18 15:09:49 +02:00
|
|
|
XTmrCtr_SetResetValue(xtmr, 0, FPGA_AXI_HZ / 125);
|
2016-06-26 15:33:19 +02:00
|
|
|
XTmrCtr_Start(xtmr, 0);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
uint64_t counter = intc_wait(card->intc, tmr->irq);
|
2016-07-08 13:31:46 +02:00
|
|
|
info("Got IRQ: counter = %ju", counter);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
if (counter == 1)
|
2016-12-23 17:24:53 +01:00
|
|
|
return;
|
2016-07-08 13:31:46 +02:00
|
|
|
else
|
|
|
|
warn("Counter was not 1");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
intc_disable(card->intc, (1 << tmr->irq));
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to disable interrupt");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
return;
|
2016-06-14 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:24:53 +01:00
|
|
|
Test(fpga, rtds_rtt, .description = "RTDS: tight rtt")
|
2016-06-14 01:19:17 +02:00
|
|
|
{
|
2016-06-26 15:33:19 +02:00
|
|
|
int ret;
|
2017-02-18 10:43:58 -05:00
|
|
|
struct fpga_ip *dma, *rtds;
|
2016-07-08 13:31:46 +02:00
|
|
|
struct dma_mem buf;
|
|
|
|
size_t recvlen;
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
/* Get IP cores */
|
2017-03-07 06:36:23 -04:00
|
|
|
rtds = fpga_vlnv_lookup(&card->ips, &(struct fpga_vlnv) { "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL });
|
|
|
|
dma = list_lookup(&card->ips, "dma_1");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-26 15:33:19 +02:00
|
|
|
/* Check if required IP is available on FPGA */
|
2016-12-23 17:24:53 +01:00
|
|
|
cr_assert (dma && rtds);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, rtds, dma);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_connect(card->sw, dma, rtds);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
ret = dma_alloc(dma, &buf, 0x100, 0);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to allocate DMA memory");
|
2016-06-14 01:19:17 +02:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
ret = dma_read(dma, buf.base_phys, buf.len);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to start DMA read: %d", ret);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-26 15:33:19 +02:00
|
|
|
ret = dma_read_complete(dma, NULL, &recvlen);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to complete DMA read: %d", ret);
|
|
|
|
|
2016-07-08 13:31:46 +02:00
|
|
|
ret = dma_write(dma, buf.base_phys, recvlen);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to start DMA write: %d", ret);
|
2016-06-14 01:19:17 +02:00
|
|
|
|
2016-06-26 15:33:19 +02:00
|
|
|
ret = dma_write_complete(dma, NULL, NULL);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to complete DMA write: %d", ret);
|
2016-06-14 01:19:17 +02:00
|
|
|
}
|
|
|
|
|
2017-03-07 06:36:23 -04:00
|
|
|
ret = switch_disconnect(card->sw, rtds, dma);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2017-03-07 06:36:23 -04:00
|
|
|
|
|
|
|
ret = switch_disconnect(card->sw, dma, rtds);
|
2016-06-26 15:33:19 +02:00
|
|
|
if (ret)
|
|
|
|
error("Failed to configure switch");
|
2016-07-08 13:31:46 +02:00
|
|
|
|
|
|
|
ret = dma_free(dma, &buf);
|
|
|
|
if (ret)
|
|
|
|
error("Failed to release DMA memory");
|
2016-06-26 15:33:19 +02:00
|
|
|
}
|