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

106 lines
2.3 KiB
C
Raw 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 2015-2016, Steffen Vogel
* This file is part of VILLASfpga. All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited.
**********************************************************************************/
#include <unistd.h>
#include <villas/utils.h>
#include "utils.h"
2016-06-19 19:23:19 +02:00
#include "fpga/ip.h"
2016-06-14 01:19:17 +02:00
#include "fpga/fifo.h"
2016-06-19 19:23:19 +02:00
#include "fpga/intc.h"
2016-06-14 01:19:17 +02:00
2016-06-19 19:23:19 +02:00
int fifo_init(struct ip *c)
2016-06-14 01:19:17 +02:00
{
struct fifo *fifo = &c->fifo;
XLlFifo *xfifo = &fifo->inst;
2016-06-19 19:23:19 +02:00
2016-06-14 01:19:17 +02:00
int ret;
XLlFifo_Config fifo_cfg = {
2016-06-19 19:23:19 +02:00
.BaseAddress = (uintptr_t) c->card->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;
}
2016-06-19 19:23:19 +02:00
ssize_t fifo_write(struct ip *c, char *buf, size_t len)
2016-06-14 01:19:17 +02:00
{
XLlFifo *fifo = &c->fifo.inst;
uint32_t tdfv;
tdfv = XLlFifo_TxVacancy(fifo);
if (tdfv < len)
return -1;
2016-06-19 19:23:19 +02:00
2016-06-14 01:19:17 +02:00
XLlFifo_Write(fifo, buf, len);
XLlFifo_TxSetLen(fifo, len);
return len;
}
2016-06-19 19:23:19 +02:00
ssize_t fifo_read(struct ip *c, char *buf, size_t len)
2016-06-14 01:19:17 +02:00
{
XLlFifo *fifo = &c->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
2016-07-08 13:32:18 +02:00
while (!XLlFifo_IsRxDone(fifo))
intc_wait(c->card->intc, c->irq);
XLlFifo_IntClear(fifo, XLLF_INT_RC_MASK);
2016-06-14 01:19:17 +02:00
/* Get length of next frame */
rxlen = XLlFifo_RxGetLen(fifo);
nextlen = MIN(rxlen, len);
2016-06-14 01:19:17 +02:00
/* Read from FIFO */
XLlFifo_Read(fifo, buf, nextlen);
return nextlen;
}
int fifo_parse(struct ip *c)
{
struct fifo *fifo = &c->fifo;
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;
}
2016-07-08 13:32:18 +02:00
int fifo_reset(struct ip *c)
{
XLlFifo_Reset(&c->fifo.inst);
return 0;
}
static struct ip_type ip = {
.vlnv = { "xilinx.com", "ip", "axi_fifo_mm_s", NULL },
.init = fifo_init,
2016-07-08 13:32:18 +02:00
.parse = fifo_parse,
.reset = fifo_reset
};
REGISTER_IP_TYPE(&ip)