1 //*****************************************************************************
2 //
3 //  am_hal_rtc.c
4 //! @file
5 //!
6 //! @brief Functions for interfacing with the Real-Time Clock (RTC).
7 //!
8 //! @addtogroup rtc2 Real-Time Clock (RTC)
9 //! @ingroup apollo2hal
10 //! @{
11 //
12 //*****************************************************************************
13 
14 //*****************************************************************************
15 //
16 // Copyright (c) 2017, Ambiq Micro
17 // All rights reserved.
18 //
19 // Redistribution and use in source and binary forms, with or without
20 // modification, are permitted provided that the following conditions are met:
21 //
22 // 1. Redistributions of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // 3. Neither the name of the copyright holder nor the names of its
30 // contributors may be used to endorse or promote products derived from this
31 // software without specific prior written permission.
32 //
33 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
37 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 // POSSIBILITY OF SUCH DAMAGE.
44 //
45 // This is part of revision 1.2.11 of the AmbiqSuite Development Package.
46 //
47 //*****************************************************************************
48 
49 #include <stdint.h>
50 #include <stdbool.h>
51 #include "am_mcu_apollo.h"
52 
53 //*****************************************************************************
54 //
55 // Converts a Binary Coded Decimal (BCD) byte to its Decimal form.
56 //
57 //*****************************************************************************
58 static uint8_t
bcd_to_dec(uint8_t ui8BCDByte)59 bcd_to_dec(uint8_t ui8BCDByte)
60 {
61   return (((ui8BCDByte & 0xF0) >> 4) * 10) + (ui8BCDByte & 0x0F);
62 }
63 
64 //*****************************************************************************
65 //
66 // Converts a Decimal byte to its Binary Coded Decimal (BCD) form.
67 //
68 //*****************************************************************************
69 static uint8_t
dec_to_bcd(uint8_t ui8DecimalByte)70 dec_to_bcd(uint8_t ui8DecimalByte)
71 {
72   return (((ui8DecimalByte / 10) << 4) | (ui8DecimalByte % 10));
73 }
74 
75 //*****************************************************************************
76 //
77 //! @brief Selects the clock source for the RTC.
78 //!
79 //! @param ui32OSC the clock source for the RTC.
80 //!
81 //! This function selects the clock source for the RTC.
82 //!
83 //! Valid values for ui32OSC are:
84 //!
85 //!     AM_HAL_RTC_OSC_LFRC
86 //!     AM_HAL_RTC_OSC_XT
87 //!
88 //! @return None
89 //
90 //*****************************************************************************
91 void
am_hal_rtc_osc_select(uint32_t ui32OSC)92 am_hal_rtc_osc_select(uint32_t ui32OSC)
93 {
94     //
95     // Set XT if flag is set.
96     // Otherwise configure for LFRC.
97     //
98     if (ui32OSC)
99     {
100         AM_REG(CLKGEN, OCTRL) |= AM_REG_CLKGEN_OCTRL_OSEL_M;
101     }
102     else
103     {
104         AM_REG(CLKGEN, OCTRL) &= ~AM_REG_CLKGEN_OCTRL_OSEL_M;
105     }
106 }
107 
108 //*****************************************************************************
109 //
110 //! @brief Enable/Start the RTC oscillator.
111 //!
112 //! Starts the RTC oscillator.
113 //!
114 //! @return None.
115 //
116 //*****************************************************************************
117 void
am_hal_rtc_osc_enable(void)118 am_hal_rtc_osc_enable(void)
119 {
120     //
121     // Start the RTC Oscillator.
122     //
123     AM_REG(RTC, RTCCTL) &= ~AM_REG_RTC_RTCCTL_RSTOP(1);
124 }
125 
126 //*****************************************************************************
127 //
128 //! @brief Disable/Stop the RTC oscillator.
129 //!
130 //! Stops the RTC oscillator.
131 //!
132 //! @return None.
133 //
134 //*****************************************************************************
135 void
am_hal_rtc_osc_disable(void)136 am_hal_rtc_osc_disable(void)
137 {
138     //
139     // Stop the RTC Oscillator.
140     //
141     AM_REG(RTC, RTCCTL) |= AM_REG_RTC_RTCCTL_RSTOP(1);
142 }
143 
144 //*****************************************************************************
145 //
146 //! @brief Configures the RTC for 12 or 24 hour time keeping.
147 //!
148 //! @param b12Hour - A 'true' configures the RTC for 12 hour time keeping.
149 //!
150 //! Configures the RTC for 12 (true) or 24 (false) hour time keeping.
151 //!
152 //! @return None.
153 //
154 //*****************************************************************************
155 void
am_hal_rtc_time_12hour(bool b12Hour)156 am_hal_rtc_time_12hour(bool b12Hour)
157 {
158     //
159     // Set the 12/24 hour bit.
160     //
161     AM_REG(RTC, RTCCTL) |= AM_REG_RTC_RTCCTL_HR1224(b12Hour);
162 }
163 
164 //*****************************************************************************
165 //
166 //! @brief Enable selected RTC interrupts.
167 //!
168 //! @param ui32Interrupt - desired interrupts
169 //!
170 //! Enables the RTC interrupts.
171 //!
172 //! ui32Interrupt should be an OR of the following:
173 //!
174 //!     AM_HAL_RTC_INT_ALM
175 //!     AM_HAL_RTC_INT_OF
176 //!     AM_HAL_RTC_INT_ACC
177 //!     AM_HAL_RTC_INT_ACF
178 //!
179 //! @return None.
180 //
181 //*****************************************************************************
182 void
am_hal_rtc_int_enable(uint32_t ui32Interrupt)183 am_hal_rtc_int_enable(uint32_t ui32Interrupt)
184 {
185     //
186     // Enable the interrupts.
187     //
188     AM_REG(RTC, INTEN) |= ui32Interrupt;
189 }
190 
191 //*****************************************************************************
192 //
193 //! @brief Return the enabled RTC interrupts.
194 //!
195 //! Returns the enabled RTC interrupts.
196 //!
197 //! @return enabled RTC interrupts. Return is a logical or of:
198 //!
199 //!     AM_HAL_RTC_INT_ALM
200 //!     AM_HAL_RTC_INT_OF
201 //!     AM_HAL_RTC_INT_ACC
202 //!     AM_HAL_RTC_INT_ACF
203 //
204 //*****************************************************************************
205 uint32_t
am_hal_rtc_int_enable_get(void)206 am_hal_rtc_int_enable_get(void)
207 {
208     //
209     // Read the RTC interrupt enable register, and return its contents.
210     //
211     return AM_REG(RTC, INTEN);
212 }
213 
214 //*****************************************************************************
215 //
216 //! @brief Disable selected RTC interrupts.
217 //!
218 //! @param ui32Interrupt - desired interrupts
219 //!
220 //! Disables the RTC interrupts.
221 //!
222 //! ui32Interrupt should be an OR of the following:
223 //!
224 //!     AM_HAL_RTC_INT_ALM
225 //!     AM_HAL_RTC_INT_OF
226 //!     AM_HAL_RTC_INT_ACC
227 //!     AM_HAL_RTC_INT_ACF
228 //!
229 //! @return None.
230 //
231 //*****************************************************************************
232 void
am_hal_rtc_int_disable(uint32_t ui32Interrupt)233 am_hal_rtc_int_disable(uint32_t ui32Interrupt)
234 {
235     //
236     // Disable the interrupts.
237     //
238     AM_REG(RTC, INTEN) &= ~ui32Interrupt;
239 }
240 
241 //*****************************************************************************
242 //
243 //! @brief Sets the selected RTC interrupts.
244 //!
245 //! @param ui32Interrupt - desired interrupts
246 //!
247 //! Sets the RTC interrupts causing them to immediately trigger.
248 //!
249 //! ui32Interrupt should be an OR of the following:
250 //!
251 //!     AM_HAL_RTC_INT_ALM
252 //!     AM_HAL_RTC_INT_OF
253 //!     AM_HAL_RTC_INT_ACC
254 //!     AM_HAL_RTC_INT_ACF
255 //!
256 //! @return None.
257 //
258 //*****************************************************************************
259 void
am_hal_rtc_int_set(uint32_t ui32Interrupt)260 am_hal_rtc_int_set(uint32_t ui32Interrupt)
261 {
262     //
263     // Set the interrupts.
264     //
265     AM_REG(RTC, INTSET) = ui32Interrupt;
266 }
267 
268 //*****************************************************************************
269 //
270 //! @brief Clear selected RTC interrupts.
271 //!
272 //! @param ui32Interrupt - desired interrupts
273 //!
274 //! Clears the RTC interrupts.
275 //!
276 //! ui32Interrupt should be an OR of the following:
277 //!
278 //!     AM_HAL_RTC_INT_ALM
279 //!     AM_HAL_RTC_INT_OF
280 //!     AM_HAL_RTC_INT_ACC
281 //!     AM_HAL_RTC_INT_ACF
282 //!
283 //! @return None.
284 //
285 //*****************************************************************************
286 void
am_hal_rtc_int_clear(uint32_t ui32Interrupt)287 am_hal_rtc_int_clear(uint32_t ui32Interrupt)
288 {
289     //
290     // Clear the interrupts.
291     //
292     AM_REG(RTC, INTCLR) = ui32Interrupt;
293 }
294 
295 //*****************************************************************************
296 //
297 //! @brief Returns the RTC interrupt status.
298 //!
299 //! @param bEnabledOnly - return the status of only the enabled interrupts.
300 //!
301 //! Returns the RTC interrupt status.
302 //!
303 //! @return Bitwise representation of the current interrupt status.
304 //!
305 //! The return value will be the logical OR of one or more of the following
306 //! values:
307 //!
308 //!     AM_HAL_RTC_INT_ALM
309 //!     AM_HAL_RTC_INT_OF
310 //!     AM_HAL_RTC_INT_ACC
311 //!     AM_HAL_RTC_INT_ACF
312 //
313 //*****************************************************************************
314 uint32_t
am_hal_rtc_int_status_get(bool bEnabledOnly)315 am_hal_rtc_int_status_get(bool bEnabledOnly)
316 {
317     //
318     // Get the interrupt status.
319     //
320     if (bEnabledOnly)
321     {
322         uint32_t u32RetVal;
323         u32RetVal  = AM_REG(RTC, INTSTAT);
324         u32RetVal &= AM_REG(RTC, INTEN);
325         return u32RetVal &
326                 (AM_HAL_RTC_INT_ALM | AM_HAL_RTC_INT_OF |
327                 AM_HAL_RTC_INT_ACC | AM_HAL_RTC_INT_ACF);
328     }
329     else
330     {
331         return (AM_REG(RTC, INTSTAT) & (AM_HAL_RTC_INT_ALM |
332                                         AM_HAL_RTC_INT_OF |
333                                         AM_HAL_RTC_INT_ACC |
334                                         AM_HAL_RTC_INT_ACF));
335     }
336 }
337 
338 //*****************************************************************************
339 //
340 //! @brief Set the Real Time Clock counter registers.
341 //!
342 //! @param *pTime - A pointer to the time structure.
343 //!
344 //! Sets the RTC counter registers to the supplied values.
345 //!
346 //! @return None.
347 //
348 //*****************************************************************************
349 void
am_hal_rtc_time_set(am_hal_rtc_time_t * pTime)350 am_hal_rtc_time_set(am_hal_rtc_time_t *pTime)
351 {
352     //
353     // Enable writing to the counters.
354     //
355     AM_REG(RTC, RTCCTL) |= AM_REG_RTC_RTCCTL_WRTC(1);
356 
357     //
358     // Write the RTCLOW register.
359     //
360     AM_REG(RTC, CTRLOW) =
361         AM_REG_RTC_CTRLOW_CTRHR(dec_to_bcd(pTime->ui32Hour))                |
362         AM_REG_RTC_CTRLOW_CTRMIN(dec_to_bcd(pTime->ui32Minute))             |
363         AM_REG_RTC_CTRLOW_CTRSEC(dec_to_bcd(pTime->ui32Second))             |
364         AM_REG_RTC_CTRLOW_CTR100(dec_to_bcd(pTime->ui32Hundredths));
365 
366     //
367     // Write the RTCUP register.
368     //
369     AM_REG(RTC, CTRUP) =
370         AM_REG_RTC_CTRUP_CEB((pTime->ui32CenturyEnable))                   |
371         AM_REG_RTC_CTRUP_CB((pTime->ui32Century))                          |
372         AM_REG_RTC_CTRUP_CTRWKDY((pTime->ui32Weekday))                     |
373         AM_REG_RTC_CTRUP_CTRYR(dec_to_bcd((pTime->ui32Year)))              |
374         AM_REG_RTC_CTRUP_CTRMO(dec_to_bcd((pTime->ui32Month)))             |
375         AM_REG_RTC_CTRUP_CTRDATE(dec_to_bcd((pTime->ui32DayOfMonth)));
376 
377     //
378     // Disable writing to the counters.
379     //
380     AM_REG(RTC, RTCCTL) |= AM_REG_RTC_RTCCTL_WRTC(0);
381 }
382 
383 //*****************************************************************************
384 //
385 //! @brief Get the Real Time Clock current time.
386 //!
387 //! @param *pTime - A pointer to the time structure to store the current time.
388 //!
389 //! Gets the RTC's current time
390 //!
391 //! @return 0 for success and 1 for error.
392 //
393 //*****************************************************************************
394 uint32_t
am_hal_rtc_time_get(am_hal_rtc_time_t * pTime)395 am_hal_rtc_time_get(am_hal_rtc_time_t *pTime)
396 {
397     uint32_t ui32RTCLow, ui32RTCUp, ui32Value;
398 
399     //
400     // Read the upper and lower RTC registers.
401     //
402     ui32RTCLow = AM_REG(RTC, CTRLOW);
403     ui32RTCUp = AM_REG(RTC, CTRUP);
404 
405     //
406     // Break out the lower word.
407     //
408     ui32Value =
409         ((ui32RTCLow & AM_REG_RTC_CTRLOW_CTRHR_M) >> AM_REG_RTC_CTRLOW_CTRHR_S);
410     pTime->ui32Hour = bcd_to_dec(ui32Value);
411 
412     ui32Value =
413         ((ui32RTCLow & AM_REG_RTC_CTRLOW_CTRMIN_M) >> AM_REG_RTC_CTRLOW_CTRMIN_S);
414     pTime->ui32Minute = bcd_to_dec(ui32Value);
415 
416     ui32Value =
417         ((ui32RTCLow & AM_REG_RTC_CTRLOW_CTRSEC_M) >> AM_REG_RTC_CTRLOW_CTRSEC_S);
418     pTime->ui32Second = bcd_to_dec(ui32Value);
419 
420     ui32Value =
421         ((ui32RTCLow & AM_REG_RTC_CTRLOW_CTR100_M) >> AM_REG_RTC_CTRLOW_CTR100_S);
422     pTime->ui32Hundredths = bcd_to_dec(ui32Value);
423 
424     //
425     // Break out the upper word.
426     //
427     pTime->ui32ReadError =
428         ((ui32RTCUp & AM_REG_RTC_CTRUP_CTERR_M) >> AM_REG_RTC_CTRUP_CTERR_S);
429 
430     pTime->ui32CenturyEnable =
431         ((ui32RTCUp & AM_REG_RTC_CTRUP_CEB_M) >> AM_REG_RTC_CTRUP_CEB_S);
432 
433     pTime->ui32Century =
434         ((ui32RTCUp & AM_REG_RTC_CTRUP_CB_M) >> AM_REG_RTC_CTRUP_CB_S);
435 
436     ui32Value =
437         ((ui32RTCUp & AM_REG_RTC_CTRUP_CTRWKDY_M) >> AM_REG_RTC_CTRUP_CTRWKDY_S);
438     pTime->ui32Weekday = bcd_to_dec(ui32Value);
439 
440     ui32Value =
441         ((ui32RTCUp & AM_REG_RTC_CTRUP_CTRYR_M) >> AM_REG_RTC_CTRUP_CTRYR_S);
442     pTime->ui32Year = bcd_to_dec(ui32Value);
443 
444     ui32Value =
445         ((ui32RTCUp & AM_REG_RTC_CTRUP_CTRMO_M) >> AM_REG_RTC_CTRUP_CTRMO_S);
446     pTime->ui32Month = bcd_to_dec(ui32Value);
447 
448     ui32Value =
449         ((ui32RTCUp & AM_REG_RTC_CTRUP_CTRDATE_M) >> AM_REG_RTC_CTRUP_CTRDATE_S);
450     pTime->ui32DayOfMonth = bcd_to_dec(ui32Value);
451 
452     //
453     // Was there a read error?
454     //
455     if (pTime->ui32ReadError)
456     {
457         return 1;
458     }
459     else
460     {
461         return 0;
462     }
463 }
464 
465 //*****************************************************************************
466 //
467 //! @brief Sets the alarm repeat interval.
468 //!
469 //! @param ui32RepeatInterval the desired repeat interval.
470 //!
471 //! Sets the alarm repeat interval.
472 //!
473 //! Valid values for ui32RepeatInterval:
474 //!
475 //!     AM_HAL_RTC_ALM_RPT_DIS
476 //!     AM_HAL_RTC_ALM_RPT_YR
477 //!     AM_HAL_RTC_ALM_RPT_MTH
478 //!     AM_HAL_RTC_ALM_RPT_WK
479 //!     AM_HAL_RTC_ALM_RPT_DAY
480 //!     AM_HAL_RTC_ALM_RPT_HR
481 //!     AM_HAL_RTC_ALM_RPT_MIN
482 //!     AM_HAL_RTC_ALM_RPT_SEC
483 //!     AM_HAL_RTC_ALM_RPT_10TH
484 //!     AM_HAL_RTC_ALM_RPT_100TH
485 //!
486 //! @return None.
487 //
488 //*****************************************************************************
489 void
am_hal_rtc_alarm_interval_set(uint32_t ui32RepeatInterval)490 am_hal_rtc_alarm_interval_set(uint32_t ui32RepeatInterval)
491 {
492     uint32_t ui32RptInt, ui32Alm100, ui32Value;
493 
494     switch(ui32RepeatInterval)
495     {
496         //
497         // If repeat every 10th set RPT and ALM100 field accordinly
498         //
499         case AM_HAL_RTC_ALM_RPT_10TH:
500             ui32RptInt = AM_HAL_RTC_ALM_RPT_SEC;
501             ui32Alm100 = AM_HAL_RTC_ALM100_10TH;
502             break;
503         //
504         // If repeat every 100th set RPT and ALM100 field accordinly
505         //
506         case AM_HAL_RTC_ALM_RPT_100TH:
507             ui32RptInt = AM_HAL_RTC_ALM_RPT_SEC;
508             ui32Alm100 = AM_HAL_RTC_ALM100_100TH;
509             break;
510         //
511         // Otherwise set RPT as value passed.  ALM100 values need to be 0xnn
512         // in this setting where n = 0-9.
513         //
514         default:
515             //
516             // Get the current value of the ALM100 field.
517             //
518             ui32Value = AM_BFR(RTC, ALMLOW, ALM100);
519 
520             //
521             // If ALM100 was previous EVERY_10TH or EVERY_100TH reset to zero
522             // otherwise keep previous setting.
523             //
524             ui32Alm100 = ui32Value >= 0xF0 ? 0 : ui32Value;
525 
526             //
527             // Set RPT value to value passed.
528             //
529             ui32RptInt = ui32RepeatInterval;
530             break;
531     }
532 
533     //
534     // Write the interval to the register.
535     //
536     AM_BFW(RTC, RTCCTL, RPT, ui32RptInt);
537 
538     //
539     // Write the Alarm 100 bits in the ALM100 register.
540     //
541     AM_BFW(RTC, ALMLOW, ALM100, ui32Alm100);
542 }
543 
544 //*****************************************************************************
545 //
546 //! @brief Sets the RTC's Alarm.
547 //!
548 //! @param *pTime - A pointer to the time structure.
549 //! @param ui32RepeatInterval - the desired alarm repeat interval.
550 //!
551 //! Set the Real Time Clock Alarm Parameters.
552 //!
553 //! Valid values for ui32RepeatInterval:
554 //!
555 //!     AM_HAL_RTC_ALM_RPT_DIS
556 //!     AM_HAL_RTC_ALM_RPT_YR
557 //!     AM_HAL_RTC_ALM_RPT_MTH
558 //!     AM_HAL_RTC_ALM_RPT_WK
559 //!     AM_HAL_RTC_ALM_RPT_DAY
560 //!     AM_HAL_RTC_ALM_RPT_HR
561 //!     AM_HAL_RTC_ALM_RPT_MIN
562 //!     AM_HAL_RTC_ALM_RPT_SEC
563 //!     AM_HAL_RTC_ALM_RPT_10TH
564 //!     AM_HAL_RTC_ALM_RPT_EVERY_100TH
565 //!
566 //! @return None.
567 //
568 //*****************************************************************************
569 void
am_hal_rtc_alarm_set(am_hal_rtc_time_t * pTime,uint32_t ui32RepeatInterval)570 am_hal_rtc_alarm_set(am_hal_rtc_time_t *pTime, uint32_t ui32RepeatInterval)
571 {
572     uint8_t ui8Value = 0;
573 
574     //
575     // Write the interval to the register.
576     //
577     AM_REG(RTC, RTCCTL) |=
578         AM_REG_RTC_RTCCTL_RPT(ui32RepeatInterval > 0x7 ? 0x7 : ui32RepeatInterval);
579 
580     //
581     // Check if the interval is 10th or every 100th and track it in ui8Value.
582     //
583     if (ui32RepeatInterval == AM_HAL_RTC_ALM_RPT_10TH)
584     {
585         ui8Value = 0xF0;
586     }
587     else if (ui32RepeatInterval == AM_HAL_RTC_ALM_RPT_100TH)
588     {
589         ui8Value = 0xFF;
590     }
591 
592     //
593     // Write the ALMUP register.
594     //
595     AM_REG(RTC, ALMUP) =
596         AM_REG_RTC_ALMUP_ALMWKDY((pTime->ui32Weekday))                     |
597         AM_REG_RTC_ALMUP_ALMMO(dec_to_bcd((pTime->ui32Month)))             |
598         AM_REG_RTC_ALMUP_ALMDATE(dec_to_bcd((pTime->ui32DayOfMonth)));
599 
600     //
601     // Write the ALMLOW register.
602     //
603     AM_REG(RTC, ALMLOW) =
604         AM_REG_RTC_ALMLOW_ALMHR(dec_to_bcd(pTime->ui32Hour))                |
605         AM_REG_RTC_ALMLOW_ALMMIN(dec_to_bcd(pTime->ui32Minute))             |
606         AM_REG_RTC_ALMLOW_ALMSEC(dec_to_bcd(pTime->ui32Second))             |
607         AM_REG_RTC_ALMLOW_ALM100(dec_to_bcd(pTime->ui32Hundredths) | ui8Value);
608 }
609 
610 //*****************************************************************************
611 //
612 //! @brief Get the Real Time Clock Alarm Parameters
613 //!
614 //! @param *pTime - A pointer to the time structure to store the current alarm.
615 //!
616 //! Gets the RTC's Alarm time
617 //!
618 //! @return None.
619 //
620 //*****************************************************************************
621 void
am_hal_rtc_alarm_get(am_hal_rtc_time_t * pTime)622 am_hal_rtc_alarm_get(am_hal_rtc_time_t *pTime)
623 {
624     uint32_t ui32ALMLow, ui32ALMUp, ui32Value;
625 
626     //
627     // Read the upper and lower RTC registers.
628     //
629     ui32ALMLow = AM_REG(RTC, ALMLOW);
630     ui32ALMUp = AM_REG(RTC, ALMUP);
631 
632     //
633     // Break out the lower word.
634     //
635     ui32Value =
636         ((ui32ALMLow & AM_REG_RTC_ALMLOW_ALMHR_M) >> AM_REG_RTC_ALMLOW_ALMHR_S);
637     pTime->ui32Hour = bcd_to_dec(ui32Value);
638 
639     ui32Value =
640         ((ui32ALMLow & AM_REG_RTC_ALMLOW_ALMMIN_M) >> AM_REG_RTC_ALMLOW_ALMMIN_S);
641     pTime->ui32Minute = bcd_to_dec(ui32Value);
642 
643     ui32Value =
644         ((ui32ALMLow & AM_REG_RTC_ALMLOW_ALMSEC_M) >> AM_REG_RTC_ALMLOW_ALMSEC_S);
645     pTime->ui32Second = bcd_to_dec(ui32Value);
646 
647     ui32Value =
648         ((ui32ALMLow & AM_REG_RTC_ALMLOW_ALM100_M) >> AM_REG_RTC_ALMLOW_ALM100_S);
649     pTime->ui32Hundredths = bcd_to_dec(ui32Value);
650 
651     //
652     // Break out the upper word.
653     //
654     pTime->ui32ReadError = 0;
655     pTime->ui32CenturyEnable = 0;
656     pTime->ui32Century = 0;
657 
658     ui32Value =
659         ((ui32ALMUp & AM_REG_RTC_ALMUP_ALMWKDY_M) >> AM_REG_RTC_ALMUP_ALMWKDY_S);
660     pTime->ui32Weekday = bcd_to_dec(ui32Value);
661 
662     pTime->ui32Year = 0;
663 
664     ui32Value =
665         ((ui32ALMUp & AM_REG_RTC_ALMUP_ALMMO_M) >> AM_REG_RTC_ALMUP_ALMMO_S);
666     pTime->ui32Month = bcd_to_dec(ui32Value);
667 
668     ui32Value =
669         ((ui32ALMUp & AM_REG_RTC_ALMUP_ALMDATE_M) >> AM_REG_RTC_ALMUP_ALMDATE_S);
670     pTime->ui32DayOfMonth = bcd_to_dec(ui32Value);
671 }
672 
673 //*****************************************************************************
674 //
675 // End Doxygen group.
676 //! @}
677 //
678 //*****************************************************************************
679