Skip to content

Commit

Permalink
Merge pull request RIOT-OS#20240 from benpicco/cpu/atmega-no_thread
Browse files Browse the repository at this point in the history
cpu/avr8_common: fix build with !core_thread
  • Loading branch information
benpicco authored Jan 9, 2024
2 parents 4c74405 + cb76cc1 commit 2e3037c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ void kernel_init(void)
main_trampoline, NULL, "main");
}
else {
/* RIOT without threads */
irq_enable();
main_trampoline(NULL);
while (1) {}
return;
}

cpu_switch_context_exit();
Expand Down
7 changes: 6 additions & 1 deletion cpu/avr8_common/thread_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ void NORETURN avr8_enter_thread_mode(void)

void thread_yield_higher(void)
{
if (!IS_USED(MODULE_CORE_THREAD)) {
return;
}

if (irq_is_in() == 0) {
avr8_context_save();
sched_run();
Expand All @@ -278,7 +282,8 @@ void avr8_exit_isr(void)
__asm__ volatile ("" : : : "memory");

/* schedule should switch context when returning from a non nested interrupt */
if (sched_context_switch_request && avr8_state_irq_count == 0) {
if (sched_context_switch_request && avr8_state_irq_count == 0 &&
IS_USED(MODULE_CORE_THREAD)) {
avr8_context_save();
sched_run();
avr8_context_restore();
Expand Down
7 changes: 6 additions & 1 deletion cpu/native/native_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ void isr_cpu_switch_context_exit(void)
ucontext_t *ctx;

DEBUG("isr_cpu_switch_context_exit\n");
if ((sched_context_switch_request == 1) || (thread_get_active() == NULL)) {
if (((sched_context_switch_request == 1) || (thread_get_active() == NULL))
&& IS_USED(MODULE_CORE_THREAD)) {
sched_run();
}

Expand Down Expand Up @@ -210,7 +211,11 @@ void isr_thread_yield(void)
native_irq_handler();
}

if (!IS_USED(MODULE_CORE_THREAD)) {
return;
}
sched_run();

/* Use intermediate cast to uintptr_t to silence -Wcast-align.
* stacks are manually word aligned in thread_static_init() */
ucontext_t *ctx = (ucontext_t *)(uintptr_t)(thread_get_active()->sp);
Expand Down
4 changes: 3 additions & 1 deletion makefiles/features_modules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ USEMODULE += $(filter cortexm_svc, $(FEATURES_USED))

# select core_idle_thread if the feature no_idle_thread is *not* used
ifeq (, $(filter no_idle_thread, $(FEATURES_USED)))
USEMODULE += core_idle_thread
ifneq (,$(filter core_thread, $(USEMODULE)))
USEMODULE += core_idle_thread
endif
endif

# use mpu_stack_guard if the feature is used
Expand Down

0 comments on commit 2e3037c

Please sign in to comment.