github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/interrupt/interrupt_avr.go (about) 1 //go:build avr 2 3 package interrupt 4 5 import "device" 6 7 // State represents the previous global interrupt state. 8 type State uint8 9 10 // Disable disables all interrupts and returns the previous interrupt state. It 11 // can be used in a critical section like this: 12 // 13 // state := interrupt.Disable() 14 // // critical section 15 // interrupt.Restore(state) 16 // 17 // Critical sections can be nested. Make sure to call Restore in the same order 18 // as you called Disable (this happens naturally with the pattern above). 19 func Disable() (state State) { 20 // SREG is at I/O address 0x3f. 21 return State(device.AsmFull(` 22 in {}, 0x3f 23 cli 24 `, nil)) 25 } 26 27 // Restore restores interrupts to what they were before. Give the previous state 28 // returned by Disable as a parameter. If interrupts were disabled before 29 // calling Disable, this will not re-enable interrupts, allowing for nested 30 // cricital sections. 31 func Restore(state State) { 32 // SREG is at I/O address 0x3f. 33 device.AsmFull("out 0x3f, {state}", map[string]interface{}{ 34 "state": state, 35 }) 36 } 37 38 // In returns whether the system is currently in an interrupt. 39 // 40 // Warning: this always returns false on AVR, as there does not appear to be a 41 // reliable way to determine whether we're currently running inside an interrupt 42 // handler. 43 func In() bool { 44 return false 45 }