Skip to content

Commit f5d30f5

Browse files
committed
fixed a few more reported mistakes in interrupts chapter
1 parent 2208e10 commit f5d30f5

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

mdbook/src/15-interrupts/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ generate an interrupt before you are ready to handle it.
5454

5555
**Note** As with most microcontrollers, there is a lot of flexibility in when the GPIOTE can generate an interrupt. Interrupts can be generated on low-to-high pin transition, high-to-low (as here), any change ("edge"), when low, or when high. On the nRF52833, interrupts generate an event that must be manually cleared in the ISR to ensure that the ISR is not called a second time for the same interrupt. Other microcontrollers may work a little differently — you should read Rust crate and microcontroller documentation to understand the details on a different board.
5656

57-
When you push the A Button, you will see an "ouch" message and then a panic. Why does the interrupt handler call `panic!()`? Try commenting the `panic!()` call out and see what happens when you push the button. You will see "ouch" messages scroll off the screen. The NVIC records when an interrupt has been issued: that "event" is kept until it is explicitly cleared by the running program. Without the `panic!()`, when the interrupt handler returns the NVIC will (in this case) re-enable the interrupt, notice that there is still an interrupt event pending, and run the handler again. This will continue forever: each time the interrupt handler returns it will be called again. In the next section we will see how to clear the interrupt indication from within the interrupt handler.
57+
When you push the A Button, you will see an "ouch" message and then a panic. Why does the interrupt
58+
handler call `panic!()`? Try commenting the `panic!()` call out and see what happens when you push
59+
the button. You will see "ouch" messages scroll off the screen. The NVIC records when an interrupt
60+
has been issued: that "event" is kept until it is explicitly cleared by the running program. Without
61+
the `panic!()`, when the interrupt handler returns the NVIC will (in this case) re-enable the
62+
interrupt, notice that there is still an interrupt event pending, and run the handler again. This
63+
will continue forever: each time the interrupt handler returns it will be called again. As we will
64+
see in a bit, the interrupt indication can be cleared from within the interrupt handler using the
65+
`reset_event()` peripheral method.
5866

5967
You may define ISRs for many different interrupt sources: when I2C is ready, when a timer expires,
6068
and on and on. Inside an ISR you can do pretty much anything you want, but it's good practice to

mdbook/src/15-interrupts/sharing-data-with-globals.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,25 @@ and the rest of the program.
266266
Give this example (`examples/count.rs`) a run and note that the count is bumped up 1 on every push
267267
of the MB2 A button.
268268

269+
```rust
270+
{{#include examples/count.rs}}
271+
```
272+
269273
> **NOTE** It is always a good idea to compile examples involving interrupt handling with
270274
> `--release`. Long interrupt handlers can lead to a lot of confusion.
271275
272276
Really, though, that `rprintln!()` in the interrupt handler is bad practice: while the interrupt
273277
handler is running the printing code, nothing else can move forward. Let's move the reporting to the
274278
main loop, just after the `wfi()` "wait for interrupt". The count will then be reported every time
275-
an interrupt handler finishes (`examples/count-bounce.rs`). Again, the count is bumped up 1 on every
276-
push of the MB2 A button.
279+
an interrupt handler finishes (`examples/count-bounce.rs`).
280+
281+
```rust
282+
{{#include examples/count-bounce.rs}}
283+
```
277284

278-
Maybe. Especially if your MB2 is old (!), you may see a single press bump the counter by
279-
several. *This is not a software bug.* Mostly. In the next section, I'll talk about what might be
280-
going on and how we should deal with it.
285+
In this example the count is bumped up 1 on every push of the MB2 A button. Maybe. Especially if
286+
your MB2 is old (!), you may see a single press bump the counter by several. *This is not a software
287+
bug.* Mostly. In the next section, I'll talk about what might be going on and how we should deal
288+
with it.
281289

282290
[Interrupts Is Threads]: https://onevariable.com/blog/interrupts-is-threads

0 commit comments

Comments
 (0)