cc2538: gpio: Fix usage of parameters in macros
The parameters in the GPIO macros were used without being parenthesized. This could generate wrong values for register assignments in the case of expressions passed as arguments to these macros. Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
This commit is contained in:
parent
a6227e1e3e
commit
300d2d79ae
|
@ -91,42 +91,42 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK) \
|
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_DIR) &= ~PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_DIR) &= ~(PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE to output.
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE to output.
|
||||||
* \param PORT_BASE GPIO Port register offset
|
* \param PORT_BASE GPIO Port register offset
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK) \
|
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_DIR) |= PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_DIR) |= (PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE high.
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE high.
|
||||||
* \param PORT_BASE GPIO Port register offset
|
* \param PORT_BASE GPIO Port register offset
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK) \
|
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK) \
|
||||||
do { REG((PORT_BASE | GPIO_DATA) + (PIN_MASK << 2)) = 0xFF; } while(0)
|
do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = 0xFF; } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE low.
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE low.
|
||||||
* \param PORT_BASE GPIO Port register offset
|
* \param PORT_BASE GPIO Port register offset
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_CLR_PIN(PORT_BASE, PIN_MASK) \
|
#define GPIO_CLR_PIN(PORT_BASE, PIN_MASK) \
|
||||||
do { REG((PORT_BASE | GPIO_DATA) + (PIN_MASK << 2)) = 0x00; } while(0)
|
do { REG(((PORT_BASE) | GPIO_DATA) + ((PIN_MASK) << 2)) = 0x00; } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE to detect edge.
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE to detect edge.
|
||||||
* \param PORT_BASE GPIO Port register offset
|
* \param PORT_BASE GPIO Port register offset
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_DETECT_EDGE(PORT_BASE, PIN_MASK) \
|
#define GPIO_DETECT_EDGE(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_IS) &= ~PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_IS) &= ~(PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE to detect level.
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE to detect level.
|
||||||
* \param PORT_BASE GPIO Port register offset
|
* \param PORT_BASE GPIO Port register offset
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_DETECT_LEVEL(PORT_BASE, PIN_MASK) \
|
#define GPIO_DETECT_LEVEL(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_IS) |= PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_IS) |= (PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
||||||
* interrupt on both edges.
|
* interrupt on both edges.
|
||||||
|
@ -134,7 +134,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_TRIGGER_BOTH_EDGES(PORT_BASE, PIN_MASK) \
|
#define GPIO_TRIGGER_BOTH_EDGES(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_IBE) |= PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_IBE) |= (PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
||||||
* interrupt on single edge (controlled by GPIO_IEV).
|
* interrupt on single edge (controlled by GPIO_IEV).
|
||||||
|
@ -142,7 +142,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_TRIGGER_SINGLE_EDGE(PORT_BASE, PIN_MASK) \
|
#define GPIO_TRIGGER_SINGLE_EDGE(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_IBE) &= ~PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_IBE) &= ~(PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
||||||
* interrupt on rising edge.
|
* interrupt on rising edge.
|
||||||
|
@ -150,7 +150,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_DETECT_RISING(PORT_BASE, PIN_MASK) \
|
#define GPIO_DETECT_RISING(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_IEV) |= PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_IEV) |= (PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
/** \brief Set pins with PIN_MASK of port with PORT_BASE to trigger an
|
||||||
* interrupt on falling edge.
|
* interrupt on falling edge.
|
||||||
|
@ -158,7 +158,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_DETECT_FALLING(PORT_BASE, PIN_MASK) \
|
#define GPIO_DETECT_FALLING(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_IEV) &= ~PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_IEV) &= ~(PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Enable interrupt triggering for pins with PIN_MASK of port with
|
/** \brief Enable interrupt triggering for pins with PIN_MASK of port with
|
||||||
* PORT_BASE.
|
* PORT_BASE.
|
||||||
|
@ -166,7 +166,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_ENABLE_INTERRUPT(PORT_BASE, PIN_MASK) \
|
#define GPIO_ENABLE_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 Disable interrupt triggering for pins with PIN_MASK of port with
|
/** \brief Disable interrupt triggering for pins with PIN_MASK of port with
|
||||||
* PORT_BASE.
|
* PORT_BASE.
|
||||||
|
@ -174,7 +174,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#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 Configure the pin to be under peripheral control with PIN_MASK of
|
/** \brief Configure the pin to be under peripheral control with PIN_MASK of
|
||||||
* port with PORT_BASE.
|
* port with PORT_BASE.
|
||||||
|
@ -182,7 +182,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_PERIPHERAL_CONTROL(PORT_BASE, PIN_MASK) \
|
#define GPIO_PERIPHERAL_CONTROL(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_AFSEL) |= PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_AFSEL) |= (PIN_MASK); } while(0)
|
||||||
|
|
||||||
/** \brief Configure the pin to be software controlled with PIN_MASK of port
|
/** \brief Configure the pin to be software controlled with PIN_MASK of port
|
||||||
* with PORT_BASE.
|
* with PORT_BASE.
|
||||||
|
@ -190,7 +190,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
* \param PIN_MASK Pin number mask. Pin 0: 0x01, Pin 1: 0x02 ... Pin 7: 0x80
|
||||||
*/
|
*/
|
||||||
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK) \
|
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK) \
|
||||||
do { REG(PORT_BASE | GPIO_AFSEL) &= ~PIN_MASK; } while(0)
|
do { REG((PORT_BASE) | GPIO_AFSEL) &= ~(PIN_MASK); } while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Converts a pin number to a pin mask
|
* \brief Converts a pin number to a pin mask
|
||||||
|
@ -198,7 +198,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \return A pin mask which can be used as the PIN_MASK argument of the macros
|
* \return A pin mask which can be used as the PIN_MASK argument of the macros
|
||||||
* in this category
|
* in this category
|
||||||
*/
|
*/
|
||||||
#define GPIO_PIN_MASK(PIN) (1 << PIN)
|
#define GPIO_PIN_MASK(PIN) (1 << (PIN))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Converts a port number to the port base address
|
* \brief Converts a port number to the port base address
|
||||||
|
@ -206,7 +206,7 @@ typedef void (* gpio_callback_t)(uint8_t port, uint8_t pin);
|
||||||
* \return The base address for the registers corresponding to that port
|
* \return The base address for the registers corresponding to that port
|
||||||
* number.
|
* number.
|
||||||
*/
|
*/
|
||||||
#define GPIO_PORT_TO_BASE(PORT) (GPIO_A_BASE + (PORT << 12))
|
#define GPIO_PORT_TO_BASE(PORT) (GPIO_A_BASE + ((PORT) << 12))
|
||||||
/** @} */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/** \name GPIO Register offset declarations
|
/** \name GPIO Register offset declarations
|
||||||
|
|
Loading…
Reference in a new issue