mirror of
https://github.com/apache/nuttx.git
synced 2025-12-08 02:32:54 +08:00
Compare commits
6 Commits
dependabot
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e87082b195 | ||
|
|
2c0e105cad | ||
|
|
f5741c0ea1 | ||
|
|
f7526522a1 | ||
|
|
d697f1c4f6 | ||
|
|
1bf71795fc |
@@ -4525,6 +4525,19 @@ config LPUART1_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config LPUART1_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure LPUART1 RX pin on close"
|
||||
default n
|
||||
|
||||
config LPUART1_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure LPUART1 TX pin on close"
|
||||
default n
|
||||
|
||||
config LPUART1_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on LPUART1_RS485
|
||||
bool "Unconfigure LPUART1 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # LPUART1_SERIALDRIVER
|
||||
|
||||
choice
|
||||
@@ -4566,6 +4579,19 @@ config USART1_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config USART1_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure USART1 RX pin on close"
|
||||
default n
|
||||
|
||||
config USART1_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure USART1 TX pin on close"
|
||||
default n
|
||||
|
||||
config USART1_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on USART1_RS485
|
||||
bool "Unconfigure USART1 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # USART1_SERIALDRIVER
|
||||
|
||||
choice
|
||||
@@ -4607,6 +4633,19 @@ config USART2_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config USART2_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure USART2 RX pin on close"
|
||||
default n
|
||||
|
||||
config USART2_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure USART2 TX pin on close"
|
||||
default n
|
||||
|
||||
config USART2_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on USART2_RS485
|
||||
bool "Unconfigure USART2 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # USART2_SERIALDRIVER
|
||||
|
||||
choice
|
||||
@@ -4648,6 +4687,19 @@ config USART3_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config USART3_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure USART3 RX pin on close"
|
||||
default n
|
||||
|
||||
config USART3_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure USART3 TX pin on close"
|
||||
default n
|
||||
|
||||
config USART3_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on USART3_RS485
|
||||
bool "Unconfigure USART3 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # USART3_SERIALDRIVER
|
||||
|
||||
choice
|
||||
@@ -4689,6 +4741,19 @@ config UART4_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config UART4_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure UART4 RX pin on close"
|
||||
default n
|
||||
|
||||
config UART4_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure UART4 TX pin on close"
|
||||
default n
|
||||
|
||||
config UART4_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on UART4_RS485
|
||||
bool "Unconfigure UART4 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # UART4_SERIALDRIVER
|
||||
|
||||
choice
|
||||
@@ -4730,6 +4795,19 @@ config UART5_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config UART5_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure UART5 RX pin on close"
|
||||
default n
|
||||
|
||||
config UART5_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure UART5 TX pin on close"
|
||||
default n
|
||||
|
||||
config UART5_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on UART5_RS485
|
||||
bool "Unconfigure UART5 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # UART5_SERIALDRIVER
|
||||
|
||||
choice
|
||||
@@ -4771,6 +4849,19 @@ config USART6_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config USART6_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure USART6 RX pin on close"
|
||||
default n
|
||||
|
||||
config USART6_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure USART6 TX pin on close"
|
||||
default n
|
||||
|
||||
config USART6_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on USART6_RS485
|
||||
bool "Unconfigure USART6 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # USART6_SERIALDRIVER
|
||||
|
||||
if UART7_SERIALDRIVER
|
||||
@@ -4800,6 +4891,19 @@ config UART7_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config UART7_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure UART7 RX pin on close"
|
||||
default n
|
||||
|
||||
config UART7_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure UART7 TX pin on close"
|
||||
default n
|
||||
|
||||
config UART7_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on UART7_RS485
|
||||
bool "Unconfigure UART7 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # UART7_SERIALDRIVER
|
||||
|
||||
if UART8_SERIALDRIVER
|
||||
@@ -4829,6 +4933,19 @@ config UART8_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config UART8_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure UART8 RX pin on close"
|
||||
default n
|
||||
|
||||
config UART8_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure UART8 TX pin on close"
|
||||
default n
|
||||
|
||||
config UART8_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on UART8_RS485
|
||||
bool "Unconfigure UART8 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # UART8_SERIALDRIVER
|
||||
|
||||
if UART9_SERIALDRIVER
|
||||
@@ -4858,6 +4975,19 @@ config UART9_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config UART9_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure UART9 RX pin on close"
|
||||
default n
|
||||
|
||||
config UART9_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure UART9 TX pin on close"
|
||||
default n
|
||||
|
||||
config UART9_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on UART9_RS485
|
||||
bool "Unconfigure UART9 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # UART9_SERIALDRIVER
|
||||
|
||||
if USART10_SERIALDRIVER
|
||||
@@ -4887,6 +5017,19 @@ config USART10_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config USART10_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure USART10 RX pin on close"
|
||||
default n
|
||||
|
||||
config USART10_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure USART10 TX pin on close"
|
||||
default n
|
||||
|
||||
config USART10_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on USART10_RS485
|
||||
bool "Unconfigure USART10 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # USART10_SERIALDRIVER
|
||||
|
||||
if USART11_SERIALDRIVER
|
||||
@@ -4916,6 +5059,19 @@ config USART11_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config USART11_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure USART11 RX pin on close"
|
||||
default n
|
||||
|
||||
config USART11_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure USART11 TX pin on close"
|
||||
default n
|
||||
|
||||
config USART11_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on USART11_RS485
|
||||
bool "Unconfigure USART11 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # USART11_SERIALDRIVER
|
||||
|
||||
if UART12_SERIALDRIVER
|
||||
@@ -4945,6 +5101,19 @@ config UART12_RXDMA
|
||||
---help---
|
||||
In high data rate usage, Rx DMA may eliminate Rx overrun errors
|
||||
|
||||
config UART12_UNCONFIG_RX_ON_CLOSE
|
||||
bool "Unconfigure UART12 RX pin on close"
|
||||
default n
|
||||
|
||||
config UART12_UNCONFIG_TX_ON_CLOSE
|
||||
bool "Unconfigure UART12 TX pin on close"
|
||||
default n
|
||||
|
||||
config UART12_UNCONFIG_DIR_ON_CLOSE
|
||||
depends on UART12_RS485
|
||||
bool "Unconfigure UART12 DIR pin on close"
|
||||
default n
|
||||
|
||||
endif # UART12_SERIALDRIVER
|
||||
|
||||
if STM32H5_SERIALDRIVER
|
||||
|
||||
@@ -125,6 +125,12 @@
|
||||
# define CONFIG_STM32H5_PM_SERIAL_ACTIVITY 10
|
||||
#endif
|
||||
|
||||
/* USART Unconfigure bits */
|
||||
|
||||
#define USART_UNCONFIGURE_RX (1 << 0)
|
||||
#define USART_UNCONFIGURE_TX (1 << 1)
|
||||
#define USART_UNCONFIGURE_DIR (1 << 2)
|
||||
|
||||
/* Keep track if a Break was set
|
||||
*
|
||||
* Note:
|
||||
@@ -214,10 +220,13 @@ struct stm32_serial_s
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
const uint32_t rs485_dir_gpio; /* U[S]ART RS-485 DIR GPIO pin configuration */
|
||||
const bool rs485_dir_polarity; /* U[S]ART RS-485 DIR pin state for TX enabled */
|
||||
const uint32_t rs485_dir_gpio; /* U[S]ART RS-485 DIR GPIO pin configuration */
|
||||
uint8_t rs485_flags; /* U[S]ART RS-485 flags
|
||||
* (compatible with struct serial_rs485)
|
||||
*/
|
||||
#endif
|
||||
const bool islpuart; /* Is this device a Low Power UART? */
|
||||
const uint8_t unconfigure; /* Unconfigure pins on close */
|
||||
const bool islpuart; /* Is this device a Low Power UART? */
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
@@ -472,12 +481,26 @@ static struct stm32_serial_s g_lpuart1priv =
|
||||
# ifdef CONFIG_USART1_RS485
|
||||
.rs485_dir_gpio = GPIO_LPUART1_RS485_DIR,
|
||||
# if (CONFIG_USART1_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_LPUART1_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_LPUART1_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_LPUART1_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -533,12 +556,26 @@ static struct stm32_serial_s g_usart1priv =
|
||||
# ifdef CONFIG_USART1_RS485
|
||||
.rs485_dir_gpio = GPIO_USART1_RS485_DIR,
|
||||
# if (CONFIG_USART1_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_USART1_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_USART1_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_USART1_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -596,12 +633,26 @@ static struct stm32_serial_s g_usart2priv =
|
||||
# ifdef CONFIG_USART2_RS485
|
||||
.rs485_dir_gpio = GPIO_USART2_RS485_DIR,
|
||||
# if (CONFIG_USART2_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_USART2_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_USART2_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_USART2_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -659,12 +710,26 @@ static struct stm32_serial_s g_usart3priv =
|
||||
# ifdef CONFIG_USART3_RS485
|
||||
.rs485_dir_gpio = GPIO_USART3_RS485_DIR,
|
||||
# if (CONFIG_USART3_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_USART3_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_USART3_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_USART3_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -722,12 +787,26 @@ static struct stm32_serial_s g_uart4priv =
|
||||
# ifdef CONFIG_UART4_RS485
|
||||
.rs485_dir_gpio = GPIO_UART4_RS485_DIR,
|
||||
# if (CONFIG_UART4_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_UART4_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_UART4_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_UART4_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -785,12 +864,26 @@ static struct stm32_serial_s g_uart5priv =
|
||||
# ifdef CONFIG_UART5_RS485
|
||||
.rs485_dir_gpio = GPIO_UART5_RS485_DIR,
|
||||
# if (CONFIG_UART5_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_UART5_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_UART5_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_UART5_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -848,12 +941,26 @@ static struct stm32_serial_s g_usart6priv =
|
||||
# ifdef CONFIG_USART6_RS485
|
||||
.rs485_dir_gpio = GPIO_USART6_RS485_DIR,
|
||||
# if (CONFIG_USART6_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_USART6_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_USART6_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_USART6_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -911,12 +1018,26 @@ static struct stm32_serial_s g_uart7priv =
|
||||
# ifdef CONFIG_UART7_RS485
|
||||
.rs485_dir_gpio = GPIO_UART7_RS485_DIR,
|
||||
# if (CONFIG_UART7_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_UART7_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_UART7_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_UART7_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -974,12 +1095,26 @@ static struct stm32_serial_s g_uart8priv =
|
||||
# ifdef CONFIG_UART8_RS485
|
||||
.rs485_dir_gpio = GPIO_UART8_RS485_DIR,
|
||||
# if (CONFIG_UART8_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_UART8_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_UART8_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_UART8_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1037,12 +1172,26 @@ static struct stm32_serial_s g_uart9priv =
|
||||
# ifdef CONFIG_UART9_RS485
|
||||
.rs485_dir_gpio = GPIO_UART9_RS485_DIR,
|
||||
# if (CONFIG_UART9_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_UART9_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_UART9_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_UART9_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1100,12 +1249,26 @@ static struct stm32_serial_s g_usart10priv =
|
||||
# ifdef CONFIG_USART10_RS485
|
||||
.rs485_dir_gpio = GPIO_USART10_RS485_DIR,
|
||||
# if (CONFIG_USART10_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_USART10_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_USART10_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_USART10_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1163,12 +1326,26 @@ static struct stm32_serial_s g_usart11priv =
|
||||
# ifdef CONFIG_USART11_RS485
|
||||
.rs485_dir_gpio = GPIO_USART11_RS485_DIR,
|
||||
# if (CONFIG_USART11_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_USART11_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_USART11_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_USART11_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1226,12 +1403,26 @@ static struct stm32_serial_s g_uart12priv =
|
||||
# ifdef CONFIG_UART12_RS485
|
||||
.rs485_dir_gpio = GPIO_UART12_RS485_DIR,
|
||||
# if (CONFIG_UART12_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_AFTER_SEND,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
.rs485_flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
|
||||
# endif
|
||||
# endif
|
||||
.lock = SP_UNLOCKED,
|
||||
.unconfigure = 0
|
||||
#if defined(CONFIG_UART12_UNCONFIG_RX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_RX
|
||||
#endif
|
||||
#if defined(CONFIG_UART12_UNCONFIG_TX_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_TX
|
||||
#endif
|
||||
#if defined(CONFIG_UART12_UNCONFIG_DIR_ON_CLOSE)
|
||||
|
|
||||
USART_UNCONFIGURE_DIR
|
||||
#endif
|
||||
,
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -2005,10 +2196,11 @@ static int stm32serial_setup(struct uart_dev_s *dev)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
if (priv->rs485_dir_gpio != 0)
|
||||
if ((priv->rs485_flags & SER_RS485_ENABLED) != 0)
|
||||
{
|
||||
stm32_configgpio(priv->rs485_dir_gpio);
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity);
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio,
|
||||
(bool) (priv->rs485_flags & SER_RS485_RTS_AFTER_SEND));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2242,8 +2434,15 @@ static void stm32serial_shutdown(struct uart_dev_s *dev)
|
||||
* then this may need to be a configuration option.
|
||||
*/
|
||||
|
||||
stm32_unconfiggpio(priv->tx_gpio);
|
||||
stm32_unconfiggpio(priv->rx_gpio);
|
||||
if (priv->unconfigure & USART_UNCONFIGURE_TX)
|
||||
{
|
||||
stm32_unconfiggpio(priv->tx_gpio);
|
||||
}
|
||||
|
||||
if (priv->unconfigure & USART_UNCONFIGURE_RX)
|
||||
{
|
||||
stm32_unconfiggpio(priv->rx_gpio);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SERIAL_OFLOWCONTROL
|
||||
if (priv->cts_gpio != 0)
|
||||
@@ -2260,7 +2459,8 @@ static void stm32serial_shutdown(struct uart_dev_s *dev)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
if (priv->rs485_dir_gpio != 0)
|
||||
if ((priv->rs485_dir_gpio != 0) &&
|
||||
(priv->unconfigure & USART_UNCONFIGURE_DIR))
|
||||
{
|
||||
stm32_unconfiggpio(priv->rs485_dir_gpio);
|
||||
}
|
||||
@@ -2429,7 +2629,9 @@ static int stm32serial_interrupt(int irq, void *context, void *arg)
|
||||
(priv->ie & USART_CR1_TCIE) != 0 &&
|
||||
(priv->ie & USART_CR1_TXEIE) == 0)
|
||||
{
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity);
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio,
|
||||
(bool) (priv->rs485_flags &
|
||||
SER_RS485_RTS_AFTER_SEND));
|
||||
stm32serial_restoreusartint(priv, priv->ie & ~USART_CR1_TCIE);
|
||||
}
|
||||
#endif
|
||||
@@ -2479,6 +2681,110 @@ static int stm32serial_interrupt(int irq, void *context, void *arg)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32serial_set_rs485_mode
|
||||
*
|
||||
* Description:
|
||||
* Handle mode set ioctl (TIOCSRS485) to enable
|
||||
* and disable RS-485 mode. This is part of the serial ioctl logic.
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
static inline int stm32serial_set_rs485_mode(struct stm32_serial_s *priv,
|
||||
const struct serial_rs485 *mode)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
DEBUGASSERT(priv && mode);
|
||||
if (priv->rs485_dir_gpio == 0)
|
||||
{
|
||||
/* Can't configure RS485 dir pin if pin is not defined */
|
||||
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
flags = enter_critical_section();
|
||||
priv->sr = stm32serial_getreg(priv, STM32_USART_ISR_OFFSET);
|
||||
|
||||
priv->rs485_flags = mode->flags &
|
||||
(SER_RS485_ENABLED |
|
||||
SER_RS485_RTS_ON_SEND |
|
||||
SER_RS485_RTS_AFTER_SEND |
|
||||
SER_RS485_RX_DURING_TX);
|
||||
/* Cases:
|
||||
* Enabling, serial transfer currently in progress:
|
||||
* Set the pin to the transfer in progress state and let the interrupt take
|
||||
* care of it
|
||||
* Enabling, no serial transfer currently in progress:
|
||||
* Set the pin to the no transfer in progress state.
|
||||
*/
|
||||
|
||||
if (mode->flags & SER_RS485_ENABLED)
|
||||
{
|
||||
stm32_configgpio(priv->rs485_dir_gpio);
|
||||
if ((priv->sr & USART_ISR_TC) != 0)
|
||||
{
|
||||
/* Transmission is complete, set to "after send' state */
|
||||
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, (bool) (priv->rs485_flags &
|
||||
SER_RS485_RTS_AFTER_SEND));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Transmission is currently in progress, set to "on send" state */
|
||||
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, (bool) (priv->rs485_flags &
|
||||
SER_RS485_RTS_ON_SEND));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (priv->unconfigure & USART_UNCONFIGURE_DIR)
|
||||
{
|
||||
stm32_unconfiggpio(priv->rs485_dir_gpio);
|
||||
}
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32serial_get_rs485_mode
|
||||
*
|
||||
* Description:
|
||||
* Handle RS485 mode get ioctl (TIOCGRS485) to get the
|
||||
* current RS-485 mode.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
static inline int stm32serial_get_rs485_mode(struct stm32_serial_s *priv,
|
||||
struct serial_rs485 *mode)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
DEBUGASSERT(priv && mode);
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Assume disabled */
|
||||
|
||||
memset(mode, 0, sizeof(struct serial_rs485));
|
||||
|
||||
mode->flags = priv->rs485_flags &
|
||||
(SER_RS485_ENABLED |
|
||||
SER_RS485_RTS_ON_SEND |
|
||||
SER_RS485_RTS_AFTER_SEND |
|
||||
SER_RS485_RX_DURING_TX);
|
||||
|
||||
leave_critical_section(flags);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32serial_ioctl
|
||||
*
|
||||
@@ -2852,7 +3158,21 @@ static int stm32serial_ioctl(struct file *filep, int cmd,
|
||||
break;
|
||||
# endif
|
||||
#endif
|
||||
#ifdef HAVE_RS485
|
||||
case TIOCSRS485: /* Set RS485 mode, arg: pointer to struct serial_rs485 */
|
||||
{
|
||||
ret = stm32serial_set_rs485_mode(
|
||||
priv, (const struct serial_rs485 *)((uintptr_t)arg));
|
||||
}
|
||||
break;
|
||||
|
||||
case TIOCGRS485: /* Get RS485 mode, arg: pointer to struct serial_rs485 */
|
||||
{
|
||||
ret = stm32serial_get_rs485_mode(
|
||||
priv, (struct serial_rs485 *)((uintptr_t)arg));
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
@@ -3308,9 +3628,10 @@ static void stm32serial_send(struct uart_dev_s *dev, int ch)
|
||||
(struct stm32_serial_s *)dev->priv;
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
if (priv->rs485_dir_gpio != 0)
|
||||
if ((priv->rs485_flags & SER_RS485_ENABLED) != 0)
|
||||
{
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, priv->rs485_dir_polarity);
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, (bool) (priv->rs485_flags &
|
||||
SER_RS485_RTS_ON_SEND));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -3353,7 +3674,7 @@ static void stm32serial_txint(struct uart_dev_s *dev, bool enable)
|
||||
*/
|
||||
|
||||
# ifdef HAVE_RS485
|
||||
if (priv->rs485_dir_gpio != 0)
|
||||
if ((priv->rs485_flags & SER_RS485_ENABLED) != 0)
|
||||
{
|
||||
ie |= USART_CR1_TCIE;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
|
||||
{
|
||||
/* Calculate the timeout in milliseconds */
|
||||
|
||||
msec = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
|
||||
msec = timeout->tv_sec * 1000 + (timeout->tv_usec + 999) / 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -230,10 +230,12 @@
|
||||
|
||||
/* Protocol-level socket operations. */
|
||||
|
||||
#define SOL_IP IPPROTO_IP /* See options in include/netinet/ip.h */
|
||||
#define SOL_IPV6 IPPROTO_IPV6 /* See options in include/netinet/ip6.h */
|
||||
#define SOL_TCP IPPROTO_TCP /* See options in include/netinet/tcp.h */
|
||||
#define SOL_UDP IPPROTO_UDP /* See options in include/netinit/udp.h */
|
||||
#define SOL_IP IPPROTO_IP /* See options in include/netinet/in.h */
|
||||
#define SOL_IPV6 IPPROTO_IPV6 /* See options in include/netinet/in.h */
|
||||
#define SOL_TCP IPPROTO_TCP /* See options in include/netinet/in.h */
|
||||
#define SOL_UDP IPPROTO_UDP /* See options in include/netinet/in.h */
|
||||
#define SOL_RAW IPPROTO_RAW /* See options in include/netinet/in.h */
|
||||
#define SOL_ICMPV6 IPPROTO_ICMPV6 /* See options in include/netinet/in.h */
|
||||
|
||||
/* Bluetooth-level operations. */
|
||||
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
NET_BUFPOOL_DECLARE(g_can_connections, sizeof(struct can_conn_s),
|
||||
CONFIG_CAN_PREALLOC_CONNS, CONFIG_CAN_ALLOC_CONNS,
|
||||
CONFIG_CAN_MAX_CONNS);
|
||||
static mutex_t g_free_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/* A list of all allocated NetLink connections */
|
||||
|
||||
@@ -100,7 +99,7 @@ FAR struct can_conn_s *can_alloc(void)
|
||||
|
||||
/* The free list is protected by a a mutex. */
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_can_connections);
|
||||
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_can_connections);
|
||||
if (conn != NULL)
|
||||
@@ -128,7 +127,7 @@ FAR struct can_conn_s *can_alloc(void)
|
||||
dq_addlast(&conn->sconn.node, &g_active_can_connections);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_can_connections);
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ void can_free(FAR struct can_conn_s *conn)
|
||||
|
||||
DEBUGASSERT(conn->crefs == 0);
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_can_connections);
|
||||
|
||||
/* Remove the connection from the active list */
|
||||
|
||||
@@ -157,7 +156,7 @@ void can_free(FAR struct can_conn_s *conn)
|
||||
|
||||
NET_BUFPOOL_FREE(g_can_connections, conn);
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_can_connections);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
NET_BUFPOOL_DECLARE(g_icmp_connections, sizeof(struct icmp_conn_s),
|
||||
CONFIG_NET_ICMP_PREALLOC_CONNS,
|
||||
CONFIG_NET_ICMP_ALLOC_CONNS, CONFIG_NET_ICMP_MAX_CONNS);
|
||||
static mutex_t g_free_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/* A list of all allocated IPPROTO_ICMP socket connections */
|
||||
|
||||
@@ -85,24 +84,21 @@ static dq_queue_t g_active_icmp_connections;
|
||||
FAR struct icmp_conn_s *icmp_alloc(void)
|
||||
{
|
||||
FAR struct icmp_conn_s *conn = NULL;
|
||||
int ret;
|
||||
|
||||
/* The free list is protected by a mutex. */
|
||||
|
||||
ret = nxmutex_lock(&g_free_lock);
|
||||
if (ret >= 0)
|
||||
NET_BUFPOLL_LOCK(g_icmp_connections);
|
||||
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_icmp_connections);
|
||||
if (conn != NULL)
|
||||
{
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_icmp_connections);
|
||||
if (conn != NULL)
|
||||
{
|
||||
/* Enqueue the connection into the active list */
|
||||
/* Enqueue the connection into the active list */
|
||||
|
||||
dq_addlast(&conn->sconn.node, &g_active_icmp_connections);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
dq_addlast(&conn->sconn.node, &g_active_icmp_connections);
|
||||
}
|
||||
|
||||
NET_BUFPOLL_UNLOCK(g_icmp_connections);
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -123,7 +119,7 @@ void icmp_free(FAR struct icmp_conn_s *conn)
|
||||
|
||||
/* Take the mutex (perhaps waiting) */
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_icmp_connections);
|
||||
|
||||
/* Is this the last reference on the connection? It might not be if the
|
||||
* socket was cloned.
|
||||
@@ -146,7 +142,7 @@ void icmp_free(FAR struct icmp_conn_s *conn)
|
||||
NET_BUFPOOL_FREE(g_icmp_connections, conn);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_icmp_connections);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -321,7 +321,7 @@ static int icmp_getsockopt_internal(FAR struct socket *psock, int option,
|
||||
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
return ENOPROTOOPT;
|
||||
return -ENOPROTOOPT;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
@@ -383,10 +383,10 @@ static int icmp_getsockopt(FAR struct socket *psock, int level, int option,
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case IPPROTO_IP:
|
||||
case SOL_IP:
|
||||
return ipv4_getsockopt(psock, option, value, value_len);
|
||||
|
||||
case IPPROTO_ICMP:
|
||||
case SOL_RAW:
|
||||
return icmp_getsockopt_internal(psock, option, value, value_len);
|
||||
|
||||
default:
|
||||
@@ -429,7 +429,7 @@ static int icmp_setsockopt_internal(FAR struct socket *psock, int option,
|
||||
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
return ENOPROTOOPT;
|
||||
return -ENOPROTOOPT;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
@@ -486,10 +486,10 @@ static int icmp_setsockopt(FAR struct socket *psock, int level, int option,
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case IPPROTO_IP:
|
||||
case SOL_IP:
|
||||
return ipv4_setsockopt(psock, option, value, value_len);
|
||||
|
||||
case IPPROTO_ICMP:
|
||||
case SOL_RAW:
|
||||
return icmp_setsockopt_internal(psock, option, value, value_len);
|
||||
|
||||
default:
|
||||
|
||||
@@ -63,7 +63,6 @@ NET_BUFPOOL_DECLARE(g_icmpv6_connections, sizeof(struct icmpv6_conn_s),
|
||||
CONFIG_NET_ICMPv6_PREALLOC_CONNS,
|
||||
CONFIG_NET_ICMPv6_ALLOC_CONNS,
|
||||
CONFIG_NET_ICMPv6_MAX_CONNS);
|
||||
static mutex_t g_free_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/* A list of all allocated IPPROTO_ICMP socket connections */
|
||||
|
||||
@@ -86,24 +85,21 @@ static dq_queue_t g_active_icmpv6_connections;
|
||||
FAR struct icmpv6_conn_s *icmpv6_alloc(void)
|
||||
{
|
||||
FAR struct icmpv6_conn_s *conn = NULL;
|
||||
int ret;
|
||||
|
||||
/* The free list is protected by a mutex. */
|
||||
|
||||
ret = nxmutex_lock(&g_free_lock);
|
||||
if (ret >= 0)
|
||||
NET_BUFPOLL_LOCK(g_icmpv6_connections);
|
||||
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_icmpv6_connections);
|
||||
if (conn != NULL)
|
||||
{
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_icmpv6_connections);
|
||||
if (conn != NULL)
|
||||
{
|
||||
/* Enqueue the connection into the active list */
|
||||
/* Enqueue the connection into the active list */
|
||||
|
||||
dq_addlast(&conn->sconn.node, &g_active_icmpv6_connections);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
dq_addlast(&conn->sconn.node, &g_active_icmpv6_connections);
|
||||
}
|
||||
|
||||
NET_BUFPOLL_UNLOCK(g_icmpv6_connections);
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -124,7 +120,7 @@ void icmpv6_free(FAR struct icmpv6_conn_s *conn)
|
||||
|
||||
/* Take the mutex (perhaps waiting) */
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_icmpv6_connections);
|
||||
|
||||
/* Remove the connection from the active list */
|
||||
|
||||
@@ -134,7 +130,7 @@ void icmpv6_free(FAR struct icmpv6_conn_s *conn)
|
||||
|
||||
NET_BUFPOOL_FREE(g_icmpv6_connections, conn);
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_icmpv6_connections);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -319,7 +319,7 @@ static int icmpv6_getsockopt_internal(FAR struct socket *psock, int option,
|
||||
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
return ENOPROTOOPT;
|
||||
return -ENOPROTOOPT;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
@@ -381,10 +381,10 @@ static int icmpv6_getsockopt(FAR struct socket *psock, int level, int option,
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case IPPROTO_IPV6:
|
||||
case SOL_IPV6:
|
||||
return ipv6_getsockopt(psock, option, value, value_len);
|
||||
|
||||
case IPPROTO_ICMPV6:
|
||||
case SOL_ICMPV6:
|
||||
return icmpv6_getsockopt_internal(psock, option, value, value_len);
|
||||
|
||||
default:
|
||||
@@ -427,7 +427,7 @@ static int icmpv6_setsockopt_internal(FAR struct socket *psock, int option,
|
||||
|
||||
if (psock->s_type != SOCK_RAW)
|
||||
{
|
||||
return ENOPROTOOPT;
|
||||
return -ENOPROTOOPT;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
@@ -484,10 +484,10 @@ static int icmpv6_setsockopt(FAR struct socket *psock, int level, int option,
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case IPPROTO_IPV6:
|
||||
case SOL_IPV6:
|
||||
return ipv6_setsockopt(psock, option, value, value_len);
|
||||
|
||||
case IPPROTO_ICMPV6:
|
||||
case SOL_ICMPV6:
|
||||
return icmpv6_setsockopt_internal(psock, option, value, value_len);
|
||||
|
||||
default:
|
||||
|
||||
@@ -475,7 +475,12 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
|
||||
#ifdef CONFIG_NET_MLD
|
||||
/* Configure the device for MLD support */
|
||||
|
||||
mld_devinit(dev);
|
||||
if ((flags & IFF_MULTICAST) != 0)
|
||||
{
|
||||
/* MLD is only supported on multicast capable devices */
|
||||
|
||||
mld_devinit(dev);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NET_ICMPv6_HAVE_STACK
|
||||
|
||||
@@ -65,7 +65,6 @@
|
||||
NET_BUFPOOL_DECLARE(g_netlink_connections, sizeof(struct netlink_conn_s),
|
||||
CONFIG_NETLINK_PREALLOC_CONNS,
|
||||
CONFIG_NETLINK_ALLOC_CONNS, CONFIG_NETLINK_MAX_CONNS);
|
||||
static mutex_t g_free_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/* A list of all allocated NetLink connections */
|
||||
|
||||
@@ -167,7 +166,7 @@ FAR struct netlink_conn_s *netlink_alloc(void)
|
||||
|
||||
/* The free list is protected by a mutex. */
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_netlink_connections);
|
||||
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_netlink_connections);
|
||||
if (conn != NULL)
|
||||
@@ -177,7 +176,7 @@ FAR struct netlink_conn_s *netlink_alloc(void)
|
||||
dq_addlast(&conn->sconn.node, &g_active_netlink_connections);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_netlink_connections);
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -198,7 +197,7 @@ void netlink_free(FAR struct netlink_conn_s *conn)
|
||||
|
||||
DEBUGASSERT(conn->crefs == 0);
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_netlink_connections);
|
||||
|
||||
/* Remove the connection from the active list */
|
||||
|
||||
@@ -215,7 +214,7 @@ void netlink_free(FAR struct netlink_conn_s *conn)
|
||||
|
||||
NET_BUFPOOL_FREE(g_netlink_connections, conn);
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_netlink_connections);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -66,7 +66,6 @@
|
||||
NET_BUFPOOL_DECLARE(g_pkt_connections, sizeof(struct pkt_conn_s),
|
||||
CONFIG_NET_PKT_PREALLOC_CONNS,
|
||||
CONFIG_NET_PKT_ALLOC_CONNS, CONFIG_NET_PKT_MAX_CONNS);
|
||||
static mutex_t g_free_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/* A list of all allocated packet socket connections */
|
||||
|
||||
@@ -104,7 +103,7 @@ FAR struct pkt_conn_s *pkt_alloc(void)
|
||||
|
||||
/* The free list is protected by a mutex. */
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_pkt_connections);
|
||||
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_pkt_connections);
|
||||
if (conn)
|
||||
@@ -114,7 +113,7 @@ FAR struct pkt_conn_s *pkt_alloc(void)
|
||||
dq_addlast(&conn->sconn.node, &g_active_pkt_connections);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_pkt_connections);
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -133,7 +132,7 @@ void pkt_free(FAR struct pkt_conn_s *conn)
|
||||
|
||||
DEBUGASSERT(conn->crefs == 0);
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_pkt_connections);
|
||||
|
||||
/* Remove the connection from the active list */
|
||||
|
||||
@@ -143,7 +142,7 @@ void pkt_free(FAR struct pkt_conn_s *conn)
|
||||
|
||||
NET_BUFPOOL_FREE(g_pkt_connections, conn);
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_pkt_connections);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -91,7 +91,6 @@
|
||||
NET_BUFPOOL_DECLARE(g_udp_connections, sizeof(struct udp_conn_s),
|
||||
CONFIG_NET_UDP_PREALLOC_CONNS,
|
||||
CONFIG_NET_UDP_ALLOC_CONNS, CONFIG_NET_UDP_MAX_CONNS);
|
||||
static mutex_t g_free_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/* A list of all allocated UDP connections */
|
||||
|
||||
@@ -566,7 +565,7 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain)
|
||||
|
||||
/* The free list is protected by a mutex. */
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_udp_connections);
|
||||
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_udp_connections);
|
||||
|
||||
@@ -599,7 +598,7 @@ FAR struct udp_conn_s *udp_alloc(uint8_t domain)
|
||||
dq_addlast(&conn->sconn.node, &g_active_udp_connections);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_udp_connections);
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -622,7 +621,7 @@ void udp_free(FAR struct udp_conn_s *conn)
|
||||
|
||||
DEBUGASSERT(conn->crefs == 0);
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_udp_connections);
|
||||
conn->lport = 0;
|
||||
|
||||
/* Remove the connection from the active list */
|
||||
@@ -654,7 +653,7 @@ void udp_free(FAR struct udp_conn_s *conn)
|
||||
|
||||
NET_BUFPOOL_FREE(g_udp_connections, conn);
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_udp_connections);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -63,7 +63,6 @@ NET_BUFPOOL_DECLARE(g_usrsock_connections, sizeof(struct usrsock_conn_s),
|
||||
CONFIG_NET_USRSOCK_PREALLOC_CONNS,
|
||||
CONFIG_NET_USRSOCK_ALLOC_CONNS,
|
||||
CONFIG_NET_USRSOCK_MAX_CONNS);
|
||||
static mutex_t g_free_lock = NXMUTEX_INITIALIZER;
|
||||
|
||||
/* A list of all allocated usrsock connections */
|
||||
|
||||
@@ -88,7 +87,7 @@ FAR struct usrsock_conn_s *usrsock_alloc(void)
|
||||
|
||||
/* The free list is protected by a a mutex. */
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_usrsock_connections);
|
||||
|
||||
conn = NET_BUFPOOL_TRYALLOC(g_usrsock_connections);
|
||||
if (conn)
|
||||
@@ -104,7 +103,7 @@ FAR struct usrsock_conn_s *usrsock_alloc(void)
|
||||
dq_addlast(&conn->sconn.node, &g_active_usrsock_connections);
|
||||
}
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_usrsock_connections);
|
||||
return conn;
|
||||
}
|
||||
|
||||
@@ -123,7 +122,7 @@ void usrsock_free(FAR struct usrsock_conn_s *conn)
|
||||
|
||||
DEBUGASSERT(conn->crefs == 0);
|
||||
|
||||
nxmutex_lock(&g_free_lock);
|
||||
NET_BUFPOLL_LOCK(g_usrsock_connections);
|
||||
|
||||
/* Remove the connection from the active list */
|
||||
|
||||
@@ -137,7 +136,7 @@ void usrsock_free(FAR struct usrsock_conn_s *conn)
|
||||
|
||||
NET_BUFPOOL_FREE(g_usrsock_connections, conn);
|
||||
|
||||
nxmutex_unlock(&g_free_lock);
|
||||
NET_BUFPOLL_UNLOCK(g_usrsock_connections);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -98,6 +98,7 @@ FAR void *net_bufpool_timedalloc(FAR struct net_bufpool_s *pool,
|
||||
unsigned int timeout)
|
||||
{
|
||||
FAR struct net_bufnode_s *node;
|
||||
FAR void *buf;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
@@ -121,6 +122,8 @@ FAR void *net_bufpool_timedalloc(FAR struct net_bufpool_s *pool,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nxrmutex_lock(&pool->lock);
|
||||
|
||||
/* If we get here, then we didn't exceed maxalloc. */
|
||||
|
||||
if (pool->dynalloc > 0 && sq_peek(&pool->freebuffers) == NULL)
|
||||
@@ -128,7 +131,8 @@ FAR void *net_bufpool_timedalloc(FAR struct net_bufpool_s *pool,
|
||||
node = kmm_zalloc(pool->nodesize * pool->dynalloc);
|
||||
if (node == NULL)
|
||||
{
|
||||
return NULL;
|
||||
buf = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Now initialize each connection structure */
|
||||
@@ -141,7 +145,11 @@ FAR void *net_bufpool_timedalloc(FAR struct net_bufpool_s *pool,
|
||||
}
|
||||
}
|
||||
|
||||
return sq_remfirst(&pool->freebuffers);
|
||||
buf = sq_remfirst(&pool->freebuffers);
|
||||
|
||||
out:
|
||||
nxrmutex_unlock(&pool->lock);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -170,12 +178,16 @@ void net_bufpool_free(FAR struct net_bufpool_s *pool, FAR void *node)
|
||||
{
|
||||
FAR struct net_bufnode_s *net_bufnode = node;
|
||||
|
||||
net_bufpool_lock(pool);
|
||||
|
||||
/* Set the buffer to zero, to make sure all nodes in the free buffer
|
||||
* pool are zeroed.
|
||||
*/
|
||||
|
||||
memset(net_bufnode, 0, pool->nodesize);
|
||||
sq_addlast(&net_bufnode->node, &pool->freebuffers);
|
||||
|
||||
net_bufpool_unlock(pool);
|
||||
}
|
||||
|
||||
nxsem_post(&pool->sem);
|
||||
@@ -205,3 +217,60 @@ int net_bufpool_test(FAR struct net_bufpool_s *pool)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_bufpool_navail
|
||||
*
|
||||
* Description:
|
||||
* Return the number of available buffers in the buffer pool.
|
||||
*
|
||||
* Assumptions:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_bufpool_navail(FAR struct net_bufpool_s *pool)
|
||||
{
|
||||
int val = 0;
|
||||
int ret;
|
||||
|
||||
ret = nxsem_get_value(&pool->sem, &val);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = val;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_bufpool_lock
|
||||
*
|
||||
* Description:
|
||||
* Use the bufpool lock to protect the node of the buffer pool.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pool - The lock of pool to be locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void net_bufpool_lock(FAR struct net_bufpool_s *pool)
|
||||
{
|
||||
nxrmutex_lock(&pool->lock);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_bufpool_unlock
|
||||
*
|
||||
* Description:
|
||||
* Finish using the bufpool lock to protect the node of the buffer pool.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pool - The lock of pool to be unlocked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void net_bufpool_unlock(FAR struct net_bufpool_s *pool)
|
||||
{
|
||||
nxrmutex_unlock(&pool->lock);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
dynalloc, \
|
||||
-(int)(nodesize), \
|
||||
SEM_INITIALIZER(NET_BUFPOOL_MAX(prealloc, dynalloc, maxalloc)), \
|
||||
NXRMUTEX_INITIALIZER, \
|
||||
{ NULL, NULL } \
|
||||
};
|
||||
|
||||
@@ -105,6 +106,9 @@
|
||||
#define NET_BUFPOOL_ALLOC(p) net_bufpool_timedalloc(&p, UINT_MAX)
|
||||
#define NET_BUFPOOL_FREE(p,n) net_bufpool_free(&p, n)
|
||||
#define NET_BUFPOOL_TEST(p) net_bufpool_test(&p)
|
||||
#define NET_BUFPOOL_NAVAIL(p) net_bufpool_navail(&p)
|
||||
#define NET_BUFPOLL_LOCK(p) net_bufpool_lock(&p)
|
||||
#define NET_BUFPOLL_UNLOCK(p) net_bufpool_unlock(&p)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
@@ -132,6 +136,7 @@ struct net_bufpool_s
|
||||
|
||||
sem_t sem; /* The semaphore for waiting for free buffers */
|
||||
|
||||
rmutex_t lock; /* The lock for the pool */
|
||||
sq_queue_t freebuffers;
|
||||
};
|
||||
|
||||
@@ -415,6 +420,45 @@ void net_bufpool_free(FAR struct net_bufpool_s *pool, FAR void *node);
|
||||
|
||||
int net_bufpool_test(FAR struct net_bufpool_s *pool);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_bufpool_navail
|
||||
*
|
||||
* Description:
|
||||
* Return the number of available buffers in the buffer pool.
|
||||
*
|
||||
* Assumptions:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int net_bufpool_navail(FAR struct net_bufpool_s *pool);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_bufpool_lock
|
||||
*
|
||||
* Description:
|
||||
* Use the bufpool lock to protect the node of the buffer pool.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pool - The lock of pool to be locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void net_bufpool_lock(FAR struct net_bufpool_s *pool);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_bufpool_unlock
|
||||
*
|
||||
* Description:
|
||||
* Finish using the bufpool lock to protect the node of the buffer pool.
|
||||
*
|
||||
* Input Parameters:
|
||||
* pool - The lock of pool to be unlocked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void net_bufpool_unlock(FAR struct net_bufpool_s *pool);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_chksum_adjust
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user