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

Changeset a8a0d43 in mainline


Ignore:
Timestamp:
2012-04-14T18:08:21Z (10 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master
Children:
80d3f846
Parents:
cf72943
Message:

rtc: inhibit updates, write the cmos registers and then restore normal working conditions

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

Legend:

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

    rcf72943 ra8a0d43  
    3030#define _CMOS_RTC_H_
    3131
    32 #define RTC_SEC         0x00
    33 #define RTC_MIN         0x02
    34 #define RTC_HOUR        0x04
    35 #define RTC_DAY         0x07
    36 #define RTC_MON         0x08
    37 #define RTC_YEAR        0x09
     32#define RTC_SEC           0x00
     33#define RTC_MIN           0x02
     34#define RTC_HOUR          0x04
     35#define RTC_DAY           0x07
     36#define RTC_MON           0x08
     37#define RTC_YEAR          0x09
    3838
    39 #define RTC_STATUS_B    0x0B
    40 #define RTC_MASK_24H    0x02 /* 24h mode */
    41 #define RTC_MASK_BCD    0x04 /* BCD mode */
     39#define RTC_STATUS_B      0x0B
     40#define RTC_MASK_24H      0x02 /* 24h mode */
     41#define RTC_MASK_BCD      0x04 /* BCD mode */
     42#define RTC_MASK_INH      0x80 /* Inhibit updates */
    4243
    43 #define RTC_STATUS_D    0x0D
    44 #define RTC_BATTERY_OK  0x80 /* Battery status */
     44#define RTC_STATUS_D      0x0D
     45#define RTC_BATTERY_OK    0x80 /* Battery status */
    4546
    46 #define RTC_STATUS_A    0x0A
    47 #define RTC_MASK_UPDATE 0x80 /* Update in progress */
     47#define RTC_STATUS_A      0x0A
     48#define RTC_MASK_UPDATE   0x80 /* Update in progress */
     49#define RTC_MASK_CLK_STOP 0x70 /* Stop the clock */
    4850
    4951#endif
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    rcf72943 ra8a0d43  
    9191static int rtc_dev_remove(ddf_dev_t *dev);
    9292static int rtc_tm_sanity_check(struct tm *t);
     93static void rtc_register_write(rtc_t *rtc, int reg, int data);
    9394
    9495
     
    247248}
    248249
    249 /* XXX */
    250 #if 0
    251250/** Write a register to the CMOS memory
    252251 *
     
    261260        pio_write_8(rtc->port + 1, data);
    262261}
    263 
    264 #endif
    265 
    266 /* XXX */
    267262
    268263/** Check if an update is in progress
     
    373368rtc_time_set(ddf_fun_t *fun, struct tm *t)
    374369{
    375         int rc;
     370        int  rc;
    376371        bool bcd_mode;
     372        int  reg_b;
     373        int  reg_a;
    377374        rtc_t *rtc = RTC_FROM_FNODE(fun);
    378375
     
    381378                return rc;
    382379
    383         t->tm_mon++; /* Must start from 1, not from 0 */
     380        t->tm_mon++; /* counts from 1, not from 0 */
    384381
    385382        fibril_mutex_lock(&rtc->mutex);
    386383
     384        reg_b = rtc_register_read(rtc, RTC_STATUS_B);
     385
    387386        /* Check if the rtc is working in bcd mode */
    388         bcd_mode = !(rtc_register_read(rtc, RTC_STATUS_B) & RTC_MASK_BCD);
     387        bcd_mode = !(reg_b & RTC_MASK_BCD);
    389388        if (bcd_mode) {
    390389                /* Convert the tm struct fields in BCD mode */
     
    397396        }
    398397
    399         /* XXX Inhibit updates */
     398        /* Inhibit updates */
     399        rtc_register_write(rtc, RTC_STATUS_B, reg_b | RTC_MASK_INH);
     400
     401        /* Write current time to RTC */
     402        rtc_register_write(rtc, RTC_SEC, t->tm_sec);
     403        rtc_register_write(rtc, RTC_MIN, t->tm_min);
     404        rtc_register_write(rtc, RTC_HOUR, t->tm_hour);
     405        rtc_register_write(rtc, RTC_DAY, t->tm_mday);
     406        rtc_register_write(rtc, RTC_MON, t->tm_mon);
     407        rtc_register_write(rtc, RTC_YEAR, t->tm_year);
     408
     409        /* Stop the clock */
     410        reg_a = rtc_register_read(rtc, RTC_STATUS_A);
     411        rtc_register_write(rtc, RTC_STATUS_A, RTC_MASK_CLK_STOP | reg_a);
     412       
     413        /* Enable updates */
     414        rtc_register_write(rtc, RTC_STATUS_B, reg_b);
     415        rtc_register_write(rtc, RTC_STATUS_A, reg_a);
    400416
    401417        fibril_mutex_unlock(&rtc->mutex);
Note: See TracChangeset for help on using the changeset viewer.