• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

rtc_spe.c

Go to the documentation of this file.
00001 /****************** COPYRIGHT (C) 2007-2010 RAISONANCE S.A.S. *****************/
00014 /******************************************************************************/
00015 
00016 /* Includes ------------------------------------------------------------------*/
00017 #include "circle.h"
00018 
00020 
00021 /* Private define ------------------------------------------------------------*/
00022 //#define BUG_RTC_CRYSTAL   // YRT20091112
00023 
00024 /* Private variables ---------------------------------------------------------*/
00025 
00026 /* Public functions for CircleOS ---------------------------------------------*/
00027 
00028 /*******************************************************************************
00029 *
00030 *                                RTC_Init
00031 *
00032 *******************************************************************************/
00040 /******************************************************************************/
00041 NODEBUG2 void RTC_Init( void )
00042 {
00043     /* CK_RTC clock selection */
00044     RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE );
00045 
00046     /* Allow access to BKP Domain */
00047     PWR_BackupAccessCmd( ENABLE );
00048 
00049     /* Enable the LSE OSC */
00050     RCC_LSEConfig( RCC_LSE_ON );
00051 
00052     /* Disable the LSI OSC */
00053 //    RCC_LSICmd( DISABLE );    //__YRT20091112
00054 
00055     /* Wait till LSE is ready */
00056 #ifndef BUG_RTC_CRYSTAL
00057 #if LED_INV
00058     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_RESET );   // Green
00059 #else
00060     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_SET );     // Green
00061 #endif
00062 
00063     while ( RCC_GetFlagStatus( RCC_FLAG_LSERDY ) == RESET )
00064         {}
00065 
00066 #if LED_INV
00067     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_SET );   // Green
00068 #else
00069     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED0, Bit_RESET );     // Green
00070 #endif
00071 #endif
00072 
00073     /* Select the RTC Clock Source */
00074     RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE );
00075 
00076     /* Enable the RTC Clock */
00077     RCC_RTCCLKCmd( ENABLE );
00078 
00079 #ifndef BUG_RTC_CRYSTAL
00080 #if LED_INV
00081     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );   // Red
00082 #else
00083     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );     // Red
00084 #endif
00085 
00086     /* Wait for RTC registers synchronization */
00087     RTC_WaitForSynchro();
00088 
00089 #if LED_INV
00090     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );       // Red
00091 #else
00092     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );     // Red
00093 #endif
00094 #endif
00095 
00096     /* Wait until last write operation on RTC registers has finished */
00097     RTC_WaitForLastTask();
00098 
00099     /* Enable the RTC Second interrupt */
00100     RTC_ITConfig( RTC_IT_SEC, ENABLE );
00101 
00102     /* Wait until last write operation on RTC registers has finished */
00103     RTC_WaitForLastTask();
00104 
00105     /* Set RTC prescaler: set RTC period to 1sec */
00106     /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
00107     RTC_SetPrescaler( 32767 );
00108 
00109 #ifndef BUG_RTC_CRYSTAL
00110 #if LED_INV
00111     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );   // Red
00112 #else
00113     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );     // Red
00114 #endif
00115 
00116     /* Wait until last write operation on RTC registers has finished */
00117     RTC_WaitForLastTask();
00118 
00119 #if LED_INV
00120     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_SET );       // Red
00121 #else
00122     GPIO_WriteBit( GPIOx_LED, GPIO_Pin_LED1, Bit_RESET );     // Red
00123 #endif
00124 #endif
00125 }
00126 
00128 
00129 /* Public functions ----------------------------------------------------------*/
00130 
00131 /*******************************************************************************
00132 *
00133 *                                RTC_GetTime
00134 *
00135 *******************************************************************************/
00145 /******************************************************************************/
00146 void RTC_GetTime( u8* THH, u8* TMM, u8* TSS )
00147 {
00148     counter_t Tmp;
00149 
00150     /* Load the Counter value */
00151     Tmp = RTC_GetCounter();
00152 
00153     /* Compute  hours */
00154     *THH = ( Tmp / 3600 ) % 24;
00155 
00156     /* Compute minutes */
00157     *TMM = ( Tmp / 60 ) % 60;
00158 
00159     /* Compute seconds */
00160     *TSS = Tmp % 60;
00161 }
00162 
00163 /*******************************************************************************
00164 *
00165 *                                RTC_SetTime
00166 *
00167 *******************************************************************************/
00177 /******************************************************************************/
00178 void RTC_SetTime( u8 THH, u8 TMM, u8 TSS )
00179 {
00180     /* Adjust the counter value */
00181     RTC_SetCounter( THH * 3600 + TMM * 60 + TSS );
00182 }
00183 
00184 /*******************************************************************************
00185 *
00186 *                                RTC_DisplayTime
00187 *
00188 *******************************************************************************/
00196 /******************************************************************************/
00197 void RTC_DisplayTime( void )
00198 {
00199     static counter_t last_time = 0;
00200     counter_t new_time = RTC_GetCounter();
00201 
00202     // Time and/or Vbat
00203 
00204     if ( last_time != new_time )
00205     {
00206         last_time = new_time ;
00207 
00208         if ( fDisplayTime == 1 )
00209         {
00210             DRAW_DisplayTime( 6, 0 ) ;
00211 
00212             #if DISPLAY_TEMP
00213             UTIL_SetTempMode(0);
00214             DRAW_DisplayTemp( 90, 0 );
00215             #endif
00216         }
00217     }
00218 }