Example #1
0
/* get 1/100 seconds from clock */
BYTE rtc_get_centisecond(int bcd)
{
#ifdef HAVE_GETTIMEOFDAY
    struct timeval t;

    gettimeofday(&t, NULL);
    return (BYTE)((bcd) ? int_to_bcd(t.tv_usec / 10000) : t.tv_usec / 10000);
#else
    return (BYTE)((bcd) ? int_to_bcd(archdep_rtc_get_centisecond()) : archdep_rtc_get_centisecond());
#endif
}
Example #2
0
/* get hours from time value
   0 - 23 */
BYTE rtc_get_hour(time_t time_val, int bcd)
{
    time_t now = time_val;
    struct tm *local = localtime(&now);

    return (BYTE)((bcd) ? int_to_bcd(local->tm_hour) : local->tm_hour);
}
Example #3
0
/* get the century from time value
   19 - 20 */
BYTE rtc_get_century(time_t time_val, int bcd)
{
    time_t now = time_val;
    struct tm *local = localtime(&now);

    return (BYTE)((bcd) ? int_to_bcd((int)(local->tm_year / 100) + 19) : (int)(local->tm_year / 100) + 19);
}
Example #4
0
/* get day of month from time value
   1 - 31 */
BYTE rtc_get_day_of_month(time_t time_val, int bcd)
{
    time_t now = time_val;
    struct tm *local = localtime(&now);

    return (BYTE)((bcd) ? int_to_bcd(local->tm_mday) : local->tm_mday);
}
Example #5
0
/* get 1/100 seconds from clock */
BYTE rtc_get_centisecond(int bcd)
{
#ifdef HAVE_GETTIMEOFDAY
    struct timeval t;

    gettimeofday(&t, NULL);
    return (BYTE)((bcd) ? int_to_bcd(t.tv_usec / 10000) : t.tv_usec / 10000);
#else
    /* FIXME: arch-dependent implementation will need to be made */
    #error not implemented
#endif
}
Example #6
0
/* get hours from time_value
   1 - 12 + AM/PM flag in bit 5 (0 = PM, 1 = AM) */
BYTE rtc_get_hour_am_pm(time_t time_val, int bcd)
{
    BYTE hour;
    int pm = 0;
    time_t now = time_val;
    struct tm *local = localtime(&now);

    hour = local->tm_hour;

    if (hour == 0) {
        hour = 12;
    } else if (hour == 12) {
        pm = 1;
    } else if (hour > 12) {
        hour -= 12;
        pm = 1;
    }
    hour = (BYTE)((bcd) ? int_to_bcd(hour) : hour);
    hour |= (pm << 5);
    return hour;
}