Skip to content

Commit

Permalink
cs_ela_get/set_trigconf overlooked COUNTCOMP. Now fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
algrant-arm committed Jul 21, 2023
1 parent 707c199 commit 6796460
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 9 additions & 2 deletions include/cs_ela.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*/
Expand Down
15 changes: 15 additions & 0 deletions source/cs_ela.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6796460

Please sign in to comment.