📄 rtc.c
字号:
/****************************************Copyright (c)**************************************************
**
** STR710 development team
**
**
**
**
**--------------文件信息--------------------------------------------------------------------------------
** 文 件 名: rtc.c
** 创 建 人: lhl
** 创建日期: 2006年5月10日
** 描 述: 该文件提供所有的RTC软件操作功能
**
**--------------历史版本--------------------------------------------------------------------------------
** 创 建 人: lhl
** 版 本: V1.0
** 日 期: 2006年5月10日
** 描 述: 原始版本
**
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#include "rtc.h"
#if EN_ARM_RTC > 0 //决定是否编译该文件
/******************************************* 全局变量定义 ***********************************************/
/** Formatting of a Unix 32-bit time value (seconds since 1/1 1970)
as a string in the format YYMMDDHHMMSS.**/
static const UINT8 m[12] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const UINT8 m4[12] = {
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/**store the callback and parameter**/
RTC_CB_Save_T rtc_CB_Save[4] = {
{NULL,NULL}, //seconds interrupt callback
{NULL,NULL}, //alarm
{NULL,NULL}, //overflow
{NULL,NULL} //global
};
/******************************************* 局部函数声明 ***********************************************/
void RTC_WaitForLastWrite(void);
/*********************************************************************************************************
;** 函数名称: RTC_Set_Time
;** 功能描述: 设置时钟的当前时间
;**
;** 参 数: 当前要设置的时间,为UNIX 32bit 格式
;**
;** 返 回 值: 无
;**
;** 作 者:lhl
;** 日 期: 2006年5月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
void RTC_SetTime(Time_T time)
{
UINT16 value;
RTC_WaitForLastWrite(); //wait the last write action complete
RTC_CRL |= 0x01<<4; //set RTC unit to config mode
RTC_WaitForLastWrite(); //wait the last write action complete
value = (UINT16)((time&0xffff0000)>>16);
RTC_CNTH = value; //set prescale register high bits
RTC_WaitForLastWrite(); //wait the last write action complete
value = (UINT16)(time&0x0000FFFF);
RTC_CNTL = value; //set prescale register low bits
RTC_WaitForLastWrite();
RTC_CRL &= ~(0x01<<4); //config is complete ,set RTC uint to free running mode
}
/*********************************************************************************************************
;** 函数名称: RTC_Get_Time
;** 功能描述: 获取时钟的当前时间
;**
;** 参 数:无
;**
;** 返 回 值: 当前时间值
;**
;** 作 者:lhl
;** 日 期: 2006年5月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
Time_T RTC_GetTime()
{
Time_T time;
UINT32 value;
RTC_WaitForLastWrite();
RTC_CRL |= 0x01<<4 ;
RTC_WaitForLastWrite();
value = RTC_CNTH ;
time =((UINT32)value)<<16;
RTC_WaitForLastWrite();
value = RTC_CNTL ;
RTC_WaitForLastWrite();
RTC_CRL &= ~(0x01<<4);
time = time + value;
return time;
}
/*********************************************************************************************************
;** 函数名称: RTC_Set_alarm
;** 功能描述:设置时钟定时
;**
;** 参 数:1、 定时闹钟的时间值,普通格式
;** 2、闹钟时间到后的回调函数
;**
;** 返 回 值:无
;**
;** 作 者:lhl
;** 日 期: 2006年5月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
void RTC_SetAlarm(RTC_Time_T *rtc_time,RTC_CALLBACK_T rtc_cb)
{
Time_T time;
UINT16 value;
time = RTC_String2Time(rtc_time);
rtc_CB_Save[RTC_ALM_INT].callback_para = NULL;
rtc_CB_Save[RTC_ALM_INT].rtc_callback = rtc_cb;
RTC_WaitForLastWrite(); //wait the last write action complete
RTC_CRL |= 0x01<<4 ; //set RTC unit to config mode
RTC_WaitForLastWrite(); //wait the last write action complete
value = (UINT16)(time&0xffff0000>>16);
RTC_ALRH = value; //set prescale register high bits
RTC_WaitForLastWrite(); //wait the last write action complete
value = (UINT16)(time&0x0000FFFF);
RTC_ALRL = value; //set prescale register low bits
RTC_WaitForLastWrite();
RTC_CRH |= RTC_RTAEN_Mask|RTC_RTGEN_Mask ; //
RTC_WaitForLastWrite();
RTC_CRL &= ~(0x01<<4); //config is complete ,set RTC uint to free running mode
}
/*********************************************************************************************************
;** 函数名称: RTC_Clr_alarm
;** 功能描述: 清除闹钟设置
;**
;** 参 数:无
;**
;** 返 回 值: 无
;**
;** 作 者:lhl
;** 日 期: 2006年5月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
void RTC_ClrAlarm()
{
//Time_T time;
//UINT16 value;
rtc_CB_Save[RTC_ALM_INT].callback_para = NULL;
rtc_CB_Save[RTC_ALM_INT].rtc_callback = NULL;
RTC_WaitForLastWrite(); //wait the last write action complete
RTC_CRL |= 0x01<<4; //set RTC unit to config mode
RTC_WaitForLastWrite(); //wait the last write action complete
RTC_ALRH = 0; //set prescale register high bits
RTC_WaitForLastWrite(); //wait the last write action complete
RTC_ALRL = 0; //set prescale register low bits
RTC_WaitForLastWrite();
RTC_CRH &= ~(RTC_RTAEN_Mask|RTC_RTGEN_Mask); //clr the static of int
RTC_WaitForLastWrite();
//RTC_CRL = ~(0x01<<4); //config is complete ,set RTC uint to free running mode
}
/*********************************************************************************************************
;** 函数名称: RTC_Set_Sec_Int
;** 功能描述:设置每秒时钟中断
;**
;** 参 数:1、 每秒闹钟时间到后的回调函数
;**
;** 返 回 值:无
;**
;** 作 者:lhl
;** 日 期: 2006年5月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
void RTC_SetSecInt(RTC_CALLBACK_T rtc_cb)
{
rtc_CB_Save[RTC_SEC_INT].callback_para = NULL;
rtc_CB_Save[RTC_SEC_INT].rtc_callback = rtc_cb;
RTC_WaitForLastWrite(); //wait the last write action complete
RTC_CRL |= 0x01<<4; //set RTC unit to config mode
RTC_WaitForLastWrite();
RTC_CRH |= RTC_RTSEN_Mask|RTC_RTGEN_Mask; //
RTC_WaitForLastWrite();
RTC_CRL &= ~(0x01<<4); //config is complete ,set RTC uint to free running mode
}
/*********************************************************************************************************
;** 函数名称: RTC_Clr_Sec_Int
;** 功能描述:清除每秒闹钟
;**
;** 参 数:无
;**
;** 返 回 值:无
;**
;** 作 者:lhl
;** 日 期: 2006年5月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
void RTC_ClrSecInt()
{
rtc_CB_Save[RTC_SEC_INT].callback_para = NULL;
rtc_CB_Save[RTC_SEC_INT].rtc_callback = NULL;
RTC_WaitForLastWrite(); //wait the last write action complete
RTC_CRL |= 0x01<<4; //set RTC unit to config mode
RTC_WaitForLastWrite();
RTC_CRH &= ~(RTC_RTSEN_Mask|RTC_RTGEN_Mask); //
RTC_WaitForLastWrite();
RTC_CRL &= ~(0x01<<4); //config is complete ,set RTC uint to free running mode
}
/*********************************************************************************************************
;** 函数名称: RTC_Set_Overflow_Int
;** 功能描述:设置时钟溢出(超出量程)后的处理函数
;**
;** 参 数:1、 时钟溢出后的回调函数
;**
;** 返 回 值:无
;**
;** 作 者:lhl
;** 日 期: 2006年5月10日
;**-------------------------------------------------------------------------------------------------------
;** 修 改 人:
;** 日 期:
;**------------------------------------------------------------------------------------------------------
;********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -