Hey guys from SiFive team,
I’m facing some issues to enable mtime to generate local interrupts, also I cannot read exactly the value inside the mtime register. What steps exactly I need to run before start waiting for machine time interrupt by compare? I’m using the sample code below with coreplex IP E31 (based on SiFive examples):
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include “platform.h”
#include “plic/plic_driver.h”
#include “gpio.h”
#include “uart.h”typedef void (*interrupt_function_ptr_t) (void);
interrupt_function_ptr_t localISR[32];void set_timer()
{
volatile uint64_t * mtime = (uint64_t*) (CLINT_CTRL_ADDR + CLINT_MTIME);
volatile uint64_t * mtimecmp = (uint64_t*) (CLINT_CTRL_ADDR + CLINT_MTIMECMP);
uint64_t now = mtime;
uint64_t then = now + 2RTC_FREQ;
*mtimecmp = then;printf("\n\rMTIME: %d",*mtime);
printf(“\n\rMTIMECMP: %d”,*mtimecmp);
printf(“\n\rMachine timer interrupt!”);
}/Entry Point for Machine Timer Interrupt Handler/
void machine_timer_int_isr()
{
set_timer();
}void invalid_local_isr()
{
printf(“\n\rUnexpected local interrupt!”);
}int main(void)
{
for (int lisr = 0; lisr < 32; lisr++) {
localISR[lisr] = invalid_local_isr;
}localISR[IRQ_M_TIMER] = machine_timer_int_isr; set_timer(); // Enable timer interrupts. set_csr(mie, MIP_MTIP); // Enable all interrupts set_csr(mstatus, MSTATUS_MIE); while(1) { //rdtime(); asm volatile ("wfi"); } return 0;
}