github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/runtime/interrupt/interrupt.go (about)

     1  // Package interrupt provides access to hardware interrupts. It provides a way
     2  // to define interrupts and to enable/disable them.
     3  package interrupt
     4  
     5  import "unsafe"
     6  
     7  // Interrupt provides direct access to hardware interrupts. You can configure
     8  // this interrupt through this interface.
     9  //
    10  // Do not use the zero value of an Interrupt object. Instead, call New to obtain
    11  // an interrupt handle.
    12  type Interrupt struct {
    13  	// Make this number unexported so it cannot be set directly. This provides
    14  	// some encapsulation.
    15  	num int
    16  }
    17  
    18  // New is a compiler intrinsic that creates a new Interrupt object. You may call
    19  // it only once, and must pass constant parameters to it. That means that the
    20  // interrupt ID must be a Go constant and that the handler must be a simple
    21  // function: closures are not supported.
    22  func New(id int, handler func(Interrupt)) Interrupt
    23  
    24  // handle is used internally, between IR generation and interrupt lowering. The
    25  // frontend will create runtime/interrupt.handle objects, cast them to an int,
    26  // and use that in an Interrupt object. That way the compiler will be able to
    27  // optimize away all interrupt handles that are never used in a program.
    28  // This system only works when interrupts need to be enabled before use and this
    29  // is done only through calling Enable() on this object. If interrups cannot
    30  // individually be enabled/disabled, the compiler should create a pseudo-call
    31  // (like runtime/interrupt.use()) that keeps the interrupt alive.
    32  type handle struct {
    33  	context unsafe.Pointer
    34  	funcPtr uintptr
    35  	Interrupt
    36  }