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/src/fpga.c

104 lines
2 KiB
C
Raw Normal View History

2016-06-14 01:19:17 +02:00
/** VILLASfpga utility for tests and benchmarks
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Steffen Vogel
2016-06-14 01:19:17 +02:00
**********************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
2016-06-14 01:19:17 +02:00
#include <getopt.h>
#include <villas/log.h>
#include <villas/cfg.h>
2016-06-14 01:19:17 +02:00
#include <villas/timing.h>
#include <villas/utils.h>
2016-06-19 19:23:19 +02:00
#include <villas/nodes/fpga.h>
#include <villas/kernel/rt.h>
2016-06-14 01:19:17 +02:00
#include <villas/kernel/pci.h>
#include <villas/kernel/kernel.h>
2017-03-03 20:21:33 -04:00
#include <villas/fpga/card.h>
2016-06-14 01:19:17 +02:00
#include "config.h"
/* Declarations */
2017-03-03 20:21:33 -04:00
int fpga_benchmarks(int argc, char *argv[], struct fpga_card *c);
2017-03-03 20:21:33 -04:00
struct cfg cfg;
2016-06-14 01:19:17 +02:00
void usage(char *name)
{
2017-03-03 20:21:33 -04:00
printf("Usage: %s CONFIGFILE CARD CMD [OPTIONS]\n", name);
printf(" Commands:\n");
printf(" benchmarks Do benchmarks\n\n");
printf(" Options:\n");
printf(" -d Set log level\n\n");
print_copyright();
exit(EXIT_FAILURE);
2016-06-14 01:19:17 +02:00
}
int main(int argc, char *argv[])
{
int ret;
2017-03-03 20:21:33 -04:00
struct fpga_card *card;
enum {
FPGA_BENCH
} subcommand;
2017-03-03 20:21:33 -04:00
if (argc < 4)
usage(argv[0]);
if (strcmp(argv[2], "benchmarks") == 0)
subcommand = FPGA_BENCH;
else
usage(argv[0]);
2016-06-14 01:19:17 +02:00
/* Parse arguments */
char c, *endptr;
while ((c = getopt(argc-1, argv+1, "d:")) != -1) {
2016-06-14 01:19:17 +02:00
switch (c) {
case 'd':
2017-03-03 20:21:33 -04:00
cfg.log.level = strtoul(optarg, &endptr, 10);
2016-06-14 01:19:17 +02:00
break;
case '?':
default:
usage(argv[0]);
}
}
info("Parsing configuration");
2017-03-03 20:21:33 -04:00
cfg_parse(&cfg, argv[1]);
info("Initialize real-time system");
2017-03-03 20:21:33 -04:00
rt_init(&cfg);
/* Initialize VILLASfpga card */
2017-03-03 20:21:33 -04:00
ret = fpga_init(argc, argv, config_root_setting(cfg.cfg));
2016-06-14 01:19:17 +02:00
if (ret)
error("Failed to initialize FPGA card");
2017-03-03 20:21:33 -04:00
card = fpga_lookup_card(argv[2]);
if (!card)
error("FPGA card '%s' does not exist", argv[2]);
fpga_card_dump(card);
2016-06-14 01:19:17 +02:00
/* Start subcommand */
switch (subcommand) {
2017-03-03 20:21:33 -04:00
case FPGA_BENCH: fpga_benchmarks(argc-optind-1, argv+optind+1, card); break;
}
2016-06-14 01:19:17 +02:00
/* Shutdown */
2017-03-03 20:21:33 -04:00
ret = fpga_deinit();
2016-06-14 01:19:17 +02:00
if (ret)
2017-03-03 20:21:33 -04:00
error("Failed to de-initialize FPGA card");
2017-03-03 20:21:33 -04:00
cfg_destroy(&cfg);
2016-06-14 01:19:17 +02:00
return 0;
}