Skip to content

Commit 1972a3f

Browse files
NilsRuf-EHaescolar
authored andcommitted
drivers: uart: uart_native_tty: allow multiple instances
Adds one RX thread per instance. Previously, only one global RX thread was used resulting in crashes due to the thread instance being overwritten by other instances. Signed-off-by: Nils Ruf <nils.ruf@endress.com>
1 parent c9151be commit 1972a3f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/serial/uart_native_tty.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ struct native_tty_data {
4848
uart_irq_callback_user_data_t callback;
4949
/* IRQ callback data */
5050
void *cb_data;
51+
/* Instance-specific RX thread. */
52+
struct k_thread rx_thread;
53+
/* RX thread stack. */
54+
K_KERNEL_STACK_MEMBER(rx_stack, CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE);
5155
#endif
5256
};
5357

@@ -56,8 +60,6 @@ struct native_tty_config {
5660
};
5761

5862
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
59-
static struct k_thread rx_thread;
60-
static K_KERNEL_STACK_DEFINE(rx_stack, CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE);
6163
#define NATIVE_TTY_INIT_LEVEL POST_KERNEL
6264
#else
6365
#define NATIVE_TTY_INIT_LEVEL PRE_KERNEL_1
@@ -311,8 +313,10 @@ static void native_tty_uart_irq_callback_set(const struct device *dev,
311313

312314
static void native_tty_irq_init(const struct device *dev)
313315
{
316+
struct native_tty_data *data = dev->data;
317+
314318
/* Create a thread which will wait for data - replacement for IRQ */
315-
k_thread_create(&rx_thread, rx_stack, K_KERNEL_STACK_SIZEOF(rx_stack),
319+
k_thread_create(&data->rx_thread, data->rx_stack, K_KERNEL_STACK_SIZEOF(data->rx_stack),
316320
native_tty_uart_irq_function,
317321
(void *)dev, NULL, NULL,
318322
K_HIGHEST_THREAD_PRIO, 0, K_NO_WAIT);

0 commit comments

Comments
 (0)