Commit Graph

37 Commits

Author SHA1 Message Date
Liam Murphy
079526559f Remove critical sections from PeripheralMutex interrupt handler by checking the interrupt's priority on startup.
Since `PeripheralMutex` is the only way to safely maintain state across interrupts, and it no longer allows setting the interrupt's priority, the priority changing isn't a concern.

This also prevents other causes of UB due to the interrupt being exposed during `with`, and allowing enabling the interrupt and setting its context to a bogus pointer.
2021-07-27 17:28:52 +10:00
Liam Murphy
1b7ad7080e Add Send/Sync bounds to PeripheralState 2021-07-24 12:53:57 +10:00
Liam Murphy
fc1ef4947d Fix stm32 ethernet 2021-07-05 18:18:05 +10:00
Liam Murphy
3d96b10b0c Elide lifetimes on Peripheral::state 2021-07-05 17:47:55 +10:00
Liam Murphy
744e2cbb8a extras: Fix UB in Peripheral
`Peripheral` assumed that interrupts can't be preempted,
when they can be preempted by higher priority interrupts.
So I put the interrupt handler inside a critical section,
and also added checks for whether the state had been dropped
before the critical section was entered.

I also added a `'static` bound to `PeripheralState`,
since `Pin` only guarantees that the memory it directly references
will not be invalidated.
It doesn't guarantee that memory its pointee references also won't be invalidated.

There were already some implementations of `PeripheralState`
that weren't `'static`, though,
so I added an unsafe `PeripheralStateUnchecked` trait
and forwarded the `unsafe` to the constructors of the implementors.
2021-07-05 17:42:43 +10:00
Dario Nieuwenhuis
3be49d3e79 fmt: Add dunmy use to avoid "unused variable" errors when no log is enabled. 2021-06-07 03:21:37 +02:00
Dario Nieuwenhuis
ef1ebefec0 fmt: use absolute paths 2021-06-07 03:15:05 +02:00
Dario Nieuwenhuis
e7dc5c0939 fmt: make all macros macro_rules so scoping is consistent. 2021-06-07 00:16:39 +02:00
Dario Nieuwenhuis
105c8504b6 Mark Unborrow as unsafe to implement 2021-05-19 23:29:33 +02:00
Dario Nieuwenhuis
dc67d2f4a4 impl Unborrow for &'a mut T
This plays nicer with user code that's generic over peripheral traits like `Instance` or `Pin`.
2021-05-19 23:20:26 +02:00
Rukai
149ddf2f29 Fix warnings 2021-05-17 19:48:58 +10:00
Dario Nieuwenhuis
0310e4d458 Add init fn. Initializes hw and returns Peripherals. 2021-05-17 00:57:37 +02:00
Dario Nieuwenhuis
e6a8c8bfcc Add PriorityX enums to embassy-extras::interrupt 2021-05-11 01:21:02 +02:00
Dario Nieuwenhuis
7fa0e57172 Use critical_section crate 2021-05-11 01:15:30 +02:00
Dario Nieuwenhuis
97ca54fa66 Rename PeripheralBorrow to Unborrow 2021-04-14 19:59:52 +02:00
Dario Nieuwenhuis
75c5bb19d8 extras: fix build with defmt 2021-04-10 01:48:52 +02:00
Ian McIntyre
e7c63a09e4 Mark peripherals as taken 2021-04-01 18:00:32 -04:00
Dario Nieuwenhuis
02ae53e71b Fix unused import warnings 2021-03-29 21:35:25 +02:00
xoviat
a3d876bf46 take clocks on peripheral take 2021-03-29 09:02:23 -05:00
xoviat
50ecb7d42b cleanup and consolidate peripherals macro 2021-03-29 08:57:40 -05:00
Dario Nieuwenhuis
e88d52e0da extras: fix missing absolute path in impl_borrow 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
a338841797 extras: add impl_unborrow macro 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
5646926cca nrf/rtc: update to new api 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
4ce46df160 Code size optimizations. 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
eedb51bbb6 extras: add Peripheral with shared state (like PeripheralMutex but without mutex) 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
806ee120ba extras: add missing cfg to peripherals macro 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
a0511e6caa nrf/uart: make rts/cts optional. 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
7b6086d19e nrf: add unborrow! macro 2021-03-29 00:58:58 +02:00
Dario Nieuwenhuis
a134fce122 nrf: nicer Peripherals api, add take() 2021-03-29 00:58:57 +02:00
Dario Nieuwenhuis
c0876187dd extras: move peripherals from nrf to extras 2021-03-29 00:58:57 +02:00
Thales Fragoso
d4f35c1729 Move USB to embassy-extras 2021-03-19 20:49:15 -03:00
Thales Fragoso
615bb33dcb USB: Use updated PeripheralMutex 2021-03-19 19:44:30 -03:00
Dario Nieuwenhuis
b57489eb5d peripheralmutex: separate interrupt registration to own method. 2021-03-18 18:49:10 +01:00
Dario Nieuwenhuis
0cd19a58c3 Remove free() from PeripheralMutex and all nrf drivers. 2021-03-18 18:49:10 +01:00
Dario Nieuwenhuis
f248bb17ad Allow unused stuff in fmt.rs 2021-03-18 01:42:28 +01:00
Dario Nieuwenhuis
a9076636ac Do not export fmt macros.
This was introduced by accident by me struggling with the weird intra-crate macro importing system...
2021-03-17 22:50:27 +01:00
Thales Fragoso
15c3e78408 Move nRF's util into a separate crate 2021-03-07 20:15:40 -03:00