1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-23 00:00:01 +01:00
VILLASnode/src/fpga-tests.c

407 lines
9.8 KiB
C
Raw Normal View History

2016-06-14 01:19:17 +02:00
/** Test procedures for VILLASfpga
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @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-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
#include <villas/fpga/ip.h>
2017-03-03 20:21:33 -04:00
#include <villas/fpga/card.h>
#include <villas/fpga/ips/intc.h>
#include <villas/fpga/ips/timer.h>
2016-06-14 01:19:17 +02:00
#include "config.h"
#define TEST_LEN 0x1000
#define CPU_HZ 3392389000
2016-06-19 19:23:19 +02:00
/* Forward Declarations */
2017-03-03 20:21:33 -04:00
int fpga_test_intc(struct fpga_card *c);
int fpga_test_timer(struct fpga_card *c);
int fpga_test_fifo(struct fpga_card *c);
int fpga_test_dma(struct fpga_card *c);
int fpga_test_xsg(struct fpga_card *c);
int fpga_test_hls_dft(struct fpga_card *c);
int fpga_test_rtds_rtt(struct fpga_card *c);
int fpga_tests(int argc, char *argv[], struct fpga_card *c)
{
int ret;
struct {
const char *name;
2017-03-03 20:21:33 -04:00
int (*func)(struct fpga_card *c);
} tests[] = {
{ "Interrupt Controller", fpga_test_intc },
{ "Timer Counter", fpga_test_timer },
{ "FIFO", fpga_test_fifo },
{ "DMA", fpga_test_dma },
{ "XSG: multiply_add", fpga_test_xsg },
{ "HLS: hls_dft", fpga_test_hls_dft },
{ "RTDS: tight rtt", fpga_test_rtds_rtt }
};
for (int i = 0; i < ARRAY_LEN(tests); i++) {
2017-03-03 20:21:33 -04:00
ret = tests[i].func(c);
info("%s: %s", tests[i].name, (ret == 0) ? GRN("passed") : RED("failed"));
}
return 0;
}
2017-03-03 20:21:33 -04:00
int fpga_test_intc(struct fpga_card *c)
2016-06-14 01:19:17 +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-03 20:21:33 -04:00
if (!c->intc)
2016-06-19 19:23:19 +02:00
return -1;
2017-03-03 20:21:33 -04:00
ret = intc_enable(c->intc, 0xFF00, 0);
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-03 20:21:33 -04:00
XIntc_Out32((uintptr_t) c->map + c->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-03 20:21:33 -04:00
intc_wait(c->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-03 20:21:33 -04:00
isr = XIntc_In32((uintptr_t) c->map + c->intc->baseaddr + XIN_ISR_OFFSET);
2016-06-19 19:23:19 +02:00
2017-03-03 20:21:33 -04:00
ret = intc_disable(c->intc, 0xFF00);
if (ret)
error("Failed to disable interrupt");
2016-06-14 01:19:17 +02:00
return (isr & 0xFF00) ? -1 : 0; /* ISR should get cleared by MSI_Grant_signal */
}
2017-03-03 20:21:33 -04:00
int fpga_test_xsg(struct fpga_card *c)
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-03 20:21:33 -04:00
xsg = fpga_vlnv_lookup(&c->ips, &(struct fpga_vlnv) { NULL, "sysgen", "xsg_multiply", NULL });
dma = fpga_vlnv_lookup(&c->ips, &(struct fpga_vlnv) { "xilinx.com", "ip", "axi_dma", NULL });
2016-06-14 01:19:17 +02:00
/* Check if required IP is available on FPGA */
if (!dma || !xsg || !dma)
return -1;
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-03 20:21:33 -04:00
ret = switch_connect(c->sw, dma, xsg);
if (ret)
error("Failed to configure switch");
2017-03-03 20:21:33 -04:00
ret = switch_connect(c->sw, xsg, dma);
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
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
for (int i = 0; i < 6; i++)
2016-06-19 19:23:19 +02:00
err += abs(factor * src[i] - dst[i]);
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-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, dma, xsg);
if (ret)
error("Failed to configure switch");
2017-03-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, xsg, dma);
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-06-19 19:23:19 +02:00
return err > 1e-3;
2016-06-14 01:19:17 +02:00
}
2017-03-03 20:21:33 -04:00
int fpga_test_hls_dft(struct fpga_card *c)
{
int ret;
2017-02-18 10:43:58 -05:00
struct fpga_ip *hls, *rtds;
2017-03-03 20:21:33 -04:00
rtds = fpga_vlnv_lookup(&c->ips, &(struct fpga_vlnv) { "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL });
hls = fpga_vlnv_lookup(&c->ips, &(struct fpga_vlnv) { NULL, "hls", "hls_dft", NULL });
/* Check if required IP is available on FPGA */
if (!hls || !rtds)
return -1;
2017-03-03 20:21:33 -04:00
ret = intc_enable(c->intc, (1 << rtds->irq), 0);
if (ret)
error("Failed to enable interrupt");
2017-03-03 20:21:33 -04:00
ret = switch_connect(c->sw, rtds, hls);
if (ret)
error("Failed to configure switch");
2017-03-03 20:21:33 -04:00
ret = switch_connect(c->sw, hls, rtds);
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
2017-03-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, rtds, hls);
if (ret)
error("Failed to configure switch");
2017-03-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, hls, rtds);
if (ret)
error("Failed to configure switch");
return 0;
}
2017-03-03 20:21:33 -04:00
int fpga_test_fifo(struct fpga_card *c)
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-03 20:21:33 -04:00
fifo = fpga_vlnv_lookup(&c->ips, &(struct fpga_vlnv) { "xilinx.com", "ip", "axi_fifo_mm_s", NULL });
if (!fifo)
return -1;
2017-03-03 20:21:33 -04:00
ret = intc_enable(c->intc, (1 << fifo->irq), 0);
if (ret)
error("Failed to enable interrupt");
2017-03-03 20:21:33 -04:00
ret = switch_connect(c->sw, fifo, fifo);
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));
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-03 20:21:33 -04:00
ret = intc_disable(c->intc, (1 << fifo->irq));
if (ret)
error("Failed to disable interrupt");
2017-03-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, fifo, fifo);
if (ret)
error("Failed to configure switch");
2016-06-14 01:19:17 +02:00
/* Compare data */
return memcmp(src, dst, sizeof(src));
}
2017-03-03 20:21:33 -04:00
int fpga_test_dma(struct fpga_card *c)
2016-06-14 01:19:17 +02:00
{
int ret = -1;
2016-07-08 13:31:46 +02:00
struct dma_mem mem, src, dst;
2017-03-03 20:21:33 -04:00
list_foreach(struct fpga_ip *dma, &c->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 */
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);
if (ret)
return -1;
ret = dma_mem_split(&mem, &src, &dst);
if (ret)
return -1;
/* Get new random data */
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-19 19:23:19 +02:00
int irq_mm2s = dma->irq;
int irq_s2mm = dma->irq + 1;
2017-03-03 20:21:33 -04:00
ret = intc_enable(c->intc, (1 << irq_mm2s) | (1 << irq_s2mm), 0);
if (ret)
error("Failed to enable interrupt");
2016-06-14 01:19:17 +02:00
2017-03-03 20:21:33 -04:00
ret = switch_connect(c->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
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-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, dma, dma);
if (ret)
error("Failed to configure switch");
2017-03-03 20:21:33 -04:00
ret = intc_disable(c->intc, (1 << irq_mm2s) | (1 << irq_s2mm));
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-06-19 19:23:19 +02:00
return ret;
2016-06-14 01:19:17 +02:00
}
2017-03-03 20:21:33 -04:00
int fpga_test_timer(struct fpga_card *c)
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-03 20:21:33 -04:00
tmr = fpga_vlnv_lookup(&c->ips, &(struct fpga_vlnv) { "xilinx.com", "ip", "axi_timer", NULL });
if (!tmr)
return -1;
XTmrCtr *xtmr = &tmr->timer.inst;
2017-03-03 20:21:33 -04:00
ret = intc_enable(c->intc, (1 << tmr->irq), 0);
if (ret)
error("Failed to enable interrupt");
2016-06-14 01:19:17 +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);
XTmrCtr_Start(xtmr, 0);
2016-06-14 01:19:17 +02:00
2017-03-03 20:21:33 -04:00
uint64_t counter = intc_wait(c->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)
return 0;
else
warn("Counter was not 1");
2016-06-14 01:19:17 +02:00
2017-03-03 20:21:33 -04:00
intc_disable(c->intc, (1 << tmr->irq));
if (ret)
error("Failed to disable interrupt");
2016-06-14 01:19:17 +02:00
return -1;
}
2017-03-03 20:21:33 -04:00
int fpga_test_rtds_rtt(struct fpga_card *c)
2016-06-14 01:19:17 +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-03 20:21:33 -04:00
rtds = fpga_vlnv_lookup(&c->ips, &(struct fpga_vlnv) { "acs.eonerc.rwth-aachen.de", "user", "rtds_axis", NULL });
dma = list_lookup(&c->ips, "dma_1");
2016-06-14 01:19:17 +02:00
/* Check if required IP is available on FPGA */
if (!dma || !rtds)
return -1;
2016-06-14 01:19:17 +02:00
2017-03-03 20:21:33 -04:00
ret = switch_connect(c->sw, rtds, dma);
if (ret)
error("Failed to configure switch");
2017-03-03 20:21:33 -04:00
ret = switch_connect(c->sw, dma, rtds);
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);
if (ret)
error("Failed to start DMA read: %d", ret);
2016-06-14 01:19:17 +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);
if (ret)
error("Failed to start DMA write: %d", ret);
2016-06-14 01:19:17 +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-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, rtds, dma);
if (ret)
error("Failed to configure switch");
2017-03-03 20:21:33 -04:00
ret = switch_disconnect(c->sw, dma, rtds);
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-14 01:19:17 +02:00
return 0;
}