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