Пример #1
0
static void reset_rtc_values( void )
{
    ErrorStatus status;

    /* Disable write protection of rtc registers */
    RTC_WriteProtectionCmd(DISABLE);
    status = RTC_EnterInitMode();
    REFERENCE_DEBUG_ONLY_VARIABLE(status);
    wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

    /* Reset calendar date registers */
    RTC->TR = 0;
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    wiced_assert( "Rtc can not synchronize", status==SUCCESS );

    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);

    /* Disable write protection of the rtc registers */
    RTC_WriteProtectionCmd(DISABLE);
    status = RTC_EnterInitMode();
    wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

    /* 2000 year 01/01 */
    RTC->DR= 0;
    RTC->DR= ( 1<<13 ) | ( 1<<8 ) | ( 1<<0 );
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    wiced_assert( "Rtc can not synchronize", status==SUCCESS );

    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);

}
Пример #2
0
static void reset_rtc_values( void )
{
    ErrorStatus status;
    int retry = 3;

    /* Disable write protection of rtc registers */
    do{
      RTC_WriteProtectionCmd(DISABLE);
      status = RTC_EnterInitMode();
      REFERENCE_DEBUG_ONLY_VARIABLE(status);
      retry--;
    }while( retry && (status!=SUCCESS) );

    check_string( status==SUCCESS, "Rtc can not enter intialisation mode");  

    /* Reset calendar date registers */
    RTC->TR = 0;
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    check_string(  status==SUCCESS, "Rtc can not synchronize" );


    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);

    /* Disable write protection of the rtc registers */
    RTC_WriteProtectionCmd(DISABLE);
    status = RTC_EnterInitMode();
    check_string(  status==SUCCESS, "Rtc can not enter intialisation mode" );

    /* 2000 year 01/01 */
    RTC->DR= 0;
    RTC->DR= ( 1<<13 ) | ( 1<<8 ) | ( 1<<0 );
    RTC_ExitInitMode();
    status = RTC_WaitForSynchro();
    check_string(status==SUCCESS, "Rtc can not synchronize");

    /* Enable write protection of rtc registers */
    RTC_WriteProtectionCmd(ENABLE);
}
Пример #3
0
void RTC_Config(void)
{
  RTC_InitTypeDef RTC_InitStructure;
  RTC_TimeTypeDef RTC_TimeStructure;
  RTC_DateTypeDef RTC_DateStructure;
  
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
  PWR_BackupAccessCmd(ENABLE);//使能备份寄存器操作
  
  RCC_LSICmd(ENABLE);
    while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
    RCC_RTCCLKCmd(ENABLE);
    RTC_WaitForSynchro();
  
  if(RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x9741)   //一个变量,看看RTC初始化没
  {
    
    RTC_WriteProtectionCmd(DISABLE);
  
    RTC_EnterInitMode();
    RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
    RTC_InitStructure.RTC_AsynchPrediv = 0x7D-1;
    RTC_InitStructure.RTC_SynchPrediv = 0xFF-1;
    RTC_Init(&RTC_InitStructure);
  
    RTC_TimeStructure.RTC_Seconds = 0x00;
    RTC_TimeStructure.RTC_Minutes = 0x01;
    RTC_TimeStructure.RTC_Hours = 0x01;
    RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
    RTC_SetTime(RTC_Format_BCD,&RTC_TimeStructure);
  
    RTC_DateStructure.RTC_Date = 30;
    RTC_DateStructure.RTC_Month = 5;
    RTC_DateStructure.RTC_WeekDay= RTC_Weekday_Thursday;
    RTC_DateStructure.RTC_Year = 12;
    RTC_SetDate(RTC_Format_BCD,&RTC_DateStructure);
  
    RTC_ExitInitMode();
    RTC_WriteBackupRegister(RTC_BKP_DR0,0X9741);
    RTC_WriteProtectionCmd(ENABLE);
    RTC_WriteBackupRegister(RTC_BKP_DR0,0x9741);  //初始化完成,设置标志
  }
  PWR_BackupAccessCmd(DISABLE);
}
Пример #4
0
static platform_result_t stm32f2_rtc_change_clock( rtc_clock_state_t* current, rtc_clock_state_t target )
{
    uint8_t sync_div;
    uint8_t async_div;
    ErrorStatus status;

    /* Changing the synchronous and asynchronous prescalers according to the current clocking state and target_clock_state */
    /* of the RTC */
    if( *current == CLOCKING_EVERY_SEC )
    {
        if( target == CLOCKING_EVERY_1p25MSEC )
        {
            sync_div = 0;
            async_div= 40;

            /* Disable write protection of rtc registers, now we will be able to update RTC register values */
            RTC_WriteProtectionCmd(DISABLE);

            /* Enable initialisation mode */
            status = RTC_EnterInitMode();
            REFERENCE_DEBUG_ONLY_VARIABLE(status);
            wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

            /* Update RTC prescaler */
            RTC->PRER = (uint32_t)( sync_div );
            RTC->PRER |= (uint32_t)(async_div << 16);
            RTC_ExitInitMode();

            /* Enable write proteciton of rtc registers back */
            RTC_WriteProtectionCmd(ENABLE);
            *current = CLOCKING_EVERY_1p25MSEC;
            return PLATFORM_SUCCESS;
        }
        else
        {
            return PLATFORM_SUCCESS;
        }
    }
    else if( *current == CLOCKING_EVERY_1p25MSEC )
    {
        if( target == CLOCKING_EVERY_SEC )
        {
            /* We will get approximately 800Hz clock, 1 tick will correspond to 1.25ms(0,00125s), by addind 8 together we will get 1ms  */
            /* the closest division factor which is 40.96( 32768/800 ), we will take 41, the error will be very very tiny */
            async_div = 127;
            sync_div = 255;

            /* Disable write protection of rtc registers */
            RTC_WriteProtectionCmd(DISABLE);

            /* Enable initialisation mode */
            status = RTC_EnterInitMode();
            wiced_assert( "Rtc can not enter intialisation mode", status==SUCCESS );

            /* Update RTC prescaler */
            RTC->PRER = (uint32_t)( sync_div );
            RTC->PRER |= (uint32_t)(async_div << 16);

            RTC_ExitInitMode();

            /* Enable write proteciton of rtc registers back */
            RTC_WriteProtectionCmd(ENABLE);
            *current = CLOCKING_EVERY_SEC;
            return PLATFORM_SUCCESS;
        }
        else
        {
            return PLATFORM_SUCCESS;
        }
    }
    return PLATFORM_SUCCESS;
}