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 |
64 |
zero_gravi |
and the `MTI` machine timer CPU interrupt (`MTI`) is directly connected to the top's `mtime_irq_i` input.
|
27 |
60 |
zero_gravi |
|
28 |
64 |
zero_gravi |
The 64-bit system time can be accessed via the `TIME_LO` and `TIME_HI` memory-mapped registers (read/write) and also via
|
29 |
65 |
zero_gravi |
the CPU's `time[h]` CSRs (read-only). A 64-bit time compare register - accessible via memory-mapped `TIMECMP_LO` and `TIMECMP_HI`
|
30 |
|
|
registers - is used to configure an interrupt to the CPU. The interrupt is triggered
|
31 |
64 |
zero_gravi |
whenever `TIME` (high & low part) >= `TIMECMP` (high & low part) and is directly forwarded to the CPU's `MTI` interrupt.
|
32 |
65 |
zero_gravi |
The interrupt remain active (=pending) until `TIME` < `TIMECMP` (either by modifying `TIME` or `TIMECMP`).
|
33 |
60 |
zero_gravi |
|
34 |
64 |
zero_gravi |
.MTIME register map (`struct NEORV32_MTIME`)
|
35 |
60 |
zero_gravi |
[cols="<3,<3,^1,^1,<6"]
|
36 |
|
|
[options="header",grid="all"]
|
37 |
|
|
|=======================
|
38 |
|
|
| Address | Name [C] | Bits | R/W | Function
|
39 |
64 |
zero_gravi |
| `0xffffff90` | `NEORV32_MTIME.TIME_LO` | 31:0 | r/w | machine system time, low word
|
40 |
|
|
| `0xffffff94` | `NEORV32_MTIME.TIME_HI` | 31:0 | r/w | machine system time, high word
|
41 |
|
|
| `0xffffff98` | `NEORV32_MTIME.TIMECMP_LO` | 31:0 | r/w | time compare, low word
|
42 |
|
|
| `0xffffff9c` | `NEORV32_MTIME.TIMECMP_HI` | 31:0 | r/w | time compare, high word
|
43 |
60 |
zero_gravi |
|=======================
|