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

     1  //go:build rp2040
     2  
     3  package machine
     4  
     5  import (
     6  	"device/rp"
     7  	"runtime/volatile"
     8  	"unsafe"
     9  )
    10  
    11  // RESETS_RESET_Msk is bitmask to reset all peripherals
    12  //
    13  // TODO: This field is not available in the device file.
    14  const RESETS_RESET_Msk = 0x01ffffff
    15  
    16  type resetsType struct {
    17  	reset     volatile.Register32
    18  	wdSel     volatile.Register32
    19  	resetDone volatile.Register32
    20  }
    21  
    22  var resets = (*resetsType)(unsafe.Pointer(rp.RESETS))
    23  
    24  // resetBlock resets hardware blocks specified
    25  // by the bit pattern in bits.
    26  func resetBlock(bits uint32) {
    27  	resets.reset.SetBits(bits)
    28  }
    29  
    30  // unresetBlock brings hardware blocks specified by the
    31  // bit pattern in bits out of reset.
    32  func unresetBlock(bits uint32) {
    33  	resets.reset.ClearBits(bits)
    34  }
    35  
    36  // unresetBlockWait brings specified hardware blocks
    37  // specified by the bit pattern in bits
    38  // out of reset and wait for completion.
    39  func unresetBlockWait(bits uint32) {
    40  	unresetBlock(bits)
    41  	for !resets.resetDone.HasBits(bits) {
    42  	}
    43  }