2018-01-09 16:37:02 +01:00
|
|
|
/** FIFO related helper functions
|
|
|
|
*
|
|
|
|
* These functions present a simpler interface to Xilinx' FIFO driver (XLlFifo_*)
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @author Daniel Krebs <github@daniel-krebs.net>
|
|
|
|
* @copyright 2017, Steffen Vogel
|
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASfpga
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <xilinx/xstatus.h>
|
|
|
|
#include <xilinx/xllfifo.h>
|
|
|
|
|
|
|
|
#include "log.hpp"
|
|
|
|
#include "fpga/ips/fifo.hpp"
|
|
|
|
#include "fpga/ips/intc.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace fpga {
|
|
|
|
namespace ip {
|
|
|
|
|
|
|
|
// instantiate factory to make available to plugin infrastructure
|
|
|
|
static FifoFactory factory;
|
|
|
|
|
|
|
|
bool
|
|
|
|
FifoFactory::configureJson(IpCore &ip, json_t *json_ip)
|
|
|
|
{
|
2018-01-10 15:26:52 +01:00
|
|
|
auto logger = getLogger();
|
|
|
|
|
2018-01-09 16:37:02 +01:00
|
|
|
if(not IpNodeFactory::configureJson(ip, json_ip)) {
|
2018-01-10 15:26:52 +01:00
|
|
|
logger->error("Configuring IpNode failed");
|
2018-01-09 16:37:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-16 14:46:00 +01:00
|
|
|
bool Fifo::init()
|
2018-01-09 16:37:02 +01:00
|
|
|
{
|
2018-02-13 14:13:14 +01:00
|
|
|
auto logger = getLogger();
|
|
|
|
|
2018-01-09 16:37:02 +01:00
|
|
|
XLlFifo_Config fifo_cfg;
|
|
|
|
|
2018-02-13 14:13:14 +01:00
|
|
|
fifo_cfg.Axi4BaseAddress = getBaseAddr(axi4Memory);
|
2018-01-09 16:37:02 +01:00
|
|
|
|
|
|
|
// use AXI4 for Data, AXI4-Lite for control
|
2018-02-13 14:13:14 +01:00
|
|
|
fifo_cfg.Datainterface = (fifo_cfg.Axi4BaseAddress != -1) ? 1 : 0;
|
2018-01-09 16:37:02 +01:00
|
|
|
|
2018-02-13 14:13:14 +01:00
|
|
|
if (XLlFifo_CfgInitialize(&xFifo, &fifo_cfg, getBaseAddr(registerMemory)) != XST_SUCCESS)
|
2018-01-09 16:37:02 +01:00
|
|
|
return false;
|
|
|
|
|
2018-02-13 14:13:14 +01:00
|
|
|
if(irqs.find(irqName) == irqs.end()) {
|
|
|
|
logger->error("IRQ '{}' not found but required", irqName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-09 16:37:02 +01:00
|
|
|
// Receive complete IRQ
|
|
|
|
XLlFifo_IntEnable(&xFifo, XLLF_INT_RC_MASK);
|
2018-02-13 14:13:14 +01:00
|
|
|
irqs[irqName].irqController->enableInterrupt(irqs[irqName], false);
|
2018-01-09 16:37:02 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Fifo::stop()
|
|
|
|
{
|
|
|
|
// Receive complete IRQ
|
|
|
|
XLlFifo_IntDisable(&xFifo, XLLF_INT_RC_MASK);
|
2018-02-13 14:13:14 +01:00
|
|
|
irqs[irqName].irqController->disableInterrupt(irqs[irqName]);
|
2018-01-09 16:37:02 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Fifo::write(const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t tdfv;
|
|
|
|
|
|
|
|
tdfv = XLlFifo_TxVacancy(&xFifo);
|
|
|
|
if (tdfv < len)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// buf has to be re-casted because Xilinx driver doesn't use const
|
|
|
|
XLlFifo_Write(&xFifo, (void*) buf, len);
|
|
|
|
XLlFifo_TxSetLen(&xFifo, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Fifo::read(void *buf, size_t len)
|
|
|
|
{
|
|
|
|
size_t nextlen = 0;
|
2018-01-10 15:45:24 +01:00
|
|
|
size_t rxlen;
|
2018-01-09 16:37:02 +01:00
|
|
|
|
|
|
|
while (!XLlFifo_IsRxDone(&xFifo))
|
2018-02-13 14:13:14 +01:00
|
|
|
irqs[irqName].irqController->waitForInterrupt(irqs[irqName]);
|
2018-01-09 16:37:02 +01:00
|
|
|
|
|
|
|
XLlFifo_IntClear(&xFifo, XLLF_INT_RC_MASK);
|
|
|
|
|
|
|
|
/* Get length of next frame */
|
|
|
|
rxlen = XLlFifo_RxGetLen(&xFifo);
|
2018-01-10 15:45:24 +01:00
|
|
|
nextlen = std::min(rxlen, len);
|
2018-01-09 16:37:02 +01:00
|
|
|
|
|
|
|
/* Read from FIFO */
|
|
|
|
XLlFifo_Read(&xFifo, buf, nextlen);
|
|
|
|
|
|
|
|
return nextlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
|
|
|
|
ssize_t fifo_write(struct fpga_ip *c, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct fifo *fifo = (struct fifo *) c->_vd;
|
|
|
|
|
|
|
|
XLlFifo *xllfifo = &fifo->inst;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t fifo_read(struct fpga_ip *c, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct fifo *fifo = (struct fifo *) c->_vd;
|
|
|
|
|
|
|
|
XLlFifo *xllfifo = &fifo->inst;
|
|
|
|
|
|
|
|
size_t nextlen = 0;
|
|
|
|
uint32_t rxlen;
|
|
|
|
|
|
|
|
while (!XLlFifo_IsRxDone(xllfifo))
|
|
|
|
intc_wait(c->card->intc, c->irq);
|
|
|
|
XLlFifo_IntClear(xllfifo, XLLF_INT_RC_MASK);
|
|
|
|
|
|
|
|
/* Get length of next frame */
|
|
|
|
rxlen = XLlFifo_RxGetLen(xllfifo);
|
|
|
|
nextlen = MIN(rxlen, len);
|
|
|
|
|
|
|
|
/* Read from FIFO */
|
|
|
|
XLlFifo_Read(xllfifo, buf, nextlen);
|
|
|
|
|
|
|
|
return nextlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fifo_parse(struct fpga_ip *c, json_t *cfg)
|
|
|
|
{
|
|
|
|
struct fifo *fifo = (struct fifo *) c->_vd;
|
|
|
|
|
|
|
|
int baseaddr_axi4 = -1, ret;
|
|
|
|
|
|
|
|
json_error_t err;
|
|
|
|
|
|
|
|
fifo->baseaddr_axi4 = -1;
|
|
|
|
|
|
|
|
ret = json_unpack_ex(cfg, &err, 0, "{ s?: i }", "baseaddr_axi4", &baseaddr_axi4);
|
|
|
|
if (ret)
|
|
|
|
jerror(&err, "Failed to parse configuration of FPGA IP '%s'", c->name);
|
|
|
|
|
|
|
|
fifo->baseaddr_axi4 = baseaddr_axi4;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fifo_reset(struct fpga_ip *c)
|
|
|
|
{
|
|
|
|
struct fifo *fifo = (struct fifo *) c->_vd;
|
|
|
|
|
|
|
|
XLlFifo_Reset(&fifo->inst);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // namespace ip
|
|
|
|
} // namespace fpga
|
|
|
|
} // namespace villas
|