From 59d55ece06240dd5284bb01f90087a41c50f4f4c Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Wed, 25 Jan 2012 11:31:57 -0800 Subject: [PATCH] Indicate which signals in GPIOGET have changed since the last call Signed-off-by: Randall Spangler BUG=none TEST=at EC console, gpioget twice, then toggle an output using gpioset, then gpioget again May see *'s the first time. Second time, should see no *'s. Third time, should see a * only the toggled output (and any input signals which respond to it). Change-Id: Ibc1870839201008592b7982049cc352c1779a0e3 --- chip/lm4/gpio.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/chip/lm4/gpio.c b/chip/lm4/gpio.c index 0c84f1d1cb..c637f26b1e 100644 --- a/chip/lm4/gpio.c +++ b/chip/lm4/gpio.c @@ -280,10 +280,27 @@ DECLARE_IRQ(LM4_IRQ_GPIOQ, __gpio_q_interrupt, 1); /*****************************************************************************/ /* Console commands */ +static uint8_t last_val[(GPIO_COUNT + 7) / 8]; + +/* If v is different from the last value for index i, updates the last value + * and returns 1; else returns 0. */ +static int last_val_changed(int i, int v) +{ + if (v && !(last_val[i / 8] & (1 << (i % 8)))) { + last_val[i / 8] |= 1 << (i % 8); + return 1; + } else if (!v && last_val[i / 8] & (1 << (i % 8))) { + last_val[i / 8] &= ~(1 << (i % 8)); + return 1; + } else { + return 0; + } +} + static int command_gpio_get(int argc, char **argv) { const struct gpio_info *g = gpio_list; - int i; + int changed, v, i; /* If a signal is specified, print only that one */ if (argc == 2) { @@ -293,15 +310,23 @@ static int command_gpio_get(int argc, char **argv) return EC_ERROR_UNKNOWN; } g = gpio_list + i; - uart_printf(" %d %s\n", gpio_get_level(i), g->name); + v = gpio_get_level(i); + changed = last_val_changed(i, v); + uart_printf(" %d%c %s\n", v, (changed ? '*' : ' '), g->name); + return EC_SUCCESS; } /* Otherwise print them all */ uart_puts("Current GPIO levels:\n"); for (i = 0; i < GPIO_COUNT; i++, g++) { - if (g->mask) - uart_printf(" %d %s\n", gpio_get_level(i), g->name); + if (!g->mask) + continue; /* Skip unsupported signals */ + + v = gpio_get_level(i); + changed = last_val_changed(i, v); + uart_printf(" %d%c %s\n", v, (changed ? '*' : ' '), g->name); + /* We have enough GPIOs that we'll overflow the output buffer * without flushing */ uart_flush_output();