thread_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Koen Zandberg <koen@bergzand.net>
3  * 2021 Inria
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser General
6  * Public License v2.1. See the file LICENSE in the top level directory for more
7  * details.
8  */
9 
20 #ifndef THREAD_ARCH_H
21 #define THREAD_ARCH_H
22 
23 #include "irq.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define THREAD_API_INLINED
30 
31 #ifndef DOXYGEN /* Doxygen is in core/include/thread.h */
32 
33 static inline void _ecall_dispatch(uint32_t num, void *ctx)
34 {
35  /* function arguments are in a0 and a1 as per ABI */
36  __asm__ volatile (
37  "add a0, x0, %[num] \n"
38  "add a1, x0, %[ctx] \n"
39  "ECALL\n"
40  : /* No outputs */
41  :[num] "r" (num), [ctx] "r" (ctx)
42  : "memory", "a0", "a1"
43  );
44 }
45 
46 static inline __attribute__((always_inline)) void thread_yield_higher(void)
47 {
48  if (irq_is_in()) {
50  }
51  else {
52  _ecall_dispatch(0, NULL);
53  }
54 }
55 
56 #endif /* DOXYGEN */
57 
58 #ifdef __cplusplus
59 }
60 #endif
61 
62 #endif /* THREAD_ARCH_H */
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.