aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2012-08-19 13:45:56 +0800
committerAndy Green <andy.green@linaro.org>2012-08-19 13:45:56 +0800
commit50d021b14581feb8909339f243308686410f1d5c (patch)
tree235852306777e696a05a6223dd633970237db0e2
parent0238feaadd323bb89cb436358538fb3ef41635a1 (diff)
prepare for multi channel capture and simultaneous probe start
Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r--arm-probe.c271
-rw-r--r--arm-probe.h2
-rw-r--r--configuration.c3
3 files changed, 177 insertions, 99 deletions
diff --git a/arm-probe.c b/arm-probe.c
index 91beb20..ea56202 100644
--- a/arm-probe.c
+++ b/arm-probe.c
@@ -23,7 +23,10 @@ struct pollfd pollfds[MAX_PROBES];
int count_pollfds = 0;
int verbose = 0;
int average_len = 1;
-char channel_name[64];
+char channel_name[MAX_PROBES][64];
+int count_channel_names = 0;
+int matched_channel_names = 0;
+int shouts = 0;
int channel = 0;
int ms_holdoff = 0;
int ms_capture = 0;
@@ -205,6 +208,7 @@ static void init_aep(struct aep *aep, const char *device_filepath)
aep->started = 0;
aep->ignore = 0;
aep->triggered = 0;
+ aep->done_config = 0;
aep->selected_channel = -1;
strncpy(aep->dev_filepath, device_filepath,
@@ -412,6 +416,7 @@ unripe:
if (ch->trigger_filter > trigger_filter_us / 100) {
aep->triggered = 1;
+ shouts = 0;
ch->trigger_filter = 0;
fprintf(stderr, "%s: triggered "
"%.2fV %.5fW pretrig %d "
@@ -427,20 +432,22 @@ unripe:
aep->rx_count++;
if ((aep->rx_count & 0x3ff) == 0) {
- fprintf(stderr, "%s: pretrigger %.2fV "
- "%.4fA (ofs-only:%fV corr:%fV) %fW",
- ch->channel_name, v1, v2,
- avg_mean_us(&ch->avg_mean_current) /
- ADC_COUNTS_PER_VOLT_CH2 + vo1,
- correct(v1, avg_mean_us(
- &ch->avg_mean_current) /
- ADC_COUNTS_PER_VOLT_CH2 + vo1),
- v1 * v2);
-
- if (ch->pretrigger_samples_taken < ch->ring_samples)
- fprintf(stderr, " (filling pretrig)");
-
- fprintf(stderr, " \r");
+ if (!shouts)
+ fprintf(stderr, "PRETRIGGER: ");
+
+ fprintf(stderr, "[%s: %4.2fV %6.4fA %9.6fW] ",
+ ch->channel_name, v1, v2, v1 * v2);
+
+ shouts |= 1 << aep->index;
+
+ if (shouts == (1 << matched_channel_names) - 1) {
+ shouts = 0;
+
+ if (ch->pretrigger_samples_taken < ch->ring_samples)
+ fprintf(stderr, " (filling pretrig)");
+
+ fprintf(stderr, " \r");
+ }
}
}
@@ -527,35 +534,28 @@ unripe:
done:
if ((aep->samples & 0x7ff) == 0) {
- if (show_raw)
- fprintf(stderr, "%s: %.2fV %fA (shunt: avg+ofs:%fV "
- "corrected:%fV offset:%fV ADC:%d) %fW ",
- ch->channel_name, v1, v2, (avg_mean_us(
- &ch->avg_mean_current) /
- ADC_COUNTS_PER_VOLT_CH2) + vo1,
- correct(v1, avg_mean_us(
- &ch->avg_mean_current) /
- ADC_COUNTS_PER_VOLT_CH2 + vo1),
- vo1, aep->current, v1 * v2);
- else
- fprintf(stderr, "%s: %.2fV %fA %fW ",
- ch->channel_name, v1, v2, v1 * v2);
-
- if (ms_capture) {
- int u, t;
- fprintf(stderr, " [");
- t = (aep->samples * 20) / (ms_capture * 10);
- for (u = 0; u < t; u++)
- fprintf(stderr, "*");
- while (u++ < 20)
- fprintf(stderr, "-");
- fprintf(stderr, "]");
- }
- if (ch->pretrigger_samples_taken < ch->ring_samples)
- fprintf(stderr, " (filling pretrig)");
-
- fprintf(stderr, " \r");
+ fprintf(stderr, "[%s: %4.2fV %6.4fA %9.6fW] ",
+ ch->channel_name, v1, v2, v1 * v2);
+
+ shouts |= 1 << aep->index;
+
+ if (shouts == (1 << matched_channel_names) - 1) {
+ shouts = 0;
+
+ if (ms_capture) {
+ int u, t;
+ fprintf(stderr, " [");
+ t = (aep->samples * 20) / (ms_capture * 10);
+ for (u = 0; u < t; u++)
+ fprintf(stderr, "*");
+ while (u++ < 20)
+ fprintf(stderr, "-");
+ fprintf(stderr, "]");
+ }
+
+ fprintf(stderr, " \r");
+ }
}
if (ms_capture && (aep->samples / 10 - ms_holdoff) > ms_capture) {
@@ -715,17 +715,12 @@ int service_aep(struct aep *aep, int samples)
return -1;
break;
case 63:
- v = AEPC_START;
- if (write(aep->fd, &v, 1) != 1)
- return -1;
-
- fprintf(stderr, "Started new probe instance "
+ fprintf(stderr, "Configured new probe instance "
"%s %s %08X %d\n",
aep->dev_filepath, aep->name,
aep->version, aep->rate);
aep->done_config |= 2;
- aep->started = 1;
aep->state = APP_FRAME_L;
aep->counter = 0;
break;
@@ -846,12 +841,12 @@ int main(int argc, char *argv[])
int fd, loop = 1, n = 0;
struct termios tty;
struct serial_struct sinfo;
- struct aep_channel *sel_ch = NULL;
- struct aep *sel_aep = NULL;
+ struct aep_channel *ch;
unsigned char *p;
unsigned char c;
char filepath[20];
struct timeval tv;
+ int not_started = 1;
int highest = 0;
int scan = 0;
int scans = 0;
@@ -925,8 +920,15 @@ int main(int argc, char *argv[])
ms_capture = atoi(optarg);
break;
case 'c':
- strncpy(channel_name, optarg, sizeof channel_name - 1);
- channel_name[sizeof channel_name - 1] = '\0';
+ if (count_channel_names == MAX_PROBES) {
+ fprintf(stderr, "too many channels named\n");
+ return -1;
+ }
+ strncpy(channel_name[count_channel_names], optarg,
+ sizeof channel_name[0] - 1);
+ channel_name[count_channel_names]
+ [sizeof channel_name[0] - 1] = '\0';
+ count_channel_names++;
break;
case 'q':
mv_min = atoi(optarg);
@@ -1119,36 +1121,19 @@ post_si:
for (n = 0; n < CHANNELS_PER_PROBE; n++) {
struct aep_channel *ch = &aeps[scan].ch[n];
- if (strcmp(ch->channel_name, channel_name))
+ for (m = 0; m < count_channel_names; m++)
+ if (!strcmp(ch->channel_name, channel_name[m]))
+ break;
+
+ if (m == count_channel_names)
continue;
+
+ matched_channel_names++;
+
aeps[scan].selected_channel = n;
- sel_ch = ch;
- sel_aep = &aeps[scan];
- if (!(awaiting_capture & (1 << scan))) {
+ if (!(awaiting_capture & (1 << scan)) && verbose)
fprintf(stderr, "seen selected channel %s\n",
ch->channel_name_pretty);
- if (stdinline[0]) {
- if (just_power)
- printf("%s %s\n", stdinline,
- ch->channel_name_pretty);
- else
- printf("%s %s(V) %s(A) %s(W)\n",
- stdinline,
- ch->channel_name_pretty,
- ch->channel_name_pretty,
- ch->channel_name_pretty);
- get_stdin_line(stdinline,
- sizeof stdinline);
- } else
- if (just_power)
- printf("sample %s(W)\n",
- ch->channel_name_pretty);
- else
- printf("sample %s(V) %s(A) %s(W)\n",
- ch->channel_name_pretty,
- ch->channel_name_pretty,
- ch->channel_name_pretty);
- }
awaiting_capture |= 1 << scan;
}
@@ -1174,6 +1159,84 @@ bail:
continue;
}
+ /* if we're waiting to start but saw every channel / probe */
+
+//fprintf(stderr, "* %d %d %d\n", not_started, count_channel_names, matched_channel_names);
+
+ if (not_started &&
+ count_channel_names == matched_channel_names) {
+ /* nobody is waiting for config completion? */
+
+ c = 0;
+ for (m = 0; m <= highest; m++)
+ if (aeps[m].fd > 0) {
+// fprintf(stderr, "%d: %d %d\n",
+// m, aeps[m].selected_channel, aeps[m].done_config);
+ c = 1;
+ if (aeps[m].selected_channel >= 0 && aeps[m].done_config != 3)
+ goto post_start;
+ }
+
+ if (c == 0)
+ goto post_start;
+
+ /*
+ * the number of guys we would start
+ * is all of them, is it? Becuase we need to
+ * eliminate cross-channel latency as far as we
+ * can
+ */
+
+ c = 0;
+ for (m = 0; m <= highest; m++) {
+// fprintf(stderr, "%d: %d %d %d\n", m,aeps[m].fd, aeps[m].done_config, aeps[m].selected_channel);
+ if (aeps[m].fd > 0 && aeps[m].done_config == 3 && aeps[m].selected_channel >= 0)
+ c++;
+ }
+
+ if (c != matched_channel_names)
+ goto post_start;
+
+ /* tell everyone to start */
+
+ fprintf(stderr, "Starting...\n");
+ if (stdinline[0]) {
+ printf("%s", stdinline);
+ get_stdin_line(stdinline, sizeof stdinline);
+ } else
+ printf("sample");
+
+ for (m = 0; m <= highest; m++)
+ if (aeps[m].fd > 0 &&
+ aeps[m].done_config == 3 &&
+ aeps[m].selected_channel >= 0) {
+ struct aep_channel *ch = &aeps[m].ch[aeps[m].selected_channel];
+ if (verbose)
+ fprintf(stderr, "sending start to %d\n", m);
+ c = AEPC_START;
+ if (write(aeps[m].fd, &c, 1) != 1) {
+ fprintf(stderr,
+ "Failed to send start\n");
+ }
+
+ if (just_power)
+ printf(" %s(W)",
+ ch->channel_name_pretty);
+ else
+ printf(" %s(V) %s(A) %s(W)",
+ ch->channel_name_pretty,
+ ch->channel_name_pretty,
+ ch->channel_name_pretty);
+
+ aeps[m].started = 1;
+ not_started = 0;
+ aeps[m].sec_last_traffic = tv.tv_sec;
+ }
+
+ printf("\n");
+ }
+post_start:
+
/* somebody had something for us */
for (m = 0; m <= highest; m++) {
@@ -1184,9 +1247,13 @@ bail:
/* check for timeout */
if (tv.tv_sec > aeps[m].sec_last_traffic + 2) {
- fprintf(stderr, "%s: timeout\n",
- aeps[m].dev_filepath);
- goto died;
+// fprintf(stderr, "%d: %d %d\n", m, aeps[m].done_config, aeps[m].started);
+ if (aeps[m].done_config != 3 ||
+ aeps[m].started) {
+ fprintf(stderr, "%s: timeout\n",
+ aeps[m].dev_filepath);
+ goto died;
+ }
}
for (n = 0; n < count_pollfds; n++)
@@ -1233,8 +1300,10 @@ bail:
died:
fprintf(stderr, "removing probe due to error...\n");
- if (aeps[m].selected_channel >= 0)
+ if (aeps[m].selected_channel >= 0) {
awaiting_capture &= ~(1 << m);
+ matched_channel_names--;
+ }
probe_fini(&aeps[m]);
remove_pollfd(aeps[m].fd);
aeps[m].fd = 0;
@@ -1259,6 +1328,10 @@ died:
if (verbose)
fprintf(stderr,
"service failed\n");
+ if (aeps[m].selected_channel >= 0) {
+ awaiting_capture &= ~(1 << m);
+ matched_channel_names--;
+ }
probe_fini(&aeps[n]);
remove_pollfd(aeps[n].fd);
aeps[n].fd = 0;
@@ -1273,22 +1346,26 @@ died:
}
- if (sel_aep)
- if (configure(sel_aep, sel_aep->dev_filepath,
- config_filepath, sel_ch) < 0)
+ for (m = 0; m <= highest; m++) {
+ if (aeps[m].fd <= 0)
+ continue;
+ if (aeps[m].selected_channel < 0)
+ continue;
+ ch = &aeps[m].ch[aeps[m].selected_channel];
+ if (configure(&aeps[m], aeps[m].dev_filepath, config_filepath,
+ ch) < 0)
fprintf(stderr, "adaptive: failed to update config\n");
- if (sel_ch && sel_ch->min[0] != 999)
- fprintf(stderr, " Voltage: %.2fV min, %.2fV max \n"
- " Current: %.4fA min, %.4fA max\n"
- " Power: %fW min, %fW max\n",
- sel_ch->min[0], sel_ch->max[0],
- sel_ch->min[1], sel_ch->max[1],
- sel_ch->min[2], sel_ch->max[2]);
-
- for (n = 0; n < highest; n++)
- if (aeps[n].fd > 0)
- probe_fini(&aeps[n]);
+ if (ch->min[0] != 999)
+ fprintf(stderr, "%12s: %4.2fV - %4.2fV, "
+ "%6.4fA - %6.4fA, "
+ "%9.6fW - %9.6fW\n",
+ ch->channel_name,
+ ch->min[0], ch->max[0],
+ ch->min[1], ch->max[1],
+ ch->min[2], ch->max[2]);
+ probe_fini(&aeps[n]);
+ }
fprintf(stderr, "exited\n");
diff --git a/arm-probe.h b/arm-probe.h
index 36d5630..8c67357 100644
--- a/arm-probe.h
+++ b/arm-probe.h
@@ -99,4 +99,4 @@ extern int configure(struct aep *aep, const char *dev_filepath,
const char *config_filepath, struct aep_channel *wch);
extern char configuration_name[64];
extern unsigned int ms_pretrigger;
-
+extern int verbose;
diff --git a/configuration.c b/configuration.c
index acd16c0..29df72e 100644
--- a/configuration.c
+++ b/configuration.c
@@ -181,7 +181,8 @@ int configure(struct aep *aep, const char *dev_filepath,
ch->vnoise[1],
ch->pretrigger_ms,
ch->channel_name_pretty);
- fprintf(stderr, "Updating config "
+ if (verbose)
+ fprintf(stderr, "Updating config "
"with \"%s\"\n", linebuf);
write(wfd, linebuf, strlen(linebuf));
}