Landin library reference discuss source

platform/cortex_m/cortex_m.ldn

1--  M-profile CPU operations, from armv6-m up. The saved mask is an ordinary
2--  explicit value. Restore it in lexical reverse order; masking does not stop
3--  DMA or faults.
4compiler.assert(compiler.arch == cortex_m0)
5
6--- Disable maskable interrupts and return the previous PRIMASK. Save the
7--- result and pass it to `restore_interrupts`, including on early returns.
8--- NMI and HardFault remain unmasked.
9public disable_interrupts: () -> (previous: u32) =
10    previous = assembler.block("mrs {mask}, primask\ncpsid i",
11                               out mask: u32 at general)
12end disable_interrupts
13
14--- Restore a saved PRIMASK value. Only bit zero is implemented; use the value
15--- returned by `disable_interrupts` to preserve nesting.
16public restore_interrupts: (previous: u32) -> none =
17    assembler.block("msr primask, {mask}\nisb sy",
18                    in mask: u32 at general = previous)
19end restore_interrupts
20
21--- Read the current PRIMASK interrupt mask.
22public interrupt_mask: () -> (current: u32) =
23    current = assembler.block("mrs {mask}, primask", out mask: u32 at general)
24end interrupt_mask
25
26--- Issue a completion barrier and wait for an interrupt. Wakeups can be
27--- spurious; recheck the condition after waking.
28---
29--- Architectural completion before sleep does not acknowledge a device.
30public wait_for_interrupt: () -> none =
31    assembler.block("dsb sy\nwfi")
32end wait_for_interrupt
33
34--- Issue a data memory barrier (DMB) to order memory accesses. This is not
35--- a proof that a device operation completed.
36public device_barrier: () -> none =
37    compiler.device_barrier()
38end device_barrier
39
40--- Issue a data synchronization barrier (DSB) to wait for preceding explicit
41--- memory accesses to complete.
42public completion_barrier: () -> none =
43    compiler.completion_barrier()
44end completion_barrier
45
46--- Prevent compiler memory knowledge from moving across this point. This
47--- emits no device-completion protocol.
48public compiler_barrier: () -> none =
49    compiler.compiler_barrier()
50end compiler_barrier