Skip to content

Commit b237597

Browse files
aescolarnashif
authored andcommitted
arch: posix: isolate arch-soc/board IF from kernel-arch IF
The POSIX ARCH delegates some of the tasks which normally are taken care of by the ARCH to the SOC or BOARD levels. To avoid changes in the kernel-arch IF propagating into the arch-soc and arch-board interfaces (which would break off-tree posix boards) isolate them. Also move arch inlined functions into the arch.h header, and out from the headers which specify the posix arch-soc and arch-board interfaces. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent d1aca7f commit b237597

File tree

8 files changed

+121
-118
lines changed

8 files changed

+121
-118
lines changed

arch/posix/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ zephyr_library_compile_definitions(NO_POSIX_CHEATS)
55
zephyr_library_sources(
66
cpuhalt.c
77
fatal.c
8+
irq.c
89
posix_core.c
910
swap.c
1011
thread.c

arch/posix/core/irq.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2019 Oticon A/S
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "posix_soc_if.h"
8+
#include "board_irq.h"
9+
10+
void z_arch_irq_offload(irq_offload_routine_t routine, void *parameter)
11+
{
12+
posix_irq_offload(routine, parameter);
13+
}
14+
15+
#ifdef CONFIG_DYNAMIC_INTERRUPTS
16+
/**
17+
* Configure a dynamic interrupt.
18+
*
19+
* Use this instead of IRQ_CONNECT() if arguments cannot be known at build time.
20+
*
21+
* @param irq IRQ line number
22+
* @param priority Interrupt priority
23+
* @param routine Interrupt service routine
24+
* @param parameter ISR parameter
25+
* @param flags Arch-specific IRQ configuration flags
26+
*
27+
* @return The vector assigned to this interrupt
28+
*/
29+
int z_arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
30+
void (*routine)(void *parameter),
31+
void *parameter, u32_t flags)
32+
{
33+
posix_isr_declare(irq, (int)flags, routine, parameter);
34+
posix_irq_priority_set(irq, priority, flags);
35+
return irq;
36+
}
37+
#endif /* CONFIG_DYNAMIC_INTERRUPTS */

arch/posix/include/posix_soc_if.h

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "posix_trace.h"
1818
#include "soc_irq.h" /* Must exist and define _ARCH_IRQ/ISR_* macros */
19+
#include "irq_offload.h"
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -24,33 +25,14 @@ extern "C" {
2425
void posix_halt_cpu(void);
2526
void posix_atomic_halt_cpu(unsigned int imask);
2627

27-
void z_arch_irq_enable(unsigned int irq);
28-
void z_arch_irq_disable(unsigned int irq);
29-
int z_arch_irq_is_enabled(unsigned int irq);
28+
void posix_irq_enable(unsigned int irq);
29+
void posix_irq_disable(unsigned int irq);
30+
int posix_irq_is_enabled(unsigned int irq);
3031
unsigned int posix_irq_lock(void);
3132
void posix_irq_unlock(unsigned int key);
3233
void posix_irq_full_unlock(void);
3334
int posix_get_current_irq(void);
34-
/* irq_offload() from irq_offload.h must also be defined by the SOC or board */
35-
36-
static inline unsigned int z_arch_irq_lock(void)
37-
{
38-
return posix_irq_lock();
39-
}
40-
41-
static inline void z_arch_irq_unlock(unsigned int key)
42-
{
43-
posix_irq_unlock(key);
44-
}
45-
46-
/**
47-
* Returns true if interrupts were unlocked prior to the
48-
* z_arch_irq_lock() call that produced the key argument.
49-
*/
50-
static inline bool z_arch_irq_unlocked(unsigned int key)
51-
{
52-
return key == false;
53-
}
35+
void posix_irq_offload(irq_offload_routine_t routine, void *parameter);
5436

5537
#ifdef __cplusplus
5638
}

boards/posix/native_posix/board_irq.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

8-
#ifndef _BOARD_IRQ_H
9-
#define _BOARD_IRQ_H
8+
#ifndef BOARDS_POSIX_NATIVE_POSIX_BOARD_IRQ_H
9+
#define BOARDS_POSIX_NATIVE_POSIX_BOARD_IRQ_H
1010

1111
#include "sw_isr_table.h"
1212
#include "zephyr/types.h"
@@ -15,9 +15,9 @@
1515
extern "C" {
1616
#endif
1717

18-
void z_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
19-
void *isr_param_p);
20-
void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
18+
void posix_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
19+
void *isr_param_p);
20+
void posix_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
2121

2222
/**
2323
* Configure a static interrupt.
@@ -32,8 +32,8 @@ void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
3232
*/
3333
#define Z_ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
3434
({ \
35-
z_isr_declare(irq_p, 0, isr_p, isr_param_p); \
36-
z_irq_priority_set(irq_p, priority_p, flags_p); \
35+
posix_isr_declare(irq_p, 0, isr_p, isr_param_p); \
36+
posix_irq_priority_set(irq_p, priority_p, flags_p); \
3737
irq_p; \
3838
})
3939

@@ -45,8 +45,9 @@ void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
4545
*/
4646
#define Z_ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \
4747
({ \
48-
z_isr_declare(irq_p, ISR_FLAG_DIRECT, (void (*)(void *))isr_p, NULL); \
49-
z_irq_priority_set(irq_p, priority_p, flags_p); \
48+
posix_isr_declare(irq_p, ISR_FLAG_DIRECT, (void (*)(void *))isr_p, \
49+
NULL); \
50+
posix_irq_priority_set(irq_p, priority_p, flags_p); \
5051
irq_p; \
5152
})
5253

@@ -86,4 +87,4 @@ extern void posix_irq_check_idle_exit(void);
8687
}
8788
#endif
8889

89-
#endif /* _BOARD_IRQ_H */
90+
#endif /* BOARDS_POSIX_NATIVE_POSIX_BOARD_IRQ_H */

boards/posix/native_posix/irq_handler.c

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,17 @@ void posix_irq_full_unlock(void)
194194
hw_irq_ctrl_change_lock(false);
195195
}
196196

197-
void z_arch_irq_enable(unsigned int irq)
197+
void posix_irq_enable(unsigned int irq)
198198
{
199199
hw_irq_ctrl_enable_irq(irq);
200200
}
201201

202-
void z_arch_irq_disable(unsigned int irq)
202+
void posix_irq_disable(unsigned int irq)
203203
{
204204
hw_irq_ctrl_disable_irq(irq);
205205
}
206206

207-
int z_arch_irq_is_enabled(unsigned int irq)
207+
int posix_irq_is_enabled(unsigned int irq)
208208
{
209209
return hw_irq_ctrl_is_irq_enabled(irq);
210210
}
@@ -217,8 +217,8 @@ int posix_get_current_irq(void)
217217
/**
218218
* Configure a static interrupt.
219219
*
220-
* z_isr_declare will populate the interrupt table table with the interrupt's
221-
* parameters, the vector table and the software ISR table.
220+
* posix_isr_declare will populate the interrupt table table with the
221+
* interrupt's parameters, the vector table and the software ISR table.
222222
*
223223
* We additionally set the priority in the interrupt controller at
224224
* runtime.
@@ -229,7 +229,7 @@ int posix_get_current_irq(void)
229229
* @param isr_param_p ISR parameter
230230
* @param flags_p IRQ options
231231
*/
232-
void z_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
232+
void posix_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
233233
void *isr_param_p)
234234
{
235235
irq_vector_table[irq_p].irq = irq_p;
@@ -247,35 +247,11 @@ void z_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
247247
*
248248
* @return N/A
249249
*/
250-
void z_irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags)
250+
void posix_irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags)
251251
{
252252
hw_irq_ctrl_prio_set(irq, prio);
253253
}
254254

255-
#ifdef CONFIG_DYNAMIC_INTERRUPTS
256-
/**
257-
* Configure a dynamic interrupt.
258-
*
259-
* Use this instead of IRQ_CONNECT() if arguments cannot be known at build time.
260-
*
261-
* @param irq IRQ line number
262-
* @param priority Interrupt priority
263-
* @param routine Interrupt service routine
264-
* @param parameter ISR parameter
265-
* @param flags Arch-specific IRQ configuration flags
266-
*
267-
* @return The vector assigned to this interrupt
268-
*/
269-
int z_arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
270-
void (*routine)(void *parameter), void *parameter,
271-
u32_t flags)
272-
{
273-
z_isr_declare(irq, (int)flags, routine, parameter);
274-
z_irq_priority_set(irq, priority, flags);
275-
return irq;
276-
}
277-
#endif /* CONFIG_DYNAMIC_INTERRUPTS */
278-
279255
/**
280256
* Similar to ARM's NVIC_SetPendingIRQ
281257
* set a pending IRQ from SW
@@ -318,12 +294,12 @@ static void offload_sw_irq_handler(void *a)
318294
*
319295
* Raise the SW IRQ assigned to handled this
320296
*/
321-
void z_arch_irq_offload(irq_offload_routine_t routine, void *parameter)
297+
void posix_irq_offload(irq_offload_routine_t routine, void *parameter)
322298
{
323299
off_routine = routine;
324300
off_parameter = parameter;
325-
z_isr_declare(OFFLOAD_SW_IRQ, 0, offload_sw_irq_handler, NULL);
326-
z_arch_irq_enable(OFFLOAD_SW_IRQ);
301+
posix_isr_declare(OFFLOAD_SW_IRQ, 0, offload_sw_irq_handler, NULL);
302+
posix_irq_enable(OFFLOAD_SW_IRQ);
327303
posix_sw_set_pending_IRQ(OFFLOAD_SW_IRQ);
328-
z_arch_irq_disable(OFFLOAD_SW_IRQ);
304+
posix_irq_disable(OFFLOAD_SW_IRQ);
329305
}

boards/posix/nrf52_bsim/board_irq.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* SPDX-License-Identifier: Apache-2.0
66
*/
77

8-
#ifndef _BOARD_IRQ_H
9-
#define _BOARD_IRQ_H
8+
#ifndef BOARDS_POSIX_NRF52_BSIM_BOARD_IRQ_H
9+
#define BOARDS_POSIX_NRF52_BSIM_BOARD_IRQ_H
1010

1111
#include "sw_isr_table.h"
1212
#include "zephyr/types.h"
@@ -15,9 +15,9 @@
1515
extern "C" {
1616
#endif
1717

18-
void z_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
19-
void *isr_param_p);
20-
void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
18+
void posix_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
19+
void *isr_param_p);
20+
void posix_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
2121

2222
/**
2323
* Configure a static interrupt.
@@ -32,8 +32,8 @@ void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
3232
*/
3333
#define Z_ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \
3434
({ \
35-
z_isr_declare(irq_p, 0, isr_p, isr_param_p); \
36-
z_irq_priority_set(irq_p, priority_p, flags_p); \
35+
posix_isr_declare(irq_p, 0, isr_p, isr_param_p); \
36+
posix_irq_priority_set(irq_p, priority_p, flags_p); \
3737
irq_p; \
3838
})
3939

@@ -45,8 +45,9 @@ void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags);
4545
*/
4646
#define Z_ARCH_IRQ_DIRECT_CONNECT(irq_p, priority_p, isr_p, flags_p) \
4747
({ \
48-
z_isr_declare(irq_p, ISR_FLAG_DIRECT, (void (*)(void *))isr_p, NULL); \
49-
z_irq_priority_set(irq_p, priority_p, flags_p); \
48+
posix_isr_declare(irq_p, ISR_FLAG_DIRECT, (void (*)(void *))isr_p, \
49+
NULL); \
50+
posix_irq_priority_set(irq_p, priority_p, flags_p); \
5051
irq_p; \
5152
})
5253

@@ -86,4 +87,4 @@ extern void posix_irq_check_idle_exit(void);
8687
}
8788
#endif
8889

89-
#endif /* _BOARD_IRQ_H */
90+
#endif /* BOARDS_POSIX_NRF52_BSIM_BOARD_IRQ_H */

boards/posix/nrf52_bsim/irq_handler.c

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -253,26 +253,21 @@ void posix_irq_full_unlock(void)
253253
hw_irq_ctrl_change_lock(false);
254254
}
255255

256-
void z_arch_irq_enable(unsigned int irq)
256+
void posix_irq_enable(unsigned int irq)
257257
{
258258
hw_irq_ctrl_enable_irq(irq);
259259
}
260260

261-
void z_arch_irq_disable(unsigned int irq)
261+
void posix_irq_disable(unsigned int irq)
262262
{
263263
hw_irq_ctrl_disable_irq(irq);
264264
}
265265

266-
int z_arch_irq_is_enabled(unsigned int irq)
266+
int posix_irq_is_enabled(unsigned int irq)
267267
{
268268
return hw_irq_ctrl_is_irq_enabled(irq);
269269
}
270270

271-
void z_arch_isr_direct_header(void)
272-
{
273-
/* Nothing to be done */
274-
}
275-
276271
int posix_get_current_irq(void)
277272
{
278273
return currently_running_irq;
@@ -281,8 +276,8 @@ int posix_get_current_irq(void)
281276
/**
282277
* Configure a static interrupt.
283278
*
284-
* z_isr_declare will populate the interrupt table table with the interrupt's
285-
* parameters, the vector table and the software ISR table.
279+
* posix_isr_declare will populate the interrupt table table with the
280+
* interrupt's parameters, the vector table and the software ISR table.
286281
*
287282
* We additionally set the priority in the interrupt controller at
288283
* runtime.
@@ -293,7 +288,7 @@ int posix_get_current_irq(void)
293288
* @param isr_param_p ISR parameter
294289
* @param flags_p IRQ options
295290
*/
296-
void z_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
291+
void posix_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
297292
void *isr_param_p)
298293
{
299294
irq_vector_table[irq_p].irq = irq_p;
@@ -311,35 +306,11 @@ void z_isr_declare(unsigned int irq_p, int flags, void isr_p(void *),
311306
*
312307
* @return N/A
313308
*/
314-
void z_irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags)
309+
void posix_irq_priority_set(unsigned int irq, unsigned int prio, uint32_t flags)
315310
{
316311
hw_irq_ctrl_prio_set(irq, prio);
317312
}
318313

319-
#ifdef CONFIG_DYNAMIC_INTERRUPTS
320-
/**
321-
* Configure a dynamic interrupt.
322-
*
323-
* Use this instead of IRQ_CONNECT() if arguments cannot be known at build time.
324-
*
325-
* @param irq IRQ line number
326-
* @param priority Interrupt priority
327-
* @param routine Interrupt service routine
328-
* @param parameter ISR parameter
329-
* @param flags Arch-specific IRQ configuration flags
330-
*
331-
* @return The vector assigned to this interrupt
332-
*/
333-
int z_arch_irq_connect_dynamic(unsigned int irq, unsigned int priority,
334-
void (*routine)(void *parameter), void *parameter,
335-
u32_t flags)
336-
{
337-
z_isr_declare(irq, (int)flags, routine, parameter);
338-
z_irq_priority_set(irq, priority, flags);
339-
return irq;
340-
}
341-
#endif /* CONFIG_DYNAMIC_INTERRUPTS */
342-
343314
/**
344315
* Similar to ARM's NVIC_SetPendingIRQ
345316
* set a pending IRQ from SW
@@ -382,14 +353,14 @@ static void offload_sw_irq_handler(void *a)
382353
*
383354
* Raise the SW IRQ assigned to handled this
384355
*/
385-
void z_arch_irq_offload(irq_offload_routine_t routine, void *parameter)
356+
void posix_irq_offload(irq_offload_routine_t routine, void *parameter)
386357
{
387358
off_routine = routine;
388359
off_parameter = parameter;
389-
z_isr_declare(OFFLOAD_SW_IRQ, 0, offload_sw_irq_handler, NULL);
390-
z_arch_irq_enable(OFFLOAD_SW_IRQ);
360+
posix_isr_declare(OFFLOAD_SW_IRQ, 0, offload_sw_irq_handler, NULL);
361+
posix_irq_enable(OFFLOAD_SW_IRQ);
391362
posix_sw_set_pending_IRQ(OFFLOAD_SW_IRQ);
392-
z_arch_irq_disable(OFFLOAD_SW_IRQ);
363+
posix_irq_disable(OFFLOAD_SW_IRQ);
393364
}
394365

395366
/**

0 commit comments

Comments
 (0)