|
1 | 1 | ## Sharing Data With Globals |
2 | 2 |
|
3 | | -> **NOTE** This content is partially taken with permission from the blog post |
| 3 | +> **NOTE** This content is partially taken (with permission) from the blog post |
4 | 4 | > *[Interrupts Is Threads]* by James Munns, which contains more discussion about this |
5 | 5 | > topic. |
6 | 6 |
|
7 | 7 | As I mentioned in the last section, when an interrupt occurs we aren't passed any arguments and |
8 | 8 | cannot return any result. This makes it hard for our program interact with peripherals and other |
9 | | -main program state. Before worrying about this |
10 | | -bare-metal embedded problem, it is likely worth thinking about threads in "std" Rust. |
| 9 | +main program state. Before worrying about this bare-metal embedded problem, it is likely worth |
| 10 | +thinking about threads in "std" Rust. |
11 | 11 |
|
12 | 12 | ### "std" Rust: Sharing Data With A Thread |
13 | 13 |
|
@@ -174,15 +174,15 @@ data could end up corrupted. |
174 | 174 | In embedded Rust we care about the same things when it comes to sharing data with interrupt |
175 | 175 | handlers! Similar to threads, interrupts can occur at any time, sort of like a thread waking up and |
176 | 176 | accessing some shared data. This means that the data we share with an interrupt must live long |
177 | | -enough, and we must be careful to ensure that our main code isn't in the middle of accessing some |
178 | | -data shared with the interrupt, just to have the interrupt run and ALSO access that data! |
| 177 | +enough, and we must be careful to ensure that our main code isn't in the middle of working with some |
| 178 | +data shared with an ISR when that ISR gets run and *also* tries to work with the data! |
179 | 179 |
|
180 | 180 | In fact, in embedded Rust, we model interrupts in a similar way that we model threads in Rust: the |
181 | 181 | same rules apply, for the same reasons. However, in embedded Rust, we have some crucial differences: |
182 | 182 |
|
183 | 183 | * Interrupts don't work exactly like threads: we set them up ahead of time, and they wait until some |
184 | 184 | event happens (like a button being pressed, or a timer expiring). At that point they run, but |
185 | | - without access to any context. |
| 185 | + without access to any passed-in context. |
186 | 186 |
|
187 | 187 | * Interrupts can be triggered multiple times, once for each time that the event occurs. |
188 | 188 |
|
@@ -275,8 +275,8 @@ main loop, just after the `wfi()` "wait for interrupt". The count will then be r |
275 | 275 | an interrupt handler finishes (`examples/count-bounce.rs`). Again, the count is bumped up 1 on every |
276 | 276 | push of the MB2 A button. |
277 | 277 |
|
278 | | -Maybe. Especially if your MB2 is old, you may see a single press bump the counter by several. *This |
279 | | -is not a software bug.* Mostly. In the next section, I'll talk about what might be going on and how |
280 | | -we should deal with it. |
| 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. |
281 | 281 |
|
282 | 282 | [Interrupts Is Threads]: https://onevariable.com/blog/interrupts-is-threads |
0 commit comments