2929
3030/* rtc date upper bound reaches the year of 2099. */
3131#define RTC_TM_UPPER_BOUND \
32- { .tm_year = CONV_TO_TM_YEAR(2099 ), \
33- .tm_mon = CONV_TO_TM_MON(12), \
34- .tm_mday = 31 , \
35- .tm_hour = 23, \
36- .tm_min = 59 , \
37- .tm_sec = 59 , \
32+ { .tm_year = CONV_TO_TM_YEAR(2038 ), \
33+ .tm_mon = CONV_TO_TM_MON(1), \
34+ .tm_mday = 19 , \
35+ .tm_hour = 3, \
36+ .tm_min = 14 , \
37+ .tm_sec = 07 , \
3838}
3939
4040/* rtc date lower bound reaches the year of 2000. */
@@ -57,8 +57,8 @@ static rt_size_t nu_rtc_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_siz
5757static rt_size_t nu_rtc_write (rt_device_t dev , rt_off_t pos , const void * buffer , rt_size_t size );
5858#endif
5959
60- static rt_err_t nu_rtc_is_date_valid (const time_t * const t );
61- static void nu_rtc_init (void );
60+ static rt_err_t nu_rtc_is_date_valid (const time_t t );
61+ static rt_err_t nu_rtc_init (void );
6262
6363#if defined(RT_USING_ALARM )
6464static void nu_rtc_alarm_reset (void );
@@ -74,7 +74,7 @@ extern rt_err_t set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t secon
7474static struct rt_device device_rtc ;
7575
7676
77- static void nu_rtc_init (void )
77+ static rt_err_t nu_rtc_init (void )
7878{
7979 /* hw rtc initialise */
8080 RTC_Open (NULL );
@@ -86,6 +86,8 @@ static void nu_rtc_init(void)
8686 RTC_EnableInt (RTC_INTEN_ALMIEN_Msk );
8787 NVIC_EnableIRQ (RTC_IRQn );
8888#endif
89+
90+ return RT_EOK ;
8991}
9092
9193
@@ -173,7 +175,7 @@ static rt_size_t nu_rtc_write(rt_device_t dev, rt_off_t pos, const void *buffer,
173175#endif
174176
175177
176- static rt_err_t nu_rtc_is_date_valid (const time_t * const t )
178+ static rt_err_t nu_rtc_is_date_valid (const time_t t )
177179{
178180 static struct tm tm_upper = RTC_TM_UPPER_BOUND ;
179181 static struct tm tm_lower = RTC_TM_LOWER_BOUND ;
@@ -188,7 +190,7 @@ static rt_err_t nu_rtc_is_date_valid(const time_t *const t)
188190 }
189191
190192 /* check the date is supported by rtc. */
191- if ((* t > t_upper ) || (* t < t_lower ))
193+ if ((t > t_upper ) || (t < t_lower ))
192194 return - (RT_EINVAL );
193195
194196 return RT_EOK ;
@@ -230,11 +232,11 @@ static rt_err_t nu_rtc_control(rt_device_t dev, int cmd, void *args)
230232 case RT_DEVICE_CTRL_RTC_SET_TIME :
231233
232234 time = (time_t * ) args ;
233- tm_in = gmtime (time );
234235
235- if (nu_rtc_is_date_valid (time ) != RT_EOK )
236- return RT_ERROR ;
236+ if (nu_rtc_is_date_valid (* time ) != RT_EOK )
237+ return - ( RT_ERROR ) ;
237238
239+ tm_in = gmtime (time );
238240 hw_time .u32Year = CONV_FROM_TM_YEAR (tm_in -> tm_year );
239241 hw_time .u32Month = CONV_FROM_TM_MON (tm_in -> tm_mon );
240242 hw_time .u32Day = tm_in -> tm_mday ;
0 commit comments