diff options
author | Andy Green <andy.green@linaro.org> | 2012-10-22 17:21:48 +0800 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2012-10-22 17:52:04 +0800 |
commit | 8154df94d446ae306384c84f3392a1d6ba970775 (patch) | |
tree | 530eb10b9af2901fbf7cbf42e637c2bbce86c5cb | |
parent | 9ccd7d5f3c7b0597141e41a8f763d358b3198d0a (diff) |
remove capture averaging from library add to arm probe
Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r-- | arm-probe/arm-probe.c | 59 | ||||
-rw-r--r-- | libarmep/aepd-interface.h | 21 | ||||
-rw-r--r-- | libarmep/libarmep.h | 13 | ||||
-rw-r--r-- | libarmep/sample.c | 36 | ||||
-rw-r--r-- | libarmep/service.c | 17 |
5 files changed, 83 insertions, 63 deletions
diff --git a/arm-probe/arm-probe.c b/arm-probe/arm-probe.c index fde030d..e36e23a 100644 --- a/arm-probe/arm-probe.c +++ b/arm-probe/arm-probe.c @@ -120,6 +120,13 @@ int main(int argc, char *argv[]) struct aepd_interface_result *aepd_interface_result; int first = 1; + /* simple stats on what was captured */ + + double averages[AEPD_SHARED_MAX_REAL_CHANNELS][3]; + double min[AEPD_SHARED_MAX_REAL_CHANNELS][3]; + double max[AEPD_SHARED_MAX_REAL_CHANNELS][3]; + double count_post_trigger = 0; + loop = 1; signal(SIGINT, sighandler); @@ -327,6 +334,13 @@ int main(int argc, char *argv[]) printf("#\n"); + for (n = 0; n < AEPD_SHARED_MAX_REAL_CHANNELS; n++) + for (m = 0; m < 3; m++) { + averages[n][m] = 0.0; + min[n][m] = 999; + max[n][m] = 0; + } + /* * service any AEP results */ @@ -372,6 +386,8 @@ int main(int argc, char *argv[]) } if (aepd_interface_result->triggered) printf("%f ", aepd_interface_result->samtime); + + m = 0; for (i = 0; i < aepd_interface_result->chans * 2; i += 2) { if (aepd_interface_result->triggered) { if (just_power) @@ -380,6 +396,27 @@ int main(int argc, char *argv[]) printf(" %.2f %.4f %.5f", aepd_interface_result->buf[i], aepd_interface_result->buf[i + 1], aepd_interface_result->buf[i] * aepd_interface_result->buf[i + 1]); } + + averages[m][0] += aepd_interface_result->buf[i]; + averages[m][1] += aepd_interface_result->buf[i + 1]; + averages[m][2] += aepd_interface_result->buf[i] * aepd_interface_result->buf[i + 1]; + + if (min[m][0] > aepd_interface_result->buf[i]) + min[m][0] = aepd_interface_result->buf[i]; + if (min[m][1] > aepd_interface_result->buf[i + 1]) + min[m][1] = aepd_interface_result->buf[i + 1]; + if (min[m][2] > aepd_interface_result->buf[i] * aepd_interface_result->buf[i + 1]) + min[m][2] = aepd_interface_result->buf[i] * aepd_interface_result->buf[i + 1]; + + if (max[m][0] < aepd_interface_result->buf[i]) + max[m][0] = aepd_interface_result->buf[i]; + if (max[m][1] < aepd_interface_result->buf[i + 1]) + max[m][1] = aepd_interface_result->buf[i + 1]; + if (max[m][2] < aepd_interface_result->buf[i] * aepd_interface_result->buf[i + 1]) + max[m][2] = aepd_interface_result->buf[i] * aepd_interface_result->buf[i + 1]; + + m++; + if (periodic & 0x1ff) continue; if (just_power) @@ -388,8 +425,12 @@ int main(int argc, char *argv[]) fprintf(stderr, " %.2f %.4f %.5f", aepd_interface_result->buf[i], aepd_interface_result->buf[i + 1], aepd_interface_result->buf[i] * aepd_interface_result->buf[i + 1]); } - if (aepd_interface_result->triggered) + + count_post_trigger++; + + if (aepd_interface_result->triggered) { printf("\n"); + } aep_free_result(aepd_interface); @@ -421,12 +462,12 @@ int main(int argc, char *argv[]) for (n = 0; n <= aep_context.aepd_interface->chans; n++) { if (just_power) - printf(" %.5f", aep_context.aepd_interface->averages[n][2]); + printf(" %.5f", averages[n][2]); else printf(" %.2f %.4f %.5f", - aep_context.aepd_interface->averages[n][0], - aep_context.aepd_interface->averages[n][1], - aep_context.aepd_interface->averages[n][2]); + averages[n][0] / count_post_trigger, + averages[n][1] / count_post_trigger, + averages[n][2] / count_post_trigger); } printf("\n"); @@ -442,16 +483,16 @@ int main(int argc, char *argv[]) for (n = 0; n < aepd_interface->chans; n++) { - if (aepd_interface->min[n][0] == 999) + if (min[n][0] == 999) continue; fprintf(stderr, "%12s: %4.2fV < %4.3fVavg < %4.2fV, " "%6.4fA < %6.5fAavg < %6.4fA, " "%9.6fW < %9.6fWavg < %9.6fW\n", aepd_interface->channel_name[n], - aepd_interface->min[n][0], aepd_interface->averages[n][0], aepd_interface->max[n][0], - aepd_interface->min[n][1], aepd_interface->averages[n][1], aepd_interface->max[n][1], - aepd_interface->min[n][2], aepd_interface->averages[n][2], aepd_interface->max[n][2]); + min[n][0], averages[n][0] / count_post_trigger, max[n][0], + min[n][1], averages[n][1] / count_post_trigger, max[n][1], + min[n][2], averages[n][2] / count_post_trigger, max[n][2]); } aepd_interface_destroy(aepd_interface); diff --git a/libarmep/aepd-interface.h b/libarmep/aepd-interface.h index 9b43352..cf1f34c 100644 --- a/libarmep/aepd-interface.h +++ b/libarmep/aepd-interface.h @@ -26,6 +26,10 @@ #define AEPD_SHARED_MAX_REAL_CHANNELS (8 * 3) #define AEPD_SHARED_MAX_VIRTUAL_CHANNELS (8) +/* + * this represents one set of samples over all channels for the same time + */ + struct aepd_interface_result { int triggered; /* 0 = pretrigger 1 = triggered */ int chans; /* number of channels below with data */ @@ -35,6 +39,12 @@ struct aepd_interface_result { double buf[AEPD_SHARED_MAX_REAL_CHANNELS * 2]; }; +/* + * Your code instantiates one of these by calling aepd_interface_create() + * and then passes it to device-specific struct as well as monitoring it + * for samples using aep_wait_for_next_result() + */ + struct aepd_interface { /* ringbuffer to hold channel_results until we can deal with them */ @@ -57,15 +67,12 @@ struct aepd_interface { int chans; /* number of active acquisition channels above */ int vchans; /* virtual channels (summing supplies) appear after probed physical channels in the arrays */ int finished; /* are we going down? */ - - /* simple stats on what was captured */ - - double averages[AEPD_SHARED_MAX_REAL_CHANNELS][3]; - double min[AEPD_SHARED_MAX_REAL_CHANNELS][3]; - double max[AEPD_SHARED_MAX_REAL_CHANNELS][3]; - }; +/* + * generic sample management api + */ + extern struct aepd_interface *aepd_interface_create(void); extern void aepd_interface_destroy(struct aepd_interface *aepd_interface); extern struct aepd_interface_result * aep_wait_for_next_result(struct aepd_interface *aepd_interface); diff --git a/libarmep/libarmep.h b/libarmep/libarmep.h index 2247b46..6e8f6fe 100644 --- a/libarmep/libarmep.h +++ b/libarmep/libarmep.h @@ -181,15 +181,14 @@ struct aep_channel { struct avg_mean_us avg_mean_voltage; struct avg_mean_us avg_mean_current; - /* 0: corrected V, - * 1: corrected A, - * 2: corrected W, - * 3: uncorrected V1, - * 4: uncorrected V2 + /* + * used to detect and adjust -ve drift below 0 + * 0: uncorrected V1, + * 1: uncorrected V2 */ - double min[5]; - double max[5]; + double min[2]; + double max[2]; int decimation_counter; unsigned long samples_seen; diff --git a/libarmep/sample.c b/libarmep/sample.c index df6b278..320bfd9 100644 --- a/libarmep/sample.c +++ b/libarmep/sample.c @@ -26,19 +26,17 @@ struct aep_channel *who_triggered = NULL; static void track_limits_convert_to_current(struct aep_channel *ch, double *v1, double *v2) { - double pwr; + if ((*v1 - ch->voffset[0]) < ch->min[0]) + ch->min[0] = *v1 - ch->voffset[0]; - if ((*v1 - ch->voffset[0]) < ch->min[3]) - ch->min[3] = *v1 - ch->voffset[0]; + if ((*v1 - ch->voffset[0]) > ch->max[0]) + ch->max[0] = *v1 - ch->voffset[0]; - if ((*v1 - ch->voffset[0]) > ch->max[3]) - ch->max[3] = *v1 - ch->voffset[0]; + if ((*v2 - ch->voffset[1]) < ch->min[1]) + ch->min[1] = *v2 - ch->voffset[1]; - if ((*v2 - ch->voffset[1]) < ch->min[4]) - ch->min[4] = *v2 - ch->voffset[1]; - - if ((*v2 - ch->voffset[1]) > ch->max[4]) - ch->max[4] = *v2 - ch->voffset[1]; + if ((*v2 - ch->voffset[1]) > ch->max[1]) + ch->max[1] = *v2 - ch->voffset[1]; if (!ch->aep->aep_context->auto_zero) { if (*v1 < 0) { @@ -69,20 +67,6 @@ static void track_limits_convert_to_current(struct aep_channel *ch, } *v2 = correct(ch->aep->aep_context->no_correction, *v1, *v2, ch->map_table) / ch->rshunt; - - pwr = *v1 * *v2; - if (*v1 > ch->max[0]) - ch->max[0] = *v1; - if (*v1 < ch->min[0]) - ch->min[0] = *v1; - if (*v2 > ch->max[1]) - ch->max[1] = *v2; - if (*v2 < ch->min[1]) - ch->min[1] = *v2; - if (pwr > ch->max[2]) - ch->max[2] = pwr; - if (pwr < ch->min[2]) - ch->min[2] = pwr; } int process_sample(struct aep *aep, int ch_index) @@ -262,11 +246,11 @@ unripe: "unfeasibly high\n", v1); else { ch->voffset[0] = -v1; - ch->vnoise[0] = ch->max[3] - ch->min[3]; + ch->vnoise[0] = ch->max[0] - ch->min[0]; } ch->voffset[1] = -avg_mean_us(&ch->avg_mean_current) / ADC_COUNTS_PER_VOLT_CH2; - ch->vnoise[1] = ch->max[4] - ch->min[4]; + ch->vnoise[1] = ch->max[1] - ch->min[1]; if (configure(aep->aep_context, aep, aep->dev_filepath, aep->aep_context->config_filepath, ch) < 0) fprintf(stderr, "Failed to write autozero info to config\n"); diff --git a/libarmep/service.c b/libarmep/service.c index d6d40b0..b5b736b 100644 --- a/libarmep/service.c +++ b/libarmep/service.c @@ -563,7 +563,7 @@ void sighandler(int sig) int aep_init_and_fork(struct aep_context *aep_context, char *argv[]) { - int n, m, i; + int n, i; struct aep_channel *ch; loop = 1; @@ -613,9 +613,9 @@ int aep_init_and_fork(struct aep_context *aep_context, char *argv[]) sem_close(aep_context->aepd_interface->semaphore); /* - * Compute and stash the averages + * Update channel config file */ - m = 0; + for (n = 0; n <= aep_context->highest; n++) { if (aep_context->aeps[n].fd < 1) continue; @@ -627,17 +627,6 @@ int aep_init_and_fork(struct aep_context *aep_context, char *argv[]) aep_context->aeps[n].dev_filepath, aep_context->config_filepath, ch) < 0) fprintf(stderr, "failed to update config\n"); - - aep_context->aepd_interface->averages[m][0] = ch->simple_avg[0] / ch->avg_count; - aep_context->aepd_interface->averages[m][1] = ch->simple_avg[1] / ch->avg_count; - aep_context->aepd_interface->averages[m][2] = ch->simple_avg[2] / ch->avg_count; - aep_context->aepd_interface->min[m][0] = ch->min[0]; - aep_context->aepd_interface->min[m][1] = ch->min[1]; - aep_context->aepd_interface->min[m][2] = ch->min[2]; - aep_context->aepd_interface->max[m][0] = ch->max[0]; - aep_context->aepd_interface->max[m][1] = ch->max[1]; - aep_context->aepd_interface->max[m][2] = ch->max[2]; - m++; } probe_close(&aep_context->aeps[n]); |