1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/lib/fpga/ips/fifo.c

132 lines
2.7 KiB
C
Raw Permalink Normal View History

2016-06-14 01:19:17 +02:00
/** FIFO related helper functions
*
* These functions present a simpler interface to Xilinx' FIFO driver (XLlFifo_*)
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Steffen Vogel
2016-06-14 01:19:17 +02:00
**********************************************************************************/
#include <unistd.h>
#include "utils.h"
#include "plugin.h"
2016-06-19 19:23:19 +02:00
#include "fpga/ip.h"
2017-02-18 10:43:58 -05:00
#include "fpga/card.h"
#include "fpga/ips/fifo.h"
#include "fpga/ips/intc.h"
2016-06-14 01:19:17 +02:00
int fifo_start(struct fpga_ip *c)
2016-06-14 01:19:17 +02:00
{
int ret;
2017-02-18 10:43:58 -05:00
struct fpga_card *f = c->card;
2017-03-27 12:58:40 +02:00
struct fifo *fifo = c->_vd;
2017-02-18 10:43:58 -05:00
XLlFifo *xfifo = &fifo->inst;
2016-06-14 01:19:17 +02:00
XLlFifo_Config fifo_cfg = {
2017-02-18 10:43:58 -05:00
.BaseAddress = (uintptr_t) f->map + c->baseaddr,
.Axi4BaseAddress = (uintptr_t) c->card->map + fifo->baseaddr_axi4,
.Datainterface = (fifo->baseaddr_axi4 != -1) ? 1 : 0 /* use AXI4 for Data, AXI4-Lite for control */
2016-06-14 01:19:17 +02:00
};
ret = XLlFifo_CfgInitialize(xfifo, &fifo_cfg, (uintptr_t) c->card->map + c->baseaddr);
2016-06-14 01:19:17 +02:00
if (ret != XST_SUCCESS)
return -1;
XLlFifo_IntEnable(xfifo, XLLF_INT_RC_MASK); /* Receive complete IRQ */
2016-06-14 01:19:17 +02:00
return 0;
}
int fifo_stop(struct fpga_ip *c)
{
2017-03-27 12:58:40 +02:00
struct fifo *fifo = c->_vd;
XLlFifo *xfifo = &fifo->inst;
XLlFifo_IntDisable(xfifo, XLLF_INT_RC_MASK); /* Receive complete IRQ */
return 0;
}
2017-02-18 10:43:58 -05:00
ssize_t fifo_write(struct fpga_ip *c, char *buf, size_t len)
2016-06-14 01:19:17 +02:00
{
2017-03-27 12:58:40 +02:00
struct fifo *fifo = c->_vd;
XLlFifo *xllfifo = &fifo->inst;
uint32_t tdfv;
tdfv = XLlFifo_TxVacancy(xllfifo);
if (tdfv < len)
return -1;
2016-06-19 19:23:19 +02:00
XLlFifo_Write(xllfifo, buf, len);
XLlFifo_TxSetLen(xllfifo, len);
2016-06-14 01:19:17 +02:00
return len;
}
2017-02-18 10:43:58 -05:00
ssize_t fifo_read(struct fpga_ip *c, char *buf, size_t len)
2016-06-14 01:19:17 +02:00
{
2017-03-27 12:58:40 +02:00
struct fifo *fifo = c->_vd;
XLlFifo *xllfifo = &fifo->inst;
2016-06-19 19:23:19 +02:00
2016-06-14 01:19:17 +02:00
size_t nextlen = 0;
2016-07-08 13:32:18 +02:00
uint32_t rxlen;
2016-06-14 01:19:17 +02:00
while (!XLlFifo_IsRxDone(xllfifo))
2016-07-08 13:32:18 +02:00
intc_wait(c->card->intc, c->irq);
XLlFifo_IntClear(xllfifo, XLLF_INT_RC_MASK);
2016-06-14 01:19:17 +02:00
/* Get length of next frame */
rxlen = XLlFifo_RxGetLen(xllfifo);
nextlen = MIN(rxlen, len);
2016-06-14 01:19:17 +02:00
/* Read from FIFO */
XLlFifo_Read(xllfifo, buf, nextlen);
2016-06-14 01:19:17 +02:00
return nextlen;
}
2017-02-18 10:43:58 -05:00
int fifo_parse(struct fpga_ip *c)
{
2017-03-27 12:58:40 +02:00
struct fifo *fifo = c->_vd;
int baseaddr_axi4;
if (config_setting_lookup_int(c->cfg, "baseaddr_axi4", &baseaddr_axi4))
fifo->baseaddr_axi4 = baseaddr_axi4;
else
fifo->baseaddr_axi4 = -1;
return 0;
}
2017-02-18 10:43:58 -05:00
int fifo_reset(struct fpga_ip *c)
2016-07-08 13:32:18 +02:00
{
2017-03-27 12:58:40 +02:00
struct fifo *fifo = c->_vd;
XLlFifo_Reset(&fifo->inst);
2016-07-08 13:32:18 +02:00
return 0;
}
static struct plugin p = {
.name = "Xilinx's AXI4 FIFO data mover",
.description = "",
.type = PLUGIN_TYPE_FPGA_IP,
.ip = {
2017-02-18 10:43:58 -05:00
.vlnv = { "xilinx.com", "ip", "axi_fifo_mm_s", NULL },
.type = FPGA_IP_TYPE_DM_FIFO,
.start = fifo_start,
.stop = fifo_stop,
2017-02-18 10:43:58 -05:00
.parse = fifo_parse,
.reset = fifo_reset,
.size = sizeof(struct fifo)
}
};
REGISTER_PLUGIN(&p)