Merge pull request #14560 from benpicco/cpu/mips_pic32_common-bitarithm_test_and_clear
cpu/mips_pic32_common: GPIO: use bitarithm_test_and_clear()
This commit is contained in:
commit
00d013d7cf
@ -32,6 +32,14 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Select fastest bitarithm_lsb implementation
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define BITARITHM_LSB_BUILTIN
|
||||||
|
#define BITARITHM_HAS_CLZ
|
||||||
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print the last instruction's address
|
* @brief Print the last instruction's address
|
||||||
*
|
*
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "eic.h"
|
#include "eic.h"
|
||||||
|
#include "bitarithm.h"
|
||||||
#include "periph/gpio.h"
|
#include "periph/gpio.h"
|
||||||
#include "periph_conf.h"
|
#include "periph_conf.h"
|
||||||
|
|
||||||
@ -88,14 +89,13 @@ static gpio_isr_ctx_t isr_ctx[PORT_NUMOF][GPIO_NUMOF];
|
|||||||
static void isr_handler(uint32_t port_addr)
|
static void isr_handler(uint32_t port_addr)
|
||||||
{
|
{
|
||||||
uint32_t cnstat = CNSTATx(_port(port_addr));
|
uint32_t cnstat = CNSTATx(_port(port_addr));
|
||||||
|
uint32_t port = PORTx(_port(port_addr));
|
||||||
|
|
||||||
cnstat &= (1 << GPIO_NUMOF) - 1;
|
cnstat &= (1 << GPIO_NUMOF) - 1;
|
||||||
|
uint8_t pin = 0;
|
||||||
while (cnstat) {
|
while (cnstat) {
|
||||||
/* we want the position of the first one bit, so N_bits - (N_zeros + 1) */
|
cnstat = bitarithm_test_and_clear(cnstat, &pin);
|
||||||
int pin = 32 - __builtin_clz(cnstat) - 1;
|
|
||||||
uint32_t port = PORTx(_port(port_addr));
|
|
||||||
|
|
||||||
cnstat &= ~(1 << pin);
|
|
||||||
if (isr_flank[_port_num(port_addr)][pin] == GPIO_BOTH
|
if (isr_flank[_port_num(port_addr)][pin] == GPIO_BOTH
|
||||||
|| (isr_flank[_port_num(port_addr)][pin] == GPIO_RISING && (port & (1U << pin)))
|
|| (isr_flank[_port_num(port_addr)][pin] == GPIO_RISING && (port & (1U << pin)))
|
||||||
|| (isr_flank[_port_num(port_addr)][pin] == GPIO_FALLING && !(port & (1U << pin))))
|
|| (isr_flank[_port_num(port_addr)][pin] == GPIO_FALLING && !(port & (1U << pin))))
|
||||||
@ -132,12 +132,12 @@ static void cn_isr(void)
|
|||||||
#elif defined(CPU_FAM_PIC32MZ)
|
#elif defined(CPU_FAM_PIC32MZ)
|
||||||
static void isr_handler(uint32_t port_addr)
|
static void isr_handler(uint32_t port_addr)
|
||||||
{
|
{
|
||||||
while (CNFx(_port(port_addr))) {
|
uint8_t pin = 0;
|
||||||
/* we want the position of the first one bit, so N_bits - (N_zeros + 1) */
|
unsigned state = CNFx(_port(port_addr));
|
||||||
int pin = 32 - __builtin_clz(CNFx(_port(port_addr))) - 1;
|
CNFx(_port(port_addr)) = 0;
|
||||||
|
while (state) {
|
||||||
|
state = bitarithm_test_and_clear(state, &pin);
|
||||||
isr_ctx[_port_num(port_addr)][pin].cb(isr_ctx[_port_num(port_addr)][pin].arg);
|
isr_ctx[_port_num(port_addr)][pin].cb(isr_ctx[_port_num(port_addr)][pin].arg);
|
||||||
CNFx(_port(port_addr)) &= ~(1U << pin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user