Ejemplo n.º 1
1
static void
ds1307_convert_to_time( struct rtc_time *dt, char *buf)
{
	dt->tm_sec = BCD_TO_BIN(buf[0]);
	dt->tm_min = BCD_TO_BIN(buf[1]);

	if ( TWELVE_HOUR_MODE(buf[2]) )
	{
		dt->tm_hour = HOURS_12(buf[2]);
		if (HOURS_AP(buf[2])) /* PM */
		{
			dt->tm_hour += 12;
		}
	}
	else /* 24-hour-mode */
	{
		dt->tm_hour = HOURS_24(buf[2]);
	}

	dt->tm_mday = BCD_TO_BIN(buf[4]);
	/* dt->tm_mon is zero-based */
	dt->tm_mon = BCD_TO_BIN(buf[5]) - 1;
	/* year is 1900 + dt->tm_year */
	dt->tm_year = BCD_TO_BIN(buf[6]) + 100;

	if( rtc_debug > 2)
	{
		printk("ds1307_get_datetime: year = %d\n", dt->tm_year);
		printk("ds1307_get_datetime: mon  = %d\n", dt->tm_mon);
		printk("ds1307_get_datetime: mday = %d\n", dt->tm_mday);
		printk("ds1307_get_datetime: hour = %d\n", dt->tm_hour);
		printk("ds1307_get_datetime: min  = %d\n", dt->tm_min);
		printk("ds1307_get_datetime: sec  = %d\n", dt->tm_sec);
	}
}
Ejemplo n.º 2
0
static void
rs5c372_convert_to_time(struct rtc_time *dt, unsigned char *buf)
{
	/* buf[0] is register 15 */
	dt->tm_sec = bcd2bin(buf[1]);
	dt->tm_min = bcd2bin(buf[2]);

	if (TWELVE_HOUR_MODE(buf[0])) {
		dt->tm_hour = HOURS_12(buf[3]);
		if (HOURS_AP(buf[3])) /* PM */
			dt->tm_hour += 12;
	} else /* 24-hour-mode */
		dt->tm_hour = HOURS_24(buf[3]);

	dt->tm_mday = bcd2bin(buf[5]);
	dt->tm_mon = bcd2bin(buf[6]);
	dt->tm_year = bcd2bin(buf[7]);
	if (dt->tm_year >= 70)
		dt->tm_year += 1900;
	else
		dt->tm_year += 2000;
	/* 0 is Sunday */
	dt->tm_wday = bcd2bin(buf[4] & 0x07);
	dt->tm_yday = 0;
	dt->tm_isdst= 0;

	if(rtc_debug > 2) {
		printf("rs5c372_convert_to_time: year = %d\n", dt->tm_year);
		printf("rs5c372_convert_to_time: mon  = %d\n", dt->tm_mon);
		printf("rs5c372_convert_to_time: mday = %d\n", dt->tm_mday);
		printf("rs5c372_convert_to_time: hour = %d\n", dt->tm_hour);
		printf("rs5c372_convert_to_time: min  = %d\n", dt->tm_min);
		printf("rs5c372_convert_to_time: sec  = %d\n", dt->tm_sec);
	}
}