Platform/ECM3532/M3/hw/csp/ecm3532/m3/csp/src/eta_csp_rtc.c
/***************************************************************************/
/**
 *
 *  EtaCspRtcTodSetDec - Set the time of day in decimal.
 *
 *  @param psTimeOfDay pointer to a time of day structure.
 *
 *  @return eEtaSuccess or eEtaFailure.
 *
 ******************************************************************************/
Set the time of day in decimal.
@param psTimeOfDay pointer to a time of day structure.


Set the time of day in decimal . @param psTimeOfDay pointer to a time of day structure .
tEtaStatus
EtaCspRtcTodSetDec(tTimeOfDay *psTimeOfDay)
{
     validate inputs
    bool bTwelve = psTimeOfDay-> bTwelve;
    if(   (psTimeOfDay->ui8Second    > 59)
        | (psTimeOfDay->ui8Minute    > 59)
        | (   bTwelve && (psTimeOfDay->ui8Hour > 12 || psTimeOfDay->ui8Hour == 0))
        | ( ! bTwelve && (psTimeOfDay->ui8Hour > 23))
        | (psTimeOfDay->ui8Day > 31)
        | ((psTimeOfDay->ui8Month == 4) && (psTimeOfDay->ui8Day > 30))
        | ((psTimeOfDay->ui8Month == 6) && (psTimeOfDay->ui8Day > 30))
        | ((psTimeOfDay->ui8Month == 9) && (psTimeOfDay->ui8Day > 30))
        | ((psTimeOfDay->ui8Month == 11) && (psTimeOfDay->ui8Day > 30))
        | ((psTimeOfDay->ui8Month == 2) && (psTimeOfDay->ui8Day > 29 ))
        | ((psTimeOfDay->ui8Month == 2) && (psTimeOfDay->ui16Year%4) && (psTimeOfDay->ui8Day == 29))
        | (psTimeOfDay->ui8Day == 0)
        | (psTimeOfDay->ui8DayOfWeek > 7)
        | (psTimeOfDay->ui8DayOfWeek == 0)
        | (psTimeOfDay->ui8Month > 12)
        | (psTimeOfDay->ui8Month == 0)
        | (psTimeOfDay->ui16Year > 99)
        | (psTimeOfDay->ui8Century > 1)
      )
    {
        return(eEtaFailure);
    }
     Collect the arguments
    reg_rtc_toda_t uTimeOfDayA =
    {
        .BF.SECONDS = DEC_TO_BCD(psTimeOfDay->ui8Second),
        .BF.MINUTES = DEC_TO_BCD(psTimeOfDay->ui8Minute),
        .BF.HOURS = DEC_TO_BCD(psTimeOfDay->ui8Hour)
                  | ((psTimeOfDay->bTwelve & !psTimeOfDay->bAm) << 5),
        .BF.DATE = DEC_TO_BCD(psTimeOfDay->ui8Day),
        .BF.MONTH = DEC_TO_BCD(psTimeOfDay->ui8Month),
    };
    reg_rtc_todb_t uTimeOfDayB =
    {
        .BF.DAY = DEC_TO_BCD(psTimeOfDay->ui8DayOfWeek),
        .BF.YEAR = DEC_TO_BCD((uint8_t)(psTimeOfDay->ui16Year)),
        .BF.CENTURY = DEC_TO_BCD((uint8_t)(psTimeOfDay->ui8Century)),
        .BF.TWELVE_HOUR = psTimeOfDay->bTwelve,
    };
     Now write them to the RTC hardware.
     write TOB before writing TOA
    REG_RTC_TODB = uTimeOfDayB;
    REG_RTC_TODA = uTimeOfDayA;
     All is good
    return(eEtaSuccess);
}
tEtaStatus EtaCspRtcTodSetDec ( tTimeOfDay * psTimeOfDay ) { bool bTwelve = psTimeOfDay -> bTwelve ; if ( ( psTimeOfDay -> ui8Second > 59 ) | ( psTimeOfDay -> ui8Minute > 59 ) | ( bTwelve && ( psTimeOfDay -> ui8Hour > 12 || psTimeOfDay -> ui8Hour == 0 ) ) | ( ! bTwelve && ( psTimeOfDay -> ui8Hour > 23 ) ) | ( psTimeOfDay -> ui8Day > 31 ) | ( ( psTimeOfDay -> ui8Month == 4 ) && ( psTimeOfDay -> ui8Day > 30 ) ) | ( ( psTimeOfDay -> ui8Month == 6 ) && ( psTimeOfDay -> ui8Day > 30 ) ) | ( ( psTimeOfDay -> ui8Month == 9 ) && ( psTimeOfDay -> ui8Day > 30 ) ) | ( ( psTimeOfDay -> ui8Month == 11 ) && ( psTimeOfDay -> ui8Day > 30 ) ) | ( ( psTimeOfDay -> ui8Month == 2 ) && ( psTimeOfDay -> ui8Day > 29 ) ) | ( ( psTimeOfDay -> ui8Month == 2 ) && ( psTimeOfDay -> ui16Year % 4 ) && ( psTimeOfDay -> ui8Day == 29 ) ) | ( psTimeOfDay -> ui8Day == 0 ) | ( psTimeOfDay -> ui8DayOfWeek > 7 ) | ( psTimeOfDay -> ui8DayOfWeek == 0 ) | ( psTimeOfDay -> ui8Month > 12 ) | ( psTimeOfDay -> ui8Month == 0 ) | ( psTimeOfDay -> ui16Year > 99 ) | ( psTimeOfDay -> ui8Century > 1 ) ) { return ( eEtaFailure ) ; } reg_rtc_toda_t uTimeOfDayA = { . BF . SECONDS = DEC_TO_BCD ( psTimeOfDay -> ui8Second ) , . BF . MINUTES = DEC_TO_BCD ( psTimeOfDay -> ui8Minute ) , . BF . HOURS = DEC_TO_BCD ( psTimeOfDay -> ui8Hour ) | ( ( psTimeOfDay -> bTwelve & ! psTimeOfDay -> bAm ) << 5 ) , . BF . DATE = DEC_TO_BCD ( psTimeOfDay -> ui8Day ) , . BF . MONTH = DEC_TO_BCD ( psTimeOfDay -> ui8Month ) , } ; reg_rtc_todb_t uTimeOfDayB = { . BF . DAY = DEC_TO_BCD ( psTimeOfDay -> ui8DayOfWeek ) , . BF . YEAR = DEC_TO_BCD ( ( uint8_t ) ( psTimeOfDay -> ui16Year ) ) , . BF . CENTURY = DEC_TO_BCD ( ( uint8_t ) ( psTimeOfDay -> ui8Century ) ) , . BF . TWELVE_HOUR = psTimeOfDay -> bTwelve , } ; REG_RTC_TODB = uTimeOfDayB ; REG_RTC_TODA = uTimeOfDayA ; return ( eEtaSuccess ) ; }
EtaCspRtcTodSetDec - Set the time of day in decimal.
EtaCspRtcTodSetDec - Set the time of day in decimal .
// // validate inputs // // // Collect the arguments // // // Now write them to the RTC hardware. // // write TOB before writing TOA // // All is good //