From 5bb086e0e8a535d5ae79a62af62e11512be1ffca Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 31 Jan 2013 00:47:14 -0300 Subject: [PATCH] ubb-la/: display sample rate and sample interval in the GUI --- ubb-la/gui.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- ubb-la/gui.h | 2 +- ubb-la/try.c | 5 +++-- ubb-la/ubb-la.c | 7 ++++--- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/ubb-la/gui.c b/ubb-la/gui.c index 990fafa..d8d538e 100644 --- a/ubb-la/gui.c +++ b/ubb-la/gui.c @@ -35,6 +35,7 @@ #define XRES 320 /* canvas width */ #define YRES 240 /* canvas height */ +#define TEXT_RGBA 0xffffffff /* general text */ #define MAP_BUF_RGBA 0x808080ff /* buffer in the map */ #define MAP_VIEW_RGBA 0xffffffff /* current view in the map */ #define LEVEL_RGBA 0xffff00ff /* constant level or single change */ @@ -55,6 +56,11 @@ #define MAX_ZOOM 3 +#define FREQ_X 0 +#define FREQ_Y 220 +#define INTERVAL_X 0 +#define INTERVAL_Y 230 + #define REPEAT_DELAY_MS 300 #define REPEAT_INTERVAL_MS 30 @@ -297,6 +303,45 @@ static void show_buffer(const uint8_t *buf, int skip, int nibbles, } +/* ----- Display the sample frequency -------------------------------------- */ + + +static void si_text(int x, int y, double v, const char *unit) +{ + const char *pfx; + + if (v >= 1e6) { + v /= 1e6; + pfx = "M"; + } else if (v >= 1e3) { + v /= 1e3; + pfx = "k"; + } else if (v >= 1) { + pfx = " "; + } else if (v >= 1e-3) { + v *= 1e3; + pfx = "m"; + } else if (v >= 1e-6) { + v *= 1e6; + pfx = "u"; + } else { + v *= 1e9; + pfx = "n"; + } + if (v >= 10) + textf(x, y, TEXT_RGBA, "%3d%s%s", (int) (v+0.5), pfx, unit); + else + textf(x, y, TEXT_RGBA, "%3.1f%s%s", v, pfx, unit); +} + + +static void show_freq(double freq) +{ + si_text(FREQ_X, FREQ_Y, freq, "Sa/s"); + si_text(INTERVAL_X, INTERVAL_Y, 1/freq, "s/Sa"); +} + + /* ----- Main event loop --------------------------------------------------- */ @@ -306,7 +351,7 @@ static int pos_step(int zoom) } -void gui(const uint8_t *buf, int skip, int nibbles) +void gui(const uint8_t *buf, int skip, int nibbles, double freq) { SDL_Event event; int pos = (skip+nibbles) >> 1; @@ -322,6 +367,7 @@ void gui(const uint8_t *buf, int skip, int nibbles) for (i = 0; i != 4; i++) textf(0, ch_y(i, 1), LABEL_RGBA, "CH%d", i); show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos); + show_freq(freq); update(); while (1) { diff --git a/ubb-la/gui.h b/ubb-la/gui.h index f3b552a..af977e0 100644 --- a/ubb-la/gui.h +++ b/ubb-la/gui.h @@ -18,6 +18,6 @@ void gui_init(void); -void gui(const uint8_t *buf, int skip, int nibbles); +void gui(const uint8_t *buf, int skip, int nibbles, double freq); #endif /* !GUI_H */ diff --git a/ubb-la/try.c b/ubb-la/try.c index dca868e..131a192 100644 --- a/ubb-la/try.c +++ b/ubb-la/try.c @@ -1,9 +1,10 @@ #include +#include #include "gui.h" -int main(void) +int main(int argc, char **argv) { static uint8_t buf[4000]; int i; @@ -11,6 +12,6 @@ int main(void) for (i = 0; i != 8000; i++) buf[i >> 1] |= (i & 0xf) << 4*(~i & 1); gui_init(); - gui(buf, 0, 8000); + gui(buf, 0, 8000, argv[1] ? atof(argv[1]) : 1e6); return 0; } diff --git a/ubb-la/ubb-la.c b/ubb-la/ubb-la.c index 286a787..6090f29 100644 --- a/ubb-la/ubb-la.c +++ b/ubb-la/ubb-la.c @@ -268,7 +268,8 @@ static void print_samples(FILE *file, uint8_t *buf, int skip, int nibbles) /* ----- Capture ----------------------------------------------------------- */ -static int do_buf(int nibbles, uint32_t trigger, uint32_t mask, int use_gui) +static int do_buf(int nibbles, uint32_t trigger, uint32_t mask, + const struct mmcclk *clk, int use_gui) { uint8_t *buf = physmem_malloc(4096); struct physmem_vec vec; @@ -291,7 +292,7 @@ static int do_buf(int nibbles, uint32_t trigger, uint32_t mask, int use_gui) return 0; if (use_gui) - gui(buf, INITIAL_SKIP, nibbles); + gui(buf, INITIAL_SKIP, nibbles, clk->bus_clk_hz); else print_samples(stdout, buf, INITIAL_SKIP, nibbles); @@ -459,7 +460,7 @@ int main(int argc, char **argv) gui_init(); if (!multi) { - res = !do_buf(8128, trigger, mask, use_gui); + res = !do_buf(8128, trigger, mask, &clk, use_gui); } else { frequency(&fast_clk, 84e6, 1); do_bufs(multi, 8128, &clk, &fast_clk);