Skip to main content

RtcController Class

NuGet: GHIElectronics.TinyCLR.Devices.Rtc
Assembly: GHIElectronics.TinyCLR.Devices.Rtc
Namespace: GHIElectronics.TinyCLR.Devices.Rtc

Real-time clock controller. Tracks calendar time across power cycles when backed by a coin cell, and exposes a small region of battery-backed RAM via WriteBackupMemory(byte[]) / ReadBackupMemory(byte[]).

public class RtcController : IDisposable

Properties​

Provider​

public IRtcControllerProvider Provider { get; }

The low-level provider backing this controller.

IsValid​

public bool IsValid { get; }

True when the RTC has been initialized with a valid time at least once.

InternalRC​

public bool InternalRC { get; }

True when the RTC is clocked from the internal RC oscillator rather than an external crystal.

Now​

public DateTime Now { get; set; }

Convenience accessor that returns/accepts a managed DateTime.

BackupMemorySize​

public uint BackupMemorySize { get; }

Size in bytes of the battery-backed memory region.

Methods​

GetDefault()​

public static RtcController GetDefault()

Returns the default RTC controller for this device.

Returns RtcController

FromName(string name)​

public static RtcController FromName(string name)

Returns an RTC controller identified by its native API name.

ParameterTypeDescription
namestringNative API name.

Returns RtcController

FromProvider(IRtcControllerProvider provider)​

public static RtcController FromProvider(IRtcControllerProvider provider)

Creates a controller from a custom IRtcControllerProvider.

ParameterTypeDescription
providerIRtcControllerProviderProvider implementing the clock operations.

Returns RtcController

Dispose()​

public void Dispose()

Releases the underlying provider.

GetTime()​

public RtcDateTime GetTime()

Returns the current RTC time.

Returns RtcDateTime

SetTime(RtcDateTime value)​

public void SetTime(RtcDateTime value)

Sets the RTC time. After a successful call, IsValid becomes true.

ParameterTypeDescription
valueRtcDateTimeCalendar time to write.

WriteBackupMemory(byte[] sourceData)​

public void WriteBackupMemory(byte[] sourceData)

Writes the entire sourceData array to backup memory starting at offset 0.

ParameterTypeDescription
sourceDatabyte[]Bytes to write.

WriteBackupMemory(byte[] sourceData, uint destinationOffset)​

public void WriteBackupMemory(byte[] sourceData, uint destinationOffset)

Writes the entire sourceData array to backup memory at destinationOffset.

ParameterTypeDescription
sourceDatabyte[]Bytes to write.
destinationOffsetuintOffset in backup memory where the write begins.

WriteBackupMemory(byte[] sourceData, uint sourceOffset, uint destinationOffset, int count)​

public void WriteBackupMemory(byte[] sourceData, uint sourceOffset, uint destinationOffset, int count)

Writes a slice of sourceData to backup memory.

ParameterTypeDescription
sourceDatabyte[]Source buffer.
sourceOffsetuintStarting offset within sourceData.
destinationOffsetuintStarting offset in backup memory.
countintNumber of bytes to write.

ReadBackupMemory(byte[] destinationData)​

public int ReadBackupMemory(byte[] destinationData)

Reads destinationData.Length bytes from backup memory starting at offset 0.

ParameterTypeDescription
destinationDatabyte[]Destination buffer.

Returns int — Number of bytes read.

ReadBackupMemory(byte[] destinationData, uint sourceOffset)​

public int ReadBackupMemory(byte[] destinationData, uint sourceOffset)

Reads destinationData.Length bytes from backup memory starting at sourceOffset.

ParameterTypeDescription
destinationDatabyte[]Destination buffer.
sourceOffsetuintStarting offset in backup memory.

Returns int — Number of bytes read.

ReadBackupMemory(byte[] destinationData, uint destinationOffset, uint sourceOffset, int count)​

public int ReadBackupMemory(byte[] destinationData, uint destinationOffset, uint sourceOffset, int count)

Reads a slice from backup memory into destinationData.

ParameterTypeDescription
destinationDatabyte[]Destination buffer.
destinationOffsetuintStarting offset within destinationData.
sourceOffsetuintStarting offset in backup memory.
countintNumber of bytes to read.

Returns int — Number of bytes read.

SetChargeMode(BatteryChargeMode chargeMode)​

public void SetChargeMode(BatteryChargeMode chargeMode)

Configures the backup-battery trickle charger.

ParameterTypeDescription
chargeModeBatteryChargeModeCharging policy.

Calibrate(int pulse)​

public void Calibrate(int pulse)

Applies a frequency calibration pulse to compensate crystal drift.

ParameterTypeDescription
pulseintPlatform-specific calibration value.