NMSIS-Core  Version 1.0.0-HummingBird
NMSIS-Core support for HummingBird RISC-V processor-based devices
System Device Configuration

Functions for system and clock setup available in system_<device>.c. More...

Modules

 Interrupt and Exception Handling
 Functions for interrupt, exception handle available in system_<device>.c.
 

Functions

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 HummingBird SDK. More...
 
int32_t Core_Register_IRQ (uint32_t irqn, void *handler)
 Register a riscv core interrupt and register the handler. More...
 
int32_t PLIC_Register_IRQ (uint32_t source, uint8_t priority, void *handler)
 Register a specific plic interrupt and register the handler. More...
 

Variables

uint32_t SystemCoreClock = SYSTEM_CLOCK
 Variable to hold the system core clock value. More...
 

Detailed Description

Functions for system and clock setup available in system_<device>.c.

HummingBird 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 exception handling framework template, Silicon vendor can customize these template code as they want.

Note
Please pay special attention to the static variable 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.
Attention
Be aware that a value stored to SystemCoreClock during low level initializaton (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.

Function Documentation

◆ Core_Register_IRQ()

int32_t Core_Register_IRQ ( uint32_t  irqn,
void *  handler 
)

Register a riscv core interrupt and register the handler.

This function set interrupt handler for core interrupt

Parameters
[in]irqninterrupt number
[in]handlerinterrupt handler, if NULL, handler will not be installed
Returns
-1 means invalid input parameter. 0 means successful.
Remarks
  • This function use to configure riscv core interrupt and register its interrupt handler and enable its interrupt.

Definition at line 399 of file system_hbird.c.

400 {
401  if ((irqn > 10)) {
402  return -1;
403  }
404 
405  if (handler != NULL) {
406  /* register interrupt handler entry to core handlers */
407  Interrupt_Register_CoreIRQ(irqn, (unsigned long)handler);
408  }
409  switch (irqn) {
410  case SysTimerSW_IRQn:
411  __enable_sw_irq();
412  break;
413  case SysTimer_IRQn:
415  break;
416  default:
417  break;
418  }
419 
420  return 0;
421 }

References __enable_sw_irq(), __enable_timer_irq(), Interrupt_Register_CoreIRQ(), SysTimer_IRQn, and SysTimerSW_IRQn.

◆ PLIC_Register_IRQ()

int32_t PLIC_Register_IRQ ( uint32_t  source,
uint8_t  priority,
void *  handler 
)

Register a specific plic interrupt and register the handler.

This function set priority and handler for plic interrupt

Parameters
[in]sourceinterrupt source
[in]priorityinterrupt priority
[in]handlerinterrupt handler, if NULL, handler will not be installed
Returns
-1 means invalid input parameter. 0 means successful.
Remarks
  • This function use to configure specific plic interrupt and register its interrupt handler and enable its interrupt.

Definition at line 435 of file system_hbird.c.

436 {
437  if ((source >= __PLIC_INTNUM)) {
438  return -1;
439  }
440 
441  /* set interrupt priority */
442  PLIC_SetPriority(source, priority);
443  if (handler != NULL) {
444  /* register interrupt handler entry to external handlers */
445  Interrupt_Register_ExtIRQ(source, (unsigned long)handler);
446  }
447  /* enable interrupt */
448  PLIC_EnableInterrupt(source);
450  return 0;
451 }

References __enable_ext_irq(), Interrupt_Register_ExtIRQ(), PLIC_EnableInterrupt(), and PLIC_SetPriority().

◆ SystemBannerPrint()

void SystemBannerPrint ( void  )

Banner Print for HummingBird SDK.

Definition at line 378 of file system_hbird.c.

379 {
380 #if defined(HBIRD_BANNER) && (HBIRD_BANNER == 1)
381  printf("HummingBird SDK Build Time: %s, %s\r\n", __DATE__, __TIME__);
382 #ifdef DOWNLOAD_MODE_STRING
383  printf("Download Mode: %s\r\n", DOWNLOAD_MODE_STRING);
384 #endif
385  printf("CPU Frequency %lu Hz\r\n", SystemCoreClock);
386 #endif
387 }

References SystemCoreClock.

◆ SystemCoreClockUpdate()

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 101 of file system_hbird.c.

102 {
103  /* ToDo: add code to calculate the system frequency based upon the current
104  * register settings.
105  * Note: This function can be used to retrieve the system core clock frequeny
106  * after user changed register settings.
107  */
108  SystemCoreClock = SYSTEM_CLOCK;
109 }

References SystemCoreClock.

◆ SystemInit()

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 119 of file system_hbird.c.

120 {
121  /* ToDo: add code to initialize the system
122  * Warn: do not use global variables because this function is called before
123  * reaching pre-main. RW section maybe overwritten afterwards.
124  */
125  SystemCoreClock = SYSTEM_CLOCK;
126 }

References SystemCoreClock.

Variable Documentation

◆ SystemCoreClock

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.

Attention
Compilers must be configured to avoid removing this variable in case the application program is not using it. Debugging systems require the variable to be physically present in memory so that it can be examined to configure the debugger.

Definition at line 88 of file system_hbird.c.

Referenced by SystemBannerPrint(), SystemCoreClockUpdate(), and SystemInit().

SysTimer_IRQn
@ SysTimer_IRQn
System Timer Interrupt.
Definition: core_feature_plic.h:105
__enable_timer_irq
__STATIC_FORCEINLINE void __enable_timer_irq(void)
Enable Timer IRQ Interrupts.
Definition: core_feature_base.h:397
__enable_sw_irq
__STATIC_FORCEINLINE void __enable_sw_irq(void)
Enable software IRQ Interrupts.
Definition: core_feature_base.h:419
PLIC_EnableInterrupt
__STATIC_FORCEINLINE void PLIC_EnableInterrupt(uint32_t source)
Enable interrupt for selected source plic.
Definition: core_feature_plic.h:169
__enable_ext_irq
__STATIC_FORCEINLINE void __enable_ext_irq(void)
Enable External IRQ Interrupts.
Definition: core_feature_base.h:375
SystemCoreClock
uint32_t SystemCoreClock
Variable to hold the system core clock value.
Definition: system_hbird.c:88
Interrupt_Register_ExtIRQ
void Interrupt_Register_ExtIRQ(uint32_t irqn, unsigned long int_handler)
Register an external interrupt handler for plic external interrupt number.
Definition: system_hbird.c:258
SysTimerSW_IRQn
@ SysTimerSW_IRQn
System Timer SW interrupt.
Definition: core_feature_plic.h:101
PLIC_SetPriority
__STATIC_FORCEINLINE void PLIC_SetPriority(uint32_t source, uint32_t priority)
Set interrupt priority for selected source plic.
Definition: core_feature_plic.h:232
Interrupt_Register_CoreIRQ
void Interrupt_Register_CoreIRQ(uint32_t irqn, unsigned long int_handler)
Register an core interrupt handler for core interrupt number.
Definition: system_hbird.c:244