1 |
60 |
zero_gravi |
<<<
|
2 |
|
|
:sectnums:
|
3 |
|
|
==== Machine System Timer (MTIME)
|
4 |
|
|
|
5 |
|
|
[cols="<3,<3,<4"]
|
6 |
|
|
[frame="topbot",grid="none"]
|
7 |
|
|
|=======================
|
8 |
|
|
| Hardware source file(s): | neorv32_mtime.vhd |
|
9 |
|
|
| Software driver file(s): | neorv32_mtime.c |
|
10 |
|
|
| | neorv32_mtime.h |
|
11 |
|
|
| Top entity port: | `mtime_i` | System time input from external MTIME
|
12 |
|
|
| | `mtime_o` | System time output (64-bit) for SoC
|
13 |
|
|
| Configuration generics: | _IO_MTIME_EN_ | implement MTIME when _true_
|
14 |
|
|
| CPU interrupts: | `MTI` | machine timer interrupt (see <<_processor_interrupts>>)
|
15 |
|
|
|=======================
|
16 |
|
|
|
17 |
|
|
**Theory of Operation**
|
18 |
|
|
|
19 |
|
|
The MTIME machine system timer implements the memory-mapped MTIME timer from the official RISC-V
|
20 |
|
|
specifications. This unit features a 64-bit system timer incremented with the primary processor clock.
|
21 |
|
|
The current system time can also be obtained using the `time[h]` CSRs and is made available for processor-external
|
22 |
|
|
use via the top's `mtime_o` signal.
|
23 |
|
|
|
24 |
|
|
[NOTE]
|
25 |
|
|
If the processor-internal **MTIME unit is NOT implemented**, the top's `mtime_i` input signal is used to update the `time[h]` CSRs
|
26 |
|
|
and the `MTI` machine timer interrupt) CPU interrupt is directly connected to the top's `mtime_irq_i` input.
|
27 |
|
|
|
28 |
|
|
The 64-bit system time can be accessed via the `MTIME_LO` and `MTIME_HI` memory-mapped registers (read/write) and also via
|
29 |
|
|
the CPU's `time[h]` CSRs (read-only). A 64-bit time compare register – accessible via memory-mapped `MTIMECMP_LO` and `MTIMECMP_HI`
|
30 |
|
|
registers – are used to configure an interrupt to the CPU. The interrupt is triggered
|
31 |
|
|
whenever `MTIME` (high & low part) >= `MTIMECMP` (high & low part) and is directly forwarded to the CPU's `MTI` interrupt.
|
32 |
|
|
|
33 |
|
|
[TIP]
|
34 |
|
|
The interrupt request is a single-shot signal,
|
35 |
|
|
so the CPU is triggered once if the system time is greater than or equal to the compare time. Hence,
|
36 |
|
|
another MTIME IRQ is only possible when updating `MTIMECMP`.
|
37 |
|
|
|
38 |
|
|
The 64-bit counter and the 64-bit comparator are implemented as 2×32-bit counters and comparators with a
|
39 |
|
|
registered carry to prevent a 64-bit carry chain and thus, to simplify timing closure.
|
40 |
|
|
|
41 |
|
|
.MTIME register map
|
42 |
|
|
[cols="<3,<3,^1,^1,<6"]
|
43 |
|
|
[options="header",grid="all"]
|
44 |
|
|
|=======================
|
45 |
|
|
| Address | Name [C] | Bits | R/W | Function
|
46 |
|
|
| `0xffffff90` | _MTIME_LO_ | 31:0 | r/w | machine system time, low word
|
47 |
|
|
| `0xffffff94` | _MTIME_HI_ | 31:0 | r/w | machine system time, high word
|
48 |
|
|
| `0xffffff98` | _MTIMECMP_LO_ | 31:0 | r/w | time compare, low word
|
49 |
|
|
| `0xffffff9c` | _MTIMECMP_HI_ | 31:0 | r/w | time compare, high word
|
50 |
|
|
|=======================
|