|
NMSIS-Core
Version 1.3.1
NMSIS-Core support for Nuclei processor-based devices
|
18 #ifndef __CORE_FEATURE_TIMER_H__
19 #define __CORE_FEATURE_TIMER_H__
36 #include "core_feature_base.h"
38 #if defined(__SYSTIMER_PRESENT) && (__SYSTIMER_PRESENT == 1)
58 __IOM uint32_t RESERVED0[0x3F8];
66 #define SysTimer_MTIMECTL_TIMESTOP_Pos 0U
67 #define SysTimer_MTIMECTL_TIMESTOP_Msk (1UL << SysTimer_MTIMECTL_TIMESTOP_Pos)
68 #define SysTimer_MTIMECTL_CMPCLREN_Pos 1U
69 #define SysTimer_MTIMECTL_CMPCLREN_Msk (1UL << SysTimer_MTIMECTL_CMPCLREN_Pos)
70 #define SysTimer_MTIMECTL_CLKSRC_Pos 2U
71 #define SysTimer_MTIMECTL_CLKSRC_Msk (1UL << SysTimer_MTIMECTL_CLKSRC_Pos)
73 #define SysTimer_MSIP_MSIP_Pos 0U
74 #define SysTimer_MSIP_MSIP_Msk (1UL << SysTimer_MSIP_MSIP_Pos)
76 #define SysTimer_MTIMER_Msk (0xFFFFFFFFFFFFFFFFULL)
77 #define SysTimer_MTIMERCMP_Msk (0xFFFFFFFFFFFFFFFFULL)
78 #define SysTimer_MTIMECTL_Msk (0xFFFFFFFFUL)
79 #define SysTimer_MSIP_Msk (0xFFFFFFFFUL)
80 #define SysTimer_MSFTRST_Msk (0xFFFFFFFFUL)
82 #define SysTimer_MSFRST_KEY (0x80000A5FUL)
84 #define SysTimer_CLINT_MSIP_OFS (0x1000UL)
85 #define SysTimer_CLINT_MTIMECMP_OFS (0x5000UL)
86 #define SysTimer_CLINT_MTIME_OFS (0xCFF8UL)
88 #ifndef __SYSTIMER_BASEADDR
90 #error "__SYSTIMER_BASEADDR is not defined, please check!"
93 #define SysTimer_BASE __SYSTIMER_BASEADDR
94 #define SysTimer ((SysTimer_Type *) SysTimer_BASE)
97 #define SysTimer_CLINT_MSIP_BASE(hartid) (unsigned long)((SysTimer_BASE) + (SysTimer_CLINT_MSIP_OFS) + ((hartid) << 2))
98 #define SysTimer_CLINT_MTIMECMP_BASE(hartid) (unsigned long)((SysTimer_BASE) + (SysTimer_CLINT_MTIMECMP_OFS) + ((hartid) << 3))
99 #define SysTimer_CLINT_MTIME_BASE (unsigned long)((SysTimer_BASE) + (SysTimer_CLINT_MTIME_OFS))
117 #ifndef __SYSTIMER_HARTID
118 #define SysTimer_GetHartID() (__get_hart_index())
120 #define SysTimer_GetHartID() (__SYSTIMER_HARTID)
134 #if __RISCV_XLEN == 32
136 addr = (uint8_t *)(&(
SysTimer->MTIMER));
138 __SW(addr + 4, (uint32_t)(value >> 32));
139 __SW(addr, (uint32_t)(value));
156 #if __RISCV_XLEN == 32
157 volatile uint32_t high0, low, high;
161 addr = (uint8_t *)(&(
SysTimer->MTIMER));
163 high0 =
__LW(addr + 4);
165 high =
__LW(addr + 4);
169 full = (((uint64_t)high) << 32) | low;
192 #if __RISCV_XLEN == 32
194 addr = (uint8_t *)(&(
SysTimer->MTIMERCMP));
196 __SW(addr + 4, (uint32_t)(value >> 32));
197 __SW(addr, (uint32_t)(value));
203 #if __RISCV_XLEN == 32
205 __SW(addr + 4, (uint32_t)(value >> 32));
206 __SW(addr, (uint32_t)value);
249 #if __RISCV_XLEN == 32
253 high =
__LW(addr + 4);
255 full = (((uint64_t)high) << 32) | low;
520 #if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U) && defined(__ECLIC_PRESENT) && (__ECLIC_PRESENT == 1)
617 uint64_t reload_ticks = ticks + cur_ticks;
619 if (
__USUALLY(reload_ticks > cur_ticks)) {
660 uint64_t reload_ticks = ticks + cur_ticks;
662 if (
__USUALLY(reload_ticks > cur_ticks)) {
@ SysTimer_IRQn
System Timer Interrupt.
#define SysTimer_CLINT_MSIP_BASE(hartid)
#define SysTimer_GetHartID()
SysTimer_GetHartID() is used to get timer hartid which might not be the same as cpu hart id,...
__STATIC_FORCEINLINE void SysTimer_SetMsipValue(uint32_t msip)
Set system timer MSIP register value in machine mode.
__STATIC_FORCEINLINE uint64_t SysTimer_GetLoadValue(void)
Get system timer load value.
#define SysTimer_MSIP_MSIP_Msk
SysTick Timer MSIP: MSIP Mask.
__IOM uint32_t MSFTRST
Offset: 0xFF0 (R/W) System Timer Software Core Reset Register.
#define SysTimer_MSIP_Msk
SysTick Timer MSIP value Mask.
#define ECLIC_SetLevelIRQ
__IOM uint64_t MTIMER
Offset: 0x000 (R/W) System Timer current value 64bits Register.
__STATIC_FORCEINLINE void SysTimer_SetHartCompareValue(uint64_t value, unsigned long hartid)
Set system timer compare value by hartid.
__STATIC_FORCEINLINE uint64_t SysTimer_GetHartCompareValue(unsigned long hartid)
Get system timer compare value by hartid.
__STATIC_FORCEINLINE void SysTimer_ClearSWIRQ(void)
Clear system timer software interrupt pending request in machine mode.
__STATIC_FORCEINLINE void SysTimer_Start(void)
Enable system timer counter running.
__STATIC_FORCEINLINE void SysTimer_SetLoadValue(uint64_t value)
Set system timer load value.
#define ECLIC_NON_VECTOR_INTERRUPT
Non-Vector Interrupt Mode of ECLIC.
#define __IOM
Defines 'read/write' structure member permissions.
__STATIC_FORCEINLINE uint32_t SysTick_Reload(uint64_t ticks)
System Tick Reload.
__STATIC_FORCEINLINE uint32_t __LW(volatile void *addr)
Load 32bit value from address (32 bit)
__STATIC_FORCEINLINE void SysTimer_ClearIPI(unsigned long hartid)
clear ipi to target hart using Systimer Clint
__STATIC_FORCEINLINE uint32_t SysTimer_GetHartMsipValue(unsigned long hartid)
Get system timer MSIP register value by hartid.
__STATIC_FORCEINLINE void SysTimer_SetHartMsipValue(uint32_t msip, unsigned long hartid)
Set system timer MSIP register value by hartid.
__STATIC_FORCEINLINE void SysTimer_SendIPI(unsigned long hartid)
send ipi to target hart using Systimer Clint
#define __STATIC_INLINE
Define a static function that may be inlined by the compiler.
#define SysTimer_CLINT_MTIMECMP_BASE(hartid)
__STATIC_FORCEINLINE void SysTimer_ClearHartSWIRQ(unsigned long hartid)
Clear system timer software interrupt pending request by hartid.
#define SysTimer_MSFRST_KEY
SysTick Timer Software Reset Request Key.
__STATIC_FORCEINLINE void SysTimer_SetSWIRQ(void)
Trigger or set software interrupt via system timer in machine mode.
__IOM uint32_t RESERVED1
Offset: 0xFF4 Reserved.
__STATIC_FORCEINLINE void SysTimer_SetHartSWIRQ(unsigned long hartid)
Trigger or set software interrupt via system timer by hartid.
__IOM uint32_t MTIMECTL
Offset: 0xFF8 (R/W) System Timer Control Register, previously MSTOP register.
__STATIC_FORCEINLINE uint32_t SysTimer_GetMsipValue(void)
Get system timer MSIP register value in machine mode.
__STATIC_FORCEINLINE uint32_t SysTimer_GetControlValue(void)
Get system timer control value.
#define __STATIC_FORCEINLINE
Define a static function that should be always inlined by the compiler.
__STATIC_FORCEINLINE void SysTimer_SetCompareValue(uint64_t value)
Set system timer compare value in machine mode.
__STATIC_FORCEINLINE void SysTimer_SetControlValue(uint32_t mctl)
Set system timer control value.
__STATIC_FORCEINLINE uint32_t SysTick_HartReload(uint64_t ticks, unsigned long hartid)
System Tick Reload.
#define __USUALLY(exp)
provide the compiler with branch prediction information, the branch is usually true
#define SysTimer_MTIMECTL_TIMESTOP_Msk
SysTick Timer MTIMECTL: TIMESTOP Mask.
__STATIC_FORCEINLINE uint64_t SysTimer_GetCompareValue(void)
Get system timer compare value in machine mode.
__IOM uint32_t MSIP
Offset: 0xFFC (R/W) System Timer SW interrupt Register.
__STATIC_FORCEINLINE void SysTimer_SoftwareReset(void)
Do software reset request.
__STATIC_FORCEINLINE void SysTimer_Stop(void)
Stop system timer counter running.
__STATIC_FORCEINLINE void __SW(volatile void *addr, uint32_t val)
Write 32bit value to address (32 bit)
__IOM uint64_t MTIMERCMP
Offset: 0x008 (R/W) System Timer compare Value 64bits Register.
Structure type to access the System Timer (SysTimer).
__STATIC_INLINE uint32_t SysTick_HartConfig(uint64_t ticks, unsigned long hartid)
System Tick Configuration By hartid.
#define SysTimer
SysTick configuration struct.
__STATIC_INLINE uint32_t SysTick_Config(uint64_t ticks)
System Tick Configuration.
#define SysTimer_MTIMECTL_Msk
SysTick Timer MTIMECTL/MSTOP value Mask.