NMSIS-Core  Version 1.0.0-HummingBird
NMSIS-Core support for HummingBird RISC-V processor-based devices
SysTimer Functions

Functions that configure the Core System Timer. More...

Functions

__STATIC_FORCEINLINE void SysTimer_SetLoadValue (uint64_t value)
 Set system timer load value. More...
 
__STATIC_FORCEINLINE uint64_t SysTimer_GetLoadValue (void)
 Get system timer load value. More...
 
__STATIC_FORCEINLINE void SysTimer_SetCompareValue (uint64_t value)
 Set system timer compare value. More...
 
__STATIC_FORCEINLINE uint64_t SysTimer_GetCompareValue (void)
 Get system timer compare value. More...
 
__STATIC_FORCEINLINE void SysTimer_SetSWIRQ (void)
 Trigger or set software interrupt via system timer. More...
 
__STATIC_FORCEINLINE void SysTimer_ClearSWIRQ (void)
 Clear system timer software interrupt pending request. More...
 
__STATIC_FORCEINLINE uint32_t SysTimer_GetMsipValue (void)
 Get system timer MSIP register value. More...
 
__STATIC_FORCEINLINE void SysTimer_SetMsipValue (uint32_t msip)
 Set system timer MSIP register value. More...
 
__STATIC_INLINE uint32_t SysTick_Config (uint64_t ticks)
 System Tick Configuration. More...
 
__STATIC_FORCEINLINE uint32_t SysTick_Reload (uint64_t ticks)
 System Tick Reload. More...
 

Detailed Description

Functions that configure the Core System Timer.

Function Documentation

◆ SysTick_Config()

__STATIC_INLINE uint32_t SysTick_Config ( uint64_t  ticks)

System Tick Configuration.

Initializes the System Timer and its non-vector interrupt, and starts the System Tick Timer.

In our default implementation, the timer counter will be set to zero, and it will start a timer compare non-vector interrupt when it matchs the ticks user set, during the timer interrupt user should reload the system tick using SysTick_Reload function or similar function written by user, so it can produce period timer interrupt.

Parameters
[in]ticksNumber of ticks between two interrupts.
Returns
0 Function succeeded.
1 Function failed.
See also

Definition at line 208 of file core_feature_timer.h.

209 {
213  return (0UL);
214 }

References __enable_timer_irq(), SysTimer_SetCompareValue(), and SysTimer_SetLoadValue().

◆ SysTick_Reload()

__STATIC_FORCEINLINE uint32_t SysTick_Reload ( uint64_t  ticks)

System Tick Reload.

Reload the System Timer Tick when the MTIMECMP reached TIME value

Parameters
[in]ticksNumber of ticks between two interrupts.
Returns
0 Function succeeded.
1 Function failed.
See also

Definition at line 227 of file core_feature_timer.h.

228 {
229  uint64_t cur_ticks = SysTimer->MTIME;
230  uint64_t reload_ticks = ticks + cur_ticks;
231 
232  if (__USUALLY(reload_ticks > cur_ticks)) {
233  SysTimer->MTIMECMP = reload_ticks;
234  } else {
235  /* When added the ticks value, then the MTIMERCMP < TIMER,
236  * which means the MTIMERCMP is overflowed,
237  * so we need to reset the counter to zero */
238  SysTimer->MTIME = 0;
239  SysTimer->MTIMECMP = ticks;
240  }
241 
242  return (0UL);
243 }

References __USUALLY, and SysTimer.

◆ SysTimer_ClearSWIRQ()

__STATIC_FORCEINLINE void SysTimer_ClearSWIRQ ( void  )

Clear system timer software interrupt pending request.

This function clear the system timer MSIP bit in MSIP register.

Remarks

Definition at line 162 of file core_feature_timer.h.

163 {
165 }

References SysTimer, and SysTimer_MSIP_MSIP_Msk.

◆ SysTimer_GetCompareValue()

__STATIC_FORCEINLINE uint64_t SysTimer_GetCompareValue ( void  )

Get system timer compare value.

This function get the system timer compare value in MTIMERCMP register.

Returns
compare value of system timer MTIMERCMP register.
Remarks

Definition at line 134 of file core_feature_timer.h.

135 {
136  return SysTimer->MTIMECMP;
137 }

References SysTimer.

◆ SysTimer_GetLoadValue()

__STATIC_FORCEINLINE uint64_t SysTimer_GetLoadValue ( void  )

Get system timer load value.

This function get the system timer current value in MTIMER register.

Returns
current value(64bit) of system timer MTIMER register.
Remarks

Definition at line 104 of file core_feature_timer.h.

105 {
106  return SysTimer->MTIME;
107 }

References SysTimer.

◆ SysTimer_GetMsipValue()

__STATIC_FORCEINLINE uint32_t SysTimer_GetMsipValue ( void  )

Get system timer MSIP register value.

This function get the system timer MSIP register value.

Returns
Value of Timer MSIP register.
Remarks

Definition at line 178 of file core_feature_timer.h.

179 {
180  return (uint32_t)(SysTimer->MSIP & SysTimer_MSIP_Msk);
181 }

References SysTimer, and SysTimer_MSIP_Msk.

◆ SysTimer_SetCompareValue()

__STATIC_FORCEINLINE void SysTimer_SetCompareValue ( uint64_t  value)

Set system timer compare value.

This function set the system Timer compare value in MTIMERCMP register.

Parameters
[in]valuecompare value to set system timer MTIMERCMP register.
Remarks
  • Compare value is 64bits wide.
  • If compare value is larger than current value timer interrupt generate.
  • Modify the load value or compare value less to clear the interrupt.
  • SysTimer_GetCompareValue

Definition at line 120 of file core_feature_timer.h.

121 {
122  SysTimer->MTIMECMP = value;
123 }

References SysTimer.

Referenced by SysTick_Config().

◆ SysTimer_SetLoadValue()

__STATIC_FORCEINLINE void SysTimer_SetLoadValue ( uint64_t  value)

Set system timer load value.

This function set the system timer load value in MTIMER register.

Parameters
[in]valuevalue to set system timer MTIMER register.
Remarks

Definition at line 90 of file core_feature_timer.h.

91 {
92  SysTimer->MTIME = value;
93 }

References SysTimer.

Referenced by SysTick_Config().

◆ SysTimer_SetMsipValue()

__STATIC_FORCEINLINE void SysTimer_SetMsipValue ( uint32_t  msip)

Set system timer MSIP register value.

This function set the system timer MSIP register value.

Parameters
[in]msipvalue to set MSIP register

Definition at line 189 of file core_feature_timer.h.

190 {
191  SysTimer->MSIP = (msip & SysTimer_MSIP_Msk);
192 }

References SysTimer, and SysTimer_MSIP_Msk.

◆ SysTimer_SetSWIRQ()

__STATIC_FORCEINLINE void SysTimer_SetSWIRQ ( void  )

Trigger or set software interrupt via system timer.

This function set the system timer MSIP bit in MSIP register.

Remarks

Definition at line 148 of file core_feature_timer.h.

149 {
151 }

References SysTimer, and SysTimer_MSIP_MSIP_Msk.

__enable_timer_irq
__STATIC_FORCEINLINE void __enable_timer_irq(void)
Enable Timer IRQ Interrupts.
Definition: core_feature_base.h:397
SysTimer_MSIP_MSIP_Msk
#define SysTimer_MSIP_MSIP_Msk
SysTick Timer MSIP: MSIP Mask.
Definition: core_feature_timer.h:60
SysTimer_MSIP_Msk
#define SysTimer_MSIP_Msk
SysTick Timer MSIP value Mask.
Definition: core_feature_timer.h:64
SysTimer_SetLoadValue
__STATIC_FORCEINLINE void SysTimer_SetLoadValue(uint64_t value)
Set system timer load value.
Definition: core_feature_timer.h:90
SysTimer_SetCompareValue
__STATIC_FORCEINLINE void SysTimer_SetCompareValue(uint64_t value)
Set system timer compare value.
Definition: core_feature_timer.h:120
__USUALLY
#define __USUALLY(exp)
provide the compiler with branch prediction information, the branch is usually true
Definition: nmsis_gcc.h:181
SysTimer
#define SysTimer
SysTick configuration struct.
Definition: core_feature_timer.h:72