📄 triton_rtc.c
字号:
/*
* ============================================================================
*
* TEXAS INSTRUMENTS INCORPORATED PROPRIETARY INFORMATION
*
* Property of Texas Instruments
* For Unrestricted Internal Use Only
* Unauthorized reproduction and/or distribution is strictly prohibited.
* This product is protected under copyright law and trade secret law as an
* unpublished work.
* Created 2003, (C) Copyright 2003 Texas Instruments. All rights reserved.
*
* Filename : triton_rtc.c
* Description : Set of function to test RTC module for Triton
* Project : Triton
* Author : Bruno Decroos
*
* =============================================================================
*/
/* ============================================================================
* STANDARD INCLUDE FILE
* =============================================================================
*/
#include "triton_mapping.h"
#include "triton_rtc.h"
#include "triton_test_rtc.h"
#include "result.h"
#include "testaccess.h"
/* ============================================================================
* GLOBAL VARIABLES DECLARATIONS
* =============================================================================
*/
/* ============================================================================
* LOCAL VARIABLES DECLARATIONS
* =============================================================================
*/
/* ============================================================================
* FUNCTIONS
* =============================================================================
*/
//---------------------------------------------------------------------------
// NAME : RTC_num_days
// DESCRIPTION : Numbers of days since year 00, Year 00 is a leap year
// RETURN VALUE:
// PARAMETERS :
// LIMITATIONS :
//--------------------------------------------------------------------------
int RTC_num_days(struct rtc_tm *time)
{
int cpt=0;
int cpt_feb;
int nbj = time->rtc_day - 1;
if ( !(time->rtc_year%4))
{
cpt_feb = 29;
}
else {
cpt_feb = 28;
}
switch(time->rtc_mon) {
case 1 : cpt = nbj;
break;
case 2 : cpt = 31 + nbj ;
break;
case 3 : cpt = 31 + cpt_feb + nbj;
break;
case 4 : cpt = 31 + cpt_feb + 31 + nbj;
break;
case 5 : cpt = 31 + cpt_feb + 31 + 30 + nbj;
break;
case 6 : cpt = 31 + cpt_feb + 31 + 30 + 31 + nbj;
break;
case 7 : cpt = 31 + cpt_feb + 31 + 30 + 31 + 30 + nbj;
break;
case 8 : cpt = 31 + cpt_feb + 31 + 30 + 31 + 30 + 31 + nbj;
break;
case 9 : cpt = 31 + cpt_feb + 31 + 30 + 31 + 30 + 31 + 31 + nbj;
break;
case 10: cpt = 31 + cpt_feb + 31 + 30 + 31 + 30 + 31 + 31 + 30 + nbj;
break;
case 11: cpt = 31 + cpt_feb + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + nbj;
break;
case 12: cpt = 31 + cpt_feb + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 +
nbj;
break;
}
return ( cpt + time->rtc_year * 365 + ((time->rtc_year - 1)/4) );
}
//-------------------------------------------------------------------------
// NAME : RTC_int num_sec
// DESCRIPTION : Numbers of seconds since year 00,Year 00 is a leap year
// RETURN VALUE :
// PARAMETERS : structure on the RTC register.
// LIMITATIONS :
//------------------------------------------------------------------
unsigned int RTC_num_sec(struct rtc_tm *time)
{
unsigned int nb_sec=0;
int nb_day=0;
int nb_hrs=0;
nb_day = RTC_num_days(time);
if (time->rtc_1224md == 0)
{
nb_hrs=time->rtc_hour;
}
else if (time->rtc_PM == 0)
{ /* AM */
if (time->rtc_hour == 12)
{
nb_hrs=0;
}
else
{
nb_hrs=time->rtc_hour;
}
}
else if (time->rtc_hour == 12)
{
nb_hrs=12;
}
else
{
nb_hrs=time->rtc_hour + 12;
}
nb_sec = time->rtc_sec + 60*(time->rtc_min) + 3600*nb_hrs + 24*3600*nb_day ;
return nb_sec;
}
//------------------------------------------------------------
// NAME : RTC_conv_bin
// DESCRIPTION : BCD to binary conversion function
// PARAMETERS : value in BCD
// RETURN VALUE : value in in binary
//-----------------------------------------------------------
UWORD8 RTC_conv_bin(const UWORD8 value)
{
return ( 10 * (value>>4) + (value & 0x0f) );
}
//----------------------------------------------------------------
// NAME : RTC_conv_bcd
// DESCRIPTION : Binary to BCD conversion function
// RETURN VALUE : value in BCD
// PARAMETERS : value in binary
//----------------------------------------------------------------
UWORD8 RTC_conv_bcd(const UWORD8 value)
{
return ( (value%10) | ((value/10)<<4) );
}
//----------------------------------------------------
// NAME : RTC_Busy_Falling_Edge
// DESCRIPTION: Detect a busy falling edge
// RETURN VALUE : none
// PARAMETERS : none
// LIMITATIONS :
//----------------------------------------------------
void RTC_Busy_Falling_Edge(void)
{
while (RTC_TEST_BUSY != 1) {};
while (RTC_TEST_BUSY == 1) {};
}
//-----------------------------------------------------------------------
// NAME : RTC_Init_Sec
// DESCRIPTION : Initialize the RTC seconds register
// RETURN VALUE: none
// PARAMETERS : value to store in the RTC SECOND register
// LIMITATIONS :
//-----------------------------------------------------------------------
void RTC_Init_Sec(const UWORD8 value)
{
UWORD8 second;
second = RTC_conv_bcd(value);
RTC_SECONDS_REG_WR(second);
}
//---------------------------------------------------------------------------
// NAME : RTC_Init_Min
// DESCRIPTION : Initialize the RTC minutes register
// RETURN VALUE : none
// PARAMETERS : value to store in the RTC MINUTE register
// LIMITATIONS : none
//--------------------------------------------------------------------------
void RTC_Init_Min(const UWORD8 value)
{
UWORD8 minute;
minute = RTC_conv_bcd(value);
RTC_MINUTES_REG_WR(minute);
}
//-------------------------------------------------------------------------
// NAME : RTC_Init_Hrs
// DESCRIPTION : Initialize the RTC hours register
// RETURN VALUE : none
// PARAMETERS :
// mode12 = 1 => PM-AM mode
// pm = 1 => PM (Only usued in PM_AM mode)
// LIMITATIONS :
//-----------------------------------------------------------------------
void RTC_Init_Hrs(const UWORD8 value, const char mode12, const char pm)
{
UWORD8 hour;
if (value > 12 || mode12 == 0)
{
RTC_CTRL_REG_WR(RTC_CTRL_REG_RD & ~RTC_MODE_12_24);
hour = RTC_conv_bcd(value);
}
else
{
RTC_CTRL_REG_WR( RTC_CTRL_REG_RD | RTC_MODE_12_24);
hour = RTC_conv_bcd(value) | (pm << 7);
}
RTC_HOURS_REG_WR(hour);
}
//---------------------------------------------------------------
// NAME : RTC_Init_Day
// DESCRIPTION : Initialize the RTC days register
// PARAMETERS : value is used to initialize RTC DAY register
// RETURN VALUE: none
//--------------------------------------------------------------
void RTC_Init_Day(const UWORD8 value)
{
UWORD8 day;
day = RTC_conv_bcd(value);
RTC_DAYS_REG_WR(day);
}
//------------------------------------------------------------------
// NAME : RTC_Init_Mon
// DESCRIPTION : Initialize the RTC months register
// RETURN VALUE: none
// PARAMETERS : value is used to initialize RTC MONTH register
// LIMITATIONS :
//------------------------------------------------------------------
void RTC_Init_Mon(const UWORD8 value)
{
UWORD8 month;
month = RTC_conv_bcd(value);
RTC_MONTHS_REG_WR(month);
}
//------------------------------------------------------------------
// NAME : RTC_Init_Year
// DESCRIPTION : Initialize the RTC years register
// PARAMETERS : value is used to initialize RTC YEAR register
// RETURN VALUE: none
// LIMITATIONS : none
//------------------------------------------------------------------
void RTC_Init_Year(const UWORD8 value)
{
UWORD8 year;
year = RTC_conv_bcd(value);
RTC_YEARS_REG_WR(year);
}
//---------------------------------------------------------------
// NAME : RTC_Init_Week
// DESCRIPTION : Initialize the RTC week register
// RETURN VALUE: none
// PARAMETERS : value is used to initialize RTC Week register
// LIMITATIONS :
//---------------------------------------------------------------------
void RTC_Init_Week(const UWORD8 value)
{
UWORD8 week;
week = RTC_conv_bcd(value);
RTC_WEEK_REG_WR(week);
}
//----------------------------------------------------------------------------
// NAME : RTC_Init_Time
// DESCRIPTION : Initialize the time (seconds, minutes and hours register)
// RETURN VALUE: none
// PARAMETERS : values used to store in the differents registers
//----------------------------------------------------------------------------
void RTC_Init_Time(const UWORD8 sec, const UWORD8 min, const UWORD8 hrs,
const char mode12, const char pm )
{
UWORD8 second;
UWORD8 minute;
UWORD8 hour;
second = RTC_conv_bcd(sec);
minute = RTC_conv_bcd(min);
if (hrs > 12 || mode12 == 0)
{
RTC_CTRL_REG_WR(RTC_CTRL_REG_RD & ~RTC_MODE_12_24);
hour = RTC_conv_bcd(hrs);
}
else
{
RTC_CTRL_REG_WR(RTC_CTRL_REG_RD | RTC_MODE_12_24);
hour = RTC_conv_bcd(hrs) | (pm << 7);
}
RTC_SECONDS_REG_WR(second);
RTC_MINUTES_REG_WR(minute);
RTC_HOURS_REG_WR(hour);
}
//-----------------------------------------------------------------------------
// NAME : RTC_Init_Ddate
// DESCRIPTION : Initialize the days date (days, months, years & week register)
// RETURN VALUE: none
// PARAMETERS : values used to store in the differents registers
// LIMITATIONS :
//----------------------------------------------------------------------------
void RTC_Init_Ddate(UWORD8 day, UWORD8 month,
UWORD8 year, UWORD8 week )
{
day = RTC_conv_bcd(day);
month = RTC_conv_bcd(month);
year = RTC_conv_bcd(year);
week = RTC_conv_bcd(week);
RTC_DAYS_REG_WR(day);
RTC_MONTHS_REG_WR(month);
RTC_YEARS_REG_WR(year);
RTC_WEEK_REG_WR(week);
}
//-------------------------------------------------------
// NAME : RTC_Init_Date
// DESCRIPTION : Initialize the date
// RETURN VALUE: none
// PARAMETERS : values used to store in the differents registers
// LIMITATIONS :
//------------------------------------------------------
void RTC_Init_Date(struct rtc_tm *const rtctime )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -