Loading...
Searching...
No Matches
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
10#pragma once
11
21
22#include "irq.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define THREAD_API_INLINED
29
30#ifndef DOXYGEN /* Doxygen is in core/include/thread.h */
31
32static inline void _ecall_dispatch(uint32_t num, void *ctx)
33{
34 /* function arguments are in a0 and a1 as per ABI */
35 __asm__ volatile (
36 "add a0, x0, %[num] \n"
37 "add a1, x0, %[ctx] \n"
38 "ECALL\n"
39 : /* No outputs */
40 :[num] "r" (num), [ctx] "r" (ctx)
41 : "memory", "a0", "a1"
42 );
43}
44
45static inline __attribute__((always_inline)) void thread_yield_higher(void)
46{
47 if (irq_is_in()) {
49 }
50 else {
51 _ecall_dispatch(0, NULL);
52 }
53}
54
55#endif /* DOXYGEN */
56
57#ifdef __cplusplus
58}
59#endif
60
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.