Starts the counter.
func start(mode: Mode? = nil, period: UInt64? = nil)
s7SwiftIO7CounterC5start4mode6periodyAC4ModeOSg_s6UInt64VSgtF
2Z0I1
The mode of the counter. If it’s nil, it adopts the mode set when initializing the counter.
The period of the counter in microsecond. If it’s nil, it equals the period set when initializing the counter.
import SwiftIO
The SwiftIO library allows you to access and control the hardware in an easy way.
final class Counter
The Counter class is used to track the number of the clock ticks.
enum Mode
There are two modes: oneShot means the counter works once; period means it works periodically.
oneShot
period
@frozen struct UInt64
A 64-bit unsigned integer value type.
init(_ idName: Id, mode: Mode = .period, period: UInt64 = 1_000_000)
Initializes a counter by specifying its period in microsecond.
let counterFrequency: UInt32
The frequency of counter in Hz.
let maxCountMicroseconds: UInt64
The maximum time for counter in microsecond.
let maxCountTicks: UInt32
The maximum number of ticks for counter.
let obj: UnsafeMutableRawPointer
func getTicks() -> Result<UInt32, Errno>
Gets the number of ticks that have elapsed. If the elapsed time is too long, the value may overflow.
func getTicks(from period: UInt64) -> UInt32
Converts the time in microsecond to the number of ticks.
func setInterrupt(start: Bool = true, _ callback: @escaping (UInt32) -> Void)
Executes a designated task if the specified period has elapsed.
func stop()
Stops the counter.