NMSIS-Core  Version 1.2.0
NMSIS-Core support for Nuclei processor-based devices
SysTimer Functions

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

Macros

#define SysTimer_GetHartID()   (__get_hart_index())
 SysTimer_GetHartID() is used to get timer hartid which might not be the same as cpu hart id, for example, cpu hartid may be 1, but timer hartid may be 0, then timer hartid offset is 1. 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_SetHartCompareValue (uint64_t value, unsigned long hartid)
 Set system timer compare value by hartid. More...
 
__STATIC_FORCEINLINE void SysTimer_SetCompareValue (uint64_t value)
 Set system timer compare value in machine mode. More...
 
__STATIC_FORCEINLINE uint64_t SysTimer_GetHartCompareValue (unsigned long hartid)
 Get system timer compare value by hartid. More...
 
__STATIC_FORCEINLINE uint64_t SysTimer_GetCompareValue (void)
 Get system timer compare value in machine mode. More...
 
__STATIC_FORCEINLINE void SysTimer_Start (void)
 Enable system timer counter running. More...
 
__STATIC_FORCEINLINE void SysTimer_Stop (void)
 Stop system timer counter running. More...
 
__STATIC_FORCEINLINE void SysTimer_SetControlValue (uint32_t mctl)
 Set system timer control value. More...
 
__STATIC_FORCEINLINE uint32_t SysTimer_GetControlValue (void)
 Get system timer control value. More...
 
__STATIC_FORCEINLINE void SysTimer_SetHartSWIRQ (unsigned long hartid)
 Trigger or set software interrupt via system timer by hartid. More...
 
__STATIC_FORCEINLINE void SysTimer_SetSWIRQ (void)
 Trigger or set software interrupt via system timer in machine mode. More...
 
__STATIC_FORCEINLINE void SysTimer_ClearHartSWIRQ (unsigned long hartid)
 Clear system timer software interrupt pending request by hartid. More...
 
__STATIC_FORCEINLINE void SysTimer_ClearSWIRQ (void)
 Clear system timer software interrupt pending request in machine mode. More...
 
__STATIC_FORCEINLINE uint32_t SysTimer_GetHartMsipValue (unsigned long hartid)
 Get system timer MSIP register value by hartid. More...
 
__STATIC_FORCEINLINE uint32_t SysTimer_GetMsipValue (void)
 Get system timer MSIP register value in machine mode. More...
 
__STATIC_FORCEINLINE void SysTimer_SetHartMsipValue (uint32_t msip, unsigned long hartid)
 Set system timer MSIP register value by hartid. More...
 
__STATIC_FORCEINLINE void SysTimer_SetMsipValue (uint32_t msip)
 Set system timer MSIP register value in machine mode. More...
 
__STATIC_FORCEINLINE void SysTimer_SoftwareReset (void)
 Do software reset request. More...
 
__STATIC_FORCEINLINE void SysTimer_SendIPI (unsigned long hartid)
 send ipi to target hart using Systimer Clint More...
 
__STATIC_FORCEINLINE void SysTimer_ClearIPI (unsigned long hartid)
 clear ipi to target hart using Systimer Clint More...
 
__STATIC_INLINE uint32_t SysTick_Config (uint64_t ticks)
 System Tick Configuration. More...
 
__STATIC_INLINE uint32_t SysTick_HartConfig (uint64_t ticks, unsigned long hartid)
 System Tick Configuration By hartid. More...
 
__STATIC_FORCEINLINE uint32_t SysTick_Reload (uint64_t ticks)
 System Tick Reload. More...
 
__STATIC_FORCEINLINE uint32_t SysTick_HartReload (uint64_t ticks, unsigned long hartid)
 System Tick Reload. More...
 

Detailed Description

Functions that configure the Core System Timer.

Macro Definition Documentation

◆ SysTimer_GetHartID

#define SysTimer_GetHartID ( )    (__get_hart_index())

SysTimer_GetHartID() is used to get timer hartid which might not be the same as cpu hart id, for example, cpu hartid may be 1, but timer hartid may be 0, then timer hartid offset is 1.

If defined __SYSTIMER_HARTID, it will use __SYSTIMER_HARTID as timer hartid, otherwise, it will use __get_hart_index(). The cpu hartid is get by using __get_hart_id function

Definition at line 118 of file core_feature_timer.h.

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.
Remarks
  • For __NUCLEI_N_REV >= 0x0104, the CMPCLREN bit in MTIMECTL is introduced, but we assume that the CMPCLREN bit is set to 0, so MTIMER register will not be auto cleared to 0 when MTIMER >= MTIMERCMP.
  • When the variable __Vendor_SysTickConfig is set to 1, then the function SysTick_Config is not included.
  • In this case, the file <Device>.h must contain a vendor-specific implementation of this function.
  • If user need this function to start a period timer interrupt, then in timer interrupt handler routine code, user should call SysTick_Reload with ticks to reload the timer.
  • This function only available when __SYSTIMER_PRESENT == 1 and __ECLIC_PRESENT == 1 and __Vendor_SysTickConfig == 0
See also

Definition at line 545 of file core_feature_timer.h.

546 {
547  uint64_t loadticks = SysTimer_GetLoadValue();
548  SysTimer_SetCompareValue(ticks + loadticks);
552  return (0UL);
553 }

References ECLIC_EnableIRQ, ECLIC_NON_VECTOR_INTERRUPT, ECLIC_SetLevelIRQ, ECLIC_SetShvIRQ, SysTimer_GetLoadValue(), SysTimer_IRQn, and SysTimer_SetCompareValue().

◆ SysTick_HartConfig()

__STATIC_INLINE uint32_t SysTick_HartConfig ( uint64_t  ticks,
unsigned long  hartid 
)

System Tick Configuration By hartid.

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.
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
Returns
0 Function succeeded.
1 Function failed.
Remarks
  • For __NUCLEI_N_REV >= 0x0104, the CMPCLREN bit in MTIMECTL is introduced, but we assume that the CMPCLREN bit is set to 0, so MTIMER register will not be auto cleared to 0 when MTIMER >= MTIMERCMP.
  • When the variable __Vendor_SysTickConfig is set to 1, then the function SysTick_Config is not included.
  • In this case, the file <Device>.h must contain a vendor-specific implementation of this function.
  • If user need this function to start a period timer interrupt, then in timer interrupt handler routine code, user should call SysTick_Reload with ticks to reload the timer.
  • This function only available when __SYSTIMER_PRESENT == 1 and __ECLIC_PRESENT == 1 and __Vendor_SysTickConfig == 0
  • In S-mode, hartid can't be get by using __get_hart_id function, so this api suits S-mode particularly.
See also

Definition at line 581 of file core_feature_timer.h.

582 {
583  uint64_t loadticks = SysTimer_GetLoadValue();
584  SysTimer_SetHartCompareValue(ticks + loadticks, hartid);
588  return (0UL);
589 }

References ECLIC_EnableIRQ, ECLIC_NON_VECTOR_INTERRUPT, ECLIC_SetLevelIRQ, ECLIC_SetShvIRQ, SysTimer_GetLoadValue(), SysTimer_IRQn, and SysTimer_SetHartCompareValue().

◆ SysTick_HartReload()

__STATIC_FORCEINLINE uint32_t SysTick_HartReload ( uint64_t  ticks,
unsigned long  hartid 
)

System Tick Reload.

Reload the System Timer Tick when the MTIMECMP reached TIME value

Parameters
[in]ticksNumber of ticks between two interrupts.
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
Returns
0 Function succeeded.
1 Function failed.
Remarks
  • For __NUCLEI_N_REV >= 0x0104, the CMPCLREN bit in MTIMECTL is introduced, but for this SysTick_Config function, we assume this CMPCLREN bit is set to 0, so in interrupt handler function, user still need to set the MTIMERCMP or MTIMER to reload the system tick, if vendor want to use this timer's auto clear feature, they can define __Vendor_SysTickConfig to 1, and implement SysTick_Config and SysTick_Reload functions.
  • When the variable __Vendor_SysTickConfig is set to 1, then the function SysTick_Reload is not included.
  • In this case, the file <Device>.h must contain a vendor-specific implementation of this function.
  • This function only available when __SYSTIMER_PRESENT == 1 and __ECLIC_PRESENT == 1 and __Vendor_SysTickConfig == 0
  • Since the MTIMERCMP value might overflow, if overflowed, MTIMER will be set to 0, and MTIMERCMP set to ticks
  • In S-mode, hartid can't be get by using __get_hart_id function, so this api suits S-mode particularly.
See also

Definition at line 657 of file core_feature_timer.h.

658 {
659  uint64_t cur_ticks = SysTimer_GetLoadValue();
660  uint64_t reload_ticks = ticks + cur_ticks;
661 
662  if (__USUALLY(reload_ticks > cur_ticks)) {
663  SysTimer_SetHartCompareValue(reload_ticks, hartid);
664  } else {
665  /* When added the ticks value, then the MTIMERCMP < TIMER,
666  * which means the MTIMERCMP is overflowed,
667  * so we need to reset the counter to zero */
669  SysTimer_SetHartCompareValue(ticks, hartid);
670  }
671 
672  return (0UL);
673 }

References __USUALLY, SysTimer_GetLoadValue(), SysTimer_SetHartCompareValue(), 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.
Remarks
  • For __NUCLEI_N_REV >= 0x0104, the CMPCLREN bit in MTIMECTL is introduced, but for this SysTick_Config function, we assume this CMPCLREN bit is set to 0, so in interrupt handler function, user still need to set the MTIMERCMP or MTIMER to reload the system tick, if vendor want to use this timer's auto clear feature, they can define __Vendor_SysTickConfig to 1, and implement SysTick_Config and SysTick_Reload functions.
  • When the variable __Vendor_SysTickConfig is set to 1, then the function SysTick_Reload is not included.
  • In this case, the file <Device>.h must contain a vendor-specific implementation of this function.
  • This function only available when __SYSTIMER_PRESENT == 1 and __ECLIC_PRESENT == 1 and __Vendor_SysTickConfig == 0
  • Since the MTIMERCMP value might overflow, if overflowed, MTIMER will be set to 0, and MTIMERCMP set to ticks
See also

Definition at line 614 of file core_feature_timer.h.

615 {
616  uint64_t cur_ticks = SysTimer_GetLoadValue();
617  uint64_t reload_ticks = ticks + cur_ticks;
618 
619  if (__USUALLY(reload_ticks > cur_ticks)) {
620  SysTimer_SetCompareValue(reload_ticks);
621  } else {
622  /* When added the ticks value, then the MTIMERCMP < TIMER,
623  * which means the MTIMERCMP is overflowed,
624  * so we need to reset the counter to zero */
627  }
628 
629  return (0UL);
630 }

References __USUALLY, SysTimer_GetLoadValue(), SysTimer_SetCompareValue(), and SysTimer_SetLoadValue().

◆ SysTimer_ClearHartSWIRQ()

__STATIC_FORCEINLINE void SysTimer_ClearHartSWIRQ ( unsigned long  hartid)

Clear system timer software interrupt pending request by hartid.

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

Parameters
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
Remarks
  • Clear system timer MSIP bit in MSIP register to clear the software interrupt pending.
  • In S-mode, hartid can't be get by using __get_hart_id function, so this api suits S-mode particularly.
  • SysTimer_SetHartSWIRQ
  • SysTimer_GetHartMsipValue

Definition at line 379 of file core_feature_timer.h.

380 {
381  if (hartid == 0) {
383  } else {
384  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MSIP_BASE(hartid));
385  __SW(addr, 0);
386  }
387 }

References __SW(), SysTimer, SysTimer_CLINT_MSIP_BASE, and SysTimer_MSIP_MSIP_Msk.

Referenced by SysTimer_ClearSWIRQ().

◆ SysTimer_ClearIPI()

__STATIC_FORCEINLINE void SysTimer_ClearIPI ( unsigned long  hartid)

clear ipi to target hart using Systimer Clint

This function clear ipi using Systimer clint timer.

Parameters
[in]harttarget hart

Definition at line 514 of file core_feature_timer.h.

515 {
516  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MSIP_BASE(hartid));
517  __SW(addr, 0);
518 }

References __SW(), and SysTimer_CLINT_MSIP_BASE.

◆ SysTimer_ClearSWIRQ()

__STATIC_FORCEINLINE void SysTimer_ClearSWIRQ ( void  )

Clear system timer software interrupt pending request in machine mode.

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

Remarks

Definition at line 398 of file core_feature_timer.h.

399 {
400  unsigned long hartid = SysTimer_GetHartID();
401  SysTimer_ClearHartSWIRQ(hartid);
402 }

References SysTimer_ClearHartSWIRQ(), and SysTimer_GetHartID.

◆ SysTimer_GetCompareValue()

__STATIC_FORCEINLINE uint64_t SysTimer_GetCompareValue ( void  )

Get system timer compare value in machine mode.

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

Returns
compare value of system timer MTIMERCMP register.
Remarks

Definition at line 272 of file core_feature_timer.h.

273 {
274  unsigned long hartid = SysTimer_GetHartID();
275  return SysTimer_GetHartCompareValue(hartid);
276 }

References SysTimer_GetHartCompareValue(), and SysTimer_GetHartID.

◆ SysTimer_GetControlValue()

__STATIC_FORCEINLINE uint32_t SysTimer_GetControlValue ( void  )

Get system timer control value.

This function get the system timer MTIMECTL register value.

Returns
MTIMECTL register value
Remarks

Definition at line 327 of file core_feature_timer.h.

328 {
329  return (SysTimer->MTIMECTL & SysTimer_MTIMECTL_Msk);
330 }

References SysTimer, and SysTimer_MTIMECTL_Msk.

◆ SysTimer_GetHartCompareValue()

__STATIC_FORCEINLINE uint64_t SysTimer_GetHartCompareValue ( unsigned long  hartid)

Get system timer compare value by hartid.

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

Parameters
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
Returns
compare value of system timer MTIMERCMP register.
Remarks
  • Compare value is 64bits wide.
  • In S-mode, hartid can't be get by using __get_hart_id function, so this api suits S-mode particularly.
  • SysTimer_SetHartCompareValue

Definition at line 242 of file core_feature_timer.h.

243 {
244  if (hartid == 0) {
245  return SysTimer->MTIMERCMP;
246  } else {
247  uint64_t full;
248  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MTIMECMP_BASE(hartid));
249 #if __RISCV_XLEN == 32
250  // MTIMECMP didn't increase
251  uint32_t high, low;
252 
253  high = __LW(addr + 4);
254  low = __LW(addr);
255  full = (((uint64_t)high) << 32) | low;
256 #else
257  full = __LD(addr);
258 #endif
259  return full;
260  }
261 }

References __LW(), SysTimer, and SysTimer_CLINT_MTIMECMP_BASE.

Referenced by SysTimer_GetCompareValue().

◆ SysTimer_GetHartMsipValue()

__STATIC_FORCEINLINE uint32_t SysTimer_GetHartMsipValue ( unsigned long  hartid)

Get system timer MSIP register value by hartid.

This function get the system timer MSIP register value.

Parameters
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
Returns
Value of Timer MSIP register.
Remarks

Definition at line 418 of file core_feature_timer.h.

419 {
420  if (hartid == 0) {
421  return (uint32_t)(SysTimer->MSIP & SysTimer_MSIP_Msk);
422  } else {
423  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MSIP_BASE(hartid));
424  return __LW(addr);
425  }
426 }

References __LW(), SysTimer, SysTimer_CLINT_MSIP_BASE, and SysTimer_MSIP_Msk.

Referenced by SysTimer_GetMsipValue().

◆ 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 154 of file core_feature_timer.h.

155 {
156 #if __RISCV_XLEN == 32
157  volatile uint32_t high0, low, high;
158  uint64_t full;
159  uint8_t *addr;
160 
161  addr = (uint8_t *)(&(SysTimer->MTIMER));
162 
163  high0 = __LW(addr + 4);
164  low = __LW(addr);
165  high = __LW(addr + 4);
166  if (high0 != high) {
167  low = __LW(addr);
168  }
169  full = (((uint64_t)high) << 32) | low;
170  return full;
171 #else
172  return SysTimer->MTIMER;
173 #endif
174 }

References __LW(), and SysTimer.

Referenced by SysTick_Config(), SysTick_HartConfig(), SysTick_HartReload(), and SysTick_Reload().

◆ SysTimer_GetMsipValue()

__STATIC_FORCEINLINE uint32_t SysTimer_GetMsipValue ( void  )

Get system timer MSIP register value in machine mode.

This function get the system timer MSIP register value.

Returns
Value of Timer MSIP register.
Remarks

Definition at line 440 of file core_feature_timer.h.

441 {
442  unsigned long hartid = SysTimer_GetHartID();
443  return SysTimer_GetHartMsipValue(hartid);
444 }

References SysTimer_GetHartID, and SysTimer_GetHartMsipValue().

◆ SysTimer_SendIPI()

__STATIC_FORCEINLINE void SysTimer_SendIPI ( unsigned long  hartid)

send ipi to target hart using Systimer Clint

This function send ipi using clint timer.

Parameters
[in]harttarget hart

Definition at line 502 of file core_feature_timer.h.

503 {
504  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MSIP_BASE(hartid));
505  __SW(addr, 1);
506 }

References __SW(), and SysTimer_CLINT_MSIP_BASE.

◆ SysTimer_SetCompareValue()

__STATIC_FORCEINLINE void SysTimer_SetCompareValue ( uint64_t  value)

Set system timer compare value in machine mode.

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.
  • __get_hart_id function can only be accessed in machine mode, or else exception will occur.
  • SysTimer_GetCompareValue

Definition at line 225 of file core_feature_timer.h.

226 {
227  unsigned long hartid = SysTimer_GetHartID();
228  SysTimer_SetHartCompareValue(value, hartid);
229 }

References SysTimer_GetHartID, and SysTimer_SetHartCompareValue().

Referenced by SysTick_Config(), and SysTick_Reload().

◆ SysTimer_SetControlValue()

__STATIC_FORCEINLINE void SysTimer_SetControlValue ( uint32_t  mctl)

Set system timer control value.

This function set the system timer MTIMECTL register value.

Parameters
[in]mctlvalue to set MTIMECTL register
Remarks
  • Bit TIMESTOP is used to start and stop timer. Clear TIMESTOP bit to 0 to start timer, otherwise to stop timer.
  • Bit CMPCLREN is used to enable auto MTIMER clear to zero when MTIMER >= MTIMERCMP. Clear CMPCLREN bit to 0 to stop auto clear MTIMER feature, otherwise to enable it.
  • Bit CLKSRC is used to select timer clock source. Clear CLKSRC bit to 0 to use mtime_toggle_a, otherwise use core_clk_aon
  • SysTimer_GetControlValue

Definition at line 314 of file core_feature_timer.h.

315 {
316  SysTimer->MTIMECTL = (mctl & SysTimer_MTIMECTL_Msk);
317 }

References SysTimer, and SysTimer_MTIMECTL_Msk.

◆ SysTimer_SetHartCompareValue()

__STATIC_FORCEINLINE void SysTimer_SetHartCompareValue ( uint64_t  value,
unsigned long  hartid 
)

Set system timer compare value by hartid.

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

Parameters
[in]valuecompare value to set system timer MTIMERCMP register.
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
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.
  • In S-mode, hartid can't be get by using __get_hart_id function, so this api suits S-mode particularly.
  • SysTimer_GetHartCompareValue

Definition at line 189 of file core_feature_timer.h.

190 {
191  if (hartid == 0) {
192 #if __RISCV_XLEN == 32
193  uint8_t *addr;
194  addr = (uint8_t *)(&(SysTimer->MTIMERCMP));
195  __SW(addr, -1U); // prevent load > timecmp
196  __SW(addr + 4, (uint32_t)(value >> 32));
197  __SW(addr, (uint32_t)(value));
198 #else
199  SysTimer->MTIMERCMP = value;
200 #endif
201  } else {
202  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MTIMECMP_BASE(hartid));
203 #if __RISCV_XLEN == 32
204  __SW(addr, -1U); // prevent load > timecmp
205  __SW(addr + 4, (uint32_t)(value >> 32));
206  __SW(addr, (uint32_t)value);
207 #else
208  __SD(addr, value);
209 #endif
210  }
211 }

References __SW(), SysTimer, and SysTimer_CLINT_MTIMECMP_BASE.

Referenced by SysTick_HartConfig(), SysTick_HartReload(), and SysTimer_SetCompareValue().

◆ SysTimer_SetHartMsipValue()

__STATIC_FORCEINLINE void SysTimer_SetHartMsipValue ( uint32_t  msip,
unsigned long  hartid 
)

Set system timer MSIP register value by hartid.

This function set the system timer MSIP register value.

Parameters
[in]msipvalue to set MSIP register
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
Remarks
  • In S-mode, hartid can't be get using __get_hart_id function, so this api suits S-mode particularly.
  • SysTimer_GetHartMsipValue

Definition at line 456 of file core_feature_timer.h.

457 {
458  if (hartid == 0) {
459  SysTimer->MSIP = (msip & SysTimer_MSIP_Msk);
460  } else {
461  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MSIP_BASE(hartid));
462  __SW(addr, msip);
463  }
464 }

References __SW(), SysTimer, SysTimer_CLINT_MSIP_BASE, and SysTimer_MSIP_Msk.

Referenced by SysTimer_SetMsipValue().

◆ SysTimer_SetHartSWIRQ()

__STATIC_FORCEINLINE void SysTimer_SetHartSWIRQ ( unsigned long  hartid)

Trigger or set software interrupt via system timer by hartid.

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

Parameters
[in]hartidhart ID, one hart is required to have a known hart ID of 0, other harts ID can be in 1~1023.
Remarks

Definition at line 343 of file core_feature_timer.h.

344 {
345  if (hartid == 0) {
347  } else {
348  uint8_t *addr = (uint8_t *)(SysTimer_CLINT_MSIP_BASE(hartid));
350  }
351 }

References __SW(), SysTimer, SysTimer_CLINT_MSIP_BASE, and SysTimer_MSIP_MSIP_Msk.

Referenced by SysTimer_SetSWIRQ().

◆ 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 132 of file core_feature_timer.h.

133 {
134 #if __RISCV_XLEN == 32
135  uint8_t *addr;
136  addr = (uint8_t *)(&(SysTimer->MTIMER));
137  __SW(addr, 0); // prevent carry
138  __SW(addr + 4, (uint32_t)(value >> 32));
139  __SW(addr, (uint32_t)(value));
140 #else
141  SysTimer->MTIMER = value;
142 #endif
143 }

References __SW(), and SysTimer.

Referenced by SysTick_HartReload(), and SysTick_Reload().

◆ SysTimer_SetMsipValue()

__STATIC_FORCEINLINE void SysTimer_SetMsipValue ( uint32_t  msip)

Set system timer MSIP register value in machine mode.

This function set the system timer MSIP register value.

Parameters
[in]msipvalue to set MSIP register

Definition at line 473 of file core_feature_timer.h.

474 {
475  unsigned long hartid = SysTimer_GetHartID();
476  SysTimer_SetHartMsipValue(msip, hartid);
477 }

References SysTimer_GetHartID, and SysTimer_SetHartMsipValue().

◆ SysTimer_SetSWIRQ()

__STATIC_FORCEINLINE void SysTimer_SetSWIRQ ( void  )

Trigger or set software interrupt via system timer in machine mode.

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

Remarks

Definition at line 362 of file core_feature_timer.h.

363 {
364  unsigned long hartid = SysTimer_GetHartID();
365  SysTimer_SetHartSWIRQ(hartid);
366 }

References SysTimer_GetHartID, and SysTimer_SetHartSWIRQ().

◆ SysTimer_SoftwareReset()

__STATIC_FORCEINLINE void SysTimer_SoftwareReset ( void  )

Do software reset request.

This function will do software reset request through MTIMER

  • Software need to write SysTimer_MSFRST_KEY to generate software reset request
  • The software request flag can be cleared by reset operation to clear
    Remarks
  • The software reset is sent to SoC, SoC need to generate reset signal and send back to Core
  • This function will not return, it will do while(1) to wait the Core reset happened

Definition at line 489 of file core_feature_timer.h.

490 {
491  SysTimer->MSFTRST = SysTimer_MSFRST_KEY;
492  // will reset cpu, never return
493  while (1);
494 }

References SysTimer, and SysTimer_MSFRST_KEY.

◆ SysTimer_Start()

__STATIC_FORCEINLINE void SysTimer_Start ( void  )

Enable system timer counter running.

Enable system timer counter running by clear TIMESTOP bit in MTIMECTL register.

Definition at line 284 of file core_feature_timer.h.

285 {
287 }

References SysTimer, and SysTimer_MTIMECTL_TIMESTOP_Msk.

◆ SysTimer_Stop()

__STATIC_FORCEINLINE void SysTimer_Stop ( void  )

Stop system timer counter running.

Stop system timer counter running by set TIMESTOP bit in MTIMECTL register.

Definition at line 295 of file core_feature_timer.h.

296 {
298 }

References SysTimer, and SysTimer_MTIMECTL_TIMESTOP_Msk.

SysTimer_IRQn
@ SysTimer_IRQn
System Timer Interrupt.
Definition: core_feature_eclic.h:212
SysTimer_CLINT_MSIP_BASE
#define SysTimer_CLINT_MSIP_BASE(hartid)
Definition: core_feature_timer.h:97
SysTimer_GetHartID
#define SysTimer_GetHartID()
SysTimer_GetHartID() is used to get timer hartid which might not be the same as cpu hart id,...
Definition: core_feature_timer.h:118
SysTimer_GetLoadValue
__STATIC_FORCEINLINE uint64_t SysTimer_GetLoadValue(void)
Get system timer load value.
Definition: core_feature_timer.h:154
SysTimer_MSIP_MSIP_Msk
#define SysTimer_MSIP_MSIP_Msk
SysTick Timer MSIP: MSIP Mask.
Definition: core_feature_timer.h:74
ECLIC_EnableIRQ
#define ECLIC_EnableIRQ
Definition: core_feature_eclic.h:249
SysTimer_MSIP_Msk
#define SysTimer_MSIP_Msk
SysTick Timer MSIP value Mask.
Definition: core_feature_timer.h:79
ECLIC_SetLevelIRQ
#define ECLIC_SetLevelIRQ
Definition: core_feature_eclic.h:261
SysTimer_SetHartCompareValue
__STATIC_FORCEINLINE void SysTimer_SetHartCompareValue(uint64_t value, unsigned long hartid)
Set system timer compare value by hartid.
Definition: core_feature_timer.h:189
SysTimer_GetHartCompareValue
__STATIC_FORCEINLINE uint64_t SysTimer_GetHartCompareValue(unsigned long hartid)
Get system timer compare value by hartid.
Definition: core_feature_timer.h:242
SysTimer_SetLoadValue
__STATIC_FORCEINLINE void SysTimer_SetLoadValue(uint64_t value)
Set system timer load value.
Definition: core_feature_timer.h:132
ECLIC_NON_VECTOR_INTERRUPT
#define ECLIC_NON_VECTOR_INTERRUPT
Non-Vector Interrupt Mode of ECLIC.
Definition: core_feature_eclic.h:152
__LW
__STATIC_FORCEINLINE uint32_t __LW(volatile void *addr)
Load 32bit value from address (32 bit)
Definition: core_feature_base.h:1537
SysTimer_GetHartMsipValue
__STATIC_FORCEINLINE uint32_t SysTimer_GetHartMsipValue(unsigned long hartid)
Get system timer MSIP register value by hartid.
Definition: core_feature_timer.h:418
SysTimer_SetHartMsipValue
__STATIC_FORCEINLINE void SysTimer_SetHartMsipValue(uint32_t msip, unsigned long hartid)
Set system timer MSIP register value by hartid.
Definition: core_feature_timer.h:456
SysTimer_CLINT_MTIMECMP_BASE
#define SysTimer_CLINT_MTIMECMP_BASE(hartid)
Definition: core_feature_timer.h:98
SysTimer_ClearHartSWIRQ
__STATIC_FORCEINLINE void SysTimer_ClearHartSWIRQ(unsigned long hartid)
Clear system timer software interrupt pending request by hartid.
Definition: core_feature_timer.h:379
SysTimer_MSFRST_KEY
#define SysTimer_MSFRST_KEY
SysTick Timer Software Reset Request Key.
Definition: core_feature_timer.h:82
SysTimer_SetHartSWIRQ
__STATIC_FORCEINLINE void SysTimer_SetHartSWIRQ(unsigned long hartid)
Trigger or set software interrupt via system timer by hartid.
Definition: core_feature_timer.h:343
SysTimer_SetCompareValue
__STATIC_FORCEINLINE void SysTimer_SetCompareValue(uint64_t value)
Set system timer compare value in machine mode.
Definition: core_feature_timer.h:225
__USUALLY
#define __USUALLY(exp)
provide the compiler with branch prediction information, the branch is usually true
Definition: nmsis_gcc.h:177
SysTimer_MTIMECTL_TIMESTOP_Msk
#define SysTimer_MTIMECTL_TIMESTOP_Msk
SysTick Timer MTIMECTL: TIMESTOP Mask.
Definition: core_feature_timer.h:67
__SW
__STATIC_FORCEINLINE void __SW(volatile void *addr, uint32_t val)
Write 32bit value to address (32 bit)
Definition: core_feature_base.h:1589
SysTimer
#define SysTimer
SysTick configuration struct.
Definition: core_feature_timer.h:94
SysTimer_MTIMECTL_Msk
#define SysTimer_MTIMECTL_Msk
SysTick Timer MTIMECTL/MSTOP value Mask.
Definition: core_feature_timer.h:78
ECLIC_SetShvIRQ
#define ECLIC_SetShvIRQ
Definition: core_feature_eclic.h:257