Skip to content

Commit d92791c

Browse files
committed
sw(clint): Use 64-bit accesses
1 parent 11a7063 commit d92791c

File tree

2 files changed

+26
-56
lines changed

2 files changed

+26
-56
lines changed

sw/include/regs/clint.h

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,64 +32,38 @@ typedef union {
3232
uint32_t w;
3333
} clint__msip_t;
3434

35-
// Reg - clint::mtimecmp::low
36-
#define CLINT__MTIMECMP__LOW__VALUE_bm 0xffffffff
37-
#define CLINT__MTIMECMP__LOW__VALUE_bp 0
38-
#define CLINT__MTIMECMP__LOW__VALUE_bw 32
39-
#define CLINT__MTIMECMP__LOW__VALUE_reset 0x0
35+
// Reg - clint::mtimecmp
36+
#define CLINT__MTIMECMP__LOW_bm 0xffffffff
37+
#define CLINT__MTIMECMP__LOW_bp 0
38+
#define CLINT__MTIMECMP__LOW_bw 32
39+
#define CLINT__MTIMECMP__LOW_reset 0x0
40+
#define CLINT__MTIMECMP__HIGH_bm 0xffffffff00000000
41+
#define CLINT__MTIMECMP__HIGH_bp 32
42+
#define CLINT__MTIMECMP__HIGH_bw 32
43+
#define CLINT__MTIMECMP__HIGH_reset 0x0
4044
typedef union {
4145
struct __attribute__ ((__packed__)) {
42-
uint32_t value :32;
46+
uint64_t low :32;
47+
uint64_t high :32;
4348
} f;
44-
uint32_t w;
45-
} clint__mtimecmp__low_t;
46-
47-
// Reg - clint::mtimecmp::high
48-
#define CLINT__MTIMECMP__HIGH__VALUE_bm 0xffffffff
49-
#define CLINT__MTIMECMP__HIGH__VALUE_bp 0
50-
#define CLINT__MTIMECMP__HIGH__VALUE_bw 32
51-
#define CLINT__MTIMECMP__HIGH__VALUE_reset 0x0
52-
typedef union {
53-
struct __attribute__ ((__packed__)) {
54-
uint32_t value :32;
55-
} f;
56-
uint32_t w;
57-
} clint__mtimecmp__high_t;
58-
59-
// Regfile - clint::mtimecmp
60-
typedef struct __attribute__ ((__packed__)) {
61-
clint__mtimecmp__low_t low;
62-
clint__mtimecmp__high_t high;
49+
uint64_t w;
6350
} clint__mtimecmp_t;
6451

65-
// Reg - clint::mtime::low
66-
#define CLINT__MTIME__LOW__VALUE_bm 0xffffffff
67-
#define CLINT__MTIME__LOW__VALUE_bp 0
68-
#define CLINT__MTIME__LOW__VALUE_bw 32
69-
#define CLINT__MTIME__LOW__VALUE_reset 0x0
52+
// Reg - clint::mtime
53+
#define CLINT__MTIME__LOW_bm 0xffffffff
54+
#define CLINT__MTIME__LOW_bp 0
55+
#define CLINT__MTIME__LOW_bw 32
56+
#define CLINT__MTIME__LOW_reset 0x0
57+
#define CLINT__MTIME__HIGH_bm 0xffffffff00000000
58+
#define CLINT__MTIME__HIGH_bp 32
59+
#define CLINT__MTIME__HIGH_bw 32
60+
#define CLINT__MTIME__HIGH_reset 0x0
7061
typedef union {
7162
struct __attribute__ ((__packed__)) {
72-
uint32_t value :32;
63+
uint64_t low :32;
64+
uint64_t high :32;
7365
} f;
74-
uint32_t w;
75-
} clint__mtime__low_t;
76-
77-
// Reg - clint::mtime::high
78-
#define CLINT__MTIME__HIGH__VALUE_bm 0xffffffff
79-
#define CLINT__MTIME__HIGH__VALUE_bp 0
80-
#define CLINT__MTIME__HIGH__VALUE_bw 32
81-
#define CLINT__MTIME__HIGH__VALUE_reset 0x0
82-
typedef union {
83-
struct __attribute__ ((__packed__)) {
84-
uint32_t value :32;
85-
} f;
86-
uint32_t w;
87-
} clint__mtime__high_t;
88-
89-
// Regfile - clint::mtime
90-
typedef struct __attribute__ ((__packed__)) {
91-
clint__mtime__low_t low;
92-
clint__mtime__high_t high;
66+
uint64_t w;
9367
} clint__mtime_t;
9468

9569
// Addrmap - clint

sw/lib/dif/clint.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
static volatile clint_t *const clint = (volatile clint_t *const)&__base_clint;
1515

1616
uint64_t clint_get_mtime() {
17-
return ((uint64_t)clint->mtime.high.w << 32) | (clint->mtime.low.w);
17+
return clint->mtime.w;
1818
}
1919

2020
void clint_spin_until(uint64_t tgt_mtime) {
@@ -45,11 +45,7 @@ uint64_t clint_get_core_freq(uint64_t ref_freq, uint64_t ref_time_inv) {
4545
}
4646

4747
void clint_set_mtimecmpx(uint64_t timer_idx, uint64_t value) {
48-
uint32_t vlo = (uint32_t)(value);
49-
uint32_t vhi = (uint32_t)(value >> 32);
50-
// Write high register first
51-
clint->mtimecmp[timer_idx].high.w = vhi;
52-
clint->mtimecmp[timer_idx].low.w = vlo;
48+
clint->mtimecmp[timer_idx].w = value;
5349
}
5450

5551
void clint_sleep_until(uint64_t timer_idx, uint64_t tgt_mtime) {

0 commit comments

Comments
 (0)