drivers/interrupt_controller: stm32: Use LL API
exti driver implementation does not fit all SoCs because some EXTI ip does not match stm32_exti register map provided. Instead of providing exti register map for all SoCs, use LL API which abstracts IP variations and enable uniform use of the drivers on all STM32SoCs. Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
parent
e11314a21f
commit
a985e03349
9 changed files with 87 additions and 49 deletions
|
@ -45,22 +45,6 @@
|
|||
#define EXTI_LINES 40
|
||||
#endif
|
||||
|
||||
/* 10.3.7 EXTI register map */
|
||||
struct stm32_exti {
|
||||
/* EXTI_IMR */
|
||||
u32_t imr;
|
||||
/* EXTI_EMR */
|
||||
u32_t emr;
|
||||
/* EXTI_RTSR */
|
||||
u32_t rtsr;
|
||||
/* EXTI_FTSR */
|
||||
u32_t ftsr;
|
||||
/* EXTI_SWIER */
|
||||
u32_t swier;
|
||||
/* EXTI_PR */
|
||||
u32_t pr;
|
||||
};
|
||||
|
||||
/* wrapper for user callback */
|
||||
struct __exti_cb {
|
||||
stm32_exti_callback_t cb;
|
||||
|
@ -73,30 +57,19 @@ struct stm32_exti_data {
|
|||
struct __exti_cb cb[EXTI_LINES];
|
||||
};
|
||||
|
||||
/*
|
||||
* return the proper base addr based on the line number, also we adjust
|
||||
* the line number to be relative to the base, we do this here to save
|
||||
* a bit of code size
|
||||
*/
|
||||
static inline struct stm32_exti *get_exti_addr_adjust_line(int *line)
|
||||
{
|
||||
struct stm32_exti *base = (struct stm32_exti *)EXTI_BASE;
|
||||
|
||||
#if EXTI_LINES > 32
|
||||
if (*line > 31) {
|
||||
*line -= 32;
|
||||
return base + 1;
|
||||
}
|
||||
#endif
|
||||
return base;
|
||||
}
|
||||
|
||||
int stm32_exti_enable(int line)
|
||||
{
|
||||
volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line);
|
||||
int irqnum = 0;
|
||||
|
||||
exti->imr |= 1 << line;
|
||||
if (line < 32) {
|
||||
LL_EXTI_EnableIT_0_31(1 << line);
|
||||
} else {
|
||||
#if EXTI_LINES > 32
|
||||
LL_EXTI_EnableIT_32_63(1 << (line - 32));
|
||||
#else
|
||||
__ASSERT_NO_MSG(line);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32F0X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32L0X)
|
||||
|
@ -182,9 +155,15 @@ int stm32_exti_enable(int line)
|
|||
|
||||
void stm32_exti_disable(int line)
|
||||
{
|
||||
volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line);
|
||||
|
||||
exti->imr &= ~(1 << line);
|
||||
if (line < 32) {
|
||||
LL_EXTI_DisableIT_0_31(1 << line);
|
||||
} else {
|
||||
#if EXTI_LINES > 32
|
||||
LL_EXTI_DisableIT_32_63(1 << (line - 32));
|
||||
#else
|
||||
__ASSERT_NO_MSG(line);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,9 +173,16 @@ void stm32_exti_disable(int line)
|
|||
*/
|
||||
static inline int stm32_exti_is_pending(int line)
|
||||
{
|
||||
volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line);
|
||||
|
||||
return (exti->pr & (1 << line)) ? 1 : 0;
|
||||
if (line < 32) {
|
||||
return LL_EXTI_IsActiveFlag_0_31(1 << line);
|
||||
} else {
|
||||
#if EXTI_LINES > 32
|
||||
return LL_EXTI_IsActiveFlag_32_63(1 << (line - 32));
|
||||
#else
|
||||
__ASSERT_NO_MSG(line);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,21 +192,41 @@ static inline int stm32_exti_is_pending(int line)
|
|||
*/
|
||||
static inline void stm32_exti_clear_pending(int line)
|
||||
{
|
||||
volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line);
|
||||
|
||||
exti->pr = 1 << line;
|
||||
if (line < 32) {
|
||||
LL_EXTI_ClearFlag_0_31(1 << line);
|
||||
} else {
|
||||
#if EXTI_LINES > 32
|
||||
LL_EXTI_ClearFlag_32_63(1 << (line - 32));
|
||||
#else
|
||||
__ASSERT_NO_MSG(line);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_exti_trigger(int line, int trigger)
|
||||
{
|
||||
volatile struct stm32_exti *exti = get_exti_addr_adjust_line(&line);
|
||||
|
||||
if (trigger & STM32_EXTI_TRIG_RISING) {
|
||||
exti->rtsr |= 1 << line;
|
||||
if (line < 32) {
|
||||
LL_EXTI_EnableRisingTrig_0_31(1 << line);
|
||||
} else {
|
||||
#if EXTI_LINES > 32
|
||||
LL_EXTI_EnableRisingTrig_32_63(1 << (line - 32));
|
||||
#else
|
||||
__ASSERT_NO_MSG(line);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (trigger & STM32_EXTI_TRIG_FALLING) {
|
||||
exti->ftsr |= 1 << line;
|
||||
if (line < 32) {
|
||||
LL_EXTI_EnableFallingTrig_0_31(1 << line);
|
||||
} else {
|
||||
#if EXTI_LINES > 32
|
||||
LL_EXTI_EnableFallingTrig_32_63(1 << (line - 32));
|
||||
#else
|
||||
__ASSERT_NO_MSG(line);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
*/
|
||||
#include <kernel_includes.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32f0xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SERIAL_HAS_DRIVER
|
||||
#include <stm32f0xx_ll_usart.h>
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
*/
|
||||
#include <kernel_includes.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32f1xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SERIAL_HAS_DRIVER
|
||||
#include <stm32f1xx_ll_usart.h>
|
||||
#endif
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
*/
|
||||
#include <kernel_includes.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32f2xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CLOCK_CONTROL_STM32_CUBE
|
||||
#include <stm32f2xx_ll_utils.h>
|
||||
#include <stm32f2xx_ll_bus.h>
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
*/
|
||||
#include <kernel_includes.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32f3xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SERIAL_HAS_DRIVER
|
||||
#include <stm32f3xx_ll_usart.h>
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
*/
|
||||
#include <kernel_includes.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32f4xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CLOCK_CONTROL_STM32_CUBE
|
||||
#include <stm32f4xx_ll_utils.h>
|
||||
#include <stm32f4xx_ll_bus.h>
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
*/
|
||||
#include <kernel_includes.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32f7xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CLOCK_CONTROL_STM32_CUBE
|
||||
#include <stm32f7xx_ll_utils.h>
|
||||
#include <stm32f7xx_ll_bus.h>
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
|
||||
#include <stm32l0xx_ll_system.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32l0xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SERIAL_HAS_DRIVER
|
||||
#include <stm32l0xx_ll_usart.h>
|
||||
#include <stm32l0xx_ll_lpuart.h>
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
*/
|
||||
#include <kernel_includes.h>
|
||||
|
||||
#ifdef CONFIG_EXTI_STM32
|
||||
#include <stm32l4xx_ll_exti.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_GPIO_STM32
|
||||
/* Required to enable VDDio2 for port G */
|
||||
#include <stm32l4xx_ll_pwr.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue