?? hw_rockrtc.c
字號:
/******************************************************************/
/* Copyright (C) 2007 ROCK-CHIPS FUZHOU . All Rights Reserved. */
/*******************************************************************
File : rtc.c
Desc : rtc接口函數的實現
Author : huangxinyu
Date : 2007-05-31
Notes :
$Log: hw_rockrtc.c,v $
Revision 1.1.1.1 2008/03/06 13:29:07 Lingzhaojun
no message
Revision 1.1 2007/12/13 07:28:18 Liaochaoyang
no message
Revision 1.1.1.1 2007/12/07 03:23:30 Lingzhaojun
導入紐漫260
Revision 1.3 2007/11/02 03:11:16 Huangzufang
增加RTC
Revision 1.2 2007/10/08 02:38:46 Lingzhaojun
添加版本自動注釋腳本
* huangxinyu 2007-06-01 修改RTC接口名稱
*********************************************************************/
#include "hw_include.h"
#if (RTC_TYPE == INTERNAL_RTC)
#include "hw_rockrtc.h"
#include "hwapi_interrupt.h"
#include "hw_serial.h"
#define pRTCReg ((pRTCReg_t)RTC_REG_BASE)
//static pRTCReg_t pRTCReg = (pRTCReg_t)RTC_REG_BASE;
#define RTC_CTRL_SET_FLAG(x) SetRegBits32(&(pRTCReg->RTC_CTRL),(x));
#define RTC_CTRL_CLR_FLAG(x) ClrRegBits32(&(pRTCReg->RTC_CTRL),(x));
#define RTC_SET_DIVIDER(x) MaskRegBits32(&(pRTCReg->RTC_CTRL), ~0xf8000000, (x));
#define RTC_GET_DIVIDER() ClrRegBits32(&(pRTCReg->RTC_CTRL), ~ BITMASK(27));
#define RTC_BSOS_EN() RTC_CTRL_SET_FLAG( RTC_CTRL_BSOS )
#define RTC_BSOS_DIS() RTC_CTRL_CLR_FLAG( RTC_CTRL_BSOS )
#define RTC_INTR_LEVEL() RTC_CTRL_SET_FLAG( RTC_CTRL_IT )
#define RTC_INTR_EDGE() RTC_CTRL_CLR_FLAG( RTC_CTRL_IT )
#define RTC_INTR_EN() RTC_CTRL_SET_FLAG( RTC_CTRL_INTE )
#define RTC_INTR_DIS() RTC_CTRL_CLR_FLAG( RTC_CTRL_INTE )
#define RTC_ALRM_EN() RTC_CTRL_SET_FLAG( RTC_CTRL_ALRM )
#define RTC_ALRM_DIS() RTC_CTRL_CLR_FLAG( RTC_CTRL_ALRM )
#define RTC_EN() RTC_CTRL_SET_FLAG( RTC_CTRL_EN )
#define RTC_DIS() RTC_CTRL_CLR_FLAG( RTC_CTRL_EN )
#define RTC_RESET() SetRegBits32(&(pRTCReg->RTC_CTRL),0x10000000);
/**************************************************************************
* 函數描述: 將time結構數據轉化為time寄存器中32位數
* 入口參數: *tm -- time結構數據
* 出口參數: temp -- time寄存器中32位數
* 返回值: 無
***************************************************************************/
static UINT32 rtc_time_to_u32(const rtc_time_t *tm)
{
UINT32 temp = 0;
temp |= (tm->dow << RTC_TIME_DOW);
temp |= (tm->ten_hr << RTC_TIME_TH );
temp |= (tm->hr << RTC_TIME_H );
temp |= (tm->ten_min << RTC_TIME_TM );
temp |= (tm->min << RTC_TIME_M );
temp |= (tm->ten_sec << RTC_TIME_TS );
temp |= (tm->sec << RTC_TIME_S );
temp |= (tm->sos << RTC_TIME_SOS);
return temp;
}
/**************************************************************************
* 函數描述: 將date結構數據轉化為date寄存器中32位數
* 入口參數: *dt -- date結構數據
* 出口參數: temp -- date寄存器中32位數
* 返回值: 無
***************************************************************************/
static UINT32 rtc_date_to_u32(const rtc_date_t *dt)
{
UINT32 temp = 0;
temp |= (dt->day << RTC_DATE_D );
temp |= (dt->ten_day << RTC_DATE_TD);
temp |= (dt->mth << RTC_DATE_M );
temp |= (dt->ten_mth << RTC_DATE_TM);
temp |= (dt->yr << RTC_DATE_Y );
temp |= (dt->ten_yr << RTC_DATE_TY);
temp |= (dt->cent << RTC_DATE_C );
temp |= (dt->ten_cent << RTC_DATE_TC);
return temp;
}
/**************************************************************************
* 函數描述: 將time寄存器中32位數轉化為time結構數據
* 入口參數: temp -- time寄存器中32位數
* 出口參數: *tm -- time結構數據
* 返回值: 無
***************************************************************************/
static void rtc_u32_to_time(rtc_time_t *tm, const UINT32 temp)
{
tm->sos = (temp >> RTC_TIME_SOS) & BITMASK(4);
tm->sec = (temp >> RTC_TIME_S) & BITMASK(4);
tm->ten_sec = (temp >> RTC_TIME_TS) & BITMASK(3);
tm->min = (temp >> RTC_TIME_M) & BITMASK(4);
tm->ten_min = (temp >> RTC_TIME_TM) & BITMASK(3);
tm->hr = (temp >> RTC_TIME_H) & BITMASK(4);
tm->ten_hr = (temp >> RTC_TIME_TH) & BITMASK(2);
tm->dow = (temp >> RTC_TIME_DOW) & BITMASK(3);
}
/**************************************************************************
* 函數描述: 將date寄存器中32位數轉化為date結構數據
* 入口參數: temp -- date寄存器中32位數
* 出口參數: *dt -- date結構數據
* 返回值: 無
***************************************************************************/
static void rtc_u32_to_date(rtc_date_t *dt, const data_t temp)
{
dt->day = (temp >> RTC_DATE_D) & BITMASK(4);
dt->ten_day = (temp >> RTC_DATE_TD) & BITMASK(2);
dt->mth = (temp >> RTC_DATE_M) & BITMASK(4);
dt->ten_mth = (temp >> RTC_DATE_TM) & BITMASK(1);
dt->yr = (temp >> RTC_DATE_Y) & BITMASK(4);
dt->ten_yr = (temp >> RTC_DATE_TY) & BITMASK(4);
dt->cent = (temp >> RTC_DATE_C) & BITMASK(4);
dt->ten_cent = (temp >> RTC_DATE_TC) & BITMASK(4);
}
/**************************************************************************
* 函數描述: 初始化RTC
* 入口參數: 無
* 出口參數: 無
* 返回值: TRUE -- 初始化成功
* FALSE -- 初始化失敗
***************************************************************************/
BOOL RTC_PowerOnInit(void)
{
RTC_RESET();
RTC_SET_DIVIDER(RTC_DIVIDER);
RTC_EN(); /* add by huangzf */
return TRUE;
}
/**************************************************************************
* 函數描述: 設置RTC時間
* 入口參數: RTC的時間結構(/時/分/秒/星期)
* 出口參數: 無
* 返回值: 無
***************************************************************************/
void RTC_Set_Time(rtc_date_time_t *rtc)
{
UINT32 temp;
rtc_time_t tm;
tm.ten_hr = (rtc->hour)/10;
tm.hr = (rtc->hour) - (tm.ten_hr*10);
tm.ten_min = (rtc->minute)/10;
tm.min = (rtc->minute) - (tm.ten_min*10);
tm.ten_sec = (rtc->sec)/10;
tm.sec = (rtc->sec) - (tm.ten_sec*10);
tm.sos = 0 ;
tm.dow = rtc->week;
temp = rtc_time_to_u32(&tm);
WriteReg32(&(pRTCReg->RTC_TIME), temp);
}
/**************************************************************************
* 函數描述: 設置RTC日期
* 入口參數: RTC的日期結構(年/月/日)
* 出口參數: 無
* 返回值: 無
***************************************************************************/
void RTC_Set_Date(rtc_date_time_t *rtc)
{
UINT32 temp;
rtc_date_t dt;
dt.ten_cent = (rtc->year)/1000;
dt.cent = ((rtc->year)/100)-(dt.ten_cent*10) ;
dt.ten_yr = ((rtc->year)/10) - (dt.ten_cent*100) - (dt.cent*10);
dt.yr = (rtc->year) - (dt.ten_cent*1000) - (dt.cent*100) -(dt.ten_yr*10);
dt.ten_mth = (rtc->mon)/10 ;
dt.mth = (rtc->mon) - (dt.ten_mth*10);
dt.ten_day = (rtc->day)/10;
dt.day = (rtc->day) - (dt.ten_day*10) ;
temp = rtc_date_to_u32(&dt);
WriteReg32(&(pRTCReg->RTC_DATE),temp);
}
/**************************************************************************
* 函數描述: 得到RTC時間
* 入口參數: 無
* 出口參數: RTC的時間結構數據(/時/分/秒/星期)
* 返回值: 無
***************************************************************************/
void RTC_Get_Time(rtc_date_time_t *rtc)
{
rtc_time_t tm;
UINT32 temp = ReadReg32(&(pRTCReg->RTC_TIME));
rtc_u32_to_time(&tm, temp);
rtc->hour = tm.ten_hr*10 + tm.hr;
rtc->minute = tm.ten_min*10 + tm.min;
rtc->sec= tm.ten_sec*10 + tm.sec;
rtc->week = tm.dow;
}
/**************************************************************************
* 函數描述: 得到RTC日期
* 入口參數: 無
* 出口參數: RTC的日期結構數據(年/月/日)
* 返回值: 無
***************************************************************************/
void RTC_Get_Date(rtc_date_time_t *rtc)
{
rtc_date_t dt;
UINT32 temp = ReadReg32(&(pRTCReg->RTC_DATE));
rtc_u32_to_date(&dt, temp);
rtc->year = dt.ten_cent*1000 + dt.cent*100 + dt.ten_yr*10 + dt.yr;
rtc->mon = dt.ten_mth*10 + dt.mth;
rtc->day= dt.ten_day*10 + dt.day;
}
/**************************************************************************
* 函數描述: 設置RTC值
* 入口參數: RTC的年/月/日/時/分/秒/星期 結構數據
* 出口參數: 無
* 返回值: 0 -- 設置成功
* 非0 -- 設置失敗
***************************************************************************/
int RTC_Set(rtc_date_time_t *rtc)
{
RTC_Set_Time(rtc);
RTC_Set_Date(rtc);
RTC_EN();
return 0;
}
/**************************************************************************
* 函數描述: 讀取RTC值
* 入口參數: 無
* 出口參數: RTC的年/月/日/時/分/秒/星期 結構數據
* 返回值: 0 -- 讀取成功
* 非0 -- 讀取失敗
***************************************************************************/
int RTC_Read(rtc_date_time_t *rtc)
{
RTC_Get_Time(rtc);
RTC_Get_Date(rtc);
return 0;
}
/**************************************************************************
* 函數描述: 設置鬧鐘
* 入口參數: 無
* 出口參數: 鬧鐘的星期或日/時/分/星期或日選擇 結構數據,鬧鐘通道
* 返回值: 1 -- 成功
* 0 -- 失敗
***************************************************************************/
int ALARM_Set(alarm_time_t * tm,INT8U ch)
{
return 0;
}
/**************************************************************************
* 函數描述: 讀取鬧鐘
* 入口參數: 無
* 出口參數: 鬧鐘的星期或日/時/分/星期或日選擇 結構數據,鬧鐘通道
* 返回值: 1 -- 讀取成功
* 0 -- 讀取失敗
***************************************************************************/
int ALARM_Get(alarm_time_t * tm,INT8U ch)
{
return 0;
}
/**************************************************************************
* 函數描述: 打開鬧鐘
* 入口參數: 無
* 出口參數: 鬧鐘通道
* 返回值: 0 -- 讀取成功
* 非0 -- 讀取失敗
***************************************************************************/
int ALARM_Open(INT8U ch)
{
return 0;
}
/**************************************************************************
* 函數描述: 關閉鬧鐘
* 入口參數: 無
* 出口參數: 鬧鐘通道
* 返回值: 1 -- 讀取成功
* 0 -- 讀取失敗
***************************************************************************/
int ALARM_Close(INT8U ch)
{
return 0;
}
/**************************************************************************
* 函數描述: 清除鬧鐘中斷
* 入口參數: 無
* 出口參數: 鬧鐘通道
* 返回值: 0 -- 讀取成功
* 非0 -- 讀取失敗
***************************************************************************/
int ALARM_Clear(INT8U ch)
{
return 1;
}
/**************************************************************************
* 函數描述: 讀鬧鐘IE狀態
* 入口參數: 無
* 出口參數: 鬧鐘通道
* 返回值: 0 -- 關
* 1 -- 開
***************************************************************************/
int ALARM_GetIESta(INT8U ch)
{
return 0;
}
/**************************************************************************
* 函數描述: 讀鬧鐘IF狀態
* 入口參數: 無
* 出口參數: 鬧鐘通道
* 返回值: 0 -- 關
* 1 -- 開
***************************************************************************/
int ALARM_GetIFSta(INT8U ch)
{
return 0;
}
/**************************************************************************
* 函數描述: 方波輸出頻率設置
* 入口參數: 無
* 出口參數: 鬧鐘通道
* 返回值: 0 -- 讀取成功
* 非0 -- 讀取失敗
***************************************************************************/
void RTC_FQW_FreqSet(INT8U freq_mode)
{
}
/**************************************************************************
* 函數描述: 方波輸出頻率開
* 入口參數: 無
* 出口參數: 無
* 返回值:
***************************************************************************/
void RTC_FQW_Enable(void)
{
}
/**************************************************************************
* 函數描述: 方波輸出頻率關
* 入口參數: 無
* 出口參數: 無
* 返回值:
***************************************************************************/
void RTC_FQW_Disable(void)
{
}
/**************************************************************************
* 函數描述: 檢測掉點狀態
* 入口參數: 無
* 出口參數: 鬧鐘通道
* 返回值: 0 -- 正常
* 1 -- 掉點
***************************************************************************/
int RTC_GetVL(void)
{
return 0;
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -