Skip to content

Commit 6b918bc

Browse files
committed
cpu/riscv_common: Add periph xh3irq support
1 parent aaef175 commit 6b918bc

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

cpu/riscv_common/periph/xh3irq.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
#include "xh3irq.h"
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Tom Hert <[email protected]>
3+
* SPDX-FileCopyrightText: 2025 HAW Hamburg
4+
* SPDX-License-Identifier: LGPL-2.1-only
5+
*/
6+
27
#include <stdio.h>
38

4-
uint32_t xh3irq_has_pending(void) {
9+
#include "bit.h"
10+
#include "xh3irq.h"
11+
12+
uint32_t xh3irq_has_pending(void)
13+
{
514
/*
615
* Get MEIP which is the external interrupt pending bit
716
* from the Machine Interrupt Pending Register address
817
*/
9-
uint32_t meip = (read_csr(0x344) >> MEIP_OFFSET) & MEIP_MASK;
18+
uint32_t mip_reg = read_csr(0x344);
19+
uint32_t meip = bit_check32(&mip_reg, MEIP_OFFSET);
1020

1121
return (meip != 0);
1222
}
1323

14-
void xh3irq_handler(void) {
24+
void xh3irq_handler(void)
25+
{
1526
/*
1627
* Get MEINEXT at 0xbe4 which is the next highest interrupt to handle (Bit 2-10).
1728
* This will also automagically clear the interrupt (See 3.8.6.1.2.)
@@ -23,14 +34,15 @@ void xh3irq_handler(void) {
2334
*/
2435
uint32_t meinext = (read_csr(0xBE4) >> MEINEXT_IRQ_OFFSET) & MEINEXT_MASK;
2536

26-
void (*isr)(void) = (void (*)(void))vector_cpu[meinext];
37+
void (*isr)(void) = (void (*)(void)) vector_cpu[meinext];
2738
#ifdef DEVELHELP
2839
printf("Calling isr %p for irq %ld\n", isr, meinext);
2940
#endif
3041
isr();
3142
}
3243

33-
void _meiea_set_req_bit(uint32_t irq_no, uint32_t bit_val) {
44+
void _meiea_set_req_bit(uint32_t irq_no, uint32_t bit_val)
45+
{
3446
uint32_t index = irq_no / INTERRUPT_ARRAY_MASK_OFFSET;
3547
uint32_t mask = bit_val << (irq_no % INTERRUPT_ARRAY_MASK_OFFSET);
3648

@@ -45,7 +57,6 @@ void _meiea_set_req_bit(uint32_t irq_no, uint32_t bit_val) {
4557
__asm__ volatile(
4658
"csrs 0xbe0, %0\n"
4759
: : "r"(index | (mask << INTERRUPT_ARRAY_MASK_OFFSET))
48-
4960
);
5061
}
5162

@@ -70,6 +81,5 @@ void xh3irq_force_irq(uint32_t irq_no)
7081
*/
7182
__asm__ volatile(
7283
"csrs 0xbe2, %0\n"
73-
: : "r"(index | (mask << INTERRUPT_ARRAY_MASK_OFFSET))
74-
);
84+
: : "r"(index | (mask << INTERRUPT_ARRAY_MASK_OFFSET)));
7585
}

0 commit comments

Comments
 (0)