From 4729d00b30ff7c0224337217f65496c86b8df75d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 16 Jan 2013 03:56:17 -0300 Subject: [PATCH] ubb-patgen/ubb-patgen.c: run at realtime priority while waiting for trigger --- ubb-patgen/ubb-patgen.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ubb-patgen/ubb-patgen.c b/ubb-patgen/ubb-patgen.c index 00d33ac..863d534 100644 --- a/ubb-patgen/ubb-patgen.c +++ b/ubb-patgen/ubb-patgen.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -248,6 +249,36 @@ static const char *load_pattern(const char *s) } +/* ----- Real-time mode ---------------------------------------------------- */ + + +void realtimize(void) +{ + struct sched_param prm; + + prm.sched_priority = sched_get_priority_max(SCHED_FIFO); + if (prm.sched_priority < 0) { + perror("sched_get_priority_max SCHED_FIFO"); + exit(1); + } + if (sched_setscheduler(0, SCHED_FIFO, &prm) < 0) { + perror("sched_setscheduler SCHED_FIFO"); + exit(1); + } +} + + +void unrealtime(void) +{ + struct sched_param prm = { .sched_priority = 0 }; + + if (sched_setscheduler(0, SCHED_OTHER, &prm) < 0) { + perror("sched_setscheduler SCHED_OTHER"); + exit(1); + } +} + + /* ----- DMA control ------------------------------------------------------- */ @@ -409,6 +440,8 @@ static void mmc_buffer(const struct mmcclk *clk, PDFUNS = mask; + realtimize(); + if (trigger != -1) wait_trigger(trigger, debounce, debounce_ns); if (wait_ns->tv_sec || wait_ns->tv_nsec) @@ -425,6 +458,8 @@ static void mmc_buffer(const struct mmcclk *clk, (1 << 31) | /* no descriptor */ 1; /* enable transfer */ + unrealtime(); + wait_dma_done(); wait_fifo_empty(); wait_shifted(clk);