📄 73x_rtc.c
字号:
/******************** (C) COPYRIGHT 2005 STMicroelectronics ********************
* File Name : 73x_rtc.c
* Author : MCD Application Team
* Date First Issued : 09/27/2005 : V1.0
* Description : This file provides all the RTC software functions.
**********************************************************************************
* History:
* 09/27/2005 : V1.0
**********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*********************************************************************************/
/* Standard includes -------------------------------------------------------- */
#include "73x_rtc.h"
#include "73x_cfg.h"
/* Include of other module interface headers ---------------------------------*/
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Interface functions -------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/******************************************************************************
* Function Name : RTC_DeInit
* Description : Deinitializes the RTC peripheral registers to their default
* reset values.
* Input : None
* Output : None
* Return : None
******************************************************************************/
void RTC_DeInit (void)
{
CFG_PeripheralClockConfig(CFG_CLK_RTC,DISABLE);
CFG_PeripheralClockConfig(CFG_CLK_RTC,ENABLE);
}
/******************************************************************************
* Function Name : RTC _Init
* Description : Initializes the RTC peripheral according to the specified
* parameters in the RTC_InitTypeDef structure.
* Input : RTC_InitStruct: pointer to an RTC_InitTypeDef structure that
contains the configuration information for the RTC peripheral.
* Output : None
* Return : None
******************************************************************************/
void RTC_Init (RTC_InitTypeDef* RTC_InitStruct)
{
/* Reset RTC Registers */
RTC->CRL = 0x20;
RTC->PRLH = 0x0;
RTC->PRLL = 0x8000;
RTC->DIVH = 0x0;
RTC->DIVL = 0x8000;
RTC->CNTH = 0x0;
RTC->CNTL = 0x0;
RTC->ALRH = 0xFFFF;
RTC->ALRL = 0xFFFF;
/* Alarm config */
/* Loop until the Last operation Completion */
while (!(RTC->CRL & RTC_RTOFF_Mask));
/* Set the CNF flag to enter in the Configuration Mode */
RTC->CRL |= RTC_CNF_Mask;
/* Set the ALARM MSB word */
RTC->ALRH = (RTC_InitStruct->RTC_Alarm & 0xFFFF0000) >> 16;
/* Set the ALARM LSB word */
RTC->ALRL = (RTC_InitStruct->RTC_Alarm & 0x0000FFFF);
/* Reset the CNF flag to exit from the Configuration Mode */
RTC->CRL &= ~RTC_CNF_Mask;
/* Loop until the Last operation Completion */
while (!(RTC->CRL & RTC_RTOFF_Mask));
/* Prescaler config */
if ( RTC_GetPrescalerValue() != RTC_InitStruct->RTC_Prescaler )
{
/* Loop until the Last operation Completion */
while (!(RTC->CRL & RTC_RTOFF_Mask));
/* Set the CNF flag to enter in the Configuration Mode */
RTC->CRL |= RTC_CNF_Mask;
/* Set RTC PRESCALER MSB word */
RTC->PRLH = (RTC_InitStruct->RTC_Prescaler & 0xFFFF0000) >> 16;
/* Set RTC PRESCALER LSB word */
RTC->PRLL = (RTC_InitStruct->RTC_Prescaler & 0x0000FFFF);
/* Reset the CNF flag to exit from the Configuration Mode */
RTC->CRL &= ~RTC_CNF_Mask;
}
/* Counter Config */
/* Loop until the Last operation Completion */
while (!(RTC->CRL & RTC_RTOFF_Mask));
/* Set the CNF flag to enter in the Configuration Mode */
RTC->CRL |= RTC_CNF_Mask;
/* SET RTC COUNTER MSB word */
RTC->CNTH =(RTC_InitStruct->RTC_Counter & 0xFFFF0000) >> 16;
/* SET RTC COUNTER LSB word */
RTC->CNTL =(RTC_InitStruct->RTC_Counter & 0x0000FFFF);
/* Reset the CNF flag to exit from the Configuration Mode */
RTC->CRL &= ~RTC_CNF_Mask;
/* Loop until the Last operation Completion */
while (!(RTC->CRL & RTC_RTOFF_Mask));
}
/******************************************************************************
* Function Name : RTC_StructInit
* Description : Fills in a RTC_InitTypeDef structure with the reset value of
* each parameter.
* Input : RTC_InitStruct: pointer to an RTC_InitTypeDef structure
which will be initialized.
* Output : None
* Return : None.
******************************************************************************/
void RTC_StructInit(RTC_InitTypeDef* RTC_InitStruct)
{
/* Reset RTC init structure parameters values */
RTC_InitStruct->RTC_Prescaler = 0x8000 ;
RTC_InitStruct->RTC_Counter = 0x0;
RTC_InitStruct->RTC_Alarm = 0xFFFFFFFF;
}
/******************************************************************************
* Function Name : RTC_SetCounter
* Description : Sets the new RTC counter value.
* Input : RTC_Counter: new Counter Value
* Output : None
* Return : None
*******************************************************************************/
void RTC_SetCounter(u32 RTC_Counter)
{
/* Wait For Last Task Completion */
RTC_WaitForLastTask();
/* Enter In Configuration Mode */
RTC_EnterCfgMode();
/* SET RTC COUNTER MSB word */
RTC->CNTH =(RTC_Counter & 0xFFFF0000) >> 16;
/* SET RTC COUNTER LSB word */
RTC->CNTL =(RTC_Counter & 0x0000FFFF);
/* Exit From Configuration Mode */
RTC_ExitCfgMode ();
/* Wait For Last Task Completion */
RTC_WaitForLastTask();
}
/*******************************************************************************
* Function Name : RTC_GetCounterValue
* Description : Gets the RTC Counter value.
* Input : None
* Output : None
* Return : The Counter value
*******************************************************************************/
u32 RTC_GetCounterValue(void)
{
u16 tmp = RTC->CNTL;
return ( (u32)RTC->CNTH << 16 ) |tmp ;
}
/******************************************************************************
* Function Name : RTC_SetPrescaler
* Description : Set the new Prescaler Value
* Input : RTC_prescaler: new Prescaler Value
* Output : None
* Return : None
*******************************************************************************/
void RTC_SetPrescaler(u32 RTC_prescaler)
{
if(RTC_GetPrescalerValue () != RTC_prescaler)
{
/* Wait For Last Task Completion */
RTC_WaitForLastTask ();
/* Enter In Configuration Mode */
RTC_EnterCfgMode ();
/* Set RTC PRESCALER MSB word */
RTC->PRLH = (RTC_prescaler & 0x000F0000) >> 16;
/* Set RTC PRESCALER LSB word */
RTC->PRLL = (RTC_prescaler & 0x0000FFFF);
/* Exit From Configuration Mode*/
RTC_ExitCfgMode ();
/* Wait For Last Task Completion */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -