Skip to content
Snippets Groups Projects
Commit 3b402e79 authored by BRONES Romain's avatar BRONES Romain
Browse files

feat(archiver): test application archiver

parent e49b2cda
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <unistd.h>
#include <poll.h>
#include <sys/mman.h>
#include <stdint.h>
#include <fcntl.h>
int main(){
int fd_ddr, fd_ddr_ro; // File descriptors for DDR4
int fd_dst; // File descriptor for destination
unsigned int fcnt=0; // Binary file counter
int rp;
ssize_t s_wr;
const uint32_t unmask = 1;
uint32_t info;
char fname[128];
char *src;
struct pollfd pfd;
// Open file descriptor for DDR4
fd_ddr = open("/dev/ddr4", O_RDWR);
fd_ddr_ro = open("/dev/ddr4", O_RDONLY);
if (fd_ddr <= 0 || fd_ddr_ro <= 0) {
fprintf(stderr, "Failed to open UIO device.\n");
return -1;
};
pfd.fd = fd_ddr;
pfd.events = POLLIN;
// Open MMAP for DDR4
src = mmap(NULL, 0x20000000, PROT_READ, MAP_SHARED, fd_ddr_ro, 0);
// Open destination file
snprintf(fname, 128, "/mnt/data/archiver/file_%08d.bin", fcnt);
fd_dst = creat(fname, 0);
if (fd_dst <= 0) {
fprintf(stderr, "Failed to open destination file '%s'.\n", fname);
return -2;
};
// Unmask interrupt
s_wr = write(fd_ddr, &unmask, sizeof(unmask));
if (s_wr != (ssize_t)sizeof(unmask)) {
fprintf(stderr, "Error when unmasking interrupt !\n");
return -3;
};
// Wait for interrupt
fprintf(stdout, "Waiting for interrupt...");
rp = poll(&pfd, 1, -1); // Timeout = -1, infinite wait
if (rp >= 1) {
read(fd_ddr, &info, sizeof(info));
fprintf(stdout, "Read %d interrupts\n", info);
} else if (rp == 0) {
fprintf(stderr, "Wait for IRQ interrupted, timeout or signal.\n");
return -4;
} else {
fprintf(stderr, "Failed poll.\n");
return -5;
//fprintf(stderr, "Failed poll. Relaunch for next iteration.\n");
//continue;
};
// Copy data
s_wr = write(fd_dst, &src, 0x1000);
if (s_wr < 0x1000) {
fprintf(stderr, "Error while writing to file '%s'.\n", fname);
}
close(fd_dst);
return 0;
}
......@@ -5,19 +5,19 @@ LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda
inherit pkgconfig
SRC_URI = "file://testread.cpp"
SRC_URI = "file://archiver.c"
S = "${WORKDIR}"
DEPENDS = "deviceaccess"
DEPENDS = ""
do_compile() {
${CXX} `pkg-config ChimeraTK-DeviceAccess --cflags --libs` testread.cpp -o testread
${CC} -O archiver.c -o archiver
}
do_install() {
install -d ${D}/${bindir}/
install -m 0755 testread ${D}/${bindir}
install -m 0755 archiver ${D}/${bindir}
}
INSANE_SKIP_${PN} = "ldflags"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment