irq/src/main.cpp

73 lines
1.2 KiB
C++

/*
* Subject: Interrupt Controller (IRQ), irq@MuraxSoc (RV32I)
* Lang: Asm, C, C++ (Father of all programming languages)
* OS: Bare Metal @verilated MuraxSoc
* Tested: gdb@jtag
* Authored: mpabi@2024/PI
*/
#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() {
// println("hello world arty a7 v1");
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;
}