cc2538: gpio: Add macros to get interrupt status

Introduce new useful GPIO macros to:
 - get the raw interrupt status of a port,
 - get the masked interrupt status of a port,
 - get the power-up interrupt status of a port.

These macros are cleaner and less error-prone than raw register access
code copied all over the place.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.com>
This commit is contained in:
Benoît Thébaudeau 2015-04-08 22:49:50 +02:00
parent 41d9078ed4
commit 1e67ab3941
2 changed files with 34 additions and 1 deletions

View file

@ -93,7 +93,7 @@ gpio_port_isr(uint8_t port)
base = GPIO_PORT_TO_BASE(port); base = GPIO_PORT_TO_BASE(port);
notify(REG(base + GPIO_MIS), port); notify(GPIO_GET_MASKED_INT_STATUS(base), port);
GPIO_CLEAR_INTERRUPT(base, 0xFF); GPIO_CLEAR_INTERRUPT(base, 0xFF);
GPIO_CLEAR_POWER_UP_INTERRUPT(port, 0xFF); GPIO_CLEAR_POWER_UP_INTERRUPT(port, 0xFF);

View file

@ -210,6 +210,31 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
#define GPIO_DISABLE_INTERRUPT(PORT_BASE, PIN_MASK) \ #define GPIO_DISABLE_INTERRUPT(PORT_BASE, PIN_MASK) \
do { REG((PORT_BASE) + GPIO_IE) &= ~(PIN_MASK); } while(0) do { REG((PORT_BASE) + GPIO_IE) &= ~(PIN_MASK); } while(0)
/** \brief Get raw interrupt status of port with PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \return Bit-mask reflecting the raw interrupt status of all the port pins
*
* The bits set in the returned bit-mask reflect the status of the interrupts
* trigger conditions detected (raw, before interrupt masking), indicating that
* all the requirements are met, before they are finally allowed to trigger by
* the interrupt mask. The bits cleared indicate that corresponding input pins
* have not initiated an interrupt.
*/
#define GPIO_GET_RAW_INT_STATUS(PORT_BASE) \
REG((PORT_BASE) + GPIO_RIS)
/** \brief Get masked interrupt status of port with PORT_BASE.
* \param PORT_BASE GPIO Port register offset
* \return Bit-mask reflecting the masked interrupt status of all the port pins
*
* The bits set in the returned bit-mask reflect the status of input lines
* triggering an interrupt. The bits cleared indicate that either no interrupt
* has been generated, or the interrupt is masked. This is the state of the
* interrupt after interrupt masking.
*/
#define GPIO_GET_MASKED_INT_STATUS(PORT_BASE) \
REG((PORT_BASE) + GPIO_MIS)
/** \brief Clear interrupt triggering for pins with PIN_MASK of port with /** \brief Clear interrupt triggering for pins with PIN_MASK of port with
* PORT_BASE. * PORT_BASE.
* \param PORT_BASE GPIO Port register offset * \param PORT_BASE GPIO Port register offset
@ -270,6 +295,14 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
do { REG(GPIO_PORT_TO_BASE(PORT) + GPIO_PI_IEN) &= \ do { REG(GPIO_PORT_TO_BASE(PORT) + GPIO_PI_IEN) &= \
~((PIN_MASK) << ((PORT) << 3)); } while(0) ~((PIN_MASK) << ((PORT) << 3)); } while(0)
/** \brief Get power-up interrupt status of port PORT.
* \param PORT GPIO Port (not port base address)
* \return Bit-mask reflecting the power-up interrupt status of all the port
* pins
*/
#define GPIO_GET_POWER_UP_INT_STATUS(PORT) \
((REG(GPIO_PORT_TO_BASE(PORT) + GPIO_IRQ_DETECT_ACK) >> ((PORT) << 3)) & 0xFF)
/** \brief Clear power-up interrupt triggering for pins with PIN_MASK of port /** \brief Clear power-up interrupt triggering for pins with PIN_MASK of port
* PORT. * PORT.
* \param PORT GPIO Port (not port base address) * \param PORT GPIO Port (not port base address)