/** ****************************************************************************** * @file xl_rtc.c * @author Kirk ,xu.wang * @version 4.5.2 * @date Fri Mar 26 17:29:12 2021 * @brief This file provide function about RTC firmware program ****************************************************************************** * @attention * * 2019 by Chipways Communications,Inc. All Rights Reserved. * This software is supplied under the terms of a license * agreement or non-disclosure agreement with Chipways. * Passing on and copying of this document,and communication * of its contents is not permitted without prior written * authorization. * *

© COPYRIGHT 2019 Chipways

****************************************************************************** */ #if defined(__cplusplus) extern "C" { #endif /* __cplusplus */ /* Includes ---------------------------------------------------------------*/ #include "xl_rtc.h" /** @addtogroup XL6600_StdPeriph_Driver * @{ */ /** @defgroup RTC RTC Module * @brief RTC Driver Modules Library * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** @defgroup RTC_Private_Functions * @{ */ /** * @brief RTCĬÈϳõʼ»¯ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè * @retval None */ void RTC_DeInit(RTC_Type *RTCx) { /* Deinitializes to default reset values */ RTCx->SC = 0x0000; } /** * @brief ³õʼ»¯RTC * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£ * @param RTC_InitStruct:RTC_InitTypeDefÀàÐ͵ÄÖ¸Õ룬°üº¬ÁËRTCÍâÉèµÄÉèÖÃÐÅÏ¢ * @retval None */ void RTC_Init(RTC_Type *RTCx, const RTC_InitTypeDef *RTC_InitStruct) { uint32_t tmpreg; /*---------------------------- RTC SC Configuration ------------------------*/ /* Get the RTC SC value. */ tmpreg = RTCx->SC ; /* Clear bits Value in SC register.*/ tmpreg &= ~(RTC_SC_RTCLKS_MASK | RTC_SC_RTCPS_MASK); /* Set the bit RTCLKS,RTCPS in CR Register. */ tmpreg |= (uint32_t)((((uint32_t)(((uint32_t)(RTC_InitStruct->RTC_ClkSrc))<RTC_ClkPres))<SC = tmpreg ; } /** * @brief RTCʹÄÜ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£ * @param NewState: RTCʹÄÜ״̬ * Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ: * @arg ENABLE: RTCʹÄÜ * @arg DISABLE: RTCʧÄÜ * @retval None */ void RTC_EnableCmd(RTC_Type *RTCx, FunctionalState NewState) { if(NewState == ENABLE) { RTCx->SC |= RTC_SC_RTCEN_MASK; } else { RTCx->SC &= (~RTC_SC_RTCEN_MASK); } } /** * @brief RTCÖжÏʹÄÜ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£ * @param NewState: RTCÖжÏʹÄÜ״̬ * Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ: * @arg ENABLE: RTCÖжÏʹÄÜ * @arg DISABLE: RTCÖжÏʧÄÜ * @retval None */ void RTC_InterruptEn(RTC_Type *RTCx,FunctionalState NewState) { if(NewState != DISABLE ) { /* Real-time interrupt requests are enabled. */ RTCx->SC |= RTC_SC_RTIE_MASK; } else { /* Real-time interrupt requests are disabled. */ RTCx->SC &= ~RTC_SC_RTIE_MASK; } } /** * @brief RTCʵʱÊä³öʹÄÜ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè * @param NewState: RTCʵʱÊä³öʹÄÜ״̬ * Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ: * @arg ENABLE: ʹÄÜRTCʵʱÊä³ö * @arg DISABLE: ʧÄÜRTCʵʱÊä³ö * @retval None */ void RTC_CountOutputEn(RTC_Type *RTCx,FunctionalState NewState) { if(NewState != DISABLE ) { /* Real-time counter output enabled. */ RTCx->SC |= RTC_SC_RTCO_MASK; } else { /* Real-time counter output disabled. */ RTCx->SC &= ~RTC_SC_RTCO_MASK; } } /** * @brief »ñÈ¡RTCʵʱÖжϱê־λ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£ * @retval ʵʱÖжϱê־λ */ ITStatus RTC_GetInterruptFlag(const RTC_Type *RTCx) { return ((RTCx->SC & RTC_SC_RTIF_MASK) == RTC_SC_RTIF_MASK); } /** * @brief Çå¿ÕRTCʵʱÖжϱê־λ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£ * @retval None */ void RTC_ClrInterruptFlag(RTC_Type *RTCx) { /* Writing a logic 1 clears the bit and the real-time interrupt request */ RTCx->SC |= RTC_SC_RTIF_MASK; } /** * @brief ÉèÖÃRTCÄ£Êý¼Ä´æÆ÷ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè * @param RTC_ModValue: RTCµÄÄ£ÊýÖµ * @retval None */ void RTC_SetModValue(RTC_Type *RTCx,uint16_t RTC_ModValue) { /* modulo Value of RTC. */ RTCx->MOD = RTC_ModValue; } /** * @brief »ñµÃRTC¼ÆÊýÆ÷µÄµ±Ç°Öµ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£ * @retval None */ uint16_t RTC_GetCountValue(const RTC_Type *RTCx) { uint16_t countvalue; /* the value of the current RTC count. */ countvalue= (uint16_t)RTCx->CNT ; return countvalue; } /** * @brief RTCʱ¼ä´Á¼ÆÊýÆ÷ʹÄÜ * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè * @param NewState: RTCʱ¼ä´ÁʹÄÜ״̬ * Õâ¸ö²ÎÊý¿ÉÒÔÈ¡ÏÂÃæµÄÖµ: * @arg ENABLE: ʹÄÜRTCʱ¼ä´Á¼ÆÊý * @arg DISABLE: ʧÄÜRTCʱ¼ä´Á¼ÆÊý * @retval None */ void RTC_TimeStampEnableCmd(RTC_Type *RTCx, FunctionalState NewState) { if(NewState == ENABLE) { RTCx->STAMP_CFG |= RTC_STAMP_CFG_CNTEN_MASK; } else { RTCx->STAMP_CFG &= ~RTC_STAMP_CFG_CNTEN_MASK; } } /** * @brief »ñÈ¡RTCʱ¼ä´Á¼ÆÊý * @param RTCx: ÊäÈë¿ÉÓõÄRTCÍâÉè¡£ * @retval None */ uint64_t RTC_GetStampCountValue(const RTC_Type *RTCx) { uint64_t countvalue; /* the value of the current RTC count. */ countvalue= (uint64_t)RTCx->STAMP_CNT ; return countvalue; } /** * @} */ /** * @} */ /** * @} */ #ifdef __cplusplus } #endif /* __cplusplus */