irq/src/main.cpp

73 lines
1.2 KiB
C++
Raw Normal View History

2024-06-02 07:14:45 +00:00
/*
* Subject: Interrupt Controller (IRQ), irq@MuraxSoc (RV32I)
2024-06-02 14:19:36 +00:00
* Lang: Asm, C, C++ (Father of all programming languages)
* OS: Bare Metal @verilated MuraxSoc
2024-06-02 07:14:45 +00:00
* Tested: gdb@jtag
2024-06-02 14:19:36 +00:00
* Authored: mpabi@2024/PI
2024-06-02 07:14:45 +00:00
*/
2024-06-01 21:14:04 +00:00
#include <stdint.h>
#include "murax.h"
void print(const char*str){
while(*str){
// uart_write(UART,*str);
str++;
}
}
void println(const char*str){
print(str);
// uart_write(UART,'\n');
}
volatile int mati = 0;
// Modern C++ aproach
// ---
class TimeR {
public:
static inline uint32_t readValue() {
return ptr->VALUE;
}
private:
static const Timer_Reg* ptr ;
};
const Timer_Reg* TimeR::ptr = reinterpret_cast<const Timer_Reg*>(0xF0020040);
// ---
int main() {
2024-06-02 07:14:45 +00:00
// println("hello world arty a7 v1");
2024-06-01 21:14:04 +00:00
interruptCtrl_init(TIMER_INTERRUPT);
prescaler_init(TIMER_PRESCALER);
timer_init(TIMER_A);
TIMER_PRESCALER->LIMIT = 0x10;
TIMER_A->LIMIT = 0x10000-1;
TIMER_A->CLEARS_TICKS = 0x10002;
TIMER_INTERRUPT->PENDINGS = 0xF;
TIMER_INTERRUPT->MASKS = 0x1;
while(1){
++mati;
}
}
extern "C" void irqCallback(){
static volatile int count = 0;
++count;
TIMER_INTERRUPT->PENDINGS = 1;
}