svd2rust icon indicating copy to clipboard operation
svd2rust copied to clipboard

Add support for atomic operations in microcontrollers that support it

Open dvc94ch opened this issue 7 years ago • 1 comments

svd2rust should generate an additional (set, clear, toggle or and, or, xor) operations when atomic's are supported. While ARM MCU's provide stateless registers, the E310-G000 does not. Instead it provides AMOAND, AMOOR, AMOXOR instructions to be used instead.

This currently makes hard to implement embedded-hal traits without violating safety, since turning an OutputPin high requires a modify operation, which is not atomic.

dvc94ch avatar Mar 25 '18 14:03 dvc94ch

Atomic modify operation is verified in this HAL crate: gpio.rs file. I believe we can refer to this pull request: https://github.com/rust-embedded/svd2rust/pull/407 We may always perform atomic operations on chips, which falls back to normal read-and-write when atomic operations are not supported. By this optimization we would save output binary length as we could make more use of instructions provided. This optimization may not accelerate runtime speed, would result in faster or (at least) the same speed; that's because for some chips they just unwrap atomic instructions into normal read-and-write after prepocessed instruction fetch. But considering code size, it would be worth a try to do this optimization .

There's another problem on memory order for atomic modify if there is one. There are many memory Orderings in standard library. Which ordering should we choose for modify function?

luojia65 avatar Mar 01 '20 07:03 luojia65