⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triton_rtc.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
📖 第 1 页 / 共 3 页
字号:
{
  UWORD8 sec;
  UWORD8 min;
  UWORD8 hour;
  UWORD8 day;
  UWORD8 mon;
  UWORD8 year;
  UWORD8 wday;

  sec = RTC_conv_bcd(rtctime->rtc_sec);
  min = RTC_conv_bcd(rtctime->rtc_min);
  if ((rtctime->rtc_hour) > 12 || (rtctime->rtc_1224md) == 0)
    {
      RTC_CTRL_REG_WR(RTC_CTRL_REG_RD & ~RTC_MODE_12_24);
      hour = RTC_conv_bcd(rtctime->rtc_hour);
    } else
      {
	RTC_CTRL_REG_WR(RTC_CTRL_REG_RD | RTC_MODE_12_24);
	hour = RTC_conv_bcd(rtctime->rtc_hour) | (rtctime->rtc_PM << 7);
      }

  day  = RTC_conv_bcd(rtctime->rtc_day);
  mon  = RTC_conv_bcd(rtctime->rtc_mon);
  year = RTC_conv_bcd(rtctime->rtc_year);
  wday = RTC_conv_bcd(rtctime->rtc_wday);

  RTC_DAYS_REG_WR(day);
  RTC_MONTHS_REG_WR(mon);
  RTC_YEARS_REG_WR(year);
  RTC_WEEK_REG_WR(wday);	
  RTC_SECONDS_REG_WR(sec);
  RTC_MINUTES_REG_WR(min);
  RTC_HOURS_REG_WR(hour);

}


//------------------------------------------------------------------------
// NAME        : RTC_SetAlarm
// DESCRIPTION : Set the alarm registers 
// RETURN VALUE: none
// PARAMETERS  : values used to store in the differents registers
//----------------------------------------------------------------------
void RTC_SetAlarm(struct rtc_tm *rtctime )
{
  UWORD8 sec;
  UWORD8 min;
  UWORD8 hour;
  UWORD8 day;
  UWORD8 mon;
  UWORD8 year;

  sec = RTC_conv_bcd(rtctime->rtc_sec);
  min = RTC_conv_bcd(rtctime->rtc_min);

  if ( (rtctime->rtc_hour) > 12 || (rtctime->rtc_1224md) == 0 )
    {
      hour = RTC_conv_bcd(rtctime->rtc_hour);
    } 

  else
    {
      hour = RTC_conv_bcd(rtctime->rtc_hour) | (rtctime->rtc_PM << 7);
    }

  day  = RTC_conv_bcd(rtctime->rtc_day);
  mon  = RTC_conv_bcd(rtctime->rtc_mon);
  year = RTC_conv_bcd(rtctime->rtc_year);


  RTC_ALARM_DAYS_REG_WR(day);
  RTC_ALARM_MONTHS_REG_WR(mon);
  RTC_ALARM_YEARS_REG_WR(year);	
  RTC_ALARM_SECONDS_REG_WR(sec);
  RTC_ALARM_MINUTES_REG_WR(min);
  RTC_ALARM_HOURS_REG_WR(hour);
}


//--------------------------------------------------------------------
//  NAME        : RTC_SetMode12_24
//  DESCRIPTION : Set the mode 12_24 0=>24 hours mode	
//  RETURN VALUE: None
//  PARAMETERS  : 12 or 24 hours mode
//  LIMITATIONS : 
//-------------------------------------------------------------------------
void RTC_SetMode12_24(const UWORD8 mode)
{
  if ( mode == RTC_12_MODE)
    RTC_CTRL_REG_WR(RTC_CTRL_REG_RD | mode << 3);
  else
    RTC_CTRL_REG_WR(RTC_CTRL_REG_RD & 0xfff7);
}


//--------------------------------------------------------------------
//  NAME 	: RTC_GetSec
//  DESCRIPTION	: Return the RTC seconds register
//  RETURN VALUE: value store in the RTC SECOND register
//  PARAMETERS	: none
//  LIMITATIONS	: 
//--------------------------------------------------------------------
UWORD8 RTC_GetSec(void)
{
  return RTC_conv_bin(RTC_SECONDS_REG_RD);
}



//--------------------------------------------------------------
//  NAME 	: RTC_GetMin
//  DESCRIPTION	: Return the RTC minutes register
//  RETURN VALUE	: value store in the RTC MINUTE register
//  PARAMETERS	: none
//---------------------------------------------------------------
UWORD8 RTC_GetMin(void)
{
  return RTC_conv_bin(RTC_MINUTES_REG_RD);
}


//--------------------------------------------------------------
// NAME 	: RTC_GetHrs
// DESCRIPTION	: Return the RTC hours register
// RETURN VALUE	: value store in the RTC HOUR register
// PARAMETERS	: none
//-------------------------------------------------------------
UWORD8 RTC_GetHrs(void)
{
  return RTC_conv_bin(0x7f & RTC_HOURS_REG_RD);
}

//-----------------------------------------------------------------
// NAME 	: RTC_GetPMnAM
// DESCRIPTION	: Return the PM_AM mode AM=>0 PM=>1
// RETURN VALUE	: Return if it's the morning or the afternoon.
// PARAMETERS	: none
//-----------------------------------------------------------------
UWORD8 RTC_GetPMnAM(void)
{
  return( (RTC_HOURS_REG_RD & 0x80) >> 7);
}


//-------------------------------------------------------------
// NAME 		: RTC_GetMode12_24
// DESCRIPTION	: Return the mode 12_24 0=>24 hours mode	
// RETURN VALUE	: mode actually used => 12 or 24 hours mode
// PARAMETERS	: none
// LIMITATIONS	: 
//-------------------------------------------------------------
UWORD8 RTC_GetMode12_24(void)
{
  return((RTC_CTRL_REG_RD & RTC_MODE_12_24 )>>3);
}


//-------------------------------------------------------------
// NAME 	: RTC_GetDay
// DESCRIPTION	: Return the RTC days register
// RETURN VALUE	: value store in the RTC DAY register
// PARAMETERS	: none
// LIMITATIONS	: 
//-------------------------------------------------------------
UWORD8 RTC_GetDay(void)
{
  return RTC_conv_bin(RTC_DAYS_REG_RD);
}


//------------------------------------------------------------
// NAME 	: RTC_GetMon
// DESCRIPTION	: Return the RTC months register
// RETURN VALUE	: value store in the RTC MONTH register
// PARAMETERS	: none
// LIMITATIONS	: 
//------------------------------------------------------------
UWORD8 RTC_GetMon(void)
{
  return RTC_conv_bin(RTC_MONTHS_REG_RD);
}


//-----------------------------------------------------------
// NAME 	: RTC_GetYear
// DESCRIPTION	: Return the RTC years register
// RETURN VALUE	: value store in the RTC YEAR register
// PARAMETERS	: none
//-----------------------------------------------------------
UWORD8 RTC_GetYear(void)
{	
  return RTC_conv_bin(RTC_YEARS_REG_RD);
}


//----------------------------------------------------------------
// NAME 	: RTC_GetWeek
// DESCRIPTION	: Return the RTC week register
// RETURN VALUE	: value store in the RTC WEEK register
// PARAMETERS	: none
//----------------------------------------------------------------
UWORD8 RTC_GetWeek(void)
{
  return RTC_conv_bin(RTC_WEEK_REG_RD);
}

//--------------------------------------------------------
// NAME 	: RTC_GetDate
// DESCRIPTION	: Get the date 
// RETURN VALUE	: Actual date.
// PARAMETERS	: strcture on the RTC registers
//--------------------------------------------------------
void RTC_GetDate(struct rtc_tm *rtctime )
{
  UWORD8 sec;
  UWORD8 min;
  UWORD8 hour;
  UWORD8 day;
  UWORD8 mon;
  UWORD8 year;
  UWORD8 wday;
  UWORD8 hr_reg;

  sec    = RTC_SECONDS_REG_RD;
  min    = RTC_MINUTES_REG_RD;
  hr_reg = RTC_HOURS_REG_RD;
  hour   = (0x7f & hr_reg);
  day    = RTC_DAYS_REG_RD;
  mon    = RTC_MONTHS_REG_RD;
  year   = RTC_YEARS_REG_RD;
  wday   = RTC_WEEK_REG_RD;	

  rtctime->rtc_sec = RTC_conv_bin(sec);
  rtctime->rtc_min = RTC_conv_bin(min);
  rtctime->rtc_hour = RTC_conv_bin(hour);

  if (   RTC_conv_bin(hour) > 12
	 || ((RTC_CTRL_REG_RD & RTC_MODE_12_24) >> 3) == 0)
    {
      rtctime->rtc_1224md = 0;
      rtctime->rtc_PM = 0;
    } 

  else
    {
      rtctime->rtc_1224md = 1;
      if (((hr_reg & 0x80)>>7) == RTC_AM)
	rtctime->rtc_PM = RTC_AM;
      else
	rtctime->rtc_PM = RTC_PM;
    }

  rtctime->rtc_day = RTC_conv_bin(day);
  rtctime->rtc_mon = RTC_conv_bin(mon);
  rtctime->rtc_year = RTC_conv_bin(year);
  rtctime->rtc_wday = RTC_conv_bin(wday);
}

//--------------------------------------------------------
// NAME 	: RTC_GetAlarm
// DESCRIPTION	: Get the Alarm date 
// RETURN VALUE	: Actual alarm date.
// PARAMETERS	: structure on the RTC registers
//--------------------------------------------------------
void RTC_GetAlarm(struct rtc_tm *rtctime )
{
  UWORD8 sec;
  UWORD8 min;
  UWORD8 hour;
  UWORD8 day;
  UWORD8 mon;
  UWORD8 year;
  UWORD8 wday;
  UWORD8 hr_reg;

  sec    = RTC_ALARM_SECONDS_REG_RD;
  min    = RTC_ALARM_MINUTES_REG_RD;
  hr_reg = RTC_ALARM_HOURS_REG_RD;
  hour   = (0x7f & hr_reg);
  day    = RTC_ALARM_DAYS_REG_RD;
  mon    = RTC_ALARM_MONTHS_REG_RD;
  year   = RTC_ALARM_YEARS_REG_RD;
  wday   = 9;	

  rtctime->rtc_sec = RTC_conv_bin(sec);
  rtctime->rtc_min = RTC_conv_bin(min);
  rtctime->rtc_hour = RTC_conv_bin(hour);

  if (((hr_reg & 0x80)>>7) == RTC_AM)
    rtctime->rtc_PM = RTC_AM;
  else
    rtctime->rtc_PM = RTC_PM;

  rtctime->rtc_day = RTC_conv_bin(day);
  rtctime->rtc_mon = RTC_conv_bin(mon);
  rtctime->rtc_year = RTC_conv_bin(year);
  rtctime->rtc_wday = RTC_conv_bin(wday);
}


//------------------------------------------------------------------------
//  NAME        : RTC_GetStatus
//  DESCRIPTION : return the status value
//  PARAMETERS  : none
//  RETURN VALUE: Status Value
//  LIMITATIONS : None
//------------------------------------------------------------------------
UWORD8 RTC_GetStatus (void)
{
  return ( RTC_STATUS_REG_RD );
}

//------------------------------------------------------------------------
//  NAME 	: RTC_Rounding_30s
//  DESCRIPTION : Rounding to the closest minute, 
//                       by setting ROUND_30S bit of the control register.
//  PARAMETERS  : none
//  RETURN VALUE: none
//  LIMITATIONS : None
//------------------------------------------------------------------------
void RTC_Rounding_30s(void)
{	
  RTC_CTRL_REG_WR(RTC_CTRL_REG_RD | RTC_ROUND_30S);
}


//------------------------------------------------------------------------
//  NAME 	: RTC_Wait_unit_clk
//  DESCRIPTION : Waiting routine : ~2400 clk unit
//  PARAMETERS  : none
//  RETURN VALUE: none
//  LIMITATIONS : None
//------------------------------------------------------------------------
void RTC_Wait_unit_clk (void)
{
  int i;
  for (i=0;i<20;){i++;}
}


//-----------------------------------------------------------------------------
// RTC_TestRegisters
//-----------------------------------------------------------------------------
UWORD16 RTC_TestRegisters(void)
{
  UWORD16 err = TEST_OK;

  // TC Registers 	

  if ( RTC_SECONDS_REG_RD != 0x00 )
    {
      RES_Set(ERR_RTC_SEC);
      err = TEST_BAD;
    }

  if ( RTC_MINUTES_REG_RD != 0x00 )
    {
      RES_Set(ERR_RTC_MIN);
      err = TEST_BAD;
    }

  if ( RTC_HOURS_REG_RD != 0x00 )
    {
      RES_Set(ERR_RTC_HRS);
      err = TEST_BAD;
    }

  if ( RTC_DAYS_REG_RD != 0x01 )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -