diff options
author | Keith Short <keithshort@chromium.org> | 2021-04-15 09:28:43 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-04-17 01:30:29 +0000 |
commit | c01b28e5da86b783917523beaa97b1b81d38019c (patch) | |
tree | 2c309f07e67f3744654e6980121eab7d93479caf | |
parent | 5cfbf60b311ac4dc0e1d4602508f609cea673301 (diff) | |
download | chrome-ec-c01b28e5da86b783917523beaa97b1b81d38019c.tar.gz |
zephyr: validate interrupt flags at build time
The name spaces for GPIO interrupt flags are similar between Chromium EC
and Zephyr. Add a build time check that the flags are valid for Zephyr.
BUG=b:182398910
BRANCH=none
TEST=zmake testall
TEST=Set a GPIO interrupt flag to an invalid value and verify build
error.
Cq-Depend: chromium:2825909
Signed-off-by: Keith Short <keithshort@chromium.org>
Change-Id: I27caff1fed3827c09450c743cb62ce8a7cbdaac4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2826415
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | zephyr/shim/src/gpio.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/zephyr/shim/src/gpio.c b/zephyr/shim/src/gpio.c index 37cfe3e3b4..30a074b9fd 100644 --- a/zephyr/shim/src/gpio.c +++ b/zephyr/shim/src/gpio.c @@ -81,6 +81,29 @@ static void gpio_handler_shim(const struct device *port, } /* + * Validate interrupt flags are valid for the Zephyr GPIO driver. + */ +#define IS_GPIO_INTERRUPT_FLAG(flag, mask) ((flag & mask) == mask) +#define VALID_GPIO_INTERRUPT_FLAG(flag) \ + (IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_RISING) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_FALLING) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_BOTH) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_LOW) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_HIGH) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_TO_INACTIVE) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_EDGE_TO_ACTIVE) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_INACTIVE) || \ + IS_GPIO_INTERRUPT_FLAG(flag, GPIO_INT_LEVEL_ACTIVE)) + +#define GPIO_INT(sig, f, cb) \ + BUILD_ASSERT(VALID_GPIO_INTERRUPT_FLAG(f), \ + STRINGIFY(sig) " is not using Zephyr interrupt flags"); +#ifdef EC_CROS_GPIO_INTERRUPTS +EC_CROS_GPIO_INTERRUPTS +#endif +#undef GPIO_INT + +/* * Each zephyr project should define EC_CROS_GPIO_INTERRUPTS in their gpio_map.h * file if there are any interrupts that should be registered. The * corresponding handler will be declared here, which will prevent |