From: Uwe Hermann Date: Tue, 22 Feb 2011 16:57:03 +0000 (+0100) Subject: Add SR_ prefix to the KHZ/MHZ/GHZ macros. X-Git-Tag: libsigrok-0.1.0~313 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=59df0c77e2906323290544ea62801831818ec096;p=libsigrok.git Add SR_ prefix to the KHZ/MHZ/GHZ macros. --- diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index bc36764e..61e926ea 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -43,22 +43,22 @@ static GSList *device_instances = NULL; static uint64_t supported_samplerates[] = { - KHZ(200), - KHZ(250), - KHZ(500), - MHZ(1), - MHZ(5), - MHZ(10), - MHZ(25), - MHZ(50), - MHZ(100), - MHZ(200), + SR_KHZ(200), + SR_KHZ(250), + SR_KHZ(500), + SR_MHZ(1), + SR_MHZ(5), + SR_MHZ(10), + SR_MHZ(25), + SR_MHZ(50), + SR_MHZ(100), + SR_MHZ(200), 0, }; static struct sr_samplerates samplerates = { - KHZ(200), - MHZ(200), + SR_KHZ(200), + SR_MHZ(200), 0, supported_samplerates, }; @@ -561,15 +561,15 @@ static int set_samplerate(struct sr_device_instance *sdi, if (supported_samplerates[i] == 0) return SR_ERR_SAMPLERATE; - if (samplerate <= MHZ(50)) { + if (samplerate <= SR_MHZ(50)) { ret = upload_firmware(0, sigma); sigma->num_probes = 16; } - if (samplerate == MHZ(100)) { + if (samplerate == SR_MHZ(100)) { ret = upload_firmware(1, sigma); sigma->num_probes = 8; } - else if (samplerate == MHZ(200)) { + else if (samplerate == SR_MHZ(200)) { ret = upload_firmware(2, sigma); sigma->num_probes = 4; } @@ -608,7 +608,7 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) if (!probe->enabled || !probe->trigger) continue; - if (sigma->cur_samplerate >= MHZ(100)) { + if (sigma->cur_samplerate >= SR_MHZ(100)) { /* Fast trigger support. */ if (trigger_set) { g_warning("Asix Sigma only supports a single " @@ -839,7 +839,7 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, /* Check if trigger is in this chunk. */ if (triggerpos != -1) { - if (sigma->cur_samplerate <= MHZ(50)) + if (sigma->cur_samplerate <= SR_MHZ(50)) triggerpos -= EVENTS_PER_CLUSTER - 1; if (triggerpos < 0) @@ -1220,13 +1220,13 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) /* If the samplerate has not been set, default to 200 KHz. */ if (sigma->cur_firmware == -1) - set_samplerate(sdi, KHZ(200)); + set_samplerate(sdi, SR_KHZ(200)); /* Enter trigger programming mode. */ sigma_set_register(WRITE_TRIGGER_SELECT1, 0x20, sigma); /* 100 and 200 MHz mode. */ - if (sigma->cur_samplerate >= MHZ(100)) { + if (sigma->cur_samplerate >= SR_MHZ(100)) { sigma_set_register(WRITE_TRIGGER_SELECT1, 0x81, sigma); /* Find which pin to trigger on from mask. */ @@ -1243,7 +1243,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) triggerselect |= 1 << 3; /* All other modes. */ - } else if (sigma->cur_samplerate <= MHZ(50)) { + } else if (sigma->cur_samplerate <= SR_MHZ(50)) { build_basic_trigger(&lut, sigma); sigma_write_trigger_lut(&lut, sigma); @@ -1264,10 +1264,10 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) sigma_set_register(WRITE_TRIGGER_SELECT1, triggerselect, sigma); /* Set clock select register. */ - if (sigma->cur_samplerate == MHZ(200)) + if (sigma->cur_samplerate == SR_MHZ(200)) /* Enable 4 probes. */ sigma_set_register(WRITE_CLOCK_SELECT, 0xf0, sigma); - else if (sigma->cur_samplerate == MHZ(100)) + else if (sigma->cur_samplerate == SR_MHZ(100)) /* Enable 8 probes. */ sigma_set_register(WRITE_CLOCK_SELECT, 0x00, sigma); else { @@ -1275,7 +1275,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) * 50 MHz mode (or fraction thereof). Any fraction down to * 50 MHz / 256 can be used, but is not supported by sigrok API. */ - frac = MHZ(50) / sigma->cur_samplerate - 1; + frac = SR_MHZ(50) / sigma->cur_samplerate - 1; clockselect.async = 0; clockselect.fraction = frac; diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index c318cb39..2f32b2cd 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -65,7 +65,7 @@ static int capabilities[] = { static struct sr_samplerates samplerates = { 1, - GHZ(1), + SR_GHZ(1), 1, NULL, }; @@ -89,7 +89,7 @@ static uint8_t genmode_default[] = { /* List of struct sr_device_instance, maintained by opendev()/closedev(). */ static GSList *device_instances = NULL; -static uint64_t cur_samplerate = KHZ(200); +static uint64_t cur_samplerate = SR_KHZ(200); static uint64_t limit_samples = 0; static uint64_t limit_msec = 0; static int default_genmode = GENMODE_DEFAULT; diff --git a/hardware/link-mso19/link-mso19.c b/hardware/link-mso19/link-mso19.c index 648fe5bb..3c2be11d 100644 --- a/hardware/link-mso19/link-mso19.c +++ b/hardware/link-mso19/link-mso19.c @@ -47,13 +47,34 @@ static int capabilities[] = { }; static uint64_t supported_samplerates[] = { - 100, 200, 500, KHZ(1), KHZ(2), KHZ(5), KHZ(10), KHZ(20), - KHZ(50), KHZ(100), KHZ(200), KHZ(500), MHZ(1), MHZ(2), MHZ(5), - MHZ(10), MHZ(20), MHZ(50), MHZ(100), MHZ(200), 0 + 100, + 200, + 500, + SR_KHZ(1), + SR_KHZ(2), + SR_KHZ(5), + SR_KHZ(10), + SR_KHZ(20), + SR_KHZ(50), + SR_KHZ(100), + SR_KHZ(200), + SR_KHZ(500), + SR_MHZ(1), + SR_MHZ(2), + SR_MHZ(5), + SR_MHZ(10), + SR_MHZ(20), + SR_MHZ(50), + SR_MHZ(100), + SR_MHZ(200), + 0, }; static struct sr_samplerates samplerates = { - 100, MHZ(200), 0, supported_samplerates, + 100, + SR_MHZ(200), + 0, + supported_samplerates, }; static GSList *device_instances = NULL; @@ -283,7 +304,7 @@ static int mso_configure_trigger(struct sr_device_instance *sdi) ops[2] = mso_trans(3, dso_trigger & 0xff); ops[3] = mso_trans(4, (dso_trigger >> 8) & 0xff); ops[4] = mso_trans(11, - mso->dso_trigger_width / HZ_TO_NS(mso->cur_rate)); + mso->dso_trigger_width / SR_HZ_TO_NS(mso->cur_rate)); ops[5] = mso_trans(15, (2 | mso->slowmode)); /* FIXME SPI/I2C Triggers */ diff --git a/hardware/link-mso19/link-mso19.h b/hardware/link-mso19/link-mso19.h index dddcd852..79078f5d 100644 --- a/hardware/link-mso19/link-mso19.h +++ b/hardware/link-mso19/link-mso19.h @@ -83,23 +83,23 @@ struct rate_map { }; static struct rate_map rate_map[] = { - { MHZ(200), 0x0205, 0 }, - { MHZ(100), 0x0105, 0 }, - { MHZ(50), 0x0005, 0 }, - { MHZ(20), 0x0303, 0 }, - { MHZ(10), 0x0308, 0 }, - { MHZ(5), 0x030c, 0 }, - { MHZ(2), 0x0330, 0 }, - { MHZ(1), 0x0362, 0 }, - { KHZ(500), 0x03c6, 0 }, - { KHZ(200), 0x07f2, 0 }, - { KHZ(100), 0x0fe6, 0 }, - { KHZ(50), 0x1fce, 0 }, - { KHZ(20), 0x4f86, 0 }, - { KHZ(10), 0x9f0e, 0 }, - { KHZ(5), 0x03c7, 0x20 }, - { KHZ(2), 0x07f3, 0x20 }, - { KHZ(1), 0x0fe7, 0x20 }, + { SR_MHZ(200), 0x0205, 0 }, + { SR_MHZ(100), 0x0105, 0 }, + { SR_MHZ(50), 0x0005, 0 }, + { SR_MHZ(20), 0x0303, 0 }, + { SR_MHZ(10), 0x0308, 0 }, + { SR_MHZ(5), 0x030c, 0 }, + { SR_MHZ(2), 0x0330, 0 }, + { SR_MHZ(1), 0x0362, 0 }, + { SR_KHZ(500), 0x03c6, 0 }, + { SR_KHZ(200), 0x07f2, 0 }, + { SR_KHZ(100), 0x0fe6, 0 }, + { SR_KHZ(50), 0x1fce, 0 }, + { SR_KHZ(20), 0x4f86, 0 }, + { SR_KHZ(10), 0x9f0e, 0 }, + { SR_KHZ(5), 0x03c7, 0x20 }, + { SR_KHZ(2), 0x07f3, 0x20 }, + { SR_KHZ(1), 0x0fe7, 0x20 }, { 500, 0x1fcf, 0x20 }, { 200, 0x4f87, 0x20 }, { 100, 0x9f0f, 0x20 }, diff --git a/hardware/openbench-logic-sniffer/ols.c b/hardware/openbench-logic-sniffer/ols.c index d94f7710..8f8f5cb2 100644 --- a/hardware/openbench-logic-sniffer/ols.c +++ b/hardware/openbench-logic-sniffer/ols.c @@ -49,7 +49,7 @@ #define NUM_TRIGGER_STAGES 4 #define TRIGGER_TYPES "01" #define SERIAL_SPEED B115200 -#define CLOCK_RATE MHZ(100) +#define CLOCK_RATE SR_MHZ(100) #define MIN_NUM_SAMPLES 4 /* Command opcodes */ @@ -93,7 +93,7 @@ static int capabilities[] = { static struct sr_samplerates samplerates = { 10, - MHZ(200), + SR_MHZ(200), 1, 0, }; @@ -321,7 +321,7 @@ static int hw_init(const char *deviceinfo) free(serial_params); g_slist_free(ports); - cur_samplerate = KHZ(200); + cur_samplerate = SR_KHZ(200); return final_devcnt; } diff --git a/hardware/saleae-logic/saleae-logic.c b/hardware/saleae-logic/saleae-logic.c index eff4cf9e..23ba69a9 100644 --- a/hardware/saleae-logic/saleae-logic.c +++ b/hardware/saleae-logic/saleae-logic.c @@ -73,22 +73,22 @@ static GTimeVal firmware_updated = { 0, 0 }; static libusb_context *usb_context = NULL; static uint64_t supported_samplerates[] = { - KHZ(200), - KHZ(250), - KHZ(500), - MHZ(1), - MHZ(2), - MHZ(4), - MHZ(8), - MHZ(12), - MHZ(16), - MHZ(24), + SR_KHZ(200), + SR_KHZ(250), + SR_KHZ(500), + SR_MHZ(1), + SR_MHZ(2), + SR_MHZ(4), + SR_MHZ(8), + SR_MHZ(12), + SR_MHZ(16), + SR_MHZ(24), 0, }; static struct sr_samplerates samplerates = { - KHZ(200), - MHZ(24), + SR_KHZ(200), + SR_MHZ(24), 0, supported_samplerates, }; diff --git a/hardware/zeroplus-logic-cube/zeroplus.c b/hardware/zeroplus-logic-cube/zeroplus.c index 8651e779..e9b599b8 100644 --- a/hardware/zeroplus-logic-cube/zeroplus.c +++ b/hardware/zeroplus-logic-cube/zeroplus.c @@ -90,22 +90,22 @@ static libusb_context *usb_context = NULL; static uint64_t supported_samplerates[] = { 100, 500, - KHZ(1), - KHZ(5), - KHZ(25), - KHZ(50), - KHZ(100), - KHZ(200), - KHZ(400), - KHZ(800), - MHZ(1), - MHZ(10), - MHZ(25), - MHZ(50), - MHZ(80), - MHZ(100), - MHZ(150), - MHZ(200), + SR_KHZ(1), + SR_KHZ(5), + SR_KHZ(25), + SR_KHZ(50), + SR_KHZ(100), + SR_KHZ(200), + SR_KHZ(400), + SR_KHZ(800), + SR_MHZ(1), + SR_MHZ(10), + SR_MHZ(25), + SR_MHZ(50), + SR_MHZ(80), + SR_MHZ(100), + SR_MHZ(150), + SR_MHZ(200), 0, }; @@ -445,10 +445,10 @@ static int *hw_get_capabilities(void) static int set_configuration_samplerate(uint64_t samplerate) { g_message("%s(%" PRIu64 ")", __FUNCTION__, samplerate); - if (samplerate > MHZ(1)) - analyzer_set_freq(samplerate / MHZ(1), FREQ_SCALE_MHZ); - else if (samplerate > KHZ(1)) - analyzer_set_freq(samplerate / KHZ(1), FREQ_SCALE_KHZ); + if (samplerate > SR_MHZ(1)) + analyzer_set_freq(samplerate / SR_MHZ(1), FREQ_SCALE_MHZ); + else if (samplerate > SR_KHZ(1)) + analyzer_set_freq(samplerate / SR_KHZ(1), FREQ_SCALE_KHZ); else analyzer_set_freq(samplerate, FREQ_SCALE_HZ); diff --git a/output/output_vcd.c b/output/output_vcd.c index 17505e6a..a61443db 100644 --- a/output/output_vcd.c +++ b/output/output_vcd.c @@ -106,12 +106,12 @@ static int init(struct sr_output *o) /* timescale */ /* VCD can only handle 1/10/100 (s - fs), so scale up first */ - if (ctx->samplerate > MHZ(1)) - ctx->period = GHZ(1); - else if (ctx->samplerate > KHZ(1)) - ctx->period = MHZ(1); + if (ctx->samplerate > SR_MHZ(1)) + ctx->period = SR_GHZ(1); + else if (ctx->samplerate > SR_KHZ(1)) + ctx->period = SR_MHZ(1); else - ctx->period = KHZ(1); + ctx->period = SR_KHZ(1); if (!(frequency_s = sr_period_string(ctx->period))) { g_string_free(ctx->header, TRUE); free(ctx); diff --git a/sigrok.h b/sigrok.h index 2eda97ba..946c5470 100644 --- a/sigrok.h +++ b/sigrok.h @@ -59,11 +59,11 @@ extern "C" { #define SR_MAX_PROBENAME_LEN 32 /* Handy little macros */ -#define KHZ(n) ((n) * 1000) -#define MHZ(n) ((n) * 1000000) -#define GHZ(n) ((n) * 1000000000) +#define SR_KHZ(n) ((n) * 1000) +#define SR_MHZ(n) ((n) * 1000000) +#define SR_GHZ(n) ((n) * 1000000000) -#define HZ_TO_NS(n) (1000000000 / (n)) +#define SR_HZ_TO_NS(n) (1000000000 / (n)) typedef int (*sr_receive_data_callback) (int fd, int revents, void *user_data); diff --git a/strutil.c b/strutil.c index 1c3d023f..e5278dfe 100644 --- a/strutil.c +++ b/strutil.c @@ -41,11 +41,11 @@ char *sr_samplerate_string(uint64_t samplerate) if (!o) return NULL; - if (samplerate >= GHZ(1)) + if (samplerate >= SR_GHZ(1)) r = snprintf(o, 30, "%" PRIu64 " GHz", samplerate / 1000000000); - else if (samplerate >= MHZ(1)) + else if (samplerate >= SR_MHZ(1)) r = snprintf(o, 30, "%" PRIu64 " MHz", samplerate / 1000000); - else if (samplerate >= KHZ(1)) + else if (samplerate >= SR_KHZ(1)) r = snprintf(o, 30, "%" PRIu64 " kHz", samplerate / 1000); else r = snprintf(o, 30, "%" PRIu64 " Hz", samplerate); @@ -78,11 +78,11 @@ char *sr_period_string(uint64_t frequency) if (!o) return NULL; - if (frequency >= GHZ(1)) + if (frequency >= SR_GHZ(1)) r = snprintf(o, 30, "%" PRIu64 " ns", frequency / 1000000000); - else if (frequency >= MHZ(1)) + else if (frequency >= SR_MHZ(1)) r = snprintf(o, 30, "%" PRIu64 " us", frequency / 1000000); - else if (frequency >= KHZ(1)) + else if (frequency >= SR_KHZ(1)) r = snprintf(o, 30, "%" PRIu64 " ms", frequency / 1000); else r = snprintf(o, 30, "%" PRIu64 " s", frequency); @@ -198,15 +198,15 @@ uint64_t sr_parse_sizestring(const char *sizestring) break; case 'k': case 'K': - multiplier = KHZ(1); + multiplier = SR_KHZ(1); break; case 'm': case 'M': - multiplier = MHZ(1); + multiplier = SR_MHZ(1); break; case 'g': case 'G': - multiplier = GHZ(1); + multiplier = SR_GHZ(1); break; default: val = 0;