Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
Loading...
Searching...
No Matches
clint.c
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
15
16#include "clint/clint.h"
17
21#define CLINT ((clint_hwreg_t *)SYSTEM_CLINT_CTRL)
22
23/*----------------------------------------------------------------------------*/
24/* Function implementations */
25/*----------------------------------------------------------------------------*/
26
28{
29 return CLINT->MTIME_LOW;
30}
31
32
34{
35 return CLINT->MTIME_HIGH;
36}
37
38
40{
41 return CLINT->MSIP[hart_id];
42}
43
44
46{
47 u32 lo, hi;
48 do {
49 hi = clint_getTimeHigh();
50 lo = clint_getTimeLow();
51 } while (clint_getTimeHigh() != hi);
52 return (((u64)hi) << 32) | lo;
53}
54
55
56void clint_setCmp(u64 cmp, u32 hart_id)
57{
58 volatile clint_mtimecmp_hwreg_t *p = &CLINT->MTIMECMP[hart_id];
59 p->MTIMECMP_HIGH = 0xFFFFFFFF; // Set Upper 32-bits (Offset +4 bytes) to Max
60 p->MTIMECMP_LOW = (u32)cmp; // Set Lower 32-bits (Offset +0 bytes)
61 p->MTIMECMP_HIGH = (u32)(cmp >> 32); // Set Upper 32-bits (Offset +4 bytes)
62}
63
64void clint_uDelay(u32 usec, u32 hz)
65{
66 u32 mTimePerUsec = hz/1000000;
67 u32 limit = clint_getTimeLow() + usec*mTimePerUsec;
68 while((int32_t)(limit-(clint_getTimeLow())) >= 0);
69}
70
71
73{
74 CLINT->MSIP[hart_id] = enable;
75}
76
77double clint_timerSub(u64 t0, u64 t1){
78 return ((double)(t1-t0)/(double)SYSTEM_CLINT_HZ);
79}
80
81
82
83
84
85
86
#define CLINT
Pointer to the CLINT hardware registers.
Definition clint.c:21
CLINT driver API definitions.
clint_msip_t
Definition clint.h:50
u32 clint_getTimeHigh()
Reads the high part of the current time.
Definition clint.c:33
void clint_setCmp(u64 cmp, u32 hart_id)
This function sets the compare value for the CLINT CMP register for a specific hardware thread.
Definition clint.c:56
u64 clint_getTime()
Reads the current time value from the CLINT TIME register.
Definition clint.c:45
double clint_timerSub(u64 t0, u64 t1)
Get the time difference between t0 and t1.
Definition clint.c:77
u32 clint_getTimeLow()
Reads the low part of the current time.
Definition clint.c:27
void clint_set_SoftInterrupt(clint_msip_t enable, u32 hart_id)
Sets the software interrupt state for a specific hart.
Definition clint.c:72
void clint_uDelay(u32 usec, u32 hz)
This function introduces a microsecond delay using the CLINT TIME register.
Definition clint.c:64
u32 clint_get_SoftInterrupt(u32 hart_id)
Obtain the current state of the software interrupt for a specific hart.
Definition clint.c:39
CLINT MTIMECMP hardware register map.
Definition clint.h:74
u32 MTIMECMP_LOW
Offset: 0x00, MTIMECMP Low *‍/.
Definition clint.h:75
u32 MTIMECMP_HIGH
Offset: 0x04, MTIMECMP High *‍/.
Definition clint.h:76
uint64_t u64
Definition type.h:20
uint32_t u32
Definition type.h:22