Changeset e5fbe06 in mainline
- Timestamp:
- 2012-04-18T00:17:52Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f4ebaf3c
- Parents:
- f004318
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/time/cmos-rtc/cmos-rtc.c
rf004318 re5fbe06 90 90 ipc_callid_t callid, ipc_call_t *call); 91 91 static int rtc_dev_remove(ddf_dev_t *dev); 92 static int rtc_tm_sanity_check(struct tm *t );92 static int rtc_tm_sanity_check(struct tm *t, int epoch); 93 93 static void rtc_register_write(rtc_t *rtc, int reg, int data); 94 94 static bool is_leap_year(int year); … … 287 287 bool bcd_mode; 288 288 bool pm_mode = false; 289 int epoch = 1900; 289 290 rtc_t *rtc = RTC_FROM_FNODE(fun); 290 291 … … 348 349 349 350 if (t->tm_year < 100) { 350 /* tm_year is the number of years since 1900 , it is not351 * possible it is < 100.351 /* tm_year is the number of years since 1900 but the 352 * RTC epoch is 2000. 352 353 */ 354 epoch = 2000; 353 355 t->tm_year += 100; 354 356 } … … 356 358 fibril_mutex_unlock(&rtc->mutex); 357 359 358 return rtc_tm_sanity_check(t );360 return rtc_tm_sanity_check(t, epoch); 359 361 } 360 362 … … 373 375 int reg_b; 374 376 int reg_a; 377 int epoch; 375 378 rtc_t *rtc = RTC_FROM_FNODE(fun); 376 379 377 rc = rtc_tm_sanity_check(t); 378 if (rc != EOK) 380 fibril_mutex_lock(&rtc->mutex); 381 382 /* Detect the RTC epoch */ 383 if (rtc_register_read(rtc, RTC_YEAR) < 100) 384 epoch = 2000; 385 else 386 epoch = 1900; 387 388 rc = rtc_tm_sanity_check(t, epoch); 389 if (rc != EOK) { 390 fibril_mutex_unlock(&rtc->mutex); 379 391 return rc; 392 } 380 393 381 394 t->tm_mon++; /* counts from 1, not from 0 */ 382 383 fibril_mutex_lock(&rtc->mutex);384 395 385 396 reg_b = rtc_register_read(rtc, RTC_STATUS_B); … … 435 446 * 436 447 * @param t The tm structure to check 448 * @param epoch The RTC epoch year 437 449 * 438 450 * @return EOK on success or EINVAL 439 451 */ 440 452 static int 441 rtc_tm_sanity_check(struct tm *t )453 rtc_tm_sanity_check(struct tm *t, int epoch) 442 454 { 443 455 int ndays; … … 453 465 else if (t->tm_mon < 0 || t->tm_mon > 11) 454 466 return EINVAL; 467 else if (epoch == 2000 && t->tm_year < 100) 468 return EINVAL; 455 469 else if (t->tm_year < 0) 456 470 return EINVAL;
Note:
See TracChangeset
for help on using the changeset viewer.