mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-11 23:19:30 +00:00
8135be4e90
TODO: Remove the go.mod/go.sum in internal/tools once doing so doesn't break CI (e.g. once we drop support for go 1.19) * builder/cc1as.h: fix typo found by 'make spell' * GNUmakefile: remove exception for inbetween, fix instance now found by 'make spell' * GNUmakefile: remove exception for programmmer, fix instance now found by 'make spell' * go.mod: use updated misspell. GNUmakefile: add spellfix target, use it. * ignore directories properly when invoking spellchecker. * make spell: give internal/tools its own go.mod, as misspell requires newer go * make lint: depend on tools and run the installed revive (which was perhaps implied by the change that added revive to internal/tools, but not required in GNUmakefile until we gave internal/tools its own temporary go.mod) * .github: now that 'make spell' works well, run it from CI * GNUmakefile: make spell now aborts if it finds misspelt words, so what it finds doesn't get lost in CI logs * GNUmakefile: tools: avoid -C option on go generate to make test-llvm15-go119 circleci job happy, see https://cs.opensource.google/go/go/+/2af48cbb7d85e5fdc635e75b99f949010c607786 * internal/tools/go.mod: fix format of go version to leave out patchlevel, else go complains.
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
//go:build avr
|
|
|
|
package interrupt
|
|
|
|
import "device"
|
|
|
|
// State represents the previous global interrupt state.
|
|
type State uint8
|
|
|
|
// Disable disables all interrupts and returns the previous interrupt state. It
|
|
// can be used in a critical section like this:
|
|
//
|
|
// state := interrupt.Disable()
|
|
// // critical section
|
|
// interrupt.Restore(state)
|
|
//
|
|
// Critical sections can be nested. Make sure to call Restore in the same order
|
|
// as you called Disable (this happens naturally with the pattern above).
|
|
func Disable() (state State) {
|
|
// SREG is at I/O address 0x3f.
|
|
return State(device.AsmFull(`
|
|
in {}, 0x3f
|
|
cli
|
|
`, nil))
|
|
}
|
|
|
|
// Restore restores interrupts to what they were before. Give the previous state
|
|
// returned by Disable as a parameter. If interrupts were disabled before
|
|
// calling Disable, this will not re-enable interrupts, allowing for nested
|
|
// critical sections.
|
|
func Restore(state State) {
|
|
// SREG is at I/O address 0x3f.
|
|
device.AsmFull("out 0x3f, {state}", map[string]interface{}{
|
|
"state": state,
|
|
})
|
|
}
|
|
|
|
// In returns whether the system is currently in an interrupt.
|
|
//
|
|
// Warning: this always returns false on AVR, as there does not appear to be a
|
|
// reliable way to determine whether we're currently running inside an interrupt
|
|
// handler.
|
|
func In() bool {
|
|
return false
|
|
}
|