japaric / vcell

Just like `Cell` but with volatile read / write operations
Apache License 2.0
18 stars 12 forks source link

Add atomic modify operations #7

Open SamP20 opened 5 years ago

SamP20 commented 5 years ago

The ARMv6 and ARMv7 instruction sets contain the LDREX and STREX instructions. It would be handy to add an AtomicOps trait with atomic_get/atomic_set and/or atomic_modify methods based on these instructions. This is possibly duplicating the AtomicXXX types in the core library, however I can see this being useful for splitting I/O ports into thread safe groups.

hannobraun commented 5 years ago

however I can see this being useful for splitting I/O ports into thread safe groups.

There's been some discussion on the svd2rust issue tracker that could be another solution to this issue, here: https://github.com/rust-embedded/svd2rust/issues/213

The suggestion to split registers into ownable fields comes later in the issue: https://github.com/rust-embedded/svd2rust/issues/213#issuecomment-434116049

SamP20 commented 5 years ago

The suggestion to split registers into ownable fields comes later in the issue

That's an option too. I did notice just after posting this that VolatileCell has an as_ptr method, so it would be possible to implement something at a higher level.