projekty/Source/example1/src/rtc.c

Go to the documentation of this file.
00001 /*
00002  * $Id: rtc.c,v 1 2004/11/25 10:29:00 BorisK Exp $
00003  *
00004  * Copyright (C) 2004 ONTRACK s.r.o.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    
00019  * 02111-1307, USA.
00020  *
00021  * [1] ARM-based Microcontroller LPC2119/2129/2194/2292/9994, "Preliminary User Manual", February 03, 2004
00022  *
00023  * Written by Boris Kralik <kralikbo@yahoo.com>, 2004
00024  *
00025  */
00026 #include "rtc.h"
00027 void SetAlarm(pAlarm alarm){
00028         RTC_ALSEC       =       alarm.ALSEC;
00029         RTC_ALMIN       =       alarm.ALMIN;
00030         RTC_ALHOUR      =       alarm.ALHOUR;
00031         RTC_ALDOM       =       alarm.ALDOM;
00032         RTC_ALDOW       =       alarm.ALDOW;
00033         RTC_ALDOY       =       alarm.ALDOY;
00034         RTC_ALMON       =       alarm.ALMON;
00035         RTC_ALYEAR      =       alarm.ALYEAR;
00036         RTC_AMR         =       alarm.AMR;
00037 }
00038 void StopRTC(void){
00039         #if DEBUG
00040                 UARTWriteStr("\n\rStopRTC");
00041         #endif
00042         RTC_CCR &=      (0 << 0);       //Disable RTC
00043 }
00044 void ResetRTC(pTimer Time){
00045         #if DEBUG
00046                 UARTWriteStr("\n\rResetRTC");
00047         #endif
00048         RTC_SEC         =       Time.SEC;
00049         RTC_MIN         =       Time.MIN;
00050         RTC_HOUR        =       Time.HOUR;
00051         RTC_DOM         =       Time.DOM;
00052         RTC_DOW         =       Time.DOW;
00053         RTC_DOY         =       Time.DOY;
00054         RTC_MONTH       =       Time.MONTH;
00055         RTC_YEAR        =       Time.YEAR;
00056         
00057         RTC_CCR |=      (1 << 1);       // CTCRST - CTC Reset
00058         RTC_CTIME0      =       0;
00059         RTC_CCR &=      (0 << 1);       // Reset done
00060 }
00061 void SetRTC(uint8_t IRL,pTimer Time){
00062         #if DEBUG
00063                 UARTWriteStr("\n\rSetRTC");
00064         #endif
00065         RTC_SEC         =       Time.SEC;
00066         RTC_MIN         =       Time.MIN;
00067         RTC_HOUR        =       Time.HOUR;
00068         RTC_DOM         =       Time.DOM;
00069         RTC_DOW         =       Time.DOW;
00070         RTC_DOY         =       Time.DOY;
00071         RTC_MONTH       =       Time.MONTH;
00072         RTC_YEAR        =       Time.YEAR;
00073         
00074         RTC_CCR &=      (0 << 0);       // Clock disabled
00075         RTC_CCR |=      (0 << 1);       // Clock reset
00076         RTC_CCR &=      (0 << 2);       // Test Disabled
00077         RTC_CCR &=      (0 << 3);       // Test Disabled
00078         
00079         RTC_PREINT      |=      182;
00080         RTC_PREFRAC     |=      3456;
00081         RTC_ILR          =      IRL;
00082         RTC_CIIR        =       0;
00083 }
00084 void StartRTC(void){
00085         #if DEBUG
00086                 UARTWriteStr("\n\rStartRTC");
00087         #endif
00088 //      ResetRTC();
00089         RTC_CCR |=      (1 << 0);       // Clock Enable
00090 }
00091 pTimer GetTimeRTC(void){
00092         pTimer ret;
00093         uint32_t iSecond=0,iMinutes=0,iHours=0,iDom=0,iYear=0,iMonth=0,iDoy=0,iDow=0;
00094         uint32_t Val = RTC_CTIME0;
00095         iSecond  =  (Val & 0x0000003F);
00096         iMinutes = ((Val & 0x00003F00) >> 8);
00097         iHours   = ((Val & 0x001F0000) >> 16);
00098         iDow     = ((Val & 0x07000000) >> 24);
00099         Val      = RTC_CTIME1;
00100         iDom     =   (Val & 0x0000001F);
00101         iMonth   =  ((Val & 0x00000F00) >> 8);
00102         iYear    =  ((Val & 0x0FFF0000) >> 16);
00103         iDoy     =  (RTC_CTIME2 & 0x00000FFF);
00104         #if DEBUG
00105                 UARTWriteStr("\n\r");
00106                 UARTWriteStr(itoa_16(iDom));UARTWriteStr(":");
00107                 UARTWriteStr(itoa_16(iMonth));UARTWriteStr(":");
00108                 UARTWriteStr(itoa_16(iYear));UARTWriteStr("   ");
00109                 UARTWriteStr(itoa_16(iHours));UARTWriteStr(":");
00110                 UARTWriteStr(itoa_16(iMinutes));UARTWriteStr(":");
00111                 UARTWriteStr(itoa_16(iSecond));
00112         #endif
00113         ret.SEC =       iSecond;
00114         ret.MIN =       iMinutes;
00115         ret.HOUR=       iHours;
00116         ret.DOM =       iDom;
00117         ret.DOW =       iDow;
00118         ret.DOY =       iDoy;
00119         ret.MONTH =     iMonth;
00120         ret.YEAR=       iYear;
00121         return ret;
00122 }

Generated on Fri Sep 21 13:41:54 2007 for example1 by  doxygen 1.4.7