NEORV32 - Software Framework Documentation
Functions
neorv32_cpu.c File Reference

CPU Core Functions HW driver source file. More...

#include "neorv32.h"
#include "neorv32_cpu.h"

Functions

static int __neorv32_cpu_irq_id_check (uint8_t irq_sel)
 
static uint32_t __neorv32_cpu_pmp_cfg_read (uint32_t index)
 
static void __neorv32_cpu_pmp_cfg_write (uint32_t index, uint32_t data)
 
int neorv32_cpu_irq_enable (uint8_t irq_sel)
 
int neorv32_cpu_irq_disable (uint8_t irq_sel)
 
uint64_t neorv32_cpu_get_cycle (void)
 
void neorv32_cpu_set_mcycle (uint64_t value)
 
uint64_t neorv32_cpu_get_instret (void)
 
void neorv32_cpu_set_minstret (uint64_t value)
 
uint64_t neorv32_cpu_get_systime (void)
 
void neorv32_cpu_delay_ms (uint32_t time_ms)
 
uint32_t neorv32_cpu_pmp_get_num_regions (void)
 
uint32_t neorv32_cpu_pmp_get_granularity (void)
 
int neorv32_cpu_pmp_configure_region (uint32_t index, uint32_t base, uint8_t config)
 
uint32_t neorv32_cpu_hpm_get_num_counters (void)
 
uint32_t neorv32_cpu_hpm_get_size (void)
 
uint32_t neorv32_cpu_cnt_get_size (void)
 
void neorv32_cpu_goto_user_mode (void)
 

Detailed Description

CPU Core Functions HW driver source file.

Function Documentation

◆ __neorv32_cpu_irq_id_check()

static int __neorv32_cpu_irq_id_check ( uint8_t  irq_sel)
static

Unavailable extensions warning. >Private< helper functions.

Private function: Check IRQ id.

Parameters
[in]irq_selCPU interrupt select. See NEORV32_CSR_MIE_enum.
Returns
0 if success, 1 if error (invalid irq_sel).

◆ __neorv32_cpu_pmp_cfg_read()

static uint32_t __neorv32_cpu_pmp_cfg_read ( uint32_t  index)
static

Internal helper function: Read PMP configuration register 0..15

Warning
This function requires the PMP CPU extension.
Parameters
[in]indexPMP CFG configuration register ID (0..15).
Returns
PMP CFG read data.

◆ __neorv32_cpu_pmp_cfg_write()

static void __neorv32_cpu_pmp_cfg_write ( uint32_t  index,
uint32_t  data 
)
static

Internal helper function: Write PMP configuration register 0..4

Warning
This function requires the PMP CPU extension.
Parameters
[in]indexPMP CFG configuration register ID (0..4).
[in]dataPMP CFG write data.

◆ neorv32_cpu_cnt_get_size()

uint32_t neorv32_cpu_cnt_get_size ( void  )

CPU base counters (cycle, instret): Get total counter width

Warning
This function overrides mcycle[h] CSRs.
Returns
Size of CPU counters (1-64, 0 if not implemented at all).

◆ neorv32_cpu_delay_ms()

void neorv32_cpu_delay_ms ( uint32_t  time_ms)

Delay function using busy wait.

Note
This function uses MTIME as time base. A simple ASM loop is used as fall back if system timer is not implemented.
Warning
Delay time might be less precise if M extensions is not available (especially if MTIME unit is not available).
Parameters
[in]time_msTime in ms to wait (unsigned 32-bit).

◆ neorv32_cpu_get_cycle()

uint64_t neorv32_cpu_get_cycle ( void  )

Get cycle count from cycle[h].

Note
The cycle[h] CSR is shadowed copy of the mcycle[h] CSR.
Returns
Current cycle counter (64 bit).

◆ neorv32_cpu_get_instret()

uint64_t neorv32_cpu_get_instret ( void  )

Get retired instructions counter from instret[h].

Note
The instret[h] CSR is shadowed copy of the instret[h] CSR.
Returns
Current instructions counter (64 bit).

◆ neorv32_cpu_get_systime()

uint64_t neorv32_cpu_get_systime ( void  )

Get current system time from time[h] CSR.

Note
This function requires the MTIME system timer to be implemented.
Returns
Current system time (64 bit).

◆ neorv32_cpu_goto_user_mode()

void neorv32_cpu_goto_user_mode ( void  )

Switch from privilege mode MACHINE to privilege mode USER.

Warning
This function requires the U ISA extension to be implemented.

◆ neorv32_cpu_hpm_get_num_counters()

uint32_t neorv32_cpu_hpm_get_num_counters ( void  )

Hardware performance monitors (HPM): Get number of available HPM counters.

Warning
This function overrides all available mhpmcounter* CSRs.
Returns
Returns number of available HPM counters (0..29).

◆ neorv32_cpu_hpm_get_size()

uint32_t neorv32_cpu_hpm_get_size ( void  )

Hardware performance monitors (HPM): Get total counter width

Warning
This function overrides mhpmcounter3[h] CSRs.
Returns
Size of HPM counter bits (1-64, 0 if not implemented at all).

◆ neorv32_cpu_irq_disable()

int neorv32_cpu_irq_disable ( uint8_t  irq_sel)

Disable specific CPU interrupt.

Parameters
[in]irq_selCPU interrupt select. See NEORV32_CSR_MIE_enum.
Returns
0 if success, 1 if error (invalid irq_sel).

◆ neorv32_cpu_irq_enable()

int neorv32_cpu_irq_enable ( uint8_t  irq_sel)

Enable specific CPU interrupt.

Note
Interrupts have to be globally enabled via neorv32_cpu_eint(void), too.
Parameters
[in]irq_selCPU interrupt select. See NEORV32_CSR_MIE_enum.
Returns
0 if success, 1 if error (invalid irq_sel).

◆ neorv32_cpu_pmp_configure_region()

int neorv32_cpu_pmp_configure_region ( uint32_t  index,
uint32_t  base,
uint8_t  config 
)

Physical memory protection (PMP): Configure region.

Warning
Only TOR mode is supported.
Note
This function requires the PMP CPU extension.
Only use available PMP regions. Check before using neorv32_cpu_pmp_get_regions(void).
Parameters
[in]indexRegion number (index, 0..PMP_NUM_REGIONS-1).
[in]baseRegion base address.
[in]configRegion configuration byte (see NEORV32_PMPCFG_ATTRIBUTES_enum).
Returns
Returns 0 on success, !=0 on failure.

◆ neorv32_cpu_pmp_get_granularity()

uint32_t neorv32_cpu_pmp_get_granularity ( void  )

Physical memory protection (PMP): Get minimal region size (granularity).

Warning
This function overrides PMPCFG0[0] and PMPADDR0 CSRs!
Note
This function requires the PMP CPU extension.
Returns
Returns minimal region size in bytes. Returns zero on error.

◆ neorv32_cpu_pmp_get_num_regions()

uint32_t neorv32_cpu_pmp_get_num_regions ( void  )

Physical memory protection (PMP): Get number of available regions.

Warning
This function overrides all available PMPCFG* CSRs!
Note
This function requires the PMP CPU extension.
Returns
Returns number of available PMP regions.

◆ neorv32_cpu_set_mcycle()

void neorv32_cpu_set_mcycle ( uint64_t  value)

Set mcycle[h] counter.

Parameters
[in]valueNew value for mcycle[h] CSR (64-bit).

◆ neorv32_cpu_set_minstret()

void neorv32_cpu_set_minstret ( uint64_t  value)

Set retired instructions counter minstret[h].

Parameters
[in]valueNew value for mcycle[h] CSR (64-bit).