/* ===================================================================*/ LDD_TError RTC1_SetTime(LDD_TDeviceData *DeviceDataPtr, LDD_RTC_TTime *TimePtr) { uint32_t Seconds; (void)DeviceDataPtr; /* Parameter is not used, suppress unused argument warning */ if ((TimePtr->Year < 2000U) || (TimePtr->Year > 2099U) || (TimePtr->Month > 12U) || (TimePtr->Month == 0U) || (TimePtr->Day > 31U) || (TimePtr->Day == 0U)) { /* Test correctness of given parameters */ return ERR_RANGE; /* If not correct then error */ } if (TimePtr->Year & 3U) { /* Is given year non-leap-one? */ if (ULY[TimePtr->Month] < TimePtr->Day) { /* Does the obtained number of days exceed number of days in the appropriate month & year? */ return ERR_RANGE; /* If yes (incorrect date inserted) then error */ } } else { /* Is given year leap-one? */ if (LY[TimePtr->Month] < TimePtr->Day) { /* Does the obtained number of days exceed number of days in the appropriate month & year? */ return ERR_RANGE; /* If yes (incorrect date inserted) then error */ } } Seconds = ((TimePtr->Year - 2000U) * 365U) + (((TimePtr->Year - 2000U) + 3U) / 4U); /* Compute number of days from 2000 till given year */ Seconds += MONTH_DAYS[TimePtr->Month]; /* Add number of days till given month */ Seconds += TimePtr->Day; /* Add days in given month */ if ((TimePtr->Year & 3U) || (TimePtr->Month <= 2U)) { /* For non-leap year or month <= 2, decrement day counter */ Seconds--; } Seconds = (Seconds * 86400U) + (TimePtr->Hour * 3600U) + (TimePtr->Minute * 60U) + TimePtr->Second; Seconds++; RTC_PDD_EnableCounter(RTC_BASE_PTR, PDD_DISABLE); /* Disable counter */ RTC_PDD_WriteTimePrescalerReg(RTC_BASE_PTR, 0x00U); /* Clear prescaler */ RTC_PDD_WriteTimeSecondsReg(RTC_BASE_PTR, Seconds); /* Set seconds counter */ RTC_PDD_EnableCounter(RTC_BASE_PTR, PDD_ENABLE); /* Enable counter */ return ERR_OK; }
void enableRTC() { RTC_PDD_WriteControlReg(RTC_BASE_PTR,0x1900); // enable oscillator // vTaskDelay(10); RTC_PDD_EnableCounter(RTC_BASE_PTR, PDD_ENABLE); };