mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-10 17:41:54 +00:00
Indicate which signals in GPIOGET have changed since the last call
Signed-off-by: Randall Spangler <rspangler@chromium.org> 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
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user