Timer struct in IO header
This commit is contained in:
parent
9e7ea4adb6
commit
ac9285846f
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue