Documentation ¶
Overview ¶
The rtc package facilitates working with real-time clocks (RTCs). High level functions such as NewTicker and NewTimer encapsulate the details of working with the RTC while providing interfaces that are similar to Go's time.NewTicker and time.NewTimer respectively. If more flexible programming of the RTC is needed, the NewRTC function returns an rtc object that exposes all RTC functionality. When this object is instantiated, the RTC device file is kept open until the Close function is called. For convenience, static utility functions are also provided to open and close the RTC when only one function is needed. For example, reading the clock once is possible simply by calling rtc.Time(). Note that when working with the RTC, the highest resolution for time values is one second as defined in unix.RTCTime. https://www.kernel.org/doc/html/latest/admin-guide/rtc.html https://blog.cloudflare.com/its-go-time-on-linux/ https://man7.org/linux/man-pages/man4/rtc.4.html https://code.woboq.org/linux/linux/drivers/char/rtc.c.html
Index ¶
- func Alarm(dev string) (t time.Time, err error)
- func CancelWakeAlarm(dev string) (err error)
- func Clocks() (devices []string, err error)
- func Epoch(dev string) (epoch uint, err error)
- func Frequency(dev string) (frequency uint, err error)
- func NewRTC(dev string) (*rtc, error)
- func SetAlarm(dev string, t time.Time) (err error)
- func SetAlarmInterrupt(dev string, enable bool) (err error)
- func SetEpoch(dev string, epoch uint) (err error)
- func SetFrequency(dev string, frequency uint) (err error)
- func SetPeriodicInterrupt(dev string, enable bool) (err error)
- func SetTime(dev string, t time.Time) (err error)
- func SetUpdateInterrupt(dev string, enable bool) (err error)
- func SetWakeAlarm(dev string, t time.Time) (err error)
- func Time(dev string) (t time.Time, err error)
- func WakeAlarm(dev string) (enabled bool, pending bool, t time.Time, err error)
- type Ticker
- type Timer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alarm ¶
Alarm returns the alarm time for the specified real-time clock device.
Example ¶
if t, err := Alarm("/dev/rtc"); err == nil { fmt.Printf("Current alarm time: %v\n", t) }
Output:
func CancelWakeAlarm ¶
CancelWakeAlarm cancels the wake alarm for the specified real-time clock device.
func Clocks ¶
Clocks returns a list of real-time clocks in the system.
Example ¶
if cs, err := Clocks(); err == nil { for _, c := range cs { fmt.Printf("Clock found: %s\n", c) } }
Output:
func Epoch ¶
Epoch reads the epoch from the specified real-time clock device.
Example ¶
if e, err := Epoch("/dev/rtc"); err == nil { fmt.Printf("Current epoch: %d\n", e) }
Output:
func Frequency ¶
Frequency returns the frequency of the specified real-time clock device.
Example ¶
if f, err := Frequency("/dev/rtc"); err == nil { fmt.Printf("Frequency: %d\n", f) }
Output:
func SetAlarm ¶
SetAlarm sets the alarm time for the specified real-time clock device.
Example ¶
if err := SetAlarm("/dev/rtc", time.Now().Add(time.Minute)); err != nil { panic(err) }
Output:
func SetAlarmInterrupt ¶
SetAlarmInterrupt enables or disables the alarm interrupt for the specified real-time clock device.
Example ¶
if err := SetAlarmInterrupt("/dev/rtc", true); err != nil { panic(err) }
Output:
func SetEpoch ¶
Epoch sets the epoch on the specified real-time clock device.
Example ¶
if err := SetEpoch("/dev/rtc", 99); err != nil { panic(err) }
Output:
func SetFrequency ¶
SetFrequency sets the periodic interrupt frequency of the specified real-time clock device.
Example ¶
if err := SetFrequency("/dev/rtc", 64); err != nil { panic(err) }
Output:
func SetPeriodicInterrupt ¶
SetPeriodicInterrupt enables or disables periodic interrupts for the specified real-time clock device.
func SetTime ¶
SetTime sets the time for the specified real-time clock device.
Example ¶
if err := SetTime("/dev/rtc", time.Now()); err != nil { panic(err) }
Output:
func SetUpdateInterrupt ¶
SetUpdateInterrupt enables or disables the update interrupt for the specified real-time clock device.
func SetWakeAlarm ¶
SetWakeAlarm sets the wake alarm time for the specified real-time clock device.
Types ¶
type Ticker ¶ added in v0.1.1
type Ticker struct { Chan <-chan tick // contains filtered or unexported fields }
type Timer ¶ added in v0.1.1
type Timer struct { Chan <-chan alarm // contains filtered or unexported fields }
func NewTimer ¶
TODO: Timer resolution limited to 1 second TODO: What to do if d < 1 second? TODO: Consider mimicking the time.After() patterns
Example ¶
t, err := NewTimer("/dev/rtc", time.Minute) if err != nil { panic(err) } defer t.Stop() select { case alarm := <-t.Chan: fmt.Printf("Alarm. Time:%v\n", alarm.Time) }
Output:
func NewTimerAt ¶
NewTimerAt creates a timer that will trigger an alarm at the given time.