@@ -42,7 +42,11 @@ struct ambiq_rtc_data {
4242
4343static void rtc_time_to_ambiq_time_set (const struct rtc_time * tm , am_hal_rtc_time_t * atm )
4444{
45- atm -> ui32CenturyBit = ((tm -> tm_year <= 99 ) || (tm -> tm_year >= 200 ));
45+ #if defined(CONFIG_SOC_SERIES_APOLLO3X )
46+ atm -> ui32Century = ((tm -> tm_year <= 99 ) || (tm -> tm_year >= 200 ));
47+ #else
48+ atm -> ui32CenturyBit = ((tm -> tm_year > 99 ) && (tm -> tm_year < 200 ));
49+ #endif
4650 atm -> ui32Year = tm -> tm_year ;
4751 if (tm -> tm_year > 99 ) {
4852 atm -> ui32Year = tm -> tm_year % 100 ;
@@ -68,11 +72,19 @@ static void rtc_time_to_ambiq_time_set(const struct rtc_time *tm, am_hal_rtc_tim
6872static void ambiq_time_to_rtc_time_set (const am_hal_rtc_time_t * atm , struct rtc_time * tm )
6973{
7074 tm -> tm_year = atm -> ui32Year ;
71- if (atm -> ui32CenturyBit == 0 ) {
75+ #if defined(CONFIG_SOC_SERIES_APOLLO3X )
76+ if (atm -> ui32Century == 0 ) {
7277 tm -> tm_year += 100 ;
7378 } else {
7479 tm -> tm_year += 200 ;
7580 }
81+ #else
82+ if (atm -> ui32CenturyBit == 0 ) {
83+ tm -> tm_year += 200 ;
84+ } else {
85+ tm -> tm_year += 100 ;
86+ }
87+ #endif
7688 tm -> tm_wday = atm -> ui32Weekday ;
7789 tm -> tm_mon = atm -> ui32Month - 1 ;
7890 tm -> tm_mday = atm -> ui32DayOfMonth ;
@@ -180,8 +192,6 @@ static int ambiq_rtc_alarm_get_supported_fields(const struct device *dev,
180192static int ambiq_rtc_alarm_get_time (const struct device * dev , uint16_t id , uint16_t * mask ,
181193 struct rtc_time * timeptr )
182194{
183-
184- int err = 0 ;
185195 am_hal_rtc_time_t ambiq_time = {0 };
186196 struct ambiq_rtc_data * data = dev -> data ;
187197
@@ -192,11 +202,11 @@ static int ambiq_rtc_alarm_get_time(const struct device *dev, uint16_t id, uint1
192202
193203 k_spinlock_key_t key = k_spin_lock (& data -> lock );
194204
195- err = am_hal_rtc_alarm_get ( & ambiq_time , NULL );
196- if ( err != 0 ) {
197- LOG_DBG ( "Invalid Input Value" );
198- return - EINVAL ;
199- }
205+ #if defined( CONFIG_SOC_SERIES_APOLLO3X )
206+ am_hal_rtc_alarm_get ( & ambiq_time );
207+ #else
208+ am_hal_rtc_alarm_get ( & ambiq_time , NULL ) ;
209+ #endif
200210
201211 ambiq_time_to_rtc_time_set (& ambiq_time , timeptr );
202212
@@ -208,13 +218,12 @@ static int ambiq_rtc_alarm_get_time(const struct device *dev, uint16_t id, uint1
208218
209219 k_spin_unlock (& data -> lock , key );
210220
211- return err ;
221+ return 0 ;
212222}
213223
214224static int ambiq_rtc_alarm_set_time (const struct device * dev , uint16_t id , uint16_t mask ,
215225 const struct rtc_time * timeptr )
216226{
217- int err = 0 ;
218227 struct ambiq_rtc_data * data = dev -> data ;
219228 am_hal_rtc_time_t ambiq_time = {0 };
220229 uint16_t mask_available ;
@@ -240,8 +249,13 @@ static int ambiq_rtc_alarm_set_time(const struct device *dev, uint16_t id, uint1
240249 k_spinlock_key_t key = k_spin_lock (& data -> lock );
241250
242251 /* Disable and clear the alarm */
252+ #if defined(CONFIG_SOC_SERIES_APOLLO3X )
253+ am_hal_rtc_int_disable (AM_HAL_RTC_INT_ALM );
254+ am_hal_rtc_int_clear (AM_HAL_RTC_INT_ALM );
255+ #else
243256 am_hal_rtc_interrupt_disable (AM_HAL_RTC_INT_ALM );
244257 am_hal_rtc_interrupt_clear (AM_HAL_RTC_INT_ALM );
258+ #endif
245259
246260 /* When mask is 0 */
247261 if (mask == 0 ) {
@@ -258,18 +272,18 @@ static int ambiq_rtc_alarm_set_time(const struct device *dev, uint16_t id, uint1
258272 rtc_time_to_ambiq_time_set (timeptr , & ambiq_time );
259273
260274 /* Set RTC ALARM, Ambiq must have interval != AM_HAL_RTC_ALM_RPT_DIS */
261- if (0 != am_hal_rtc_alarm_set (& ambiq_time , AM_HAL_RTC_ALM_RPT_YR )) {
262- LOG_DBG ("Invalid Input Value" );
263- err = - EINVAL ;
264- goto unlock ;
265- }
275+ am_hal_rtc_alarm_set (& ambiq_time , AM_HAL_RTC_ALM_RPT_YR );
266276
277+ #if defined(CONFIG_SOC_SERIES_APOLLO3X )
278+ am_hal_rtc_int_enable (AM_HAL_RTC_INT_ALM );
279+ #else
267280 am_hal_rtc_interrupt_enable (AM_HAL_RTC_INT_ALM );
281+ #endif
268282
269283unlock :
270284 k_spin_unlock (& data -> lock , key );
271285
272- return err ;
286+ return 0 ;
273287}
274288
275289static int ambiq_rtc_alarm_is_pending (const struct device * dev , uint16_t id )
@@ -292,7 +306,11 @@ static int ambiq_rtc_alarm_is_pending(const struct device *dev, uint16_t id)
292306static void ambiq_rtc_isr (const struct device * dev )
293307{
294308 /* Clear the RTC alarm interrupt. 8*/
309+ #if defined(CONFIG_SOC_SERIES_APOLLO3X )
310+ am_hal_rtc_int_clear (AM_HAL_RTC_INT_ALM );
311+ #else
295312 am_hal_rtc_interrupt_clear (AM_HAL_RTC_INT_ALM );
313+ #endif
296314
297315#if defined(CONFIG_RTC_ALARM )
298316 struct ambiq_rtc_data * data = dev -> data ;
@@ -321,7 +339,11 @@ static int ambiq_rtc_alarm_set_callback(const struct device *dev, uint16_t id,
321339 data -> alarm_user_callback = callback ;
322340 data -> alarm_user_data = user_data ;
323341 if ((callback == NULL ) && (user_data == NULL )) {
342+ #if defined(CONFIG_SOC_SERIES_APOLLO3X )
343+ am_hal_rtc_int_disable (AM_HAL_RTC_INT_ALM );
344+ #else
324345 am_hal_rtc_interrupt_disable (AM_HAL_RTC_INT_ALM );
346+ #endif
325347 }
326348 }
327349
@@ -332,14 +354,16 @@ static int ambiq_rtc_alarm_set_callback(const struct device *dev, uint16_t id,
332354static int ambiq_rtc_init (const struct device * dev )
333355{
334356 const struct ambiq_rtc_config * config = dev -> config ;
335- #
357+
336358#ifdef CONFIG_RTC_ALARM
337359 struct ambiq_rtc_data * data = dev -> data ;
338360#endif
339361
340- /* Enable the clock for RTC. */
341- am_hal_clkgen_control (config -> clk_src , NULL );
342-
362+ /* Enable the clock for RTC. */
363+ #if defined(CONFIG_SOC_SERIES_APOLLO3X )
364+ am_hal_clkgen_control (AM_HAL_CLKGEN_CONTROL_XTAL_START + config -> clk_src , NULL );
365+ #endif
366+ am_hal_clkgen_control (AM_HAL_CLKGEN_CONTROL_RTC_SEL_XTAL + config -> clk_src , NULL );
343367 /* Enable the RTC. */
344368 am_hal_rtc_osc_enable ();
345369
0 commit comments