rtc_inc.h File Reference


Detailed Description

System real time clock support module C header file.

REVISION

Definition in file rtc_inc.h.

#include "stdio.h"
#include "stdlib.h"
#include "../ctype.h"
#include "../c54regs.h"
#include "../feature.h"

Include dependency graph for rtc_inc.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Enumerations

enum  RTC_SPIMODE { RTC_SPIRD, RTC_SPIWR }

Functions

void RTC_init (void)
 Function initialized the RTC chip.
void RTC_setTime (st_TIME *)
 This function will fill the time registers with the contents of a time structure.
void RTC_readTime (st_TIME *)
 This function reads the time registers and fill a time structure.
int RTC_INT2BCD (int)
 This function takes an integer and converts it to a BCD number.
int RTC_BCD2INT (int, int)
 Corresponding integer value.
void RTC_control (int, int, int)
 This function will set or reset a particular bit(s) in the control registers of the RTC.


Enumeration Type Documentation

enum RTC_SPIMODE
 

Enumeration values:
RTC_SPIRD  Read RTC.
RTC_SPIWR  Write RTC.

Definition at line 71 of file rtc_inc.h.

00072 {
00073     RTC_SPIRD,  
00074     RTC_SPIWR   
00075 } RTC_SPIMODE;


Function Documentation

void RTC_control int  Action,
int  Reg1,
int  Reg2
 

This function will set or reset a particular bit(s) in the control registers of the RTC.

There are three commands. RTC_INIT, RTC_SET and RTC_RESET. RTC_INIT must first be done at system startup to bring a copy of the both registers so that they can be worked on.

Parameters:
Action command ID.
Reg1 Control register 1 value.
Reg2 Control register 2 value.

Definition at line 60 of file SYS_rtc.c.

References RTC_SPIRD, and RTC_SPIWR.

Referenced by RTC_init().

00061 {
00062     switch (Action)
00063     {
00064         default:
00065         case RTC_INIT:
00066             RTC_Control1 = RTC__spi(RTC_SPIRD, CONTROL1_ADDR + RTCRD);
00067             RTC_Control2 = RTC__spi(RTC_SPIRD, CONTROL2_ADDR + RTCRD);
00068             break;
00069             
00070         case RTC_ON:
00071             RTC_Control1 |= Reg1;
00072             RTC_Control2 |= Reg2;
00073             RTC__spi(RTC_SPIWR, (ULONG)RTC_Control1*256 + CONTROL1_ADDR + RTCWR);
00074             RTC__spi(RTC_SPIWR, (ULONG)RTC_Control2*256 + CONTROL2_ADDR + RTCWR);
00075             break;
00076             
00077         case RTC_OFF:
00078             RTC_Control1 &= (0xffff ^Reg1);
00079             RTC_Control2 &= (0xffff ^Reg2);
00080             RTC__spi(RTC_SPIWR, (ULONG)RTC_Control1*256 + CONTROL1_ADDR + RTCWR);
00081             RTC__spi(RTC_SPIWR, (ULONG)RTC_Control2*256 + CONTROL2_ADDR + RTCWR);
00082             break;          
00083     }
00084 }

int RTC_INT2BCD int  intVal  ) 
 

This function takes an integer and converts it to a BCD number.

Parameters:
intVal Integer value.
Returns:

Definition at line 193 of file SYS_rtc.c.

00194 {
00195     int INT2BCD_Data[ ] = {80,40,20,10};
00196     int i;
00197     int val = 0;
00198 
00199     for (i = 0; i < sizeof(INT2BCD_Data); i++)
00200     {
00201         val = val << 1;
00202         if (intVal >= INT2BCD_Data[i])
00203         {
00204             val |= 1;
00205             intVal = intVal % INT2BCD_Data[i];
00206         }
00207     }
00208     val = (val*16)+intVal;  
00209     return(val);
00210 }

void RTC_readTime st_TIME *  pTime  ) 
 

This function reads the time registers and fill a time structure.

Parameters:
pTime Time structure pointer.

Definition at line 113 of file SYS_rtc.c.

References RTC_SPIRD.

Referenced by MENU_statusBar(), UI_currentTimeString(), and UI_readRTC().

00114 {
00115     pTime->Second  = RTC__spi(RTC_SPIRD,SECOND_ADDR + RTCRD); 
00116     pTime->Minute  = RTC__spi(RTC_SPIRD,MINUTE_ADDR + RTCRD); 
00117     pTime->Hour    = RTC__spi(RTC_SPIRD,HOUR_ADDR + RTCRD); 
00118     pTime->Weekday = RTC__spi(RTC_SPIRD,WEEKDAY_ADDR + RTCRD); 
00119     pTime->Day     = RTC__spi(RTC_SPIRD,DAY_ADDR + RTCRD); 
00120     pTime->Month   = RTC__spi(RTC_SPIRD,MONTH_ADDR + RTCRD); 
00121     pTime->Year    = RTC__spi(RTC_SPIRD,YEAR_ADDR + RTCRD); 
00122 
00123     // Verify time structure.
00124     if( (HIBYTE_3(pTime->Second) > 5) || (LOBYTE(pTime->Second) > 9) )
00125         pTime->Second = 0x30;
00126     
00127     if( (HIBYTE_3(pTime->Minute) > 5) || (LOBYTE(pTime->Minute) > 9) )
00128         pTime->Minute = 0x30;
00129     
00130     if( (HIBYTE_2(pTime->Hour) > 2) || (LOBYTE(pTime->Hour) > 9) ||
00131          ((HIBYTE_2(pTime->Hour) == 2)&&(LOBYTE(pTime->Hour) > 3) ) )
00132         pTime->Hour = 0x03;
00133     
00134     if( (HIBYTE_2(pTime->Day) > 3) || (LOBYTE(pTime->Day) > 9) ||
00135          ((pTime->Day & 0x3F) == 0) ||
00136          ((HIBYTE_2(pTime->Day) == 3)&&(LOBYTE(pTime->Day) > 1) ) )
00137         pTime->Day = 0x18;
00138     
00139     if( (HIBYTE_1(pTime->Month) > 1) || (LOBYTE(pTime->Month) > 9) ||
00140          ((pTime->Month & 0x1F) == 0) ||
00141          ((HIBYTE_1(pTime->Month) == 1)&&(LOBYTE(pTime->Month) > 2) ) )
00142         pTime->Month = 0x05;
00143 
00144     if( (HIBYTE(pTime->Year) > 9) || (LOBYTE(pTime->Year) > 9) )
00145         pTime->Year = 0x00;
00146 }

void RTC_setTime st_TIME *  pTime  ) 
 

This function will fill the time registers with the contents of a time structure.

Parameters:
pTime Time structure pointer.

Definition at line 94 of file SYS_rtc.c.

References RTC_SPIWR.

00095 {
00096     RTC__spi(RTC_SPIWR, (ULONG)pTime->Second*256 +SECOND_ADDR + RTCWR);
00097     RTC__spi(RTC_SPIWR, (ULONG)pTime->Minute*256 +MINUTE_ADDR + RTCWR);
00098     RTC__spi(RTC_SPIWR, (ULONG)pTime->Hour*256 +HOUR_ADDR + RTCWR);
00099     RTC__spi(RTC_SPIWR, (ULONG)pTime->Weekday*256 +WEEKDAY_ADDR + RTCWR);
00100     RTC__spi(RTC_SPIWR, (ULONG)pTime->Day*256 +DAY_ADDR + RTCWR);
00101     RTC__spi(RTC_SPIWR, (ULONG)pTime->Month*256 +MONTH_ADDR + RTCWR);
00102     RTC__spi(RTC_SPIWR, (ULONG)pTime->Year*256 +YEAR_ADDR + RTCWR); 
00103 }


Generated on Wed Jan 19 01:13:16 2005 for neuros-firmware by  doxygen 1.3.9.1