Skip to content

Commit 46ce249

Browse files
authored
⚠️ rework GPTMR (#939)
2 parents c4f7caf + c1f1444 commit 46ce249

File tree

17 files changed

+127
-368
lines changed

17 files changed

+127
-368
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mimpid = 0x01040312 -> Version 01.04.03.12 -> v1.4.3.12
2929

3030
| Date | Version | Comment | Ticket |
3131
|:----:|:-------:|:--------|:------:|
32+
| 04.07.2024 | 1.10.0.10 | :warning: rework GPTMRM and remove capture mode | [#939](https://github.com/stnolting/neorv32/pull/939) |
3233
| 03.07.2024 | 1.10.0.9 | :warning: remove `AMO_RVS_GRANULARITY` generic, reservation set granularity is now fixed to 4 bytes | [#938](https://github.com/stnolting/neorv32/pull/938) |
3334
| 03.07.2024 | 1.10.0.8 | :test_tube: add XBUS to AHB3-lite bridge | [#937](https://github.com/stnolting/neorv32/pull/937) |
3435
| 02.07.2024 | 1.10.0.7 | minor rtl and software edits and cleanups | [#936](https://github.com/stnolting/neorv32/pull/936) |

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ For example, the CPU ensures _all_ memory accesses are properly acknowledged and
3232
instructions are always detected as such. Whenever an unexpected state occurs the application software is
3333
informed via _precise_ and resumable hardware exceptions.
3434

35-
* :books: For detailed information see the [NEORV32 online documentation](https://stnolting.github.io/neorv32/).
3635
* :recycle: Looking for an **all-Verilog** version? Have a look at [neorv32-verilog](https://github.com/stnolting/neorv32-verilog).
3736
* :heavy_check_mark: [Continuous integration](#project-status) to check for regressions (including RISC-V ISA compatibility check using **RISCOF**).
3837
* :open_file_folder: [Exemplary setups](https://github.com/stnolting/neorv32-setups) and
@@ -46,6 +45,7 @@ targeting various FPGA boards and toolchains to get started.
4645
* :label: The project's change log is available in [CHANGELOG.md](https://github.com/stnolting/neorv32/blob/main/CHANGELOG.md).
4746
* :rocket: Check out the [quick links below](#5-getting-started) and the
4847
[*User Guide*](https://stnolting.github.io/neorv32/ug/) to get started setting up _your_ NEORV32 processor!
48+
* :books: For detailed information see the [NEORV32 online documentation](https://stnolting.github.io/neorv32/).
4949
* :interrobang: Want to know more? Check out the [project's rationale](https://stnolting.github.io/neorv32/#_rationale).
5050

5151
Feel free to open a new [issue](https://github.com/stnolting/neorv32/issues) or start a new
@@ -140,7 +140,7 @@ allows booting application code via UART or from external SPI flash
140140
**Timers and Counters**
141141

142142
* 64-bit machine timer ([MTIME](https://stnolting.github.io/neorv32/#_machine_system_timer_mtime)), RISC-V spec. compatible
143-
* 32-bit general purpose timer ([GPTMR](https://stnolting.github.io/neorv32/#_general_purpose_timer_gptmr)) with capture input
143+
* 32-bit general purpose timer ([GPTMR](https://stnolting.github.io/neorv32/#_general_purpose_timer_gptmr))
144144
* watchdog timer ([WDT](https://stnolting.github.io/neorv32/#_watchdog_timer_wdt))
145145

146146
**Input / Output**

docs/datasheet/soc.adoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ image::neorv32_processor.png[align=center]
3636
* _optional_ custom functions subsystem for custom co-processor extensions (<<_custom_functions_subsystem_cfs,**CFS**>>)
3737
* _optional_ NeoPixel(TM)/WS2812-compatible smart LED interface (<<_smart_led_interface_neoled,**NEOLED**>>)
3838
* _optional_ external interrupt controller with up to 32 channels (<<_external_interrupt_controller_xirq,**XIRQ**>>)
39-
* _optional_ general purpose 32-bit timer (<<_general_purpose_timer_gptmr,**GPTMR**>>) with capture input
39+
* _optional_ general purpose 32-bit timer (<<_general_purpose_timer_gptmr,**GPTMR**>>)
4040
* _optional_ execute in-place module (<<_execute_in_place_module_xip,**XIP**>>)
4141
* _optional_ 1-wire serial interface controller (<<_one_wire_serial_interface_controller_onewire,**ONEWIRE**>>), compatible to the 1-wire standard
4242
* _optional_ autonomous direct memory access controller (<<_direct_memory_access_controller_dma,**DMA**>>)
@@ -151,8 +151,6 @@ Some interfaces (like the TWI and the 1-Wire bus) require tri-state drivers in t
151151
| `neoled_o` | 1 | out | - | asynchronous serial data output
152152
5+^| **<<_machine_system_timer_mtime>>**
153153
| `mtime_time_o` | 64 | out | - | MTIME system time output
154-
5+^| **<<_general_purpose_timer_gptmr>>**
155-
| `gptmr_trig_i` | 1 | in | `'L'` | timer capture input
156154
5+^| **<<_external_interrupt_controller_xirq>>**
157155
| `xirq_i` | 32 | in | `'L'` | external interrupt requests
158156
5+^| **RISC-V Machine-Mode <<_processor_interrupts>>**

docs/datasheet/soc_gptmr.adoc

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
| Hardware source files: | neorv32_gptmr.vhd |
99
| Software driver files: | neorv32_gptmr.c |
1010
| | neorv32_gptmr.h |
11-
| Top entity ports: | `gptmr_trig_i` | timer capture input
11+
| Top entity ports: | none |
1212
| Configuration generics: | `IO_GPTMR_EN` | implement general purpose timer when `true`
1313
| CPU interrupts: | fast IRQ channel 12 | timer interrupt (see <<_processor_interrupts>>)
1414
|=======================
@@ -18,14 +18,13 @@
1818

1919
The general purpose timer module implements a simple yet universal 32-bit timer. It is implemented if the processor's
2020
`IO_GPTMR_EN` top generic is set `true`. The timer provides a pre-scaled counter register that can trigger an interrupt
21-
when reaching a programmable threshold value. Additionally, a timer-capture feature is implemented that copies the current
22-
counter value to a dedicated register if a programmable edge occurs at the `gptmr_trig_i` input signal.
21+
when reaching a programmable threshold value.l.
2322

24-
Four interface registers are available: a control register (`CTRL`), a 32-bit counter register (`COUNT`), a 32-bit
25-
threshold register (`THRES`) and a 32-bit read-only capture register (`CAPTURE`). The timer is globally enabled by setting the
26-
`GPTMR_CTRL_EN` bit in the device's control register `CTRL`. When the timer is enable the `COUNT` register will start
27-
incrementing at a programmable rate, which scales the main processor clock. The pre-scaler value is configured via the
28-
three `GPTMR_CTRL_PRSCx` control register bits:
23+
The GPTMR provides three interface registers : a control register (`CTRL`), a 32-bit counter register (`COUNT`) and a
24+
32-bit threshold register (`THRES`). The timer is globally enabled by setting the `GPTMR_CTRL_EN` bit in the module's
25+
control register. When the timer is enable the `COUNT` register will start incrementing from zero at a programmable
26+
rate that scales the main processor clock. this pre-scaler is configured via the three `GPTMR_CTRL_PRSCx`
27+
control register bits:
2928

3029
.GPTMR prescaler configuration
3130
[cols="<4,^1,^1,^1,^1,^1,^1,^1,^1"]
@@ -35,40 +34,24 @@ three `GPTMR_CTRL_PRSCx` control register bits:
3534
| Resulting `clock_prescaler` | 2 | 4 | 8 | 64 | 128 | 1024 | 2048 | 4096
3635
|=======================
3736

38-
[NOTE]
39-
Disabling the timer will not clear the `COUNT` register. However, it can be manually reset at any time by
40-
writing zero to it.
41-
42-
43-
**Interval Timer**
44-
45-
Whenever the counter register `COUNT` reaches the programmable threshold value `THRES` the counter register
46-
is reset to zero and the _timer-match_ flag `GPTMR_CTRL_TRIGM` gets set. This flag has to be cleared manually
47-
by writing zero to it. Optionally, an interrupt can be triggered if the `GPTMR_CTRL_IRQM` bit is set.
37+
Whenever the counter register `COUNT` equals the programmable threshold value `THRES` the module's interrupt
38+
signal becomes pending (indicated by `GPTMR_CTRL_IRQ_PND` being set). Note that a pending interrupt has to be
39+
cleared manually by writing a `1` to `GPTMR_CTRL_IRQ_CLR`.
4840

41+
The control register's `GPTMR_CTRL_MODE` bit defines what will happen when `COUNT == THRES`.
4942

50-
**Timer Capture**
43+
* `GPTMR_CTRL_MODE = 0`: **single-shot mode** - the `COUNT` register will stop incrementing
44+
* `GPTMR_CTRL_MODE = 1`: **continuous mode** - the `COUNT` register is automatically reset and restarts incrementing from zero
5145
52-
In addition to the the internal timer, the GPTMR provides a timer-capture feature. Whenever an edge is detected
53-
at the `gptmr_trig_i` input signal the current `COUNT` value is copied to the read-only `CAPTURE` register and the
54-
_capture-trigger_ flag `GPTMR_CTRL_TRIGC` gets set. This flag has to be cleared manually by writing zero to it.
55-
Optionally, an interrupt can be triggered if the `GPTMR_CTRL_IRQC` bit is set.
56-
57-
The triggering edge can be a rising-edge (if `GPTMR_CTRL_RISE` is set), a falling-edge (if `GPTMR_CTRL_FALL` is
58-
set) or even both. By default, the `gptmr_trig_i` is sampled two times at the processor clock for checking for
59-
edges. This simple edge detection is sufficient for trigger signals that are generated by (on-chip) digital logic.
60-
61-
For sampling chip-external signals an optional filtering mode is available that can be enabled by the
62-
`GPTMR_CTRL_FILTER` bit. If this bit is set, the `gptmr_trig_i` is sampled at a reduced clock speed (1/4 of the
63-
processor clock) and the signal has to be stable for at lest 4 sample clock in order to be considered high or low.
64-
This stabilized signal is then fed to the edge detection logic.
46+
.Resetting the Counter
47+
[NOTE]
48+
Disabling the GPTMR will also clear the `COUNT` register.
6549

6650

6751
**Interrupt**
6852

69-
The GPTRM provides a single interrupt line that can be trigger by a timer-match event and/or by a timer-compare
70-
event. Once triggered, the interrupt will stay active until explicitly cleared by writing zero to the according
71-
interrupt flag (`GPTMR_CTRL_TRIGM` or `GPTMR_CTRL_TRIGC`).
53+
The GPTRM provides a single interrupt line is triggered whenever `COUNT` equals `THRES`. Once triggered, the interrupt will
54+
stay pending until explicitly cleared by writing a 1 to `GPTMR_CTRL_IRQ_CLR`.
7255

7356

7457
**Register Map**
@@ -78,17 +61,12 @@ interrupt flag (`GPTMR_CTRL_TRIGM` or `GPTMR_CTRL_TRIGC`).
7861
[options="header",grid="all"]
7962
|=======================
8063
| Address | Name [C] | Bit(s), Name [C] | R/W | Function
81-
.10+<| `0xfffff100` .10+<| `CTRL` <|`0` `GPTMR_CTRL_EN` ^| r/w <| Timer enable flag
82-
<|`3:1` `GPTMR_CTRL_PRSC2 : GPTMR_CTRL_PRSC0` ^| r/w <| 3-bit clock prescaler select
83-
<|`4` `GPTMR_CTRL_IRQM` ^| r/w <| Enable interrupt on timer-match
84-
<|`5` `GPTMR_CTRL_IRQC` ^| r/w <| Enable interrupt on capture-trigger
85-
<|`6` `GPTMR_CTRL_RISE` ^| r/w <| Capture on rising edge
86-
<|`7` `GPTMR_CTRL_FALL` ^| r/w <| Capture on falling edge
87-
<|`8` `GPTMR_CTRL_FILTER` ^| r/w <| Filter capture input
88-
<|`29:9` - ^| r/- <| _reserved_, read as zero
89-
<|`30` `GPTMR_CTRL_TRIGM` ^| r/c <| Timer-match has fired, cleared by writing 0
90-
<|`31` `GPTMR_CTRL_TRIGC` ^| r/c <| Capture-trigger has fired, cleared by writing 0
64+
.6+<| `0xfffff100` .6+<| `CTRL` <|`0` `GPTMR_CTRL_EN` ^| r/w <| Timer enable flag
65+
<|`3:1` `GPTMR_CTRL_PRSC2 : GPTMR_CTRL_PRSC0` ^| r/w <| 3-bit clock prescaler select
66+
<|`4` `GPTMR_CTRL_MODE` ^| r/w <| Operation mode (0=single-shot, 1=continuous)
67+
<|`29:5` - ^| r/- <| _reserved_, read as zero
68+
<|`30` `GPTMR_CTRL_IRQ_CLR` ^| -/w <| Write `1` to clear timer-match interrupt; auto-clears
69+
<|`31` `GPTMR_CTRL_IRQ_PND` ^| r/- <| Timer-match interrupt pending
9170
| `0xfffff104` | `THRES` |`31:0` | r/w | Threshold value register
92-
| `0xfffff108` | `COUNT` |`31:0` | r/w | Counter register
93-
| `0xfffff10C` | `CAPTURE` |`31:0` | r/- | Capture register
71+
| `0xfffff108` | `COUNT` |`31:0` | r/- | Counter register
9472
|=======================

0 commit comments

Comments
 (0)