Changeset db8d552 in mainline
- Timestamp:
- 2012-04-03T10:23:48Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 05ed9d7
- Parents:
- d9c11eed
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/time/cmos-rtc/cmos-rtc.c
rd9c11eed rdb8d552 80 80 static void rtc_close(ddf_fun_t *fun); 81 81 static bool rtc_update_in_progress(rtc_t *rtc); 82 static int rtc_register_read(ioport8_t *port, int reg); 82 static int rtc_register_read(rtc_t *rtc, int reg); 83 static int bcd2dec(int bcd); 83 84 84 85 … … 231 232 */ 232 233 static int 233 rtc_register_read( ioport8_t *port, int reg)234 { 235 pio_write_8( port, reg);236 return pio_read_8( port + 1);234 rtc_register_read(rtc_t *rtc, int reg) 235 { 236 pio_write_8(rtc->port, reg); 237 return pio_read_8(rtc->port + 1); 237 238 } 238 239 … … 246 247 rtc_update_in_progress(rtc_t *rtc) 247 248 { 248 return rtc_register_read(rtc ->port, RTC_UPDATE) & RTC_MASK_UPDATE;249 return rtc_register_read(rtc, RTC_UPDATE) & RTC_MASK_UPDATE; 249 250 } 250 251 … … 259 260 rtc_time_get(ddf_fun_t *fun, struct tm *t) 260 261 { 262 bool bcd_mode; 261 263 rtc_t *rtc = RTC_FROM_FNODE(fun); 262 264 263 265 fibril_mutex_lock(&rtc->mutex); 264 266 265 while (rtc_update_in_progress(rtc)); 267 /* now read the registers */ 268 do { 269 /* Suspend until the update process has finished */ 270 while (rtc_update_in_progress(rtc)); 271 272 t->tm_sec = rtc_register_read(rtc, RTC_SEC); 273 t->tm_min = rtc_register_read(rtc, RTC_MIN); 274 t->tm_hour = rtc_register_read(rtc, RTC_HOUR); 275 t->tm_mday = rtc_register_read(rtc, RTC_DAY); 276 t->tm_mon = rtc_register_read(rtc, RTC_MON); 277 t->tm_year = rtc_register_read(rtc, RTC_YEAR); 278 279 /* Now check if it is stable */ 280 } while( t->tm_sec != rtc_register_read(rtc, RTC_SEC) || 281 t->tm_min != rtc_register_read(rtc, RTC_MIN) || 282 t->tm_mday != rtc_register_read(rtc, RTC_DAY) || 283 t->tm_mon != rtc_register_read(rtc, RTC_MON) || 284 t->tm_year != rtc_register_read(rtc, RTC_YEAR)); 285 286 /* Check if the RTC is working in BCD mode */ 287 bcd_mode = rtc_register_read(rtc, RTC_STATUS_B) & RTC_MASK_BCD; 288 289 if (bcd_mode) { 290 t->tm_sec = bcd2dec(t->tm_sec); 291 t->tm_min = bcd2dec(t->tm_min); 292 t->tm_hour = bcd2dec(t->tm_hour); 293 t->tm_mday = bcd2dec(t->tm_mday); 294 t->tm_mon = bcd2dec(t->tm_mon); 295 t->tm_year = bcd2dec(t->tm_year); 296 } 266 297 267 298 fibril_mutex_unlock(&rtc->mutex); … … 392 423 } 393 424 425 /** Convert from BCD mode to binary mode 426 * 427 * @param bcd The number in BCD format to convert 428 * 429 * @return The converted value 430 */ 431 static int 432 bcd2dec(int bcd) 433 { 434 return ((bcd & 0xF0) >> 1) + ((bcd & 0xF0) >> 3) + (bcd & 0xf); 435 } 436 394 437 int 395 438 main(int argc, char **argv)
Note:
See TracChangeset
for help on using the changeset viewer.