Skip to content

snRuntime/src/riscv.h

Functions

Name
void snrt_wfi()
Put the hart into wait for interrupt state.
uint32_t mcycle()
void snrt_interrupt_enable(uint32_t irq)
Enable interrupt source irq.
void snrt_interrupt_disable(uint32_t irq)
Disable interrupt source.
void snrt_interrupt_global_enable(void )
Globally enable M-mode interrupts.
void snrt_interrupt_global_disable(void )
Globally disable interrupts.

Functions Documentation

function snrt_wfi

static inline void snrt_wfi()

Put the hart into wait for interrupt state.

function mcycle

static inline uint32_t mcycle()

function snrt_interrupt_enable

inline void snrt_interrupt_enable(
    uint32_t irq
)

Enable interrupt source irq.

Parameters:

  • irq one of IRQ_[S/H/M]_[SOFT/TIMER/EXT] interrupts

Enable interrupt, either wakes from wfi or if global interrupts are enabled, jumps to the IRQ handler

function snrt_interrupt_disable

inline void snrt_interrupt_disable(
    uint32_t irq
)

Disable interrupt source.

Parameters:

  • irq one of IRQ_[S/H/M]_[SOFT/TIMER/EXT]

See snrt_interrupt_enable

function snrt_interrupt_global_enable

inline void snrt_interrupt_global_enable(
    void 
)

Globally enable M-mode interrupts.

On an interrupt event the core will jump to __snrt_crt0_interrupt_handler service the interrupt and continue normal execution. Enable interrupt sources with snrt_interrupt_enable

function snrt_interrupt_global_disable

inline void snrt_interrupt_global_disable(
    void 
)

Globally disable interrupts.

Source code

// Copyright 2023 ETH Zurich and University of Bologna.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0

#include "riscv_decls.h"

static inline void snrt_wfi() { asm volatile("wfi"); }

static inline uint32_t mcycle() {
    uint32_t register r;
    asm volatile("csrr %0, mcycle" : "=r"(r) : : "memory");
    return r;
}

inline void snrt_interrupt_enable(uint32_t irq) { set_csr(mie, 1 << irq); }

inline void snrt_interrupt_disable(uint32_t irq) { clear_csr(mie, 1 << irq); }

inline void snrt_interrupt_global_enable(void) {
    set_csr(mstatus, MSTATUS_MIE);  // set M global interrupt enable
}
inline void snrt_interrupt_global_disable(void) {
    clear_csr(mstatus, MSTATUS_MIE);
}

Updated on 2023-06-19 at 09:43:56 +0000