int m48t37y_set_time(unsigned long sec) { struct rtc_time tm; /* convert to a more useful format -- note months count from 0 */ to_tm(sec, &tm); tm.tm_mon += 1; /* enable writing */ m48t37_base->control = 0x80; /* year */ m48t37_base->year = BIN2BCD(tm.tm_year % 100); m48t37_base->century = BIN2BCD(tm.tm_year / 100); /* month */ m48t37_base->month = BIN2BCD(tm.tm_mon); /* day */ m48t37_base->date = BIN2BCD(tm.tm_mday); /* hour/min/sec */ m48t37_base->hour = BIN2BCD(tm.tm_hour); m48t37_base->min = BIN2BCD(tm.tm_min); m48t37_base->sec = BIN2BCD(tm.tm_sec); /* day of week -- not really used, but let's keep it up-to-date */ m48t37_base->day = BIN2BCD(tm.tm_wday + 1); /* disable writing */ m48t37_base->control = 0x00; return 0; }
static int indy_rtc_set_time(unsigned long tim) { struct rtc_time tm; unsigned int save_control; unsigned long flags; to_tm(tim, &tm); tm.tm_mon += 1; /* tm_mon starts at zero */ tm.tm_year -= 1940; if (tm.tm_year >= 100) tm.tm_year -= 100; spin_lock_irqsave(&rtc_lock, flags); save_control = hpc3c0->rtcregs[RTC_CMD] & 0xff; hpc3c0->rtcregs[RTC_CMD] = save_control | RTC_TE; hpc3c0->rtcregs[RTC_YEAR] = BIN2BCD(tm.tm_year); hpc3c0->rtcregs[RTC_MONTH] = BIN2BCD(tm.tm_mon); hpc3c0->rtcregs[RTC_DATE] = BIN2BCD(tm.tm_mday); hpc3c0->rtcregs[RTC_HOURS] = BIN2BCD(tm.tm_hour); hpc3c0->rtcregs[RTC_MINUTES] = BIN2BCD(tm.tm_min); hpc3c0->rtcregs[RTC_SECONDS] = BIN2BCD(tm.tm_sec); hpc3c0->rtcregs[RTC_HUNDREDTH_SECOND] = 0; hpc3c0->rtcregs[RTC_CMD] = save_control; spin_unlock_irqrestore(&rtc_lock, flags); return 0; }
/* * 函数名:Time_Display * 描述 :显示当前时间值 * 输入 :-TimeVar RTC计数值,单位为 s * 输出 :无 * 调用 :内部调用 */ void Time_Display(uint32_t TimeVar,struct rtc_time *tm) { static uint32_t FirstDisplay = 1; uint32_t BJ_TimeVar; uint8_t str[15]; // 字符串暂存 /* 把标准时间转换为北京时间*/ BJ_TimeVar =TimeVar + 8*60*60; to_tm(BJ_TimeVar, tm);/*把定时器的值转换为北京时间*/ if((!tm->tm_hour && !tm->tm_min && !tm->tm_sec) || (FirstDisplay)) { GetChinaCalendar((u16)tm->tm_year, (u8)tm->tm_mon, (u8)tm->tm_mday, str); printf("\r\n\r\n 今天农历:%0.2d%0.2d,%0.2d,%0.2d", str[0], str[1], str[2], str[3]); GetChinaCalendarStr((u16)tm->tm_year,(u8)tm->tm_mon,(u8)tm->tm_mday,str); printf(" %s", str); if(GetJieQiStr((u16)tm->tm_year, (u8)tm->tm_mon, (u8)tm->tm_mday, str)) printf(" %s\n\r", str); FirstDisplay = 0; } /* 输出时间戳,公历时间 */ printf("\r UNIX时间戳 = %d ,当前时间为: %d年(%s年) %d月 %d日 (星期%s) %0.2d:%0.2d:%0.2d",TimeVar, tm->tm_year, zodiac_sign[(tm->tm_year-3)%12], tm->tm_mon, tm->tm_mday, WEEK_STR[tm->tm_wday], tm->tm_hour, tm->tm_min, tm->tm_sec); }
static int tcube_rtc_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) { char *p = page; int len; struct rtc_time tm; unsigned long curr_time; #if defined(RTC_ALARM_SUPPORT) unsigned char ctrl_reg[2]; #endif curr_time = rtc_get_time(); to_tm(curr_time, &tm); tm.tm_year -= 1900; p += sprintf(p, "rtc_time\t: %02d:%02d:%02d\n" "rtc_date\t: %04d-%02d-%02d\n" "rtc_epoch\t: %04d\n", tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 1970); #if defined(RTC_ALARM_SUPPORT) rtc_get_alm_time(&tm); rtc_get_ctrl_reg(&ctrl_reg[0]); p += sprintf(p, "alrm_time\t: %02d:%02d\n", tm.tm_hour, tm.tm_min); p += sprintf(p, "alarm_IRQ\t: %s\n", (ctrl_reg[0] & 0x40) ? "yes" : "no" ); #endif len = (p - page) - off; if (len < 0) len = 0; *eof = (len <= count) ? 1 : 0; *start = page + off; return len; }
static void SntpHandler(uchar *pkt, unsigned dest, unsigned src, unsigned len){ struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt; struct rtc_time tm; ulong seconds; #ifdef DEBUG printf("%s\n", __FUNCTION__); #endif if(dest != SntpOurPort){ return; } /* * As the RTC's used in U-Boot supports second resolution only * we simply ignore the sub-second field. */ memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong)); to_tm(ntohl(seconds) - 2208988800UL + NetTimeOffset, &tm); #if (CONFIG_COMMANDS & CFG_CMD_DATE) // TODO: find out how to use RTC on //rtc_set(&tm); #endif printf("Got SNTP response: %4d-%02d-%02d %2d:%02d:%02d\n\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); NetState = NETLOOP_SUCCESS; }
static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { struct rtc_time rtc_tm; ulong curr_time; switch (cmd) { case RTC_RD_TIME: /* Read the time/date from RTC */ curr_time = rtc_get_time(); to_tm(curr_time, &rtc_tm); rtc_tm.tm_year -= 1900; return copy_to_user((void *) arg, &rtc_tm, sizeof(rtc_tm)) ? -EFAULT : 0; case RTC_SET_TIME: /* Set the RTC */ if (!capable(CAP_SYS_TIME)) return -EACCES; if (copy_from_user(&rtc_tm, (struct rtc_time *) arg, sizeof(struct rtc_time))) return -EFAULT; curr_time = mktime(rtc_tm.tm_year + 1900, rtc_tm.tm_mon, rtc_tm.tm_mday, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec); return rtc_set_time(curr_time); default: return -EINVAL; } }
void print_image_hdr(image_header_t *hdr) { #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP) time_t timestamp = (time_t)ntohl(hdr->ih_time); struct rtc_time tm; #endif printf(" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name); #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP) to_tm (timestamp, &tm); printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); #endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */ puts(" Image Type: "); print_type(hdr); printf("\n Data Size: %d Bytes = ", ntohl(hdr->ih_size)); print_size(ntohl(hdr->ih_size), "\n"); printf(" Load Address: %08x\n" " Entry Point: %08x\n", ntohl(hdr->ih_load), ntohl(hdr->ih_ep)); if (hdr->ih_type == IH_TYPE_MULTI) { int i; ulong len; ulong *len_ptr = (ulong *) ((ulong) hdr + sizeof(image_header_t)); puts(" Contents:\n"); for (i = 0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) { printf(" Image %d: %8ld Bytes = ", i, len); print_size(len, "\n"); } } }
int m48t37y_set_time(unsigned long sec) { struct rtc_time tm; /* convert to a more useful format -- note months count from 0 */ to_tm(sec, &tm); tm.tm_mon += 1; /* enable writing */ rtc_base[0x7ff8] = 0x80; /* year */ rtc_base[0x7fff] = BIN2BCD(tm.tm_year % 100); rtc_base[0x7ff1] = BIN2BCD(tm.tm_year / 100); /* month */ rtc_base[0x7ffe] = BIN2BCD(tm.tm_mon); /* day */ rtc_base[0x7ffd] = BIN2BCD(tm.tm_mday); /* hour/min/sec */ rtc_base[0x7ffb] = BIN2BCD(tm.tm_hour); rtc_base[0x7ffa] = BIN2BCD(tm.tm_min); rtc_base[0x7ff9] = BIN2BCD(tm.tm_sec); /* day of week -- not really used, but let's keep it up-to-date */ rtc_base[0x7ffc] = BIN2BCD(tm.tm_wday + 1); /* disable writing */ rtc_base[0x7ff8] = 0x00; return 0; }
int rtc_get(struct rtc_time *tmp) { volatile rtc_t *rtc = (rtc_t *) (CFG_MCFRTC_BASE); int rtc_days, rtc_hrs, rtc_mins; int tim; rtc_days = rtc->days; rtc_hrs = rtc->hourmin >> 8; rtc_mins = RTC_HOURMIN_MINUTES(rtc->hourmin); tim = (rtc_days * 24) + rtc_hrs; tim = (tim * 60) + rtc_mins; tim = (tim * 60) + rtc->seconds; to_tm(tim, tmp); tmp->tm_yday = 0; tmp->tm_isdst = 0; #ifdef RTC_DEBUG printf("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); #endif return 0; }
/* Read the time from the RTC_STAT. time_in_seconds is seconds since Jan 1970 */ int rtc_get(struct rtc_time *tmp) { uint32_t cur_rtc_stat; int time_in_sec; int tm_sec, tm_min, tm_hr, tm_day; pr_stamp(); if (tmp == NULL) { puts("Error getting the date/time\n"); return -1; } rtc_init(); wait_for_complete(); /* Read the RTC_STAT register */ cur_rtc_stat = bfin_read_RTC_STAT(); /* Convert our encoded format into actual time values */ tm_sec = (cur_rtc_stat & RTC_SEC) >> RTC_SEC_P; tm_min = (cur_rtc_stat & RTC_MIN) >> RTC_MIN_P; tm_hr = (cur_rtc_stat & RTC_HR ) >> RTC_HR_P; tm_day = (cur_rtc_stat & RTC_DAY) >> RTC_DAY_P; /* Calculate the total number of seconds since epoch */ time_in_sec = (tm_sec) + MIN_TO_SECS(tm_min) + HRS_TO_SECS(tm_hr) + DAYS_TO_SECS(tm_day); to_tm(time_in_sec, tmp); return 0; }
/* ------------------------------------------------------------------------- */ int misc_init_r (void) { char *s, *e; image_header_t *hdr; time_t timestamp; struct rtc_time tm; char bootcmd[32]; hdr = (image_header_t *) (CFG_MONITOR_BASE - sizeof (image_header_t)); timestamp = (time_t) hdr->ih_time; to_tm (timestamp, &tm); printf ("Welcome to U-Boot on Cray L1. Compiled %4d-%02d-%02d %2d:%02d:%02d (UTC)\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); #define FACTORY_SETTINGS 0xFFFC0000 if ((s = getenv ("ethaddr")) == NULL) { e = (char *) (FACTORY_SETTINGS); if (*(e + 0) != '0' || *(e + 1) != '0' || *(e + 2) != ':' || *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') { printf ("No valid MAC address in flash location 0x3C0000!\n"); } else { printf ("Factory MAC: %s\n", e); setenv ("ethaddr", e); } } sprintf (bootcmd,"autoscript %X",(unsigned)bootscript); setenv ("bootcmd", bootcmd); return (0); }
__prep int mk48t59_set_rtc_time(unsigned long nowtime) { unsigned char save_control; struct rtc_time tm; to_tm(nowtime, &tm); /* tell the clock it's being written */ save_control = ppc_md.nvram_read_val(MK48T59_RTC_CONTROLA); ppc_md.nvram_write_val(MK48T59_RTC_CONTROLA, (save_control | MK48T59_RTC_CA_WRITE)); tm.tm_year = (tm.tm_year - 1900) % 100; BIN_TO_BCD(tm.tm_sec); BIN_TO_BCD(tm.tm_min); BIN_TO_BCD(tm.tm_hour); BIN_TO_BCD(tm.tm_mon); BIN_TO_BCD(tm.tm_mday); BIN_TO_BCD(tm.tm_year); ppc_md.nvram_write_val(MK48T59_RTC_SECONDS, tm.tm_sec); ppc_md.nvram_write_val(MK48T59_RTC_MINUTES, tm.tm_min); ppc_md.nvram_write_val(MK48T59_RTC_HOURS, tm.tm_hour); ppc_md.nvram_write_val(MK48T59_RTC_MONTH, tm.tm_mon); ppc_md.nvram_write_val(MK48T59_RTC_DAY_OF_MONTH, tm.tm_mday); ppc_md.nvram_write_val(MK48T59_RTC_YEAR, tm.tm_year); /* Turn off the write bit. */ ppc_md.nvram_write_val(MK48T59_RTC_CONTROLA, save_control); return 0; }
static int it8172_rtc_set_time(unsigned long t) { struct rtc_time tm; unsigned int flags; /* convert */ to_tm(t, &tm); /* avoid update-in-progress. */ for (;;) { local_irq_save(flags); if (! (CMOS_READ(RTC_REG_A) & RTC_UIP)) break; /* don't hold intr closed all the time */ local_irq_restore(flags); } *rtc_century_reg = bin_to_hw(tm.tm_year/100); CMOS_WRITE(bin_to_hw(tm.tm_sec), RTC_SECONDS); CMOS_WRITE(bin_to_hw(tm.tm_min), RTC_MINUTES); CMOS_WRITE(hour_bin_to_hw(tm.tm_hour), RTC_HOURS); CMOS_WRITE(bin_to_hw(tm.tm_mday), RTC_DAY_OF_MONTH); CMOS_WRITE(bin_to_hw(tm.tm_mon+1), RTC_MONTH); /* tm_mon starts from 0 */ CMOS_WRITE(bin_to_hw(tm.tm_year%100), RTC_YEAR); /* restore interrupts */ local_irq_restore(flags); return 0; }
static __inline__ void timer_check_rtc(void) { /* * update the rtc when needed, this should be performed on the * right fraction of a second. Half or full second ? * Full second works on mk48t59 clocks, others need testing. * Note that this update is basically only used through * the adjtimex system calls. Setting the HW clock in * any other way is a /dev/rtc and userland business. * This is still wrong by -0.5/+1.5 jiffies because of the * timer interrupt resolution and possible delay, but here we * hit a quantization limit which can only be solved by higher * resolution timers and decoupling time management from timer * interrupts. This is also wrong on the clocks * which require being written at the half second boundary. * We should have an rtc call that only sets the minutes and * seconds like on Intel to avoid problems with non UTC clocks. */ if ( (time_status & STA_UNSYNC) == 0 && xtime.tv_sec - last_rtc_update >= 659 && abs((xtime.tv_nsec/1000) - (1000000-1000000/HZ)) < 500000/HZ && jiffies - wall_jiffies == 1) { struct rtc_time tm; to_tm(xtime.tv_sec+1, &tm); tm.tm_year -= 1900; tm.tm_mon -= 1; if (ppc_md.set_rtc_time(&tm) == 0) last_rtc_update = xtime.tv_sec+1; else /* Try again one minute later */ last_rtc_update += 60; } }
static void SntpHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len) { struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt; struct rtc_time tm; ulong seconds; debug ("%s\n", __FUNCTION__); if (dest != SntpOurPort) return; /* * As the RTC's used in U-Boot sepport second resolution only * we simply ignore the sub-second field. */ memcpy (&seconds, &rpktp->transmit_timestamp, sizeof(ulong)); to_tm(ntohl(seconds) - 2208988800UL + NetTimeOffset, &tm); #if defined(CONFIG_CMD_DATE) rtc_set (&tm); #endif printf ("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); NetState = NETLOOP_SUCCESS; }
int _rrTime::weekDay() const { tm conv; to_tm(conv); int day=(conv.tm_wday-1); if (day<0) day+=7; if (day<0) day=0; else if (day>6) day=6; return day; }
static int mv_set_rtc(void) { MV_RTC_TIME time; to_tm(xtime.tv_sec, &time); time.year -= 2000; mvRtcTimeSet(&time); return 1; }
QString _rrTime::asStringWeekHourMin() const // weekdate day. hour:minute { tm conv; to_tm(conv); const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL }; return QString("%1 %2. %3:%4").arg(days[conv.tm_wday]).arg(conv.tm_mday,2,10,QChar('0')).arg(conv.tm_hour,2,10,QChar('0')).arg(conv.tm_min,2,10,QChar('0')); }
QString _rrTime::asStringweekDay() const { tm conv; to_tm(conv); const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL }; return QString("%1. %2").arg(conv.tm_mday,2,10,QChar('0')).arg(days[conv.tm_wday]); }
OutItrT put(OutItrT a_next, std::ios_base& a_ios, char_type a_fill, const time_type& a_time) const { if (a_time.is_special()) { return do_put_special(a_next, a_ios, a_fill, a_time.date().as_special()); } string_type format(m_format); string_type frac_str; if (format.find(seconds_with_fractional_seconds_format)) { // replace %s with %S.nnn frac_str = fractional_seconds_as_string(a_time.time_of_day(), false); char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point(); string_type replace_string(seconds_format); replace_string += sep; replace_string += frac_str; boost::algorithm::replace_all(format, seconds_with_fractional_seconds_format, replace_string); } if (format.find(fractional_seconds_format)) { // replace %f with nnnnnnn if (!frac_str.size()) { frac_str = fractional_seconds_as_string(a_time.time_of_day(), false); } boost::algorithm::replace_all(format, fractional_seconds_format, frac_str); } if (format.find(fractional_seconds_or_none_format)) { // replace %F with nnnnnnn or nothing if fs == 0 frac_str = fractional_seconds_as_string(a_time.time_of_day(), true); if (frac_str.size()) { char_type sep = std::use_facet<std::numpunct<char_type> >(a_ios.getloc()).decimal_point(); string_type replace_string; replace_string += sep; replace_string += frac_str; boost::algorithm::replace_all(format, fractional_seconds_or_none_format, replace_string); } else { boost::algorithm::erase_all(format, fractional_seconds_or_none_format); } } return do_put_tm(a_next, a_ios, a_fill, to_tm(a_time), format); }
/* * Prints information about standard * U-Boot image format from header */ static void print_uboot_ih(image_header_t *hdr) { int i; u32 len; u32 *len_ptr; #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP) struct rtc_time tm; time_t timestamp = (time_t)ntohl(hdr->ih_time); #endif puts("\n"); printf(" %-*s ", UBOOT_ALIGN_SIZE, "Image name:"); printf("%.*s\n", sizeof(hdr->ih_name), hdr->ih_name); #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP) printf(" %-*s ", UBOOT_ALIGN_SIZE, "Build date:"); to_tm(timestamp, &tm); printf("%4d-%02d-%02d %02d:%02d:%02d UTC\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); #endif printf(" %-*s ", UBOOT_ALIGN_SIZE, "Architecture:"); printf("%s\n", ih_arch_type(hdr->ih_arch)); printf(" %-*s ", UBOOT_ALIGN_SIZE, "OS/image type:"); printf("%s %s\n", ih_os_type(hdr->ih_os), ih_img_type(hdr->ih_type)); printf(" %-*s ", UBOOT_ALIGN_SIZE, "Compression:"); printf("%s\n", ih_comp_type(hdr->ih_comp)); printf(" %-*s ", UBOOT_ALIGN_SIZE, "Data size:"); print_size(ntohl(hdr->ih_size), " "); printf("(%d bytes)\n", ntohl(hdr->ih_size)); printf(" %-*s ", UBOOT_ALIGN_SIZE, "Load address:"); printf("0x%08X\n", ntohl(hdr->ih_load)); printf(" %-*s ", UBOOT_ALIGN_SIZE, "Entry point:"); printf("0x%08X\n", ntohl(hdr->ih_ep)); if (hdr->ih_type == IH_TYPE_MULTI) { len_ptr = (u32 *)((u32)hdr + sizeof(image_header_t)); printf("\n %-*s\n", UBOOT_ALIGN_SIZE, "Multi-File:"); for (i = 0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) { puts(" > "); print_size(len, " "); printf("(%d bytes)\n", len); } } puts("\n"); }
static void __maybe_unused _dump_time(int time, const char *func, int line) { struct rtc_time tm; to_tm(time, &tm); pr_debug("%s:%d time %d\n", func, line, time); _dump_tm(&tm, func, line); }
int rtc_get(struct rtc_time *time) { struct mxs_rtc_regs *rtc_regs = (struct mxs_rtc_regs *)MXS_RTC_BASE; uint32_t secs; secs = readl(&rtc_regs->hw_rtc_seconds); to_tm(secs, time); return 0; }
void beat_get_rtc_time(struct rtc_time *rtc_time) { u64 tim; if (beat_rtc_read(&tim)) tim = 0; to_tm(tim, rtc_time); rtc_time->tm_year -= 1900; rtc_time->tm_mon -= 1; }
static void rtc_post_restore (struct rtc_time *tm, unsigned int sec) { time_t t = mktime (tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec) + sec; struct rtc_time ntm; to_tm (t, &ntm); rtc_set (&ntm); }
int xicor_set_time(unsigned long t) { struct rtc_time tm; int tmp; to_tm(t, &tm); /* unlock writes to the CCR */ xicor_write(X1241REG_SR, X1241REG_SR_WEL); xicor_write(X1241REG_SR, X1241REG_SR_WEL | X1241REG_SR_RWEL); /* trivial ones */ tm.tm_sec = BIN2BCD(tm.tm_sec); xicor_write(X1241REG_SC, tm.tm_sec); tm.tm_min = BIN2BCD(tm.tm_min); xicor_write(X1241REG_MN, tm.tm_min); tm.tm_mday = BIN2BCD(tm.tm_mday); xicor_write(X1241REG_DT, tm.tm_mday); /* tm_mon starts from 0, *ick* */ tm.tm_mon ++; tm.tm_mon = BIN2BCD(tm.tm_mon); xicor_write(X1241REG_MO, tm.tm_mon); /* year is split */ tmp = tm.tm_year / 100; tm.tm_year %= 100; xicor_write(X1241REG_YR, tm.tm_year); xicor_write(X1241REG_Y2K, tmp); /* hour is the most tricky one */ tmp = xicor_read(X1241REG_HR); if (tmp & X1241REG_HR_MIL) { /* 24 hour format */ tm.tm_hour = BIN2BCD(tm.tm_hour); tmp = (tmp & ~0x3f) | (tm.tm_hour & 0x3f); } else { /* 12 hour format, with 0x2 for pm */ tmp = tmp & ~0x3f; if (tm.tm_hour >= 12) { tmp |= 0x20; tm.tm_hour -= 12; } tm.tm_hour = BIN2BCD(tm.tm_hour); tmp |= tm.tm_hour; } xicor_write(X1241REG_HR, tmp); xicor_write(X1241REG_SR, 0); return 0; }
void SFTWorker::finishFile() { m_hFh.close(); std::string file = m_pCurFile->getFullPath(); gcString str("{0}", m_pCurFile->getTimeStamp()); try { ptime t(from_iso_string(str)); bfs::path spath(file); tm pt_tm = to_tm(t); last_write_time(spath, mktime(&pt_tm)); } catch (...) { Warning(gcString("Failed to change {0} time stamp to {1}.\n", m_pCurFile->getName(), str)); } safe_delete(m_pBzs); std::string hash = "Failed to generate hash"; #ifdef NIX //struct stat s; bool isWinExe = false; if (file.size() > 4) { std::string lastFour(file.end() - 4, file.end()); std::transform(lastFour.begin(), lastFour.end(), lastFour.begin(), ::toupper); if (lastFour == ".EXE") isWinExe = true; } //( && stat(file.c_str(), &s) == 0) bool isExecutable = HasAnyFlags(m_pCurFile->getFlags(), MCFCore::MCFFileI::FLAG_XECUTABLE); if (isExecutable || isWinExe) chmod(file.c_str(), (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)); #endif if (m_pCurFile->isZeroSize() || m_pCurFile->hashCheckFile(&hash)) { m_pCT->endTask(m_uiId, BaseMCFThread::SF_STATUS_COMPLETE); } else { Warning(gcString("Hash check failed for file [{0}]: Cur: {1} != Should: {2}\n", m_pCurFile->getName(), hash, m_pCurFile->getCsum())); m_pCT->endTask(m_uiId, BaseMCFThread::SF_STATUS_HASHMISSMATCH); } }
OutItrT put(OutItrT next, std::ios_base& a_ios, char_type fill_char, const date_type& d) const { if (d.is_special()) { return do_put_special(next, a_ios, fill_char, d.as_special()); } //The following line of code required the date to support a to_tm function return do_put_tm(next, a_ios, fill_char, to_tm(d), m_format); }
int todc_set_rtc_time(unsigned long nowtime) { struct rtc_time tm; u_char save_control, save_freq_select = 0; spin_lock(&rtc_lock); to_tm(nowtime, &tm); save_control = todc_read_val(todc_info->control_a); /* Assuming MK48T59_RTC_CA_WRITE & RTC_SET are equal */ todc_write_val(todc_info->control_a, (save_control | todc_info->enable_write)); save_control &= ~(todc_info->enable_write); /* in case it was set */ if (todc_info->rtc_type == TODC_TYPE_MC146818) { save_freq_select = todc_read_val(todc_info->RTC_FREQ_SELECT); todc_write_val(todc_info->RTC_FREQ_SELECT, save_freq_select | RTC_DIV_RESET2); } tm.tm_year = (tm.tm_year - 1900) % 100; if ((todc_info->rtc_type != TODC_TYPE_MC146818) || ((save_control & RTC_DM_BINARY) == 0) || RTC_ALWAYS_BCD) { BIN_TO_BCD(tm.tm_sec); BIN_TO_BCD(tm.tm_min); BIN_TO_BCD(tm.tm_hour); BIN_TO_BCD(tm.tm_mon); BIN_TO_BCD(tm.tm_mday); BIN_TO_BCD(tm.tm_year); } todc_write_val(todc_info->seconds, tm.tm_sec); todc_write_val(todc_info->minutes, tm.tm_min); todc_write_val(todc_info->hours, tm.tm_hour); todc_write_val(todc_info->month, tm.tm_mon); todc_write_val(todc_info->day_of_month, tm.tm_mday); todc_write_val(todc_info->year, tm.tm_year); todc_write_val(todc_info->control_a, save_control); if (todc_info->rtc_type == TODC_TYPE_MC146818) { todc_write_val(todc_info->RTC_FREQ_SELECT, save_freq_select); } spin_unlock(&rtc_lock); return 0; }
unsigned int get_rtc_time(struct rtc_time *time) { unsigned long nowtime; spin_lock(&mips_rtc_lock); nowtime = rtc_get_time(); to_tm(nowtime, time); time->tm_year -= 1900; spin_unlock(&mips_rtc_lock); return RTC_24H; }