Skip to content

Commit

Permalink
kernel: Enable interrupts for MULTITHREADING=n on supported arch's
Browse files Browse the repository at this point in the history
Some applications have a use case for a tiny MULTITHREADING=n build
(which lacks most of the kernel) but still want special-purpose
drivers in that mode that might need to handle interupts.  This
creates a chicken and egg problem, as arch code (for obvious reasons)
runs _Cstart() with interrupts disabled, and enables them only on
switching into a newly created thread context.  Zephyr does not have a
"turn interrupts on now, please" API at the architecture level.

So this creates one as an arch-specific wrapper around
_arch_irq_unlock().  It's implemented as an optional macro the arch
can define to enable this behavior, falling back to the previous
scheme (and printing a helpful message) if it doesn't find it defined.
Only ARM and x86 are enabled in this patch.

Fixes zephyrproject-rtos#8393

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
  • Loading branch information
Andy Ross authored and nashif committed Aug 27, 2018
1 parent bc6fb65 commit 17e9d62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/arch/arm/cortex_m/asm_inline_gcc.h
Expand Up @@ -175,6 +175,8 @@ static ALWAYS_INLINE void _arch_irq_unlock(unsigned int key)
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
}

/* Used to unconditionally enable interrupts when MULTITHREADING=n */
#define Z_ARCH_INT_ENABLE() _arch_irq_unlock(0)

#endif /* _ASMLANGUAGE */

Expand Down
3 changes: 3 additions & 0 deletions include/arch/x86/arch.h
Expand Up @@ -445,6 +445,9 @@ static ALWAYS_INLINE void _arch_irq_unlock(unsigned int key)
_do_irq_unlock();
}

/* Used to unconditionally enable interrupts when MULTITHREADING=n */
#define Z_ARCH_INT_ENABLE() _arch_irq_unlock(0x200)

/**
* The NANO_SOFT_IRQ macro must be used as the value for the @a irq parameter
* to NANO_CPU_INT_REGISTER when connecting to an interrupt that does not
Expand Down
13 changes: 13 additions & 0 deletions kernel/init.c
Expand Up @@ -436,6 +436,18 @@ u32_t z_early_boot_rand32_get(void)
extern uintptr_t __stack_chk_guard;
#endif /* CONFIG_STACK_CANARIES */

#ifndef CONFIG_MULTITHREADING
static void enable_interrupts(void)
{
#ifdef Z_ARCH_INT_ENABLE
Z_ARCH_INT_ENABLE();
#else
# pragma message "Z_ARCH_INT_ENABLE not defined for this architecture."
# pragma message "Entry to MULTITHREADING=n app code will be with interrupts disabled."
#endif
}
#endif

/**
*
* @brief Initialize kernel
Expand Down Expand Up @@ -490,6 +502,7 @@ FUNC_NORETURN void _Cstart(void)
prepare_multithreading(dummy_thread);
switch_to_main_thread();
#else
enable_interrupts();
bg_thread_main(NULL, NULL, NULL);

while (1) {
Expand Down

0 comments on commit 17e9d62

Please sign in to comment.