From 6796460dfaf70659b971e89a00ea56f848ac6f1d Mon Sep 17 00:00:00 2001 From: Al Grant Date: Fri, 21 Jul 2023 14:21:05 +0000 Subject: [PATCH] cs_ela_get/set_trigconf overlooked COUNTCOMP. Now fixed. --- include/cs_ela.h | 11 +++++++++-- source/cs_ela.c | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/cs_ela.h b/include/cs_ela.h index b35dca4..fd00cb3 100644 --- a/include/cs_ela.h +++ b/include/cs_ela.h @@ -145,11 +145,12 @@ typedef struct { /** ELA current state - can be read while ELA is active. + The registers are sampled synchronously. */ typedef struct { unsigned int active:1; /**< True if ELA is active */ - uint32_t trigger_state; /**< Current trigger state */ - uint32_t counter; /**< Current value of the counter */ + uint32_t trigger_state; /**< Current trigger state (one-hot encoded) */ + uint32_t counter; /**< Current value of the counter for this trigger state */ uint32_t action; /**< Current action */ } cs_ela_state_t; @@ -180,6 +181,12 @@ unsigned int cs_ela_record_type(cs_ela_record_t const *); uint64_t cs_ela_record_timestamp(cs_ela_record_t const *); +/** + Get the log2 of a one-hot value. Return -1 if zero or other not one-hot value. + */ +int cs_ela_log2(uint32_t); + + /** Clear a signal buffer to zeroes. */ diff --git a/source/cs_ela.c b/source/cs_ela.c index 27ec5f2..931986a 100644 --- a/source/cs_ela.c +++ b/source/cs_ela.c @@ -216,6 +216,7 @@ int cs_ela_get_trigconf(cs_device_t dev, unsigned int ts, cs_ela_trigconf_t *tc) } tc->external_mask = _cs_read(d, CS_ELA_EXTMASK(ts)); tc->external_value = _cs_read(d, CS_ELA_EXTCOMP(ts)); + tc->counter_compare = _cs_read(d, CS_ELA_COUNTCOMP(ts)); if (ela_is_600(d)) { tc->comp_control = _cs_read(d, CS_ELA_COMPCTRL(ts)); tc->alt_comp_control = _cs_read(d, CS_ELA_ALTCOMPCTRL(ts)); @@ -247,6 +248,19 @@ static int __attribute__((unused)) is_one_hot(uint32_t n) } +int cs_ela_log2(uint32_t x) +{ + int p = 0; + if (!is_one_hot(x)) { + return -1; + } + while (x != 1) { + ++p; + x >>= 1; + } + return p; +} + int cs_ela_init_trigconf(cs_device_t dev, cs_ela_trigconf_t *tc) { @@ -297,6 +311,7 @@ int cs_ela_set_trigconf(cs_device_t dev, unsigned int ts, cs_ela_trigconf_t cons } _cs_write(d, CS_ELA_EXTMASK(ts), tc->external_mask); _cs_write(d, CS_ELA_EXTCOMP(ts), tc->external_value); + _cs_write(d, CS_ELA_COUNTCOMP(ts), tc->counter_compare); write_regs(d, CS_ELA_SIGMASK(ts), d->v.ela.comp_width/32, tc->compare_mask.v.words); write_regs(d, CS_ELA_SIGCOMP(ts), d->v.ela.comp_width/32, tc->compare_value.v.words); return 0;