/**
  ******************************************************************************
  * @file     RTC_user.c
  * @author   SINOMCU-AE
  * @brief    RTC user function
  *    
  *          This file provides functions get RTC date,time send them to uart;
  *     
  ******************************************************************************
  * @attention 
  *                           DISCLAIMER
  * The present firmware which is for guidance only aims at providing customers
  * with coding information regarding their products in order for them to save
  * time. As a result, SinoMCU shall not be held liable for any direct,indirect
  * or consequential damages with respect to any claims arising from the content 
  * of such firmware and/or the use made by customers of the coding information 
  * contained herein in connection with their products.
  *
  * <h2><center>&copy; Copyright (c) 2021 sinomcu All rights reserved.</center></h2>
  *
  ******************************************************************************
  */
  
#include "stdio.h"
#include "RTC_CFG.h"
#include "RTC_user.h"

extern FlagStatus RTC_Alarm_IRQ_Flag;

/**
  * @brief  get the current time and date.
  * @param  None
  * @retval None
  */
void get_rtc_calendar(void) {
  MS32_RTC_TimeTypeDef RtcTimeStruct ={0};
  MS32_RTC_DateTypeDef RtcDateStruct ={0};
  uint32_t sub_second=0,prediv_s=0;
  uint16_t ss_ms =0;
  
  MS32_RTC_GetTime(RTC,&RtcTimeStruct);
  MS32_RTC_GetDate(RTC,&RtcDateStruct);
  
  sub_second = MS32_RTC_TIME_GetSubSecond(RTC);
  prediv_s   = MS32_RTC_GetSynchPrescaler(RTC);
  ss_ms = (uint16_t)(((prediv_s -sub_second)*1000)/(prediv_s+1));
  
  printf("\r\nTime HH:MM:SS:%.2d:%.2d:%.2d,", RtcTimeStruct.Hours, RtcTimeStruct.Minutes, RtcTimeStruct.Seconds);
  printf("Sub Second:%.3d,", ss_ms);
  printf("Date MM-DD-YYYY:%.2d-%.2d-%.2d", RtcDateStruct.Month,RtcDateStruct.Day, 2000+RtcDateStruct.Year);
}

/******************************** END OF FILE *********************************/
