Zephyr Project API 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
arch.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 KT-Elektronik, Klaucke und Partner GmbH
3 * Copyright (c) 2024 Renesas Electronics Corporation
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
16#ifndef ZEPHYR_INCLUDE_ARCH_RX_ARCH_H_
17#define ZEPHYR_INCLUDE_ARCH_RX_ARCH_H_
18
19/* Add include for DTS generated information */
21#include <zephyr/devicetree.h>
22
24#include <zephyr/arch/rx/misc.h>
29#include <zephyr/sw_isr_table.h>
31#include <zephyr/sys/__assert.h>
32#include <zephyr/sys/util.h>
33#include <zephyr/irq.h>
34
35#define ARCH_STACK_PTR_ALIGN 4
36
37#ifndef _ASMLANGUAGE
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#define REG(addr) *((uint8_t *)(addr))
44
45/* isr for undefined interrupts (results in a fatal error) */
46void z_irq_spurious(const void *unused);
47/* internal routine documented in C file, needed by IRQ_CONNECT() macro */
48extern void z_irq_priority_set(uint32_t irq, uint32_t prio, uint32_t flags);
49
50/* Z_ISR_DECLARE will populate the .intList section with the interrupt's
51 * parameters, which will then be used by gen_irq_tables.py to create
52 * the vector table and the software ISR table. This is all done at
53 * build-time.
54 *
55 * We additionally set the priority in the interrupt controller at
56 * runtime.
57 */
58#define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
59 { \
60 Z_ISR_DECLARE(irq_p, 0, isr_p, isr_param_p); \
61 z_irq_priority_set(irq_p, priority_p, flags_p); \
62 }
63
64#if CONFIG_TRACING_ISR
65#define ARCH_ISR_DIRECT_HEADER() \
66 { \
67 _kernel.cpus[0].nested++; \
68 sys_trace_isr_enter(); \
69 }
70#else
71#define ARCH_ISR_DIRECT_HEADER() \
72 { \
73 _kernel.cpus[0].nested++; \
74 }
75#endif
76
77#if CONFIG_TRACING_ISR
78#define ARCH_ISR_DIRECT_FOOTER(check_reschedule) \
79 { \
80 if (IS_ENABLED(CONFIG_STACK_SENTINEL)) { \
81 z_check_stack_sentinel(); \
82 } \
83 sys_trace_isr_exit(); \
84 irq_lock(); \
85 if (check_reschedule && _kernel.cpus[0].nested == 1) { \
86 if (_kernel.cpus->current->base.prio >= 0 || \
87 CONFIG_NUM_METAIRQ_PRIORITIES > 0) { \
88 if (_kernel.ready_q.cache != _kernel.cpus->current) { \
89 z_rx_irq_exit(); \
90 } \
91 } \
92 } \
93 _kernel.cpus[0].nested--; \
94 }
95#else
96#define ARCH_ISR_DIRECT_FOOTER(check_reschedule) \
97 { \
98 if (IS_ENABLED(CONFIG_STACK_SENTINEL)) { \
99 z_check_stack_sentinel(); \
100 } \
101 irq_lock(); \
102 if (check_reschedule && _kernel.cpus[0].nested == 1) { \
103 if (_kernel.cpus->current->base.prio >= 0 || \
104 CONFIG_NUM_METAIRQ_PRIORITIES > 0) { \
105 if (_kernel.ready_q.cache != _kernel.cpus->current) { \
106 z_rx_irq_exit(); \
107 } \
108 } \
109 } \
110 _kernel.cpus[0].nested--; \
111 }
112#endif
113
114static ALWAYS_INLINE unsigned int arch_irq_lock(void)
115{
116 uint32_t key;
117 /* deactivate interrupts by clearing the PSW-i flag */
118 __asm__ volatile("MVFC psw, %0\n"
119 "CLRPSW i"
120 : "=r"(key)
121 :
122 : "cc");
123 /* return the value of the i-flag before clearing
124 * if irqs were locked already, it was 0 and calling
125 * arch_irq_unlock(key) will not actually unlock irqs, as this was a
126 * nested irq lock
127 */
128 return key & BIT(16);
129}
130
131static inline void arch_irq_unlock(unsigned int key)
132{
133 if (key != 0) {
134 /* re-activate interrupts by setting the PSW i-flag*/
135 __asm__ volatile("SETPSW i" ::: "cc");
136 }
137}
138
139static inline bool arch_irq_unlocked(unsigned int key)
140{
141 return key != 0;
142}
143
144static ALWAYS_INLINE _cpu_t *arch_curr_cpu(void)
145{
146 return &_kernel.cpus[0];
147}
148
149#ifdef __cplusplus
150}
151#endif
152
153#endif /* !_ASMLANGUAGE */
154
155#endif /* ZEPHYR_INCLUDE_ARCH_RX_ARCH_H_ */
Devicetree main header.
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ALWAYS_INLINE
Definition common.h:160
Public interface for configuring interrupts.
static ALWAYS_INLINE unsigned int arch_irq_lock(void)
Definition arch.h:72
static ALWAYS_INLINE void arch_irq_unlock(unsigned int key)
Definition arch.h:83
static ALWAYS_INLINE bool arch_irq_unlocked(unsigned int key)
Definition arch.h:96
flags
Definition parser.h:97
static ALWAYS_INLINE _cpu_t * arch_curr_cpu(void)
Definition arch.h:144
Renesas RX public kernel miscellaneous.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Software-managed ISR table.
Misc utilities.