/* * File: rtc.c * Project: ad74413r_native_driver * Description: RTC drivers * Author: A. Clark Sann * Date: [2025-11-28] * * Copyright (c) [2025] A. Clark Sann * All rights reserved. * * This source code is confidential and proprietary. Unauthorized copying, * redistribution, or use of this code, in whole or in part, is strictly prohibited. */ #include "rtc.h" LOG_MODULE_REGISTER(rtc, LOG_LEVEL_DBG); /* Guard: alias only exists when &rtc node is status "okay" in overlay. * When RTC is disabled (AHBSC NS access not granted), rtc == NULL and * all callers must check device_is_ready(rtc) before use. */ #if DT_HAS_ALIAS(rtc) const struct device *const rtc = DEVICE_DT_GET(DT_ALIAS(rtc)); #else const struct device *const rtc = NULL; #endif int set_date_time(const struct device *rtc) { int ret = 0; struct rtc_time tm = { .tm_year = 2026 - 1900, .tm_mon = 1 - 1, .tm_mday = 1, .tm_hour = 0, .tm_min = 0, .tm_sec = 0, }; ret = rtc_set_time(rtc, &tm); if (ret < 0) { LOG_ERR("Cannot write date time: %d", ret); return ret; } return ret; } // static int get_date_time(const struct device *rtc) // { // int ret = 0; // struct rtc_time tm; // ret = rtc_get_time(rtc, &tm); // if (ret < 0) { // LOG_ERR("Cannot read date time: %d\n", ret); // return ret; // } // // printk("RTC date and time: %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, // // tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); // return ret; // }