From ac9285846fd95e5d3db101572d228983646f9742 Mon Sep 17 00:00:00 2001 From: Luke Wren Date: Mon, 6 Dec 2021 17:16:21 +0000 Subject: [PATCH] Timer struct in IO header --- test/sim/common/tb_cxxrtl_io.h | 16 +++++++++++++--- test/sim/wfi_loop/main.c | 11 +---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/sim/common/tb_cxxrtl_io.h b/test/sim/common/tb_cxxrtl_io.h index 52aec86..330b83a 100644 --- a/test/sim/common/tb_cxxrtl_io.h +++ b/test/sim/common/tb_cxxrtl_io.h @@ -7,13 +7,23 @@ #define IO_BASE 0x80000000 -struct io_hw { +typedef struct { volatile uint32_t print_char; volatile uint32_t print_u32; volatile uint32_t exit; -}; +} io_hw_t; + +#define mm_io ((io_hw_t *const)IO_BASE) + +typedef struct { + volatile uint32_t mtime; + volatile uint32_t mtimeh; + volatile uint32_t mtimecmp; + volatile uint32_t mtimecmph; +} timer_hw_t; + +#define mm_timer ((timer_hw_t *const)(IO_BASE + 0x100)) -#define mm_io ((struct io_hw *const)IO_BASE) static inline void tb_putc(char c) { mm_io->print_char = (uint32_t)c; diff --git a/test/sim/wfi_loop/main.c b/test/sim/wfi_loop/main.c index da09184..73a980e 100644 --- a/test/sim/wfi_loop/main.c +++ b/test/sim/wfi_loop/main.c @@ -6,15 +6,6 @@ #define __wfi() asm volatile ("wfi") #define __compiler_mb() asm volatile ("" ::: "memory") -typedef struct { - volatile uint32_t mtime; - volatile uint32_t mtimeh; - volatile uint32_t mtimecmp; - volatile uint32_t mtimecmph; -} timer_hw; - -timer_hw *const timer = (timer_hw*)(IO_BASE + 0x100); - int irq_count; void __attribute__((interrupt)) isr_machine_timer() { __compiler_mb(); @@ -27,7 +18,7 @@ void __attribute__((interrupt)) isr_machine_timer() { if (irq_count >= MAX_IRQ_COUNT) asm ("csrc mie, %0" :: "r" (1u << 7)); else - timer->mtimecmp = timer->mtime + TIMER_INTERVAL; + mm_timer->mtimecmp = mm_timer->mtime + TIMER_INTERVAL; } int main() {