RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
Real Time Clock (RTC) Driver

Overview

This module provides Generic Core functions of RTC to configure and control RTC input/output and interrupt behavior.

Usage & Initialization.

This is an example show how to instantiate Real Time Clock (RTC) Driver with rtc_instance_t.

This implementation depends on I2C Driver.

#include "rtc/rtc.h"
// I2C instance configuration
#define I2C_FREQ 100000
#define I2C_CTRL_HZ SYSTEM_CLINT_HZ
#define I2C_CTRL (i2c_hwreg_t *)SYSTEM_I2C_0_IO_CTRL
// RTC instance configuration
#define RTC_CTRL RTC_DS3231_ADDR
#define RTC_DRIVER ds3231_driver
.drv = &RTC_DRIVER,
.inst = &(i2c_instance_t){
.hwreg = I2C_CTRL,
.slaveAddress = RTC_CTRL,
.samplingClockDivider = 3,
.timeout = I2C_CTRL_HZ/1000,
.tsuDat = I2C_CTRL_HZ/(I2C_FREQ*5),
.tLow = I2C_CTRL_HZ/(I2C_FREQ*2),
.tHigh = I2C_CTRL_HZ/(I2C_FREQ*2),
.tBuf = I2C_CTRL_HZ/(I2C_FREQ),
},
};
RTC.drv->applyConfig(&RTC);
RTC.drv->getTime(&RTC);
printf("Current Time: %02d:%02d:%02d\n", RTC.current_time.hours, RTC.current_time.minutes, RTC.current_time.seconds);
#define RTC_CTRL
I2C Address for the currently selected RTC (PCF8523).
Definition rtc_config.h:57
#define RTC_DRIVER
Driver Interface Table for the currently selected RTC (PCF8523).
Definition rtc_config.h:62
struct rtc_instance rtc_instance_t
Forward declaration of RTC instance.
Definition rtc.h:115
RTC driver API definitions.
I2C instance. Holds the software registers and hardware pointer.
Definition i2c.h:290
rtc_status_t(* getTime)(rtc_instance_t *rtc)
Get time function pointer.
Definition rtc.h:140
rtc_status_t(* applyConfig)(rtc_instance_t *rtc)
Apply i2c config , user can call via rtc_applyConfig as well.
Definition rtc.h:138
rtc_status_t(* enableErrorInterrupt)(rtc_instance_t *rtc)
Enable error interrupt function pointer, user can call via rtc_enableErrorInterrupt as well.
Definition rtc.h:139
u8 hours
Hours (0-23 or 1-12).
Definition rtc.h:124
u8 minutes
Minutes (0-59).
Definition rtc.h:123
u8 seconds
Seconds (0-59).
Definition rtc.h:122
rtc_data_t current_time
Current time data.
Definition rtc.h:156
const rtc_api_t * drv
Pointer to RTC API structure.
Definition rtc.h:155
See also
Supported Devices - Learn about the supported Real Time Clock device list.
Example RTC Demo - Learn how to use the driver for Real-Time Clock operations.

Topics

 API Functions
 Function definitions for RTC driver.
 Data Structures
 Structs used by the driver.
 Data Types
 Enums used by the driver.
 Driver Configuration
 Automatic hardware selection logic.
 Supported Devices
 Supported Real Time Clock (RTC) devices.