Revision abd0c6bd
b/hw/m48t59.c | ||
---|---|---|
80 | 80 |
} M48t59SysBusState; |
81 | 81 |
|
82 | 82 |
/* Fake timer functions */ |
83 |
/* Generic helpers for BCD */ |
|
84 |
static inline uint8_t toBCD (uint8_t value) |
|
85 |
{ |
|
86 |
return (((value / 10) % 10) << 4) | (value % 10); |
|
87 |
} |
|
88 |
|
|
89 |
static inline uint8_t fromBCD (uint8_t BCD) |
|
90 |
{ |
|
91 |
return ((BCD >> 4) * 10) + (BCD & 0x0F); |
|
92 |
} |
|
93 | 83 |
|
94 | 84 |
/* Alarm management */ |
95 | 85 |
static void alarm_cb (void *opaque) |
... | ... | |
219 | 209 |
break; |
220 | 210 |
case 0x1FF2: |
221 | 211 |
/* alarm seconds */ |
222 |
tmp = fromBCD(val & 0x7F);
|
|
212 |
tmp = from_bcd(val & 0x7F);
|
|
223 | 213 |
if (tmp >= 0 && tmp <= 59) { |
224 | 214 |
NVRAM->alarm.tm_sec = tmp; |
225 | 215 |
NVRAM->buffer[0x1FF2] = val; |
... | ... | |
228 | 218 |
break; |
229 | 219 |
case 0x1FF3: |
230 | 220 |
/* alarm minutes */ |
231 |
tmp = fromBCD(val & 0x7F);
|
|
221 |
tmp = from_bcd(val & 0x7F);
|
|
232 | 222 |
if (tmp >= 0 && tmp <= 59) { |
233 | 223 |
NVRAM->alarm.tm_min = tmp; |
234 | 224 |
NVRAM->buffer[0x1FF3] = val; |
... | ... | |
237 | 227 |
break; |
238 | 228 |
case 0x1FF4: |
239 | 229 |
/* alarm hours */ |
240 |
tmp = fromBCD(val & 0x3F);
|
|
230 |
tmp = from_bcd(val & 0x3F);
|
|
241 | 231 |
if (tmp >= 0 && tmp <= 23) { |
242 | 232 |
NVRAM->alarm.tm_hour = tmp; |
243 | 233 |
NVRAM->buffer[0x1FF4] = val; |
... | ... | |
246 | 236 |
break; |
247 | 237 |
case 0x1FF5: |
248 | 238 |
/* alarm date */ |
249 |
tmp = fromBCD(val & 0x1F);
|
|
239 |
tmp = from_bcd(val & 0x1F);
|
|
250 | 240 |
if (tmp != 0) { |
251 | 241 |
NVRAM->alarm.tm_mday = tmp; |
252 | 242 |
NVRAM->buffer[0x1FF5] = val; |
... | ... | |
270 | 260 |
case 0x1FF9: |
271 | 261 |
case 0x07F9: |
272 | 262 |
/* seconds (BCD) */ |
273 |
tmp = fromBCD(val & 0x7F);
|
|
263 |
tmp = from_bcd(val & 0x7F);
|
|
274 | 264 |
if (tmp >= 0 && tmp <= 59) { |
275 | 265 |
get_time(NVRAM, &tm); |
276 | 266 |
tm.tm_sec = tmp; |
... | ... | |
289 | 279 |
case 0x1FFA: |
290 | 280 |
case 0x07FA: |
291 | 281 |
/* minutes (BCD) */ |
292 |
tmp = fromBCD(val & 0x7F);
|
|
282 |
tmp = from_bcd(val & 0x7F);
|
|
293 | 283 |
if (tmp >= 0 && tmp <= 59) { |
294 | 284 |
get_time(NVRAM, &tm); |
295 | 285 |
tm.tm_min = tmp; |
... | ... | |
299 | 289 |
case 0x1FFB: |
300 | 290 |
case 0x07FB: |
301 | 291 |
/* hours (BCD) */ |
302 |
tmp = fromBCD(val & 0x3F);
|
|
292 |
tmp = from_bcd(val & 0x3F);
|
|
303 | 293 |
if (tmp >= 0 && tmp <= 23) { |
304 | 294 |
get_time(NVRAM, &tm); |
305 | 295 |
tm.tm_hour = tmp; |
... | ... | |
309 | 299 |
case 0x1FFC: |
310 | 300 |
case 0x07FC: |
311 | 301 |
/* day of the week / century */ |
312 |
tmp = fromBCD(val & 0x07);
|
|
302 |
tmp = from_bcd(val & 0x07);
|
|
313 | 303 |
get_time(NVRAM, &tm); |
314 | 304 |
tm.tm_wday = tmp; |
315 | 305 |
set_time(NVRAM, &tm); |
... | ... | |
318 | 308 |
case 0x1FFD: |
319 | 309 |
case 0x07FD: |
320 | 310 |
/* date */ |
321 |
tmp = fromBCD(val & 0x1F);
|
|
311 |
tmp = from_bcd(val & 0x1F);
|
|
322 | 312 |
if (tmp != 0) { |
323 | 313 |
get_time(NVRAM, &tm); |
324 | 314 |
tm.tm_mday = tmp; |
... | ... | |
328 | 318 |
case 0x1FFE: |
329 | 319 |
case 0x07FE: |
330 | 320 |
/* month */ |
331 |
tmp = fromBCD(val & 0x1F);
|
|
321 |
tmp = from_bcd(val & 0x1F);
|
|
332 | 322 |
if (tmp >= 1 && tmp <= 12) { |
333 | 323 |
get_time(NVRAM, &tm); |
334 | 324 |
tm.tm_mon = tmp - 1; |
... | ... | |
338 | 328 |
case 0x1FFF: |
339 | 329 |
case 0x07FF: |
340 | 330 |
/* year */ |
341 |
tmp = fromBCD(val);
|
|
331 |
tmp = from_bcd(val);
|
|
342 | 332 |
if (tmp >= 0 && tmp <= 99) { |
343 | 333 |
get_time(NVRAM, &tm); |
344 | 334 |
if (NVRAM->type == 8) |
345 |
tm.tm_year = fromBCD(val) + 68; // Base year is 1968
|
|
335 |
tm.tm_year = from_bcd(val) + 68; // Base year is 1968
|
|
346 | 336 |
else |
347 |
tm.tm_year = fromBCD(val);
|
|
337 |
tm.tm_year = from_bcd(val);
|
|
348 | 338 |
set_time(NVRAM, &tm); |
349 | 339 |
} |
350 | 340 |
break; |
... | ... | |
410 | 400 |
case 0x07F9: |
411 | 401 |
/* seconds (BCD) */ |
412 | 402 |
get_time(NVRAM, &tm); |
413 |
retval = (NVRAM->buffer[addr] & 0x80) | toBCD(tm.tm_sec);
|
|
403 |
retval = (NVRAM->buffer[addr] & 0x80) | to_bcd(tm.tm_sec);
|
|
414 | 404 |
break; |
415 | 405 |
case 0x1FFA: |
416 | 406 |
case 0x07FA: |
417 | 407 |
/* minutes (BCD) */ |
418 | 408 |
get_time(NVRAM, &tm); |
419 |
retval = toBCD(tm.tm_min);
|
|
409 |
retval = to_bcd(tm.tm_min);
|
|
420 | 410 |
break; |
421 | 411 |
case 0x1FFB: |
422 | 412 |
case 0x07FB: |
423 | 413 |
/* hours (BCD) */ |
424 | 414 |
get_time(NVRAM, &tm); |
425 |
retval = toBCD(tm.tm_hour);
|
|
415 |
retval = to_bcd(tm.tm_hour);
|
|
426 | 416 |
break; |
427 | 417 |
case 0x1FFC: |
428 | 418 |
case 0x07FC: |
... | ... | |
434 | 424 |
case 0x07FD: |
435 | 425 |
/* date */ |
436 | 426 |
get_time(NVRAM, &tm); |
437 |
retval = toBCD(tm.tm_mday);
|
|
427 |
retval = to_bcd(tm.tm_mday);
|
|
438 | 428 |
break; |
439 | 429 |
case 0x1FFE: |
440 | 430 |
case 0x07FE: |
441 | 431 |
/* month */ |
442 | 432 |
get_time(NVRAM, &tm); |
443 |
retval = toBCD(tm.tm_mon + 1);
|
|
433 |
retval = to_bcd(tm.tm_mon + 1);
|
|
444 | 434 |
break; |
445 | 435 |
case 0x1FFF: |
446 | 436 |
case 0x07FF: |
447 | 437 |
/* year */ |
448 | 438 |
get_time(NVRAM, &tm); |
449 | 439 |
if (NVRAM->type == 8) |
450 |
retval = toBCD(tm.tm_year - 68); // Base year is 1968
|
|
440 |
retval = to_bcd(tm.tm_year - 68); // Base year is 1968
|
|
451 | 441 |
else |
452 |
retval = toBCD(tm.tm_year);
|
|
442 |
retval = to_bcd(tm.tm_year);
|
|
453 | 443 |
break; |
454 | 444 |
default: |
455 | 445 |
/* Check lock registers state */ |
b/hw/mc146818rtc.c | ||
---|---|---|
259 | 259 |
} |
260 | 260 |
} |
261 | 261 |
|
262 |
static inline int to_bcd(RTCState *s, int a) |
|
262 |
static inline int rtc_to_bcd(RTCState *s, int a)
|
|
263 | 263 |
{ |
264 | 264 |
if (s->cmos_data[RTC_REG_B] & REG_B_DM) { |
265 | 265 |
return a; |
... | ... | |
268 | 268 |
} |
269 | 269 |
} |
270 | 270 |
|
271 |
static inline int from_bcd(RTCState *s, int a) |
|
271 |
static inline int rtc_from_bcd(RTCState *s, int a)
|
|
272 | 272 |
{ |
273 | 273 |
if (s->cmos_data[RTC_REG_B] & REG_B_DM) { |
274 | 274 |
return a; |
... | ... | |
281 | 281 |
{ |
282 | 282 |
struct tm *tm = &s->current_tm; |
283 | 283 |
|
284 |
tm->tm_sec = from_bcd(s, s->cmos_data[RTC_SECONDS]); |
|
285 |
tm->tm_min = from_bcd(s, s->cmos_data[RTC_MINUTES]); |
|
286 |
tm->tm_hour = from_bcd(s, s->cmos_data[RTC_HOURS] & 0x7f); |
|
284 |
tm->tm_sec = rtc_from_bcd(s, s->cmos_data[RTC_SECONDS]);
|
|
285 |
tm->tm_min = rtc_from_bcd(s, s->cmos_data[RTC_MINUTES]);
|
|
286 |
tm->tm_hour = rtc_from_bcd(s, s->cmos_data[RTC_HOURS] & 0x7f);
|
|
287 | 287 |
if (!(s->cmos_data[RTC_REG_B] & 0x02) && |
288 | 288 |
(s->cmos_data[RTC_HOURS] & 0x80)) { |
289 | 289 |
tm->tm_hour += 12; |
290 | 290 |
} |
291 |
tm->tm_wday = from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1; |
|
292 |
tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]); |
|
293 |
tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1; |
|
294 |
tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + s->base_year - 1900; |
|
291 |
tm->tm_wday = rtc_from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1;
|
|
292 |
tm->tm_mday = rtc_from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
|
|
293 |
tm->tm_mon = rtc_from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
|
|
294 |
tm->tm_year = rtc_from_bcd(s, s->cmos_data[RTC_YEAR]) + s->base_year - 1900;
|
|
295 | 295 |
} |
296 | 296 |
|
297 | 297 |
static void rtc_copy_date(RTCState *s) |
... | ... | |
299 | 299 |
const struct tm *tm = &s->current_tm; |
300 | 300 |
int year; |
301 | 301 |
|
302 |
s->cmos_data[RTC_SECONDS] = to_bcd(s, tm->tm_sec); |
|
303 |
s->cmos_data[RTC_MINUTES] = to_bcd(s, tm->tm_min); |
|
302 |
s->cmos_data[RTC_SECONDS] = rtc_to_bcd(s, tm->tm_sec);
|
|
303 |
s->cmos_data[RTC_MINUTES] = rtc_to_bcd(s, tm->tm_min);
|
|
304 | 304 |
if (s->cmos_data[RTC_REG_B] & 0x02) { |
305 | 305 |
/* 24 hour format */ |
306 |
s->cmos_data[RTC_HOURS] = to_bcd(s, tm->tm_hour); |
|
306 |
s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour);
|
|
307 | 307 |
} else { |
308 | 308 |
/* 12 hour format */ |
309 |
s->cmos_data[RTC_HOURS] = to_bcd(s, tm->tm_hour % 12); |
|
309 |
s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour % 12);
|
|
310 | 310 |
if (tm->tm_hour >= 12) |
311 | 311 |
s->cmos_data[RTC_HOURS] |= 0x80; |
312 | 312 |
} |
313 |
s->cmos_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday + 1); |
|
314 |
s->cmos_data[RTC_DAY_OF_MONTH] = to_bcd(s, tm->tm_mday); |
|
315 |
s->cmos_data[RTC_MONTH] = to_bcd(s, tm->tm_mon + 1); |
|
313 |
s->cmos_data[RTC_DAY_OF_WEEK] = rtc_to_bcd(s, tm->tm_wday + 1);
|
|
314 |
s->cmos_data[RTC_DAY_OF_MONTH] = rtc_to_bcd(s, tm->tm_mday);
|
|
315 |
s->cmos_data[RTC_MONTH] = rtc_to_bcd(s, tm->tm_mon + 1);
|
|
316 | 316 |
year = (tm->tm_year - s->base_year) % 100; |
317 | 317 |
if (year < 0) |
318 | 318 |
year += 100; |
319 |
s->cmos_data[RTC_YEAR] = to_bcd(s, year); |
|
319 |
s->cmos_data[RTC_YEAR] = rtc_to_bcd(s, year);
|
|
320 | 320 |
} |
321 | 321 |
|
322 | 322 |
/* month is between 0 and 11. */ |
... | ... | |
497 | 497 |
qemu_get_timedate(&tm, 0); |
498 | 498 |
rtc_set_date(s, &tm); |
499 | 499 |
|
500 |
val = to_bcd(s, (tm.tm_year / 100) + 19); |
|
500 |
val = rtc_to_bcd(s, (tm.tm_year / 100) + 19);
|
|
501 | 501 |
rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val); |
502 | 502 |
rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); |
503 | 503 |
} |
b/hw/omap1.c | ||
---|---|---|
3358 | 3358 |
printf("%s: conversion failed\n", __FUNCTION__); |
3359 | 3359 |
} |
3360 | 3360 |
|
3361 |
static inline uint8_t omap_rtc_bcd(int num) |
|
3362 |
{ |
|
3363 |
return ((num / 10) << 4) | (num % 10); |
|
3364 |
} |
|
3365 |
|
|
3366 |
static inline int omap_rtc_bin(uint8_t num) |
|
3367 |
{ |
|
3368 |
return (num & 15) + 10 * (num >> 4); |
|
3369 |
} |
|
3370 |
|
|
3371 | 3361 |
static uint32_t omap_rtc_read(void *opaque, target_phys_addr_t addr) |
3372 | 3362 |
{ |
3373 | 3363 |
struct omap_rtc_s *s = (struct omap_rtc_s *) opaque; |
... | ... | |
3376 | 3366 |
|
3377 | 3367 |
switch (offset) { |
3378 | 3368 |
case 0x00: /* SECONDS_REG */ |
3379 |
return omap_rtc_bcd(s->current_tm.tm_sec);
|
|
3369 |
return to_bcd(s->current_tm.tm_sec);
|
|
3380 | 3370 |
|
3381 | 3371 |
case 0x04: /* MINUTES_REG */ |
3382 |
return omap_rtc_bcd(s->current_tm.tm_min);
|
|
3372 |
return to_bcd(s->current_tm.tm_min);
|
|
3383 | 3373 |
|
3384 | 3374 |
case 0x08: /* HOURS_REG */ |
3385 | 3375 |
if (s->pm_am) |
3386 | 3376 |
return ((s->current_tm.tm_hour > 11) << 7) | |
3387 |
omap_rtc_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
|
|
3377 |
to_bcd(((s->current_tm.tm_hour - 1) % 12) + 1);
|
|
3388 | 3378 |
else |
3389 |
return omap_rtc_bcd(s->current_tm.tm_hour);
|
|
3379 |
return to_bcd(s->current_tm.tm_hour);
|
|
3390 | 3380 |
|
3391 | 3381 |
case 0x0c: /* DAYS_REG */ |
3392 |
return omap_rtc_bcd(s->current_tm.tm_mday);
|
|
3382 |
return to_bcd(s->current_tm.tm_mday);
|
|
3393 | 3383 |
|
3394 | 3384 |
case 0x10: /* MONTHS_REG */ |
3395 |
return omap_rtc_bcd(s->current_tm.tm_mon + 1);
|
|
3385 |
return to_bcd(s->current_tm.tm_mon + 1);
|
|
3396 | 3386 |
|
3397 | 3387 |
case 0x14: /* YEARS_REG */ |
3398 |
return omap_rtc_bcd(s->current_tm.tm_year % 100);
|
|
3388 |
return to_bcd(s->current_tm.tm_year % 100);
|
|
3399 | 3389 |
|
3400 | 3390 |
case 0x18: /* WEEK_REG */ |
3401 | 3391 |
return s->current_tm.tm_wday; |
3402 | 3392 |
|
3403 | 3393 |
case 0x20: /* ALARM_SECONDS_REG */ |
3404 |
return omap_rtc_bcd(s->alarm_tm.tm_sec);
|
|
3394 |
return to_bcd(s->alarm_tm.tm_sec);
|
|
3405 | 3395 |
|
3406 | 3396 |
case 0x24: /* ALARM_MINUTES_REG */ |
3407 |
return omap_rtc_bcd(s->alarm_tm.tm_min);
|
|
3397 |
return to_bcd(s->alarm_tm.tm_min);
|
|
3408 | 3398 |
|
3409 | 3399 |
case 0x28: /* ALARM_HOURS_REG */ |
3410 | 3400 |
if (s->pm_am) |
3411 | 3401 |
return ((s->alarm_tm.tm_hour > 11) << 7) | |
3412 |
omap_rtc_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
|
|
3402 |
to_bcd(((s->alarm_tm.tm_hour - 1) % 12) + 1);
|
|
3413 | 3403 |
else |
3414 |
return omap_rtc_bcd(s->alarm_tm.tm_hour);
|
|
3404 |
return to_bcd(s->alarm_tm.tm_hour);
|
|
3415 | 3405 |
|
3416 | 3406 |
case 0x2c: /* ALARM_DAYS_REG */ |
3417 |
return omap_rtc_bcd(s->alarm_tm.tm_mday);
|
|
3407 |
return to_bcd(s->alarm_tm.tm_mday);
|
|
3418 | 3408 |
|
3419 | 3409 |
case 0x30: /* ALARM_MONTHS_REG */ |
3420 |
return omap_rtc_bcd(s->alarm_tm.tm_mon + 1);
|
|
3410 |
return to_bcd(s->alarm_tm.tm_mon + 1);
|
|
3421 | 3411 |
|
3422 | 3412 |
case 0x34: /* ALARM_YEARS_REG */ |
3423 |
return omap_rtc_bcd(s->alarm_tm.tm_year % 100);
|
|
3413 |
return to_bcd(s->alarm_tm.tm_year % 100);
|
|
3424 | 3414 |
|
3425 | 3415 |
case 0x40: /* RTC_CTRL_REG */ |
3426 | 3416 |
return (s->pm_am << 3) | (s->auto_comp << 2) | |
... | ... | |
3459 | 3449 |
printf("RTC SEC_REG <-- %02x\n", value); |
3460 | 3450 |
#endif |
3461 | 3451 |
s->ti -= s->current_tm.tm_sec; |
3462 |
s->ti += omap_rtc_bin(value);
|
|
3452 |
s->ti += from_bcd(value);
|
|
3463 | 3453 |
return; |
3464 | 3454 |
|
3465 | 3455 |
case 0x04: /* MINUTES_REG */ |
... | ... | |
3467 | 3457 |
printf("RTC MIN_REG <-- %02x\n", value); |
3468 | 3458 |
#endif |
3469 | 3459 |
s->ti -= s->current_tm.tm_min * 60; |
3470 |
s->ti += omap_rtc_bin(value) * 60;
|
|
3460 |
s->ti += from_bcd(value) * 60;
|
|
3471 | 3461 |
return; |
3472 | 3462 |
|
3473 | 3463 |
case 0x08: /* HOURS_REG */ |
... | ... | |
3476 | 3466 |
#endif |
3477 | 3467 |
s->ti -= s->current_tm.tm_hour * 3600; |
3478 | 3468 |
if (s->pm_am) { |
3479 |
s->ti += (omap_rtc_bin(value & 0x3f) & 12) * 3600;
|
|
3469 |
s->ti += (from_bcd(value & 0x3f) & 12) * 3600;
|
|
3480 | 3470 |
s->ti += ((value >> 7) & 1) * 43200; |
3481 | 3471 |
} else |
3482 |
s->ti += omap_rtc_bin(value & 0x3f) * 3600;
|
|
3472 |
s->ti += from_bcd(value & 0x3f) * 3600;
|
|
3483 | 3473 |
return; |
3484 | 3474 |
|
3485 | 3475 |
case 0x0c: /* DAYS_REG */ |
... | ... | |
3487 | 3477 |
printf("RTC DAY_REG <-- %02x\n", value); |
3488 | 3478 |
#endif |
3489 | 3479 |
s->ti -= s->current_tm.tm_mday * 86400; |
3490 |
s->ti += omap_rtc_bin(value) * 86400;
|
|
3480 |
s->ti += from_bcd(value) * 86400;
|
|
3491 | 3481 |
return; |
3492 | 3482 |
|
3493 | 3483 |
case 0x10: /* MONTHS_REG */ |
... | ... | |
3495 | 3485 |
printf("RTC MTH_REG <-- %02x\n", value); |
3496 | 3486 |
#endif |
3497 | 3487 |
memcpy(&new_tm, &s->current_tm, sizeof(new_tm)); |
3498 |
new_tm.tm_mon = omap_rtc_bin(value);
|
|
3488 |
new_tm.tm_mon = from_bcd(value);
|
|
3499 | 3489 |
ti[0] = mktimegm(&s->current_tm); |
3500 | 3490 |
ti[1] = mktimegm(&new_tm); |
3501 | 3491 |
|
... | ... | |
3505 | 3495 |
} else { |
3506 | 3496 |
/* A less accurate version */ |
3507 | 3497 |
s->ti -= s->current_tm.tm_mon * 2592000; |
3508 |
s->ti += omap_rtc_bin(value) * 2592000;
|
|
3498 |
s->ti += from_bcd(value) * 2592000;
|
|
3509 | 3499 |
} |
3510 | 3500 |
return; |
3511 | 3501 |
|
... | ... | |
3514 | 3504 |
printf("RTC YRS_REG <-- %02x\n", value); |
3515 | 3505 |
#endif |
3516 | 3506 |
memcpy(&new_tm, &s->current_tm, sizeof(new_tm)); |
3517 |
new_tm.tm_year += omap_rtc_bin(value) - (new_tm.tm_year % 100);
|
|
3507 |
new_tm.tm_year += from_bcd(value) - (new_tm.tm_year % 100);
|
|
3518 | 3508 |
ti[0] = mktimegm(&s->current_tm); |
3519 | 3509 |
ti[1] = mktimegm(&new_tm); |
3520 | 3510 |
|
... | ... | |
3524 | 3514 |
} else { |
3525 | 3515 |
/* A less accurate version */ |
3526 | 3516 |
s->ti -= (s->current_tm.tm_year % 100) * 31536000; |
3527 |
s->ti += omap_rtc_bin(value) * 31536000;
|
|
3517 |
s->ti += from_bcd(value) * 31536000;
|
|
3528 | 3518 |
} |
3529 | 3519 |
return; |
3530 | 3520 |
|
... | ... | |
3535 | 3525 |
#ifdef ALMDEBUG |
3536 | 3526 |
printf("ALM SEC_REG <-- %02x\n", value); |
3537 | 3527 |
#endif |
3538 |
s->alarm_tm.tm_sec = omap_rtc_bin(value);
|
|
3528 |
s->alarm_tm.tm_sec = from_bcd(value);
|
|
3539 | 3529 |
omap_rtc_alarm_update(s); |
3540 | 3530 |
return; |
3541 | 3531 |
|
... | ... | |
3543 | 3533 |
#ifdef ALMDEBUG |
3544 | 3534 |
printf("ALM MIN_REG <-- %02x\n", value); |
3545 | 3535 |
#endif |
3546 |
s->alarm_tm.tm_min = omap_rtc_bin(value);
|
|
3536 |
s->alarm_tm.tm_min = from_bcd(value);
|
|
3547 | 3537 |
omap_rtc_alarm_update(s); |
3548 | 3538 |
return; |
3549 | 3539 |
|
... | ... | |
3553 | 3543 |
#endif |
3554 | 3544 |
if (s->pm_am) |
3555 | 3545 |
s->alarm_tm.tm_hour = |
3556 |
((omap_rtc_bin(value & 0x3f)) % 12) +
|
|
3546 |
((from_bcd(value & 0x3f)) % 12) +
|
|
3557 | 3547 |
((value >> 7) & 1) * 12; |
3558 | 3548 |
else |
3559 |
s->alarm_tm.tm_hour = omap_rtc_bin(value);
|
|
3549 |
s->alarm_tm.tm_hour = from_bcd(value);
|
|
3560 | 3550 |
omap_rtc_alarm_update(s); |
3561 | 3551 |
return; |
3562 | 3552 |
|
... | ... | |
3564 | 3554 |
#ifdef ALMDEBUG |
3565 | 3555 |
printf("ALM DAY_REG <-- %02x\n", value); |
3566 | 3556 |
#endif |
3567 |
s->alarm_tm.tm_mday = omap_rtc_bin(value);
|
|
3557 |
s->alarm_tm.tm_mday = from_bcd(value);
|
|
3568 | 3558 |
omap_rtc_alarm_update(s); |
3569 | 3559 |
return; |
3570 | 3560 |
|
... | ... | |
3572 | 3562 |
#ifdef ALMDEBUG |
3573 | 3563 |
printf("ALM MON_REG <-- %02x\n", value); |
3574 | 3564 |
#endif |
3575 |
s->alarm_tm.tm_mon = omap_rtc_bin(value);
|
|
3565 |
s->alarm_tm.tm_mon = from_bcd(value);
|
|
3576 | 3566 |
omap_rtc_alarm_update(s); |
3577 | 3567 |
return; |
3578 | 3568 |
|
... | ... | |
3580 | 3570 |
#ifdef ALMDEBUG |
3581 | 3571 |
printf("ALM YRS_REG <-- %02x\n", value); |
3582 | 3572 |
#endif |
3583 |
s->alarm_tm.tm_year = omap_rtc_bin(value);
|
|
3573 |
s->alarm_tm.tm_year = from_bcd(value);
|
|
3584 | 3574 |
omap_rtc_alarm_update(s); |
3585 | 3575 |
return; |
3586 | 3576 |
|
b/hw/twl92230.c | ||
---|---|---|
183 | 183 |
menelaus_update(s); |
184 | 184 |
} |
185 | 185 |
|
186 |
static inline uint8_t to_bcd(int val) |
|
187 |
{ |
|
188 |
return ((val / 10) << 4) | (val % 10); |
|
189 |
} |
|
190 |
|
|
191 |
static inline int from_bcd(uint8_t val) |
|
192 |
{ |
|
193 |
return ((val >> 4) * 10) + (val & 0x0f); |
|
194 |
} |
|
195 |
|
|
196 | 186 |
static void menelaus_gpio_set(void *opaque, int line, int level) |
197 | 187 |
{ |
198 | 188 |
MenelausState *s = (MenelausState *) opaque; |
b/qemu-common.h | ||
---|---|---|
248 | 248 |
struct Monitor; |
249 | 249 |
typedef struct Monitor Monitor; |
250 | 250 |
|
251 |
/* Convert a byte between binary and BCD. */ |
|
252 |
static inline uint8_t to_bcd(uint8_t val) |
|
253 |
{ |
|
254 |
return ((val / 10) << 4) | (val % 10); |
|
255 |
} |
|
256 |
|
|
257 |
static inline uint8_t from_bcd(uint8_t val) |
|
258 |
{ |
|
259 |
return ((val >> 4) * 10) + (val & 0x0f); |
|
260 |
} |
|
261 |
|
|
251 | 262 |
#include "module.h" |
252 | 263 |
|
253 | 264 |
#endif /* dyngen-exec.h hack */ |
Also available in: Unified diff