Ejemplo n.º 1
0
struct tm *ps2time_gmtime( const time_t *timep )
{
	static struct tm ret, *r;

	/* days per month -- nonleap! */
	const short __spm[12] = {
		0,
		(31),
		(31+28),
		(31+28+31),
		(31+28+31+30),
		(31+28+31+30+31),
		(31+28+31+30+31+30),
		(31+28+31+30+31+30+31),
		(31+28+31+30+31+30+31+31),
		(31+28+31+30+31+30+31+31+30),
		(31+28+31+30+31+30+31+31+30+31),
		(31+28+31+30+31+30+31+31+30+31+30),
	};
	
	time_t i;
	register time_t work = *timep % (SPD);
	r = &ret;

	r->tm_sec	= work %60; work /= 60;
	r->tm_min	= work %60;
	r->tm_hour	= work /60;

	work = *timep / (SPD);

	r->tm_wday = (4 + work) % 7;

	for( i=1970; ; ++i ) {
		register time_t k = IS_LEAP_YEAR(i) ? 366 : 365;
		
		if( work >= k )
			work -= k;
		else
			break;
	}
	
	r->tm_year	= i - 1900;
	r->tm_yday	= work;
	r->tm_mday	= 1;

	if(IS_LEAP_YEAR(i) && (work > 58)) {
		if( work == 59 )
			r->tm_mday = 2; /* 29.2. */
		
		work -= 1;
	}
	
	for( i = 11; i && (__spm[i] > work); --i);

	r->tm_mon	=i;
	r->tm_mday	+= work - __spm[i];
	
	return r;
}
Ejemplo n.º 2
0
// Get unix timestamp for a GMT date
static time_t gmmktime(struct tm *tmbuff)
{
    static const int monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    time_t tres = 0;
    int doy = 0;
    int i = 0;
    time_t _loctime_offset = 0;

    /* We do allow some ill-formed dates, but we don't do anything special
    with them and our callers really shouldn't pass them to us.  Do
    explicitly disallow the ones that would cause invalid array accesses
    or other algorithm problems. */
    if (tmbuff->tm_mon < 0 || tmbuff->tm_mon > 11 || tmbuff->tm_year < (EPOCH_YEAR - TM_YEAR_BASE))
    {
        return (time_t) -1;
    }

    /* Convert calender time to a time_t value. */
    tres = 0;

    /* Sum total amount of days from the Epoch with respect to leap years. */
    for (i = EPOCH_YEAR; i < tmbuff->tm_year + TM_YEAR_BASE; i++)
    {
        tres += 365 + IS_LEAP_YEAR(i);
    }

    /* Add days of months before current month. */
    doy = 0;
    for (i = 0; i < tmbuff->tm_mon; i++)
    {
        doy += monthDays[i];
    }
    tres += doy;
    
    /* Day of year */
    tmbuff->tm_yday = doy + tmbuff->tm_mday;

    if (tmbuff->tm_mon > 1 && IS_LEAP_YEAR(tmbuff->tm_year + TM_YEAR_BASE))
    {
        tres++;
    }
    
    /* Add days of current month and convert to total to hours. */
    tres = 24 * (tres + tmbuff->tm_mday - 1) + tmbuff->tm_hour;

    /* Add minutes part and convert total to minutes. */
    tres = 60 * tres + tmbuff->tm_min;

    /* Add seconds part and convert total to seconds. */
    tres = 60 * tres + tmbuff->tm_sec;
    
    /* For offset > 0 adjust time value for timezone
    given as local to UTC time difference in seconds). */
    tres += _loctime_offset;
    
    return tres;
}
Ejemplo n.º 3
0
static int rtc_settime(struct sunxi_rtc *rtc_dev, struct rtc_time *tm)
{
	int actual_year, actual_month, leap_year = 0, reg_val;

	actual_year = tm->tm_year + 1900;	/* tm_year is from 1900 in linux */
	actual_month = tm->tm_mon + 1;		/* month is 1..12 in RTC reg but 0..11 in linux */
	leap_year = IS_LEAP_YEAR(actual_year);

	pr_info("%s(%d): time to set %d-%d-%d %d:%d:%d\n", __func__, __LINE__, actual_year,
		actual_month, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);

	/* prevent the application seting the error time */
	if (!time_valid(tm)) {
#if 1
		pr_err("%s(%d) err: date %d-%d-%d %d:%d:%d invalid!\n", __func__, __LINE__,
			actual_year, actual_month, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
		return -EINVAL;
#else
		pr_info("%s(%d) err: date %d-%d-%d %d:%d:%d invalid, so reset to 1970-1-1 00:00:00\n", __func__, __LINE__,
			actual_year, actual_month, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
		tm->tm_sec  = 0;
		tm->tm_min  = 0;
		tm->tm_hour = 0;
		tm->tm_mday = 0;
		tm->tm_mon  = 0;  /* 0 is month 1(January) */
		tm->tm_year = 70; /* tm_year=0 is 1900, so tm_year=70 is 1970 */

		actual_year = tm->tm_year + 1900;	/* refresh actual_year for actual_year_to_reg_year below */
		actual_month = tm->tm_mon + 1;		/* refresh actual_month for below */
		leap_year = IS_LEAP_YEAR(actual_year);	/* refresh leap_year flag for below */
#endif
	}

	/* set time */
	rtc_write_reg(rtc_dev->ac100, RTC_SEC_REG_OFF, bin2bcd(tm->tm_sec) & 0x7f);
	rtc_write_reg(rtc_dev->ac100, RTC_MIN_REG_OFF, bin2bcd(tm->tm_min) & 0x7f);
	rtc_write_reg(rtc_dev->ac100, RTC_HOU_REG_OFF, bin2bcd(tm->tm_hour) & 0x3f);
	rtc_write_reg(rtc_dev->ac100, RTC_WEE_REG_OFF, bin2bcd(tm->tm_wday) & 0x7);
	rtc_write_reg(rtc_dev->ac100, RTC_DAY_REG_OFF, bin2bcd(tm->tm_mday) & 0x3f);
	rtc_write_reg(rtc_dev->ac100, RTC_MON_REG_OFF, bin2bcd(actual_month) & 0x1f);

	/* set year */
	reg_val = actual_year_to_reg_year(actual_year);
	reg_val = bin2bcd(reg_val) & 0xff;
	if (leap_year)
		reg_val |= LEAP_YEAR_FLAG;
	rtc_write_reg(rtc_dev->ac100, RTC_YEA_REG_OFF, reg_val);

	/* set write trig bit */
	rtc_write_reg(rtc_dev->ac100, RTC_UPD_TRIG_OFF, RTC_WRITE_RTIG_FLAG);
	mdelay(30); /* delay 30ms to wait write stable */

	pr_info("%s(%d): set time %d-%d-%d %d:%d:%d success!\n", __func__, __LINE__, actual_year,
		actual_month, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
	return 0;
}
Ejemplo n.º 4
0
uint16_t
clock_yday(const uint8_t day, const uint8_t month, const uint8_t year)
{
  uint16_t yday =
    pgm_read_word(&clock_monthydays[IS_LEAP_YEAR(year)][month - 1]);
  return yday + day - 1;
}
Ejemplo n.º 5
0
REUInt32 REDate::getDaysPerMonth(const REUInt32 month, const REUInt32 year)
{
	switch (month)
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			return 31;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			return 30;
			break;
		case 2:
			return (IS_LEAP_YEAR(year)) ? 29 : 28;
			break;
		default:
			break;
	}
	return 0;
}
Ejemplo n.º 6
0
uint8_t daysOfMonth(uint8_t month, uint16_t year)
{
	switch (month)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		return 31;

	case 4:
	case 6:
	case 9:
	case 11:
		return 30;

	case 2:
		if (IS_LEAP_YEAR(year))
			return 29;
		else
			return 28;
	}

	return 0;
}
Ejemplo n.º 7
0
/* Berechnung erfolgt analog DIN 1355, welche besagt:
 * Der erste Donnerstag im neuen Jahr liegt immer in der KW 1.
 * "Woche" ist dabei definiert als [Mo, ..., So].
 *
 * http://www.a-m-i.de/tips/datetime/datetime.php
 */
uint8_t
clock_woy(const uint8_t day, const uint8_t month, const uint8_t year)
{
  int16_t yday = clock_yday(day, month, year);

  /* Berechnen des Wochentags des 1. Januar */
  int16_t yday_1jan = clock_dow(1, 1, year) - 1;

  /* Sonderfälle Freitag und Samstag */
  if (yday_1jan >= 4)
    yday_1jan -= 7;

  /* Sonderfälle "Jahresanfang mit KW - Nummer aus dem Vorjahr" */
  if ((yday + yday_1jan) <= 0)
    return clock_woy(31, 12, year - 1);

  uint8_t week = ((yday + yday_1jan) / 7) + 1;

  /* 53 Kalenderwochen hat grundsätzlich nur ein Jahr, welches mit einem
   * Donnerstag anfängt! In Schaltjahren ist es auch mit einem Mittwoch
   * möglich, z.B. 1992 Andernfalls ist diese KW schon die KW1 des
   * Folgejahres. */
  if (week == 53)
  {
    if ((yday_1jan == 3) || ((yday_1jan == 2) && IS_LEAP_YEAR(year)))
      ;                         /* Das ist korrekt und erlaubt */
    else
      week = 1;                 /* Korrektur des Wertes */
  }

  return week;
}
Ejemplo n.º 8
0
static int
aw_rtc_settime(device_t dev, struct timespec *ts)
{
	struct aw_rtc_softc *sc  = device_get_softc(dev);
	struct clocktime ct;
	uint32_t clk, rdate, rtime;

	/* RTC resolution is 1 sec */
	if (ts->tv_nsec >= HALF_OF_SEC_NS)
		ts->tv_sec++;
	ts->tv_nsec = 0;

	clock_ts_to_ct(ts, &ct);
	
	if ((ct.year < YEAR_MIN) || (ct.year > YEAR_MAX)) {
		device_printf(dev, "could not set time, year out of range\n");
		return (EINVAL);
	}

	for (clk = 0; RTC_READ(sc, LOSC_CTRL_REG) & LOSC_BUSY_MASK; clk++) {
		if (clk > RTC_TIMEOUT) {
			device_printf(dev, "could not set time, RTC busy\n");
			return (EINVAL);
		}
		DELAY(1);
	}
	/* reset time register to avoid unexpected date increment */
	RTC_WRITE(sc, sc->rtc_time, 0);

	rdate = SET_DAY_VALUE(ct.day) | SET_MON_VALUE(ct.mon) |
		SET_YEAR_VALUE(ct.year - YEAR_OFFSET) | 
		SET_LEAP_VALUE(IS_LEAP_YEAR(ct.year));
			
	rtime = SET_SEC_VALUE(ct.sec) | SET_MIN_VALUE(ct.min) |
		SET_HOUR_VALUE(ct.hour);

	for (clk = 0; RTC_READ(sc, LOSC_CTRL_REG) & LOSC_BUSY_MASK; clk++) {
		if (clk > RTC_TIMEOUT) {
			device_printf(dev, "could not set date, RTC busy\n");
			return (EINVAL);
		}
		DELAY(1);
	}
	RTC_WRITE(sc, sc->rtc_date, rdate);

	for (clk = 0; RTC_READ(sc, LOSC_CTRL_REG) & LOSC_BUSY_MASK; clk++) {
		if (clk > RTC_TIMEOUT) {
			device_printf(dev, "could not set time, RTC busy\n");
			return (EINVAL);
		}
		DELAY(1);
	}
	RTC_WRITE(sc, sc->rtc_time, rtime);

	DELAY(RTC_TIMEOUT);

	return (0);
}
Ejemplo n.º 9
0
int main ( void )
{
	if ( IS_LEAP_YEAR (2011) )
		printf ( "True\n" );
	else
		printf ( "False\n" );

	return 0;
}			
Ejemplo n.º 10
0
void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time,
		uint8_t* centisec)
{
	time_t shift = EPOCH_DIFF_SEC + exfat_timezone;
	uint16_t day, month, year;
	uint16_t twosec, min, hour;
	int days;
	int i;

	/* time before exFAT epoch cannot be represented */
	if (unix_time < shift)
		unix_time = shift;

	unix_time -= shift;

	days = unix_time / SEC_IN_DAY;
	year = (4 * days) / (4 * 365 + 1);
	days -= year * 365 + LEAP_YEARS(year);
	month = 0;
	for (i = 1; i <= 12; i++)
	{
		int leap_day = (IS_LEAP_YEAR(year) && i == 2);
		int leap_sub = (IS_LEAP_YEAR(year) && i >= 3);

		if (i == 12 || days - leap_sub < days_in_year[i + 1] + leap_day)
		{
			month = i;
			days -= days_in_year[i] + leap_sub;
			break;
		}
	}
	day = days + 1;

	hour = (unix_time % SEC_IN_DAY) / SEC_IN_HOUR;
	min = (unix_time % SEC_IN_HOUR) / SEC_IN_MIN;
	twosec = (unix_time % SEC_IN_MIN) / 2;

	*date = cpu_to_le16(day | (month << 5) | (year << 9));
	*time = cpu_to_le16(twosec | (min << 5) | (hour << 11));
	if (centisec)
		*centisec = (unix_time % 2) * 100;
}
Ejemplo n.º 11
0
time_t gwtm2secs( struct tm *tm )
	{
	int i, days, year;

	/* tm_year is either:
	 * a) the result from localtime()
	 * b) a 4-digit year specified on the command line minus 1900
	 * c) a 2-digit year specified on the command line
	 * in order to handle years from 2000 to 2069 specified as c), we
	 * check for years prior to 1970, which we can't handle anyway.
	 * (actually, for zones west of GMT, there are a few hours at
	 * the end of 1969, but we assume that nobody has traces taken
	 * during those hours.)
	 */
	year = tm->tm_year + 1900;
	if ( year < 1970 )
		year += 100;

	days = 0;
	for ( i = 1970; i < year; ++i )
		{
		days += 365;
		if ( IS_LEAP_YEAR(i) )
			++days;
		}

	for ( i = 0; i < tm->tm_mon; ++i )
		days += days_in_month[i];

	if ( IS_LEAP_YEAR(year) && tm->tm_mon > 1 ) /* 1 is February */
		++days;

	days += tm->tm_mday - 1; /* -1 since days are numbered starting at 1 */

	return days * 86400 + tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec;
	}
Ejemplo n.º 12
0
uint8_t DaysPerMonth(time_t t)
{
    uint8_t mon = month(t);
    switch (mon)
    {
    case 4:
    case 6:
    case 9:
    case 11:
        return 30;
    case 2:
        return (IS_LEAP_YEAR(year(t))) ? 29 : 28;
    default:
        return 31;
    }
}
Ejemplo n.º 13
0
/* 获取最大天数 */
int system_getmaxday( int year, int month )
{
	int maxday = 0;
	if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 )
		maxday = 31;
	else if ( month == 4 || month == 6 || month == 9 || month == 11 )
		maxday = 30;
	else if ( month == 2 )
	{
		if ( IS_LEAP_YEAR( year ) )
			maxday = 29;
		else
			maxday = 28;
	}
	return maxday;
}
Ejemplo n.º 14
0
void
clock_yday2date(const uint16_t yday, const uint8_t year, uint8_t * day,
                uint8_t * month)
{
  const uint16_t *p = clock_monthydays[IS_LEAP_YEAR(year)];
  for (int8_t m = 12; m >= 0; m--)
  {
    uint16_t d = pgm_read_word(p + m);
    if (yday >= d)
    {
      *month = m + 1;
      *day = 1 + yday - d;
      break;
    }
  }
}
Ejemplo n.º 15
0
static wiced_bool_t validate_input_time_calendar( const platform_rtc_time_t* time )
{
    wiced_bool_t valid_time_calendar = WICED_FALSE;

    if ( time->sec < NUM_SECONDS_IN_MINUTE )
    {
        if ( time->min < NUM_MINUTES_IN_HOUR )
        {
            if ( time->hr < NUM_HOURS_IN_DAY )
            {
                if ( (time->weekday > 0) && (time->weekday <= NUM_DAYS_IN_WEEK) )
                {
                    if ( (time->month > 0) && (time->month <= NUM_MONTHS_IN_YEAR) )
                    {
                        if ( time->year < NUM_YEARS_IN_CENTURY )
                        {
                            if ( IS_LEAP_YEAR((RTC_CURRENT_CENTURY * 100) + time->year) == 1 )
                            {
                                if ( (time->date > 0) && (time->date <= month_days_in_leap_year[time->month]) )
                                {
                                    valid_time_calendar = WICED_TRUE;
                                }
                            }
                            else
                            {
                                if ( (time->date > 0) && (time->date <= month_days_not_leap_year[time->month]) )
                                {
                                    valid_time_calendar = WICED_TRUE;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return valid_time_calendar;
}
static
void
globus_l_job_manager_normalize_date(
    struct tm *                         tm)
{
    int                                 test_year;
    int                                 overflow_days = 0;
    static int                          mday_max[] =
    {
        31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 
    };
    static int                          mday_leap_max[] =
    {
        31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 
    };

    do
    {
        if (overflow_days > 0)
        {
            tm->tm_mday = overflow_days;
            tm->tm_mon++;
        }

        /* skipped to the next year */
        if (tm->tm_mon == 12)
        {
            tm->tm_year++;
            tm->tm_mon = 0;
        }

        test_year = tm->tm_year + 1900;
        overflow_days = IS_LEAP_YEAR(test_year) 
                ? tm->tm_mday - mday_leap_max[tm->tm_mon]
                : tm->tm_mday - mday_max[tm->tm_mon];
    } while (overflow_days > 0);
}
Ejemplo n.º 17
0
 int 
 bos_reader::key_read_date (const char *buf, double &date) const
   {
     int ret_code;
     int day, month, year;
     int days_in_current_month;
     static const int days_in_month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
     int i;
     
     if (sscanf (buf, "%d.%d.%d", &day, &month, &year) != 3)
       {
         switch (ret_code = key_read_date_ecl (buf, day, month, year))
         {
           case -1:
             {
               fprintf (stderr, "Error: invalid date format: %s\n", buf);
               return -1;
               }
             case -4:
               {
                 fprintf (stderr, "Error: invalid (nonexistent) date: %s\n", buf);
                 return -1;
               }  
           }
       }
    
     // Check month and year
     
     if (year < 1900)
       {
         fprintf (stderr, "Error: years earlier 1900 not supported: %s\n", buf);
         return -1;
       }
     
     if (month < 1 || month > 12)
       {
         fprintf (stderr, "Error: invalid (nonexistent) date: %s\n", buf);
         return -1;
       } 
     
     date = 0;
     
     for (i = 1900; i < year; i++)
       {
       if (IS_LEAP_YEAR (i))
         date += 366;
       else
         date += 365;
       }
       
     month--;  
     
     for (i = 0; i < month; i++)
       {
         date += days_in_month[i];
         if (IS_LEAP_YEAR (year) && i == 1) // February of leap year
           date++;
       }
     date += day;
     
     days_in_current_month = days_in_month[month];
     if (IS_LEAP_YEAR (year) && month == 1) // February of leap year
       days_in_current_month++;
     
     
     // check day
     if (day < 1 || day > days_in_current_month)
       {
         fprintf (stderr, "Error: invalid (nonexistent) date: %s\n", buf);
         return -1;
       }
     
     return 0;
   }
/* set rtc time */
static int sunxi_rtc_settime(struct device *dev, struct rtc_time *tm)
{
	unsigned int timeout = 0;
	int actual_year = 0;
	int line = 0;
	rtc_hh_mm_ss hhmmss = {0};
	rtc_yy_mm_dd yymmdd = {0};
	losc_ctrl losctl = {0};
	
	pr_info("%s(%d): time to set %d-%d-%d %d:%d:%d\n", __func__, __LINE__, tm->tm_year + 1900,
		tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);

	/* int tm_year; years from 1900
	 * int tm_mon; months since january 0-11
	 * the input para tm->tm_year is the offset related 1900;
	 */
	actual_year = tm->tm_year + 1900;
	if(actual_year > 2100 || actual_year < 1970) {
		dev_err(dev, "%s(%d) err: rtc only supports 130(1970~2100) years\n", __func__, __LINE__);
		return -EINVAL;
	}

	/* Any bit of [9:7] is set, the time and date
	 * register can`t be written, we re-try the entried read
	 * check at most 3 times
	 */
	 losctl = rtc_reg_list->losc_ctl;
	timeout = 3;
	do {
		if(losctl.rtc_yymmdd_acce
			|| losctl.rtc_hhmmss_acce
			|| losctl.alm_ddhhmmss_acce) {
			pr_err("%s(%d): canot change rtc now!\n", __func__, __LINE__);
			losctl = rtc_reg_list->losc_ctl;
			msleep(500);
		}
	}while(--timeout);

	/* prevent the application seting the error time */
	tm->tm_mon  += 1;
	switch(tm->tm_mon) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		if(tm->tm_mday > 31)
			line = __LINE__;
		if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
			line = __LINE__;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		if(tm->tm_mday > 30)
			line = __LINE__;
		if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
			line = __LINE__;
		break;
	case 2:
		if(IS_LEAP_YEAR(actual_year)) {
			if(tm->tm_mday > 29)
				line = __LINE__;
			if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
				line = __LINE__;
		} else {
			if(tm->tm_mday > 28)
				line = __LINE__;
			if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
				line = __LINE__;
		}
		break;
	default:
		line = __LINE__;
		break;
	}
	if(0 != line) {
		pr_info("%s(%d) err: date %d-%d-%d %d:%d:%d, so reset to 1900-1-1 00:00:00\n", __func__, line,
			tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
		tm->tm_sec  = 0;
		tm->tm_min  = 0;
		tm->tm_hour = 0;
		tm->tm_mday = 0;
		tm->tm_mon  = 0;
		tm->tm_year = 0;
	}

	pr_info("%s(%d): actually set time to %d-%d-%d %d:%d:%d\n", __func__, __LINE__, tm->tm_year + 1900,
		tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);

	/* set hour, minute, second */
	//writel(0, &rtc_reg_list->r_hh_mm_ss); /* note: must add, or set date maybe err,liugang */
	hhmmss = rtc_reg_list->r_hh_mm_ss;
	hhmmss.hour = tm->tm_hour;
	hhmmss.minute = tm->tm_min;
	hhmmss.second = tm->tm_sec;
	rtc_reg_list->r_hh_mm_ss = hhmmss;

	//at most 1 second
	timeout = 10*1000;
	losctl = rtc_reg_list->losc_ctl;
	while(losctl.rtc_hhmmss_acce && (--timeout)){
		losctl = rtc_reg_list->losc_ctl;
		udelay(100);
	}
	if(timeout == 0) {
		dev_err(dev, "%s(%d): fail to set rtc time\n", __func__, __LINE__);
		return -1;
	}

	/* set year, month, day */
	//writel(0, &rtc_reg_list->r_yy_mm_dd);
	yymmdd = rtc_reg_list->r_yy_mm_dd; 
	yymmdd.year = tm->tm_year;
	yymmdd.month = tm->tm_mon;
	yymmdd.day = tm->tm_mday;

	/* set leap year bit */
	if(IS_LEAP_YEAR(actual_year)){
		yymmdd.leap = 1;
	}
	rtc_reg_list->r_yy_mm_dd = yymmdd;
	
	timeout = 10*1000;
	losctl = rtc_reg_list->losc_ctl;
	while(losctl.rtc_yymmdd_acce && (--timeout)){
		losctl = rtc_reg_list->losc_ctl;
		udelay(100);
	}
	if(timeout == 0) {
		dev_err(dev, "%s(%d): fail to set rtc date\n", __func__, __LINE__);
		return -1;
	}

	/* wait about 70us to make sure the the time is really written into target */
	udelay(70);

	pr_info("%s(%d): end\n", __func__, __LINE__);
	return 0;
}
Ejemplo n.º 19
0
TIMESTAMP_T *tm_current(TIMESTAMP_T *tp, UINT8 tz_utc)
{
    struct timespec ts = CURRENT_TIME_SEC;
    time_t second = ts.tv_sec;
    time_t day, leap_day, month, year;

    if (!tz_utc)
        second -= sys_tz.tz_minuteswest * SECS_PER_MIN;

    if (second < UNIX_SECS_1980) {
        tp->sec  = 0;
        tp->min  = 0;
        tp->hour = 0;
        tp->day  = 1;
        tp->mon  = 1;
        tp->year = 0;
        return(tp);
    }
#if BITS_PER_LONG == 64
    if (second >= UNIX_SECS_2108) {
        tp->sec  = 59;
        tp->min  = 59;
        tp->hour = 23;
        tp->day  = 31;
        tp->mon  = 12;
        tp->year = 127;
        return(tp);
    }
#endif

    day = second / SECS_PER_DAY - DAYS_DELTA_DECADE;
    year = day / 365;

    MAKE_LEAP_YEAR(leap_day, year);
    if (year * 365 + leap_day > day)
        year--;

    MAKE_LEAP_YEAR(leap_day, year);

    day -= year * 365 + leap_day;

    if (IS_LEAP_YEAR(year) && day == accum_days_in_year[3]) {
        month = 2;
    } else {
        if (IS_LEAP_YEAR(year) && day > accum_days_in_year[3])
            day--;
        for (month = 1; month < 12; month++) {
            if (accum_days_in_year[month + 1] > day)
                break;
        }
    }
    day -= accum_days_in_year[month];

    tp->sec  = second % SECS_PER_MIN;
    tp->min  = (second / SECS_PER_MIN) % 60;
    tp->hour = (second / SECS_PER_HOUR) % 24;
    tp->day  = day + 1;
    tp->mon  = month;
    tp->year = year;

    return(tp);
}
Ejemplo n.º 20
0
int ps2time_init( void )
{
	CdvdClock_t clock;
	struct tm	tm_time;

	static unsigned int monthdays[12] = {
		31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
	};

	// query the RTC
	cdInit(CDVD_INIT_NOCHECK);
	if( !cdReadClock(&clock) )
		return -1;

	tm_time.tm_sec	= BCD2DEC(clock.second);
	tm_time.tm_min	= BCD2DEC(clock.minute);
	tm_time.tm_hour = BCD2DEC(clock.hour); // hour in Japan (GMT + 9)
	tm_time.tm_mday	= BCD2DEC(clock.day);
	tm_time.tm_mon	= BCD2DEC(clock.month) - 1; // RTC months range from 1 - 12
	tm_time.tm_year	= BCD2DEC(clock.year) + 100; // RTC returns year less 2000

	if( tm_time.tm_hour < 9 ) {
		// go back to last month
		if( tm_time.tm_mday == 1 ) {

			// go back to last year if month is january
			if( tm_time.tm_mon == 0 ) {
				tm_time.tm_mon = 11;
				tm_time.tm_year = tm_time.tm_year - 1;
			}
			else {
				tm_time.tm_mon = tm_time.tm_mon - 1;
			}

			// if going back to february and year is a leapyear
			if( tm_time.tm_mon == 1 && IS_LEAP_YEAR(tm_time.tm_year + 1900)) {
				tm_time.tm_mday = 29;
			}
			else {
				tm_time.tm_mday = monthdays[ tm_time.tm_mon ];
			}

		}
		else {
			tm_time.tm_mday = tm_time.tm_mday - 1;
		}
		tm_time.tm_hour = (24 - (9 - tm_time.tm_hour)) % 24;
	}
	else {
		tm_time.tm_hour -= 9;
	}

	g_ps2time_start = ps2time_mktime(&tm_time);

	// setup EE timer1
	*T1_MODE = 0x0000;

	// enable the overflow interrupt handler
	g_interruptID = AddIntcHandler(T1_INTC, ps2time_intr_handler, 0);
	EnableIntc(T1_INTC);
	g_interruptCount = 0;

	*T1_COUNT	= 0;
	*T1_MODE	= Tn_MODE(0x02, 0, 0, 0, 0, 0x01, 0, 0x01, 0, 0);

	// set the timezone as offset in minutes from GMT
	ps2time_setTimezone( configGetTimezone() );

	return 0;
}
Ejemplo n.º 21
0
errno_t __cdecl _tasctime_s (
    _TSCHAR *buffer,
    size_t sizeInChars,
    const struct tm *tb
    )
{
    _TSCHAR *p = buffer;
    int day, mon;
    int i;

    _VALIDATE_RETURN_ERRCODE(
        ( buffer != NULL ) && ( sizeInChars > 0 ),
        EINVAL
    )

    _RESET_STRING(buffer, sizeInChars);

    _VALIDATE_RETURN_ERRCODE(
        ( sizeInChars >= _ASCBUFSIZE ),
        EINVAL
    )
    _VALIDATE_RETURN_ERRCODE(
        ( tb != NULL ),
        EINVAL
    )
    _VALIDATE_RETURN_ERRCODE(
        ( tb->tm_year >= 0 ),
        EINVAL
    )
    // month 0 based
    _VALIDATE_RETURN_ERRCODE(
        ( ( tb->tm_mon  >= 0 ) && ( tb->tm_mon  <= 11 ) ),
        EINVAL
    )
    // hour/min/sec 0 based
    _VALIDATE_RETURN_ERRCODE(
        ( ( tb->tm_hour >= 0 ) && ( tb->tm_hour <= 23 ) ),
        EINVAL
    )
    _VALIDATE_RETURN_ERRCODE(
        ( ( tb->tm_min  >= 0 ) && ( tb->tm_min  <= 59 ) ),
        EINVAL
    )
    _VALIDATE_RETURN_ERRCODE(
        ( ( tb->tm_sec  >= 0 ) && ( tb->tm_sec  <= 59 ) ),
        EINVAL
    )
    // day 1 based
    _VALIDATE_RETURN_ERRCODE(
        (
            ( tb->tm_mday >= 1 ) &&
            (
                // Day is in valid range for the month
                ( ( _days[ tb->tm_mon + 1 ] - _days[ tb->tm_mon ] ) >=
                        tb->tm_mday ) ||
                // Special case for Feb in a leap year
                (
                    ( IS_LEAP_YEAR( tb->tm_year + 1900 ) ) &&
                    ( tb->tm_mon == 1 ) &&
                    ( tb->tm_mday <= 29 )
                )
            )
        ),
        EINVAL
    )
    // week day 0 based
    _VALIDATE_RETURN_ERRCODE(
        ( ( tb->tm_wday >= 0 ) && ( tb->tm_wday <= 6 ) ),
        EINVAL
    )


    /* copy day and month names into the buffer */

    day = tb->tm_wday * 3;      /* index to correct day string */
    mon = tb->tm_mon * 3;       /* index to correct month string */
    for (i=0; i < 3; i++,p++) {
        *p = *(__dnames + day + i);
        *(p+4) = *(__mnames + mon + i);
    }

    *p = _T(' ');           /* blank between day and month */

    p += 4;

    *p++ = _T(' ');
    p = store_dt(p, tb->tm_mday);   /* day of the month (1-31) */
    *p++ = _T(' ');
    p = store_dt(p, tb->tm_hour);   /* hours (0-23) */
    *p++ = _T(':');
    p = store_dt(p, tb->tm_min);    /* minutes (0-59) */
    *p++ = _T(':');
    p = store_dt(p, tb->tm_sec);    /* seconds (0-59) */
    *p++ = _T(' ');
    p = store_dt(p, 19 + (tb->tm_year/100)); /* year (after 1900) */
    p = store_dt(p, tb->tm_year%100);
    *p++ = _T('\n');
    *p = _T('\0');


    return 0;
}
Ejemplo n.º 22
0
BOOLEAN
FatIsValidTime (
  IN EFI_TIME         *Time
  )
/*++

Routine Description:

  Check whether a time is valid.

Arguments:

  Time                  - The time of EFI_TIME.

Returns:

  TRUE                  - The time is valid.
  FALSE                 - The time is not valid.

--*/
{
  static UINT8  MonthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  UINTN         Day;
  BOOLEAN       ValidTime;

  ValidTime = TRUE;

  //
  // Check the fields for range problems
  // Fat can only support from 1980
  //
  if (Time->Year < 1980 ||
      Time->Month < 1 ||
      Time->Month > 12 ||
      Time->Day < 1 ||
      Time->Day > 31 ||
      Time->Hour > 23 ||
      Time->Minute > 59 ||
      Time->Second > 59 ||
      Time->Nanosecond > 999999999
      ) {

    ValidTime = FALSE;

  } else {
    //
    // Perform a more specific check of the day of the month
    //
    Day = MonthDays[Time->Month - 1];
    if (Time->Month == 2 && IS_LEAP_YEAR (Time->Year)) {
      Day += 1;
      //
      // 1 extra day this month
      //
    }
    if (Time->Day > Day) {
      ValidTime = FALSE;
    }
  }

  return ValidTime;
}
Ejemplo n.º 23
0
void
clock_datetime(clock_datetime_t * d, timestamp_t t)
{
  /* seconds */
  d->sec = t % 60;
  t /= 60;

  /* minutes */
  d->min = t % 60;
  t /= 60;

  /* hours */
  d->hour = t % 24;
  t /= 24;

  /* t/84600 is always <= 51000, so we can crop this to an uint16_t */
  uint16_t days = (uint16_t) t;

  /* day of week */
  d->dow = (days + EPOCH_DOW) % 7;

  /* year: For every year from EPOCH_YEAR upto now, check for a leap year
   * (for details on leap years see http://en.wikipedia.org/wiki/Leap_year) */
  uint16_t year = EPOCH_YEAR;

  /* year, check if we have enough days left to fill a year */
  while (days >= 365)
  {
    if (IS_LEAP_YEAR(year))
    {
      /* special case: leap year is not over after 365 days... */
      if (days == 365)
        break;

      /* default case: leap years have one more day */
      days -= 1;
    }

    /* normal years have 365 days */
    days -= 365;
    year++;
  }

  d->year = year - 1900;

  /* day of year */
  d->yday = days;

  /* month */
  d->month = 0;
  for (;;)
  {
    uint8_t monthdays = clock_month_days(d->month + 1);

    /* feb has one more day in a leap year */
    if (d->month == 1 && IS_LEAP_YEAR(year))
      monthdays++;

    /* if we have not enough days left to fill this month, we are done */
    if (days < monthdays)
      break;

    days -= monthdays;
    d->month++;
  }

  d->month++;
  d->day = (uint8_t) days + 1;

  /* no daylight saving in utc */
  d->isdst = 0;
}
Ejemplo n.º 24
0
/**
 *  Parse the time columns of a record in a CSV file and set the record time.
 *
 *  If an error occurs in this function it will be appended to the log and
 *  error mail messages, and the process status will be set appropriately.
 *
 *  @param  csv           pointer to the CSVParser structure
 *  @param  record_index  record index
 *
 *  @retval  1  if successful
 *  @retval  0  if invalid time format
 *  @retval -1  if an error occurred
 */
int _csv_parse_record_time(
    CSVParser *csv,
    int        record_index)
{
    char       *time_string;
    int         status;
    int         tci, fi;
    RETimeList *tc_patterns;
    RETimeRes   match;
    RETimeRes   result;

    int         used_file_date;
    timeval_t   rec_time;
    timeval_t   prev_time;
    int         tro_interval;
    double      delta_t;
    struct tm   gmt;


    /* Get the time column indexes */

    if (!csv->tc_index) {
        if (!_csv_create_tc_index(csv)) {
            return(-1);
        }
    }

    /* Parse time strings and merge results */

    for (tci = 0; tci < csv->ntc; ++tci) {

        fi          = csv->tc_index[tci];
        tc_patterns = csv->tc_patterns[tci];

        /* Make sure this is a valid field index */

        if (fi < 0 || fi > csv->nfields) {

            ERROR( DSPROC_LIB_NAME,
                "Time column index '%d' is out of range [0, %d].\n",
                fi, csv->nfields);

            dsproc_set_status(DSPROC_ECSVPARSER);

            return(-1);
        }

        time_string = csv->values[fi][record_index];

        /* Parse time string */

        status = retime_list_execute(tc_patterns, time_string, &match);

        if (status < 0) {

            ERROR( DSPROC_LIB_NAME,
                "Time string pattern match failed for record %d.\n",
                record_index + 1);

            dsproc_set_status(DSPROC_ECSVPARSER);

            return(-1);
        }
        else if (status == 0) {

            DSPROC_BAD_RECORD_WARNING(csv->file_name, csv->nrecs,
                "Record time format '%s' does not match '%s'\n",
                time_string,
                tc_patterns->retimes[tc_patterns->npatterns - 1]->tspattern);

            return(0);
        }

        /* Merge results */

        if (tci == 0) {
            result = match;
        }
        else {
            if (match.year     != -1) result.year     = match.year;
            if (match.month    != -1) result.month    = match.month;
            if (match.mday     != -1) result.mday     = match.mday;
            if (match.hour     != -1) result.hour     = match.hour;
            if (match.min      != -1) result.min      = match.min;
            if (match.sec      != -1) result.sec      = match.sec;
            if (match.usec     != -1) result.usec     = match.usec;
            if (match.century  != -1) result.century  = match.century;
            if (match.yy       != -1) result.yy       = match.yy;
            if (match.yday     != -1) result.yday     = match.yday;
            if (match.secs1970 != -1) result.secs1970 = match.secs1970;
        }
    }

    if (result.secs1970 != -1) {

        csv->tvs[record_index].tv_sec   = result.secs1970;
        csv->tvs[record_index].tv_usec  = (result.usec == -1) ? 0 : result.usec;

        csv->tvs[record_index].tv_sec  += csv->time_offset;
        csv->tvs[record_index].tv_sec  += csv->tro_offset;

        return(1);
    }

    /* Check if we need to use the date from the file name */

    used_file_date = 0;

    if (csv->ft_patterns) {

        if (!csv->ft_result) {

            csv->ft_result = calloc(1, sizeof(RETimeRes));
            if (!csv->ft_result) {

                ERROR( DSPROC_LIB_NAME,
                    "Memory allocation error creating file name RETimeRes structure\n");

                dsproc_set_status(DSPROC_ECSVPARSER);

                return(-1);
            }

            status = dsproc_get_csv_file_name_time(csv, csv->file_name, csv->ft_result);
            if (status < 0) return(-1);
        }

        if (result.year == -1) {

            if (csv->ft_result->year != -1) {

                result.year = csv->ft_result->year;
                used_file_date = 1;
            }
            else {

                ERROR( DSPROC_LIB_NAME,
                    "Could not determine record time\n"
                    " -> year not found in record or file name time patterns\n");

                dsproc_set_status(DSPROC_ECSVPARSER);

                return(-1);
            }
        }

        if (result.month == -1) {

            if (result.yday != -1) {

                yday_to_mday(result.yday,
                    &(result.year), &(result.month), &(result.mday));
            }
            else if (csv->ft_result->month != -1) {

                result.month = csv->ft_result->month;
                used_file_date = 2;
            }
            else if (csv->ft_result->yday != -1) {

                yday_to_mday(csv->ft_result->yday,
                    &(result.year), &(result.month), &(result.mday));

                used_file_date = 3;
            }
        }

        if (result.mday == -1) {

            if (csv->ft_result->mday != -1) {
                result.mday = csv->ft_result->mday;
                used_file_date = 3;
            }
        }
    }
    else {

        /* Verify that the year was found */

        if (result.year == -1) {

            ERROR( DSPROC_LIB_NAME,
                "Could not determine record time\n"
                " -> year not found in record time pattern\n");

            dsproc_set_status(DSPROC_ECSVPARSER);

            return(-1);
        }
    }

    rec_time         = retime_get_timeval(&result);
    rec_time.tv_sec += csv->time_offset;
    rec_time.tv_sec += csv->tro_offset;

    /* Check for time rollovers if the file date was used */

    if (used_file_date && record_index > 0) {

        prev_time = csv->tvs[record_index - 1];

        if (TV_LT(rec_time, prev_time)) {

            switch (used_file_date) {

                case 1: /* yearly  */

                    gmtime_r(&(prev_time.tv_sec), &gmt);

                    if (IS_LEAP_YEAR(gmt.tm_year + 1900)) {
                        tro_interval = 366 * 86400;
                    }
                    else {
                        tro_interval = 365 * 86400;
                    }

                    if (!csv->tro_threshold) {
                        csv->tro_threshold = 86400;
                    }

                    break;

                case 2: /* monthly */

                    gmtime_r(&(prev_time.tv_sec), &gmt);

                    tro_interval = days_in_month(gmt.tm_year + 1900, gmt.tm_mon + 1)
                                 * 86400;

                    if (!csv->tro_threshold) {
                        csv->tro_threshold = 43200;
                    }

                    break;

                default: /* daily   */

                    tro_interval = 86400;

                    if (!csv->tro_threshold) {
                        csv->tro_threshold = 3600;
                    }
            }

            delta_t = (TV_DOUBLE(rec_time) + tro_interval) - TV_DOUBLE(prev_time);

            if ((delta_t > 0) && (delta_t < csv->tro_threshold)) {

                rec_time.tv_sec += tro_interval;
                csv->tro_offset += tro_interval;
            }
        }
    }

    if (record_index > 0) {

        prev_time = csv->tvs[record_index - 1];


    }



    csv->tvs[record_index] = rec_time;

    return(1);
}
Ejemplo n.º 25
0
REBOOL REDate::isLeapYear(const REUInt32 year)
{
	return IS_LEAP_YEAR(year);
}
Ejemplo n.º 26
0
TIMESTAMP_T *tm_current(TIMESTAMP_T *tp)
{
	struct timespec ts = CURRENT_TIME_SEC;
	time_t second = ts.tv_sec;
	time_t day, leap_day, month, year;

	second -= sys_tz.tz_minuteswest * SECS_PER_MIN;

	/* Jan 1 GMT 00:00:00 1980. But what about another time zone? */
	if (second < UNIX_SECS_1980) {
		tp->sec  = 0;
		tp->min  = 0;
		tp->hour = 0;
		tp->day  = 1;
		tp->mon  = 1;
		tp->year = 0;
		return(tp);
	}
#if BITS_PER_LONG == 64
	if (second >= UNIX_SECS_2108) {
		tp->sec  = 59;
		tp->min  = 59;
		tp->hour = 23;
		tp->day  = 31;
		tp->mon  = 12;
		tp->year = 127;
		return(tp);
	}
#endif

	day = second / SECS_PER_DAY - DAYS_DELTA;
	year = day / 365;
	leap_day = (year + 3) / 4;
	if (year > YEAR_2100)        /* 2100 isn't leap year */
		leap_day--;
	if (year * 365 + leap_day > day)
		year--;
	leap_day = (year + 3) / 4;
	if (year > YEAR_2100)        /* 2100 isn't leap year */
		leap_day--;
	day -= year * 365 + leap_day;

	if (IS_LEAP_YEAR(year) && day == days_in_year[3]) {
		month = 2;
	} else {
		if (IS_LEAP_YEAR(year) && day > days_in_year[3])
			day--;
		for (month = 1; month < 12; month++) {
			if (days_in_year[month + 1] > day)
				break;
		}
	}
	day -= days_in_year[month];

	tp->sec  = second % SECS_PER_MIN;
	tp->min  = (second / SECS_PER_MIN) % 60;
	tp->hour = (second / SECS_PER_HOUR) % 24;
	tp->day  = day + 1;
	tp->mon  = month;
	tp->year = year;

	return(tp);
} /* end of tm_current */
Ejemplo n.º 27
0
int day_of_week(int day, int month, int year)
{
    int count, sum_of_days;

    /* 1/1/2000 is Saturday */
    int first_day = 6;

    /* check input date */
    if (year < 2000) {
        printf("Sorry buddy, your date should be >= 1/1/2000!\n");
        return -1;
    }

    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
        if (day > 31 || day < 1) {
            printf("Sorry buddy, your date is not correct!\n");
            return -1;
        }
    }
    else if (month == 2) {

        if (IS_LEAP_YEAR(year)) {
            if (day > 29 || day < 1) {
                printf("Sorry buddy, your date is not correct!\n");
                return -1;
            }
        }
        else {
            if (day > 28 ||  day < 1) {
                printf("Sorry buddy, your date is not correct!\n");
                return -1;
            }
        }
    }
    else {
        if (day > 30 || day < 1) {
            printf("Sorry buddy, your date is not correct!\n");
            return -1;
        }
    }

    /* date is okay, convert... */
    sum_of_days = 0;

    for (count = 2000; count < year; count++) {
        sum_of_days += (((IS_LEAP_YEAR(count) == 1) ? 366 : 365)) % 7;
    }

    for (count = 1; count < month; count++) {
        if (count == 1 || count == 3 || count == 5 || count == 7 || count == 8 || count == 10 || count == 12) {
            sum_of_days += 31 % 7;
        }
        else if (count == 2) {

            if (IS_LEAP_YEAR(year)) {
                sum_of_days += 29 % 7;
            }
            else {
                sum_of_days += 28 % 7;
            }
        }
        else {
            sum_of_days += 30 % 7;
        }
    }

    sum_of_days += (day - 1) % 7;

    return (sum_of_days + first_day) % 7;
}
Ejemplo n.º 28
0
bool time_valid(struct rtc_time *tm)
{
	int actual_year, actual_month, leap_year = 0;
	int err = 0;

	actual_year = tm->tm_year + 1900;	/* tm_year is from 1900 in linux */
	actual_month = tm->tm_mon + 1;		/* month is 1..12 in RTC reg but 0..11 in linux */
	leap_year = IS_LEAP_YEAR(actual_year);

	if (rtc_valid_tm(tm) < 0) {
		pr_err("%s(%d): time(%d-%d-%d %d:%d:%d) invalid.\n", __func__, __LINE__, actual_year,
			actual_month, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
		return false;
	}

	/* int tm_year; years from 1900
	 * int tm_mon; months since january 0-11
	 * the input para tm->tm_year is the offset related 1900 */
	if(actual_year > YEAR_SUPPORT_MAX || actual_year < YEAR_SUPPORT_MIN) {
		pr_err("%s(%d) err: rtc only supports (%d~%d) years, but to set is %d\n", __func__, __LINE__,
			YEAR_SUPPORT_MIN, YEAR_SUPPORT_MAX, actual_year);
			actual_year = YEAR_SUPPORT_MAX -1;
	}

	switch(actual_month) {
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		if(tm->tm_mday > 31)
			err = __LINE__;
		if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
			err = __LINE__;
		break;
	case 4:
	case 6:
	case 9:
	case 11:
		if(tm->tm_mday > 30)
			err = __LINE__;
		if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
			err = __LINE__;
		break;
	case 2:
		if(leap_year) {
			if(tm->tm_mday > 29)
				err = __LINE__;
			if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
				err = __LINE__;
		} else {
			if(tm->tm_mday > 28)
				err = __LINE__;
			if(tm->tm_hour > 24 || tm->tm_min > 59 || tm->tm_sec > 59)
				err = __LINE__;
		}
		break;
	default:
		err = __LINE__;
		break;
	}

	if (err) {
		pr_err("%s err, line %d!\n", __func__, err);
		return false;
	}
	return true;
}