/* wait until RTC_TIME and RTC_DATE registers are synchronized with APB clock, and the shadow registers are updated  */
ErrStatus rtc_register_sync_wait(void)
/* wait until RTC_TIME and RTC_DATE registers are synchronized with APB clock, and the shadow registers are updated  */
ErrStatus rtc_register_sync_wait(void)
{
    volatile uint32_t time_index = RTC_RSYNF_TIMEOUT;
    uint32_t flag_status = RESET;
    ErrStatus error_status = ERROR;
    if ((uint32_t)RESET == (RTC_CTL & RTC_CTL_BPSHAD)){
        RTC_WPK = RTC_UNLOCK_KEY1;
        RTC_WPK = RTC_UNLOCK_KEY2;
        RTC_STAT &= (uint32_t)(~RTC_STAT_RSYNF);
        do{
            flag_status = RTC_STAT & RTC_STAT_RSYNF;
        }while((--time_index > 0) && ((uint32_t)RESET == flag_status));
        if ((uint32_t)RESET != flag_status){  
            error_status = SUCCESS;
        }
        RTC_WPK = RTC_LOCK_KEY;
    }else{ 
        error_status = SUCCESS;
    }
    return error_status;
}