![]() |
NMSIS-Core
Version 1.4.0
NMSIS-Core support for Nuclei processor-based devices
|
Functions for system and clock setup available in system_<device>.c. More...
Modules | |
Interrupt and Exception and NMI Handling | |
Functions for interrupt, exception and nmi handle available in system_<device>.c. | |
Macros | |
#define | CLINT_MSIP(base, hartid) (*(volatile uint32_t *)((uintptr_t)((base) + ((hartid) * 4)))) |
#define | SMP_CTRLREG(base, ofs) (*(volatile uint32_t *)((uintptr_t)((base) + (ofs)))) |
Functions | |
void | exc_entry_s (void) |
void | irq_entry_s (void) |
default entry for s-mode non-vector irq entry More... | |
void | default_intexc_handler (void) |
default entry for s-mode exception entry More... | |
void | SystemCoreClockUpdate (void) |
Function to update the variable SystemCoreClock. More... | |
void | SystemInit (void) |
Function to Initialize the system. More... | |
void | SystemBannerPrint (void) |
Banner Print for Nuclei SDK. More... | |
void | irq_entry (void) |
void | exc_entry (void) |
void | ECLIC_Interrupt_Init (void) |
Do ECLIC Interrupt configuration. More... | |
void | CLINT_Interrupt_Init (void) |
Do CLINT Interrupt configuration. More... | |
void | PLIC_Interrupt_Init (void) |
Do PLIC Interrupt configuration. More... | |
void | Interrupt_Init (void) |
initialize interrupt controller More... | |
int32_t | ECLIC_Register_IRQ (IRQn_Type IRQn, uint8_t shv, ECLIC_TRIGGER_Type trig_mode, uint8_t lvl, uint8_t priority, void *handler) |
Initialize a specific IRQ and register the handler. More... | |
int32_t | Core_Register_IRQ (uint32_t irqn, void *handler) |
Register a m-mode riscv core interrupt and register the handler. More... | |
int32_t | Core_Register_IRQ_S (uint32_t irqn, void *handler) |
Register a riscv s-mode core interrupt and register the handler. More... | |
int32_t | PLIC_Register_IRQ (uint32_t source, uint8_t priority, void *handler) |
Register a m-mode specific plic interrupt and register the handler. More... | |
int32_t | PLIC_Register_IRQ_S (uint32_t source, uint8_t priority, void *handler) |
Register a s-mode specific plic interrupt and register the handler. More... | |
int32_t | ECLIC_Register_IRQ_S (IRQn_Type IRQn, uint8_t shv, ECLIC_TRIGGER_Type trig_mode, uint8_t lvl, uint8_t priority, void *handler) |
Initialize a specific IRQ and register the handler for supervisor mode. More... | |
void | __sync_harts (void) |
Synchronize all harts. More... | |
static void | Trap_Init (void) |
do the init for trap More... | |
void | _premain_init (void) |
early init function before main More... | |
void | _postmain_fini (int status) |
finish function after main More... | |
void | _init (void) |
_init function called in __libc_init_array() More... | |
void | _fini (void) |
_fini function called in __libc_fini_array() More... | |
Variables | |
volatile uint32_t | SystemCoreClock = SYSTEM_CLOCK |
Variable to hold the system core clock value. More... | |
unsigned long | vector_base [] |
volatile unsigned long | CpuIRegionBase = 0xFFFFFFFF |
Nuclei RISC-V CPU IRegion Base Address Probed, you should avoid to use it in your application code, please use __IREGION_BASEADDR if you want. More... | |
Functions for system and clock setup available in system_<device>.c.
Nuclei provides a template file system_Device.c that must be adapted by the silicon vendor to match their actual device. As a minimum requirement, this file must provide:
The file configures the device and, typically, initializes the oscillator (PLL) that is part of the microcontroller device. This file might export other functions or variables that provide a more flexible configuration of the microcontroller system.
And this file also provided common interrupt, exception and NMI exception handling framework template, Silicon vendor can customize these template code as they want.
SystemCoreClock
. This variable might be used throughout the whole system initialization and runtime to calculate frequency/time related values. Thus one must assure that the variable always reflects the actual system clock speed.SystemCoreClock
during low level initialization (i.e. SystemInit()
) might get overwritten by C libray startup code and/or .bss section initialization. Thus its highly recommended to call SystemCoreClockUpdate at the beginning of the user main()
routine. #define CLINT_MSIP | ( | base, | |
hartid | |||
) | (*(volatile uint32_t *)((uintptr_t)((base) + ((hartid) * 4)))) |
Definition at line 1244 of file system_Device.c.
#define SMP_CTRLREG | ( | base, | |
ofs | |||
) | (*(volatile uint32_t *)((uintptr_t)((base) + (ofs)))) |
Definition at line 1245 of file system_Device.c.
void __sync_harts | ( | void | ) |
Synchronize all harts.
This function is used to synchronize all the harts, especially to wait the boot hart finish initialization of data section, bss section and c runtines initialization This function must be placed in .text.init section, since section initialization is not ready, global variable and static variable should be avoid to use in this function, and avoid to call other functions
Definition at line 1247 of file system_Device.c.
void _fini | ( | void | ) |
_fini function called in __libc_fini_array()
This __libc_fini_array()
function is called when exit main. user need to implement this function, otherwise when link it will error fini.c:(.text.__libc_fini_array+0x28): undefined reference to ‘_fini’
Definition at line 1554 of file system_Device.c.
void _init | ( | void | ) |
_init function called in __libc_init_array()
This __libc_init_array()
function is called during startup code, user need to implement this function, otherwise when link it will error init.c:(.text.__libc_init_array+0x26): undefined reference to ‘_init’
Definition at line 1540 of file system_Device.c.
void _postmain_fini | ( | int | status | ) |
finish function after main
[in] | status | status code return from main |
This function is executed right after main function. For RISC-V gnu toolchain, _fini function might not be called by __libc_fini_array function, so we defined a new function to do initialization
Definition at line 1518 of file system_Device.c.
void _premain_init | ( | void | ) |
early init function before main
This function is executed right before main function. For RISC-V gnu toolchain, _init function might not be called by __libc_init_array function, so we defined a new function to do initialization.
Definition at line 1324 of file system_Device.c.
References __FENCE_I(), __get_hart_id(), __RV_CSR_CLEAR, __RV_CSR_READ, __RV_CSR_SET, __RWMB, __SMP_RWMB, CpuIRegionBase, CSR_MCACHE_CTL, CSR_MCFG_INFO, CSR_MDLM_CTL, CSR_MILM_CTL, CSR_MIRGB_INFO, CSR_MMISC_CTL, DCachePresent(), EnableDCache(), EnableICache(), EnableSUCCM(), Exception_Init(), ICachePresent(), Interrupt_Init(), MCACHE_CTL_DC_ECC_CHK_EN, MCACHE_CTL_DC_ECC_EN, MCACHE_CTL_DC_ECC_EXCP_EN, MCACHE_CTL_IC_ECC_CHK_EN, MCACHE_CTL_IC_ECC_EN, MCACHE_CTL_IC_ECC_EXCP_EN, MCFG_INFO_DLM, MCFG_INFO_ILM, MDLM_CTL_DLM_ECC_CHK_EN, MDLM_CTL_DLM_ECC_EN, MDLM_CTL_DLM_ECC_EXCP_EN, MDLM_CTL_DLM_EN, MILM_CTL_ILM_ECC_CHK_EN, MILM_CTL_ILM_ECC_EN, MILM_CTL_ILM_ECC_EXCP_EN, MILM_CTL_ILM_EN, MMISC_CTL_BPU, MMISC_CTL_LDSPEC_ENABLE, SMP_CTRLREG, SystemBannerPrint(), and SystemCoreClock.
void CLINT_Interrupt_Init | ( | void | ) |
Do CLINT Interrupt configuration.
This function will initialize cpu interrupt mode to clint mode. It will
Definition at line 935 of file system_Device.c.
References __RV_CSR_WRITE, core_interrupt_handler(), core_interrupt_handler_s(), CSR_MTVEC, CSR_STVEC, exc_entry(), exc_entry_s(), system_core_interrupt_handler, system_core_interrupt_handler_s, SYSTEM_CORE_INTNUM, system_default_interrupt_handler(), system_default_interrupt_handler_s(), SystemCoreInterruptHandlers, and SystemCoreInterruptHandlers_S.
Referenced by PLIC_Interrupt_Init().
int32_t Core_Register_IRQ | ( | uint32_t | irqn, |
void * | handler | ||
) |
Register a m-mode riscv core interrupt and register the handler.
This function set interrupt handler for core interrupt in non-eclic mode
[in] | irqn | interrupt number |
[in] | handler | interrupt handler, if NULL, handler will not be installed |
Definition at line 1069 of file system_Device.c.
References __enable_sw_irq(), __enable_timer_irq(), Interrupt_Register_CoreIRQ(), SYSTEM_CORE_INTNUM, SysTimer_IRQn, and SysTimerSW_IRQn.
int32_t Core_Register_IRQ_S | ( | uint32_t | irqn, |
void * | handler | ||
) |
Register a riscv s-mode core interrupt and register the handler.
This function set interrupt handler for core interrupt in non-eclic mode
[in] | irqn | interrupt number |
[in] | handler | interrupt handler, if NULL, handler will not be installed |
Definition at line 1105 of file system_Device.c.
References __enable_sw_irq_s(), __enable_timer_irq_s(), Interrupt_Register_CoreIRQ_S(), and SYSTEM_CORE_INTNUM.
void default_intexc_handler | ( | void | ) |
default entry for s-mode exception entry
default eclic interrupt or exception interrupt handler
void ECLIC_Interrupt_Init | ( | void | ) |
Do ECLIC Interrupt configuration.
This function will initialize cpu interrupt mode to eclic mode. It will
Definition at line 879 of file system_Device.c.
References __RV_CSR_READ, __RV_CSR_SET, __RV_CSR_WRITE, CSR_MCFG_INFO, CSR_MTVEC, CSR_MTVT, CSR_MTVT2, CSR_STVEC, CSR_STVT, CSR_STVT2, ECLIC_SetCfgNlbits, ECLIC_SetMth, ECLIC_SetSth, exc_entry(), exc_entry_s(), irq_entry(), irq_entry_s(), MCFG_INFO_CLIC, MCFG_INFO_TEE, and vector_base.
Referenced by Interrupt_Init().
int32_t ECLIC_Register_IRQ | ( | IRQn_Type | IRQn, |
uint8_t | shv, | ||
ECLIC_TRIGGER_Type | trig_mode, | ||
uint8_t | lvl, | ||
uint8_t | priority, | ||
void * | handler | ||
) |
Initialize a specific IRQ and register the handler.
This function set vector mode, trigger mode and polarity, interrupt level and priority, assign handler for specific IRQn.
[in] | IRQn | NMI interrupt handler address |
[in] | shv | ECLIC_NON_VECTOR_INTERRUPT means non-vector mode, and ECLIC_VECTOR_INTERRUPT is vector mode |
[in] | trig_mode | see ECLIC_TRIGGER_Type |
[in] | lvl | interupt level |
[in] | priority | interrupt priority |
[in] | handler | interrupt handler, if NULL, handler will not be installed |
Definition at line 1033 of file system_Device.c.
References ECLIC_EnableIRQ, ECLIC_NEGTIVE_EDGE_TRIGGER, ECLIC_SetLevelIRQ, ECLIC_SetPriorityIRQ, ECLIC_SetShvIRQ, ECLIC_SetTrigIRQ, ECLIC_SetVector, ECLIC_VECTOR_INTERRUPT, and SOC_INT_MAX.
int32_t ECLIC_Register_IRQ_S | ( | IRQn_Type | IRQn, |
uint8_t | shv, | ||
ECLIC_TRIGGER_Type | trig_mode, | ||
uint8_t | lvl, | ||
uint8_t | priority, | ||
void * | handler | ||
) |
Initialize a specific IRQ and register the handler for supervisor mode.
This function set vector mode, trigger mode and polarity, interrupt level and priority, assign handler for specific IRQn.
[in] | IRQn | NMI interrupt handler address |
[in] | shv | ECLIC_NON_VECTOR_INTERRUPT means non-vector mode, and ECLIC_VECTOR_INTERRUPT is vector mode |
[in] | trig_mode | see ECLIC_TRIGGER_Type |
[in] | lvl | interupt level |
[in] | priority | interrupt priority |
[in] | handler | interrupt handler, if NULL, handler will not be installed |
Definition at line 1211 of file system_Device.c.
References ECLIC_EnableIRQ_S, ECLIC_NEGTIVE_EDGE_TRIGGER, ECLIC_SetLevelIRQ_S, ECLIC_SetPriorityIRQ_S, ECLIC_SetShvIRQ_S, ECLIC_SetTrigIRQ_S, ECLIC_SetVector_S, ECLIC_VECTOR_INTERRUPT, and SOC_INT_MAX.
void exc_entry | ( | void | ) |
Referenced by CLINT_Interrupt_Init(), ECLIC_Interrupt_Init(), and Interrupt_Init().
void exc_entry_s | ( | void | ) |
Referenced by CLINT_Interrupt_Init(), and ECLIC_Interrupt_Init().
void Interrupt_Init | ( | void | ) |
initialize interrupt controller
Do CPU interrupt initialization, if plic present, init it, then init eclic if present. So if ECLIC present, the interrupt will default configured to ECLIC interrupt mode, if you want to switch to PLIC interrupt mode, you need to call PLIC_Interrupt_Init in you application code.
By default, if ECLIC present, eclic interrupt mode will be set, otherwise it will be clint/plic interrupt mode
Definition at line 997 of file system_Device.c.
References __RV_CSR_WRITE, CSR_MTVEC, ECLIC_Interrupt_Init(), exc_entry(), and PLIC_Interrupt_Init().
Referenced by _premain_init().
void irq_entry | ( | void | ) |
Referenced by ECLIC_Interrupt_Init().
void irq_entry_s | ( | void | ) |
default entry for s-mode non-vector irq entry
Referenced by ECLIC_Interrupt_Init().
void PLIC_Interrupt_Init | ( | void | ) |
Do PLIC Interrupt configuration.
This function will initialize cpu interrupt mode to clint/plic mode. It will
Definition at line 963 of file system_Device.c.
References CLINT_Interrupt_Init(), system_default_interrupt_handler(), system_default_interrupt_handler_s(), system_mmode_extirq_handler(), system_smode_extirq_handler(), SystemCoreInterruptHandlers, SystemCoreInterruptHandlers_S, SystemMExtInterruptHandlers, and SystemSExtInterruptHandlers.
Referenced by Interrupt_Init().
int32_t PLIC_Register_IRQ | ( | uint32_t | source, |
uint8_t | priority, | ||
void * | handler | ||
) |
Register a m-mode specific plic interrupt and register the handler.
This function set priority and handler for m-mode plic interrupt
[in] | source | interrupt source |
[in] | priority | interrupt priority |
[in] | handler | interrupt handler, if NULL, handler will not be installed |
Definition at line 1143 of file system_Device.c.
References __enable_ext_irq(), Interrupt_Register_ExtIRQ(), PLIC_EnableInterrupt, and PLIC_SetPriority().
int32_t PLIC_Register_IRQ_S | ( | uint32_t | source, |
uint8_t | priority, | ||
void * | handler | ||
) |
Register a s-mode specific plic interrupt and register the handler.
This function set priority and handler for s-mode plic interrupt
[in] | source | interrupt source |
[in] | priority | interrupt priority |
[in] | handler | interrupt handler, if NULL, handler will not be installed |
Definition at line 1174 of file system_Device.c.
References __enable_ext_irq_s(), Interrupt_Register_ExtIRQ_S(), PLIC_EnableInterrupt_S, and PLIC_SetPriority().
void SystemBannerPrint | ( | void | ) |
Banner Print for Nuclei SDK.
Definition at line 847 of file system_Device.c.
References __get_hart_id(), and SystemCoreClock.
Referenced by _premain_init().
void SystemCoreClockUpdate | ( | void | ) |
Function to update the variable SystemCoreClock.
Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. The function evaluates the clock register settings and calculates the current core clock.
Definition at line 197 of file system_Device.c.
void SystemInit | ( | void | ) |
Function to Initialize the system.
Initializes the microcontroller system. Typically, this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with a variable clock speed, it updates the variable SystemCoreClock. SystemInit is called from the file startup_device.
Definition at line 214 of file system_Device.c.
|
static |
volatile unsigned long CpuIRegionBase = 0xFFFFFFFF |
Nuclei RISC-V CPU IRegion Base Address Probed, you should avoid to use it in your application code, please use __IREGION_BASEADDR if you want.
Definition at line 1241 of file system_Device.c.
Referenced by _premain_init().
volatile uint32_t SystemCoreClock = SYSTEM_CLOCK |
Variable to hold the system core clock value.
Holds the system core clock, which is the system clock frequency supplied to the SysTick timer and the processor core clock. This variable can be used by debuggers to query the frequency of the debug timer or to configure the trace clock speed.
Definition at line 184 of file system_Device.c.
Referenced by _premain_init(), and SystemBannerPrint().
|
extern |
Referenced by ECLIC_Interrupt_Init().