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

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_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
void neorv32_cpu_irq_enable (int irq_sel)
 
void neorv32_cpu_irq_disable (int 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)
 
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.

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

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.

Note
This function will return with the CPU being in user mode.

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

void neorv32_cpu_irq_disable ( int  irq_sel)

Disable specific interrupt channel.

Note
This functions also tries to clear the pending flag of the interrupt.
Parameters
[in]irq_selCPU interrupt select. See NEORV32_CSR_MIE_enum.

◆ neorv32_cpu_irq_enable()

void neorv32_cpu_irq_enable ( int  irq_sel)

Unavailable extensions warning. Enable specific interrupt channel.

Note
This functions also tries to clear the pending flag of the interrupt.
Parameters
[in]irq_selCPU interrupt select. See NEORV32_CSR_MIE_enum.

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

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.