Skip to content

Commit 9e41ea2

Browse files
committed
RFC #49: clarify ALTERNATE mode and SetClr (set^clear) behavior.
1 parent 3f18b46 commit 9e41ea2

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

text/0049-soc-gpio-peripheral.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MySoC(wiring.Component):
3939
# Use a GPIO peripheral to control four LEDs:
4040

4141
m.submodules.led_gpio = led_gpio = gpio.Peripheral(pin_count=4, addr_width=8, data_width=8)
42+
4243
for n in range(4):
4344
connect(m, led_gpio.pins[n], platform.request("led", n, dir="io"))
4445

@@ -84,25 +85,30 @@ class Mode(enum.Enum, shape=unsigned(2)):
8485
Each `Mode.pin_x` field resets to `INPUT_ONLY`.
8586

8687
If `Mode.pin_x` is `INPUT_ONLY`:
87-
- `pins[x].alt_mode` returns 0.
88-
- `Input.pin_x` returns the last value of `pins[x].i` sampled on a clock cycle.
89-
- `pins[x].oe` returns 0 `pins[x].o` return 0.
88+
- `pins[x].oe` is 0.
89+
- `pins[x].o` is connected to `Output.pin_x`.
90+
- `Input.pin_x` is connected to `pins[x].i`.
91+
- `alt_mode[x]` is 0.
9092

9193
If `Mode.pin_x` is `PUSH_PULL`:
92-
- `pins[x].alt_mode` returns 0.
93-
- `Input.pin_x` returns the last value of `pins[x].i` sampled on a clock cycle.
94-
- `pins[x].oe` returns 1 and `pins[x].o` returns `Output.pin_x`.
94+
- `pins[x].oe` is 1.
95+
- `pins[x].o` is `Output.pin_x`.
96+
- `Input.pin_x` is connected to `pins[x].i`.
97+
- `alt_mode[x]` is 0.
9598

9699
If `Mode.pin_x` is `OPEN_DRAIN`:
97-
- `pins[x].alt_mode` returns 0.
98-
- `Input.pin_x` returns the last value of `pins[x].i` sampled on a clock cycle.
99-
- `pins[x].oe` returns `~Output.pin_x` and `pins[x].o` returns 0.
100+
- `pins[x].oe` is connected to `~Output.pin_x`.
101+
- `pins[x].o` is 0.
102+
- `Input.pin_x` is connected to `pins[x].i`.
103+
- `alt_mode[x]` is 0.
100104

101105
If `Mode.pin_x` is `ALTERNATE`:
102-
- `pins[x].alt_mode` returns 1.
103-
- `Input.pin_x`, `pins[x].oe` and `pins[x].o` return implementation-specific values.
106+
- `pins[x].oe` is 0.
107+
- `pins[x].o` is connected to `Output.pin_x`.
108+
- `Input.pin_x` is connected to `pins[x].i`.
109+
- `alt_mode[x]` is 1.
104110

105-
If `ALTERNATE` mode is unimplemented, its behavior should be equivalent to `INPUT_ONLY` mode.
111+
When `alt_mode[x]` is 1, a component connected to the GPIO peripheral (such as a pin multiplexer) may assign implementation-specific functions to `Input.pin_x` and `Output.pin_x`.
106112

107113
#### Input (read-only)
108114

@@ -114,6 +120,8 @@ If `ALTERNATE` mode is unimplemented, its behavior should be equivalent to `INPU
114120
{name: 'pin_3', bits: 1, attr: 'R'},
115121
], {bits: 4})">
116122

123+
The number of synchronization stages between `pins[x].i` and `Input.pin_x` is defined by the `input_stages` parameter, which defaults to 2. Synchronization is done on rising edges of `ClockSignal("sync")`.
124+
117125
#### Output (read/write)
118126

119127
<img src="./0049-soc-gpio-peripheral/reg-output.svg"
@@ -130,18 +138,15 @@ Each `Output.pin_x` field resets to 0.
130138

131139
<img src="./0049-soc-gpio-peripheral/reg-setclr.svg"
132140
alt="bf([
133-
{name: 'set_0', bits: 1, attr: 'W'},
134-
{name: 'clr_0', bits: 1, attr: 'W'},
135-
{name: 'set_1', bits: 1, attr: 'W'},
136-
{name: 'clr_1', bits: 1, attr: 'W'},
137-
{name: 'set_2', bits: 1, attr: 'W'},
138-
{name: 'clr_2', bits: 1, attr: 'W'},
139-
{name: 'set_3', bits: 1, attr: 'W'},
140-
{name: 'clr_3', bits: 1, attr: 'W'},
141+
{name: 'pin_0', bits: 2, attr: 'W'},
142+
{name: 'pin_1', bits: 2, attr: 'W'},
143+
{name: 'pin_2', bits: 2, attr: 'W'},
144+
{name: 'pin_3', bits: 2, attr: 'W'},
141145
], {bits: 8})">
142146

143-
- Writing `1` to an `SetClr.set_x` field sets `Output.pin_x`.
144-
- Writing `1` to an `SetClr.clr_x` field clears `Output.pin_x`.
147+
- Writing `0b01` to `SetClr.pin_x` sets `Output.pin_x`.
148+
- Writing `0b10` to `SetClr.pin_x` clears `Output.pin_x`.
149+
- Writing `0b00` or `0b11` to `SetClr.pin_x` has no effect.
145150

146151
## Reference-level explanation
147152
[reference-level-explanation]: #reference-level-explanation
@@ -154,7 +159,6 @@ The members of a `gpio.PinSignature` are defined as follows:
154159

155160
```python3
156161
{
157-
"alt_mode": Out(unsigned(1)),
158162
"i": In(unsigned(1)),
159163
"o": Out(unsigned(1)),
160164
"oe": Out(unsigned(1)),
@@ -174,6 +178,7 @@ The `gpio.Peripheral` class is a `wiring.Component` implementing a GPIO controll
174178
{
175179
"bus": In(csr.Signature(addr_width, data_width)),
176180
"pins": Out(gpio.PinSignature()).array(pin_count),
181+
"alt_mode": Out(unsigned(pin_count)),
177182
}
178183
```
179184

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)