github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/soc/nxp/imx6ul/timer.go (about)

     1  // NXP i.MX6UL timer support
     2  // https://github.com/usbarmory/tamago
     3  //
     4  // Copyright (c) WithSecure Corporation
     5  // https://foundry.withsecure.com
     6  //
     7  // Use of this source code is governed by the license
     8  // that can be found in the LICENSE file.
     9  
    10  package imx6ul
    11  
    12  import (
    13  	_ "unsafe"
    14  )
    15  
    16  // Timer registers (p178, Table 2-3, IMX6ULLRM)
    17  const SYS_CNT_BASE = 0x021dc000
    18  
    19  func initTimers() {
    20  	switch Family {
    21  	case IMX6UL, IMX6ULL:
    22  		if !Native {
    23  			// use QEMU fixed CNTFRQ value (62.5MHz)
    24  			ARM.InitGenericTimers(0, 62500000)
    25  		} else {
    26  			// U-Boot value for i.MX6 family (8.0MHz)
    27  			ARM.InitGenericTimers(SYS_CNT_BASE, 8000000)
    28  		}
    29  	default:
    30  		ARM.InitGlobalTimers()
    31  	}
    32  }
    33  
    34  //go:linkname nanotime1 runtime.nanotime1
    35  func nanotime1() int64 {
    36  	return int64(ARM.TimerFn()*ARM.TimerMultiplier + ARM.TimerOffset)
    37  }