NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
Functions
neorv32_cpu.h File Reference

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

Go to the source code of this file.

Functions

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_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 (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)
 
void neorv32_cpu_goto_user_mode (void)
 
void __neorv32_crt0_after_main (int32_t return_code)
 
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_sleep (void)
 
void neorv32_cpu_eint (void)
 
void neorv32_cpu_dint (void)
 
void neorv32_cpu_breakpoint (void)
 
void neorv32_cpu_env_call (void)
 

Detailed Description

CPU Core Functions HW driver header file.

Function Documentation

◆ __neorv32_crt0_after_main()

void __neorv32_crt0_after_main ( int32_t  return_code)

Prototype for "after-main handler". This function is called if main() returns.

Parameters
[in]return_codeReturn value of main() function.

"after-main" handler that is executed after the application's main function returns (called by crt0.S start-up code)

"after-main" handler that is executed after the application's main function returns (called by crt0.S start-up code): Output minimal test report to physical UART

◆ neorv32_cpu_breakpoint()

void neorv32_cpu_breakpoint ( void  )
inline

Trigger breakpoint exception (via EBREAK instruction).

◆ 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_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 MTIME as time base. A simple (imprecise) ASM loop is used as fall back if the system timer is not implemented.
Parameters
[in]time_msTime in ms to wait (unsigned 32-bit).

◆ neorv32_cpu_dint()

void neorv32_cpu_dint ( void  )
inline

Disable global CPU interrupts (via MIE flag in mstatus CSR).

◆ neorv32_cpu_eint()

void neorv32_cpu_eint ( void  )
inline

Enable global CPU interrupts (via MIE flag in mstatus CSR).

◆ neorv32_cpu_env_call()

void neorv32_cpu_env_call ( void  )
inline

Trigger environment call exception (via ECALL instruction).

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

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 the mhpmcounter3[h] CSRs.
Returns
Size of HPM counters (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_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 ( 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).

◆ neorv32_cpu_sleep()

void neorv32_cpu_sleep ( void  )
inline

Put CPU into "sleep" mode.

Note
This function executes the WFI instruction. The WFI (wait for interrupt) instruction will make the CPU stall until an interrupt request is detected. Interrupts have to be globally enabled and at least one external source must be enabled (like the MTI machine timer interrupt) to allow the CPU to wake up again. If 'Zicsr' CPU extension is disabled, this will permanently stall the CPU.

◆ 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

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