Loading...
Searching...
No Matches
thread_arch.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021 Koen Zandberg <koen@bergzand.net>
3 * SPDX-FileCopyrightText: 2021 Inria
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
18
19#include "irq.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define THREAD_API_INLINED
26
27#ifndef DOXYGEN /* Doxygen is in core/include/thread.h */
28
29static inline void _ecall_dispatch(uint32_t num, void *ctx)
30{
31 /* function arguments are in a0 and a1 as per ABI */
32 __asm__ volatile (
33 "add a0, x0, %[num] \n"
34 "add a1, x0, %[ctx] \n"
35 "ECALL\n"
36 : /* No outputs */
37 :[num] "r" (num), [ctx] "r" (ctx)
38 : "memory", "a0", "a1"
39 );
40}
41
42static inline __attribute__((always_inline)) void thread_yield_higher(void)
43{
44 if (irq_is_in()) {
46 }
47 else {
48 _ecall_dispatch(0, NULL);
49 }
50}
51
52#endif /* DOXYGEN */
53
54#ifdef __cplusplus
55}
56#endif
57
MAYBE_INLINE bool irq_is_in(void)
Check whether called from interrupt service routine.
volatile unsigned int sched_context_switch_request
Flag indicating whether a context switch is necessary after handling an interrupt.
THREAD_MAYBE_INLINE void thread_yield_higher(void)
Lets current thread yield in favor of a higher prioritized thread.
IRQ driver interface.