/*! * \file rtc.c * * \brief Target rtc implementation * * \copyright Revised BSD License, see section \ref LICENSE. * * \code * * _ __ _ ________ _ * | |/ /(_)___ / ____/ /_ (_)___ * | // / __ \/ / / __ \/ / __ \ * / |/ / / / / /___/ / / / / /_/ / * /_/|_/_/_/ /_/\____/_/ /_/_/ .___/ * /_/ * (C) 2022-2025 XinChip * * \endcode * * \author ( XinChip ) Alex-J * * \author ( XinChip ) */ /*----------------------------------------------------------------------------------- INCLUDE HEADE FILES ------------------------------------------------------------------------------------*/ #include "rtc.h" #include "xc6xxx_hal_rtc.h" /*------------------------------------------------------------------------------------ Macros -------------------------------------------------------------------------------------*/ //#define LED1_PIN GPIO_26 //#define LED2_PIN GPIO_27 //#define KEY1_PIN GPIO_1 //#define KEY2_PIN GPIO_5 /*------------------------------------------------------------------------------------ Global Variables -------------------------------------------------------------------------------------*/ Rtc_Intr_Sta_t RTC_Intr_Sta = {.T1_CMR = false, .T2_CMR = false, .T3_CMR = false, .Day = false, .Hour = false, .Min = false, .Sec = false}; /*------------------------------------------------------------------------------------ Func Prototype -------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------ Functions -------------------------------------------------------------------------------------*/ /** * @brief rtc_demo * @details * @param void * @retval void */ void rtc_demo(void) { DEBUG("__RTC_DEMO__\r"); RTC_InitTypeDef rtc_cfg = {0}; Rtc_DateTypeDef Date = {0}; rtc_cfg.Date.Sec = 0; rtc_cfg.Date.Min = 0; rtc_cfg.Date.Hour = 18; rtc_cfg.Date.Day = 154; rtc_cfg.Date.Week = 6; rtc_cfg.DateLimit.SecLimit = 60; rtc_cfg.DateLimit.MinLimit = 60; rtc_cfg.DateLimit.HourLimit = 24; rtc_cfg.MatchTime.ch = RTC_MATCH_TIME_1; rtc_cfg.MatchTime.Sec = 5; rtc_cfg.MatchTime.Min = 02; rtc_cfg.MatchTime.Hour = 18; rtc_cfg.MatchTime.Week = RTC_WEEK_MATCH_SATURDAY; rtc_cfg.MatchTimeEnable = true; rtc_cfg.SecIT_Enable = true; rtc_cfg.MinIT_Enable = true; rtc_cfg.HourIT_Enable = true; rtc_cfg.DayIT_Enable = false; RTC_Init(XC_RTC, &rtc_cfg); RTC_Start(XC_RTC); NVIC_EnableIRQ(RTC_IRQn); while (1) { if (RTC_Intr_Sta.T1_CMR == true) { DEBUG("RTC T1 CMR Irq\n"); RTC_Intr_Sta.T1_CMR = false; } if (RTC_Intr_Sta.T2_CMR == true) { DEBUG("RTC T2 CMR Irq\n"); RTC_Intr_Sta.T2_CMR = false; } if (RTC_Intr_Sta.T3_CMR == true) { DEBUG("RTC T3 CMR Irq\n"); RTC_Intr_Sta.T3_CMR = false; } if (RTC_Intr_Sta.Sec == true) { RTC_DateGet(XC_RTC, &Date); DEBUG("%02d:%02d:%02d\n", Date.Hour, Date.Min, Date.Sec); RTC_Intr_Sta.Sec = false; } if (RTC_Intr_Sta.Min == true) { RTC_Intr_Sta.Min = false; } if (RTC_Intr_Sta.Hour == true) { RTC_Intr_Sta.Hour = false; } if (RTC_Intr_Sta.Day == true) { RTC_Intr_Sta.Day = false; } } } /** * @brief T1_CMR_Callback * @details RTC compare timer1 callback function * @param void * @retval uint8_t */ __RAM_CODE uint8_t T1_CMR_Callback(void) { RTC_Intr_Sta.T1_CMR = true; return 0; } /** * @brief T2_CMR_Callback * @details RTC compare timer2 callback function * @param void * @retval uint8_t */ __RAM_CODE uint8_t T2_CMR_Callback(void) { RTC_Intr_Sta.T2_CMR = true; return 0; } /** * @brief T3_CMR_Callback * @details RTC compare timer3 callback function * @param void * @retval uint8_t */ __RAM_CODE uint8_t T3_CMR_Callback(void) { RTC_Intr_Sta.T3_CMR = true; return 0; } /** * @brief Sec_Callback * @details RTC second callback function * @param void * @retval uint8_t */ __RAM_CODE uint8_t Sec_Callback(void) { RTC_Intr_Sta.Sec = true; return 0; } /** * @brief Min_Callback * @details RTC minute callback function * @param void * @retval uint8_t */ __RAM_CODE uint8_t Min_Callback(void) { RTC_Intr_Sta.Min = true; return 0; } /** * @brief Hour_Callback * @details RTC hour callback function * @param void * @retval uint8_t */ __RAM_CODE uint8_t Hour_Callback(void) { RTC_Intr_Sta.Hour = true; return 0; } /** * @brief Day_Callback * @details RTC Day callback function * @param void * @retval uint8_t */ __RAM_CODE uint8_t Day_Callback(void) { RTC_Intr_Sta.Day = true; return 0; }