Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 95060d5b in mainline


Ignore:
Timestamp:
2012-04-13T20:23:29Z (10 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master
Children:
1170ea3
Parents:
bb8f69d
Message:

rtc: introduce support to 12h mode of operation

Location:
uspace/drv/time/cmos-rtc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/time/cmos-rtc/cmos-regs.h

    rbb8f69d r95060d5b  
    3838
    3939#define RTC_STATUS_B    0x0B
     40#define RTC_MASK_24H    0x02
    4041#define RTC_MASK_BCD    0x04
    4142
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    rbb8f69d r95060d5b  
    268268{
    269269        bool bcd_mode;
     270        bool pm_mode = false;
    270271        rtc_t *rtc = RTC_FROM_FNODE(fun);
    271272
     
    290291                 t->tm_mon  != rtc_register_read(rtc, RTC_MON) ||
    291292                 t->tm_year != rtc_register_read(rtc, RTC_YEAR));
     293
     294        /* Check if the RTC is working in 12h mode */
     295        bool _12h_mode = !(rtc_register_read(rtc, RTC_STATUS_B) &
     296            RTC_MASK_24H);
     297
     298        if (_12h_mode) {
     299                /* The RTC is working in 12h mode, check if it is AM or PM */
     300                if (t->tm_hour & 0x80) {
     301                        /* PM flag is active, it must to be cleared
     302                         * or the BCD conversion will fail.
     303                         */
     304                        t->tm_hour &= ~0x80;
     305                        pm_mode = true;
     306                }
     307        }
    292308
    293309        /* Check if the RTC is working in BCD mode */
     
    301317                t->tm_mon  = bcd2dec(t->tm_mon);
    302318                t->tm_year = bcd2dec(t->tm_year);
     319        }
     320
     321        if (_12h_mode) {
     322                /* Convert to 24h mode */
     323                if (pm_mode) {
     324                        if (t->tm_hour < 12)
     325                                t->tm_hour += 12;
     326                } else if (t->tm_hour == 12)
     327                        t->tm_hour = 0;
    303328        }
    304329
Note: See TracChangeset for help on using the changeset viewer.