NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_cpu.h File Reference

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

#include <stdint.h>

Go to the source code of this file.

Functions

void neorv32_cpu_store_unsigned_word (uint32_t addr, uint32_t wdata)
 
void neorv32_cpu_store_unsigned_half (uint32_t addr, uint16_t wdata)
 
void neorv32_cpu_store_unsigned_byte (uint32_t addr, uint8_t wdata)
 
uint32_t neorv32_cpu_load_unsigned_word (uint32_t addr)
 
uint16_t neorv32_cpu_load_unsigned_half (uint32_t addr)
 
int16_t neorv32_cpu_load_signed_half (uint32_t addr)
 
uint8_t neorv32_cpu_load_unsigned_byte (uint32_t addr)
 
int8_t neorv32_cpu_load_signed_byte (uint32_t addr)
 
uint32_t neorv32_cpu_csr_read (const int csr_id)
 
void neorv32_cpu_csr_write (const int csr_id, uint32_t data)
 
void neorv32_cpu_csr_set (const int csr_id, uint32_t mask)
 
void neorv32_cpu_csr_clr (const int csr_id, uint32_t mask)
 
void neorv32_cpu_sleep (void)
 
Prototypes
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)
 
void neorv32_cpu_delay_ms (uint32_t time_ms)
 
uint32_t neorv32_cpu_get_clk_from_prsc (int prsc)
 
uint32_t neorv32_cpu_pmp_get_num_regions (void)
 
uint32_t neorv32_cpu_pmp_get_granularity (void)
 
int neorv32_cpu_pmp_configure_region (int index, uint32_t addr, uint8_t config)
 
uint32_t neorv32_cpu_hpm_get_num_counters (void)
 
uint32_t neorv32_cpu_hpm_get_size (void)
 
void neorv32_cpu_goto_user_mode (void)
 

Detailed Description

CPU Core Functions HW driver header file.

See also
https://stnolting.github.io/neorv32/sw/files.html

Function Documentation

◆ neorv32_cpu_csr_clr()

void neorv32_cpu_csr_clr ( const int csr_id,
uint32_t mask )
inline

Clear bit(s) in CPU control and status register (CSR).

Parameters
[in]csr_idID of CSR to write. See NEORV32_CSR_enum.
[in]maskBit mask (high-active) to clear bits (uint32_t).

◆ neorv32_cpu_csr_read()

uint32_t neorv32_cpu_csr_read ( const int csr_id)
inline

Read data from CPU control and status register (CSR).

Parameters
[in]csr_idID of CSR to read. See NEORV32_CSR_enum.
Returns
Read data (uint32_t).

◆ neorv32_cpu_csr_set()

void neorv32_cpu_csr_set ( const int csr_id,
uint32_t mask )
inline

Set bit(s) in CPU control and status register (CSR).

Parameters
[in]csr_idID of CSR to write. See NEORV32_CSR_enum.
[in]maskBit mask (high-active) to set bits (uint32_t).

◆ neorv32_cpu_csr_write()

void neorv32_cpu_csr_write ( const int csr_id,
uint32_t data )
inline

Write data to CPU control and status register (CSR).

Parameters
[in]csr_idID of CSR to write. See NEORV32_CSR_enum.
[in]dataData to write (uint32_t).

◆ neorv32_cpu_delay_ms()

void neorv32_cpu_delay_ms ( uint32_t time_ms)

Delay function using busy wait.

Note
This function uses the cycle CPU counter if available. Otherwise the MTIME system timer is used if available. A simple loop is used as alternative fall-back (imprecise!).
Parameters
[in]time_msTime in ms to wait (unsigned 32-bit).

◆ neorv32_cpu_get_clk_from_prsc()

uint32_t neorv32_cpu_get_clk_from_prsc ( int prsc)

Get actual clocking frequency from prescaler select NEORV32_CLOCK_PRSC_enum

Parameters
[in]prscPrescaler select NEORV32_CLOCK_PRSC_enum. return Actual raw clock frequency in Hz.

◆ neorv32_cpu_get_cycle()

uint64_t neorv32_cpu_get_cycle ( void )

Unavailable extensions warnings. Get cycle counter from cycle[h].

Returns
Current cycle counter (64 bit).

◆ neorv32_cpu_get_instret()

uint64_t neorv32_cpu_get_instret ( void )

Get retired instructions counter from instret[h].

Returns
Current instructions counter (64 bit).

◆ neorv32_cpu_goto_user_mode()

void neorv32_cpu_goto_user_mode ( void )

Switch from privilege mode MACHINE to privilege mode USER.

◆ 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.

Returns
Returns number of available HPM counters.

◆ 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 the mhpmcounter3[h] CSRs.
Returns
Size of HPM counters (1-64, 0 if not implemented at all).

◆ neorv32_cpu_load_signed_byte()

int8_t neorv32_cpu_load_signed_byte ( uint32_t addr)
inline

Load signed byte from address space.

Parameters
[in]addrAddress (32-bit).
Returns
Read data byte (8-bit).

◆ neorv32_cpu_load_signed_half()

int16_t neorv32_cpu_load_signed_half ( uint32_t addr)
inline

Load signed half-word from address space.

Note
An unaligned access address will raise an alignment exception.
Parameters
[in]addrAddress (32-bit).
Returns
Read data half-word (16-bit).

◆ neorv32_cpu_load_unsigned_byte()

uint8_t neorv32_cpu_load_unsigned_byte ( uint32_t addr)
inline

Load unsigned byte from address space.

Parameters
[in]addrAddress (32-bit).
Returns
Read data byte (8-bit).

◆ neorv32_cpu_load_unsigned_half()

uint16_t neorv32_cpu_load_unsigned_half ( uint32_t addr)
inline

Load unsigned half-word from address space.

Note
An unaligned access address will raise an alignment exception.
Parameters
[in]addrAddress (32-bit).
Returns
Read data half-word (16-bit).

◆ neorv32_cpu_load_unsigned_word()

uint32_t neorv32_cpu_load_unsigned_word ( uint32_t addr)
inline

Load unsigned word from address space.

Note
An unaligned access address will raise an alignment exception.
Parameters
[in]addrAddress (32-bit).
Returns
Read data word (32-bit).

◆ neorv32_cpu_pmp_configure_region()

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

Physical memory protection (PMP): Configure region.

Note
This function requires the PMP CPU extension.
Warning
This function expects a WORD address!
Parameters
[in]indexRegion number (index, 0..PMP_NUM_REGIONS-1).
[in]addrRegion address (word 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 machine cycle counter mcycle[h].

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

◆ neorv32_cpu_set_minstret()

void neorv32_cpu_set_minstret ( uint64_t value)

Set machine retired instructions counter minstret[h].

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

◆ neorv32_cpu_sleep()

void neorv32_cpu_sleep ( void )
inline

Put CPU into sleep / power-down mode.

Note
The WFI (wait for interrupt) instruction will make the CPU halt until any enabled interrupt source becomes pending.

◆ neorv32_cpu_store_unsigned_byte()

void neorv32_cpu_store_unsigned_byte ( uint32_t addr,
uint8_t wdata )
inline

Store unsigned byte to address space.

Parameters
[in]addrAddress (32-bit).
[in]wdataData byte (8-bit) to store.

◆ neorv32_cpu_store_unsigned_half()

void neorv32_cpu_store_unsigned_half ( uint32_t addr,
uint16_t wdata )
inline

Store unsigned half-word to address space.

Note
An unaligned access address will raise an alignment exception.
Parameters
[in]addrAddress (32-bit).
[in]wdataData half-word (16-bit) to store.

◆ neorv32_cpu_store_unsigned_word()

void neorv32_cpu_store_unsigned_word ( uint32_t addr,
uint32_t wdata )
inline

Store unsigned word to address space.

Note
An unaligned access address will raise an alignment exception.
Parameters
[in]addrAddress (32-bit).
[in]wdataData word (32-bit) to store.