int16 rtc_read_int16(int8 addr) { int8 a,b; a=read_rtc(addr+0); b=read_rtc(addr+1); return make16(a,b); }
int32 rtc_read_int32(int8 addr) { int8 a,b,c,d; a=read_rtc(addr+0); // MSB b=read_rtc(addr+1); c=read_rtc(addr+2); d=read_rtc(addr+3); // LSB return make32(a,b,c,d); }
void *UI_thread() { static int sw_ch=0,log_time,tot_rec,counter; do { while(READ_ADC == Yes); printf("\n /------------------------ LAB 4 ---------------------------------------/"); printf("\n /-------------- WELCOME!! INTEL GALILEO BASED DAS ---------------------/"); printf("\n /--------------- SELECT FROM FOLLOWING OPTIONS ------------------------/"); printf("\n 1.SET RTC TIME\n 2.SET RTC DATE\n 3.READ RTC TIME\n 4.READ ADC \n 5.EXIT APPLICATION\n\n ENTER OPTION : \t"); READ_ADC = Yes; scanf("%d",&sw_ch); switch(sw_ch) { case SET_CLK : set_rtc(); READ_ADC = No; break; case SET_DATE : set_date(); READ_ADC = No ; break; case READ_CLK : ui_disp = 1; read_rtc(); READ_ADC = No; break; case DATA_LOG : //pass signal to thread2 to update the adc value ui_disp = 1; read_rtc(); printf("\tLDR value = %d\n",adc_data); READ_ADC = No; break; case EXIT_APP : printf("\n GOODBYE !!! APPLICATION CLOSED\n "); exit_rtc(); end_prog = 1; break; default : printf("OOPS !!! WRONG OPTION "); } }while(end_prog == 0); pthread_exit(NULL); }
float rtc_read_float(int8 addr) { int8 a,b,c,d; union_int32_float u; a=read_rtc(addr+0); // MSB b=read_rtc(addr+1); c=read_rtc(addr+2); d=read_rtc(addr+3); // LSB u.l = make32(a,b,c,d); return u.f; }
//------------------------------------------------------------------------ // Format the Date and Time for the LCD display //------------------------------------------------------------------------ void FormatDateTime ( void ) { ulTime = read_rtc (); // get the RTC value mktm( &CurTime, ulTime ); // convert seconds to date values strftime( szTime, sizeof szTime, "%a %b %e, %Y\n%H:%M:%S", &CurTime); }
void get_time(struct tm *ptm) { struct tm *tm; time_t t; t = read_rtc(1); tm = localtime(&t); /* Sets 'tzname[]' */ bcopy(tm,ptm,sizeof(struct tm)); }
/* * Read the current time from the clock chip and convert to UNIX form. * Assumes that the year in the clock chip is valid. * Must be called with tod_lock held. */ static timestruc_t todbq4802_get(void) { timestruc_t ts; todinfo_t tod; struct rtc_t rtc; ASSERT(MUTEX_HELD(&tod_lock)); read_rtc(&rtc); DPRINTF("todbq4802_get: century=%d year=%d dom=%d hrs=%d min=%d" " sec=%d\n", rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs, rtc.rtc_min, rtc.rtc_sec); /* * tod_year is base 1900 so this code needs to adjust the true * year retrieved from the rtc's century and year fields. */ tod.tod_year = rtc.rtc_year + (rtc.rtc_century * 100) - 1900; tod.tod_month = rtc.rtc_mon; tod.tod_day = rtc.rtc_dom; tod.tod_dow = rtc.rtc_dow; tod.tod_hour = rtc.rtc_hrs; tod.tod_min = rtc.rtc_min; tod.tod_sec = rtc.rtc_sec; ts.tv_sec = tod_to_utc(tod); ts.tv_nsec = 0; return (ts); }
/*----------------------------------------------------------------------------*/ void rtc_fun(void) { MAIN_POWER_PORT_INIT(); MAIN_POWER_PORT_DISABLE(); iic_gpio_set_low(); amp_mute(1); if(alm_on_flag){ if(sys_main_vol != alrm_vol_bakup) sys_main_vol = alrm_vol_bakup; alm_on_flag = 0; } input_number_en = 0; vol_change_en=0; key_voice_en=0; main_menu = MENU_RTC; close_alarm(); dsp_set_eq_mode(0); //系统时钟div前需关闭eq SYSTEM_CLK_DIV4(); key_table_sel(0); flush_all_msg(); set_max_vol(MAX_ANOLOG_VOL,MAX_DIGITAL_VOL);///设置最大音量 dac_out_select(DAC_MUSIC, 0); rtc_mode_setting = RTC_DISPLAY; rtc_coordinate = 0; alm_coordinate = 0; if (alm_cnt) { put_msg_lifo(MSG_ALM_ON); } else { read_rtc(&curr_time); chk_date_err(); disp_port(MENU_RTC); } MAIN_POWER_PORT_INIT(); MAIN_POWER_PORT_DISABLE(); deal_rtc(); amp_mute(1); MAIN_POWER_PORT_ENABLE(); delay_10ms(3); key_voice_en=0; main_vol_set(0, CHANGE_VOL_NO_MEM); MAIN_POWER_PORT_ENABLE(); amp_mute(1); delay_10ms(80); snooze_en =0; PT2313_Init(); delay_10ms(10); PT2313_Init(); }
static void show_clock(const char **pp_rtcname, int utc) { #if SHOW_HWCLOCK_DIFF struct timeval sys_tv; #endif time_t t; char *cp; t = read_rtc(pp_rtcname, &sys_tv, utc); cp = ctime(&t); strchrnul(cp, '\n')[0] = '\0'; #if !SHOW_HWCLOCK_DIFF printf("%s 0.000000 seconds\n", cp); #else { long diff = sys_tv.tv_sec - t; if (diff < 0 /*&& tv.tv_usec != 0*/) { /* Why? */ /* diff >= 0 is ok: diff < 0, can't just use tv.tv_usec: */ /* 45.520820 43.520820 */ /* - 44.000000 - 45.000000 */ /* = 1.520820 = -1.479180, not -2.520820! */ diff++; /* should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */ sys_tv.tv_usec = 999999 - sys_tv.tv_usec; } printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec); } #endif }
/* * Read the current time from the clock chip and convert to UNIX form. * Assumes that the year in the clock chip is valid. * Must be called with tod_lock held. */ static timestruc_t todm5819_get(void) { int i; timestruc_t ts; struct rtc_t rtc; ASSERT(MUTEX_HELD(&tod_lock)); /* * Read from the tod, and if it isnt accessible wait * before retrying. */ for (i = 0; i < TODM5819_UIP_RETRY_THRESH; i++) { if (read_rtc(&rtc)) break; drv_usecwait(TODM5819_UIP_WAIT_USEC); } if (i == TODM5819_UIP_RETRY_THRESH) { /* * We couldnt read from the tod */ tod_fault_reset(); return (hrestime); } DPRINTF("todm5819_get: century=%d year=%d dom=%d hrs=%d\n", rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs); ts.tv_sec = tod_to_utc(rtc_to_tod(&rtc)); ts.tv_nsec = 0; return (ts); }
void pcf8583_init(void) { uint8_t tmp[4]; rtc_state = RTC_NOT_FOUND; uart_puts_P(PSTR("RTC ")); if (i2c_write_register(PCF8583_ADDR, REG_CONTROL, CTL_START_CLOCK) || i2c_read_registers(PCF8583_ADDR, REG_YEAR1, 4, tmp)) { uart_puts_P(PSTR("not found")); } else { if (tmp[0] == (tmp[2] ^ 0xff) && tmp[1] == (tmp[3] ^ 0xff)) { rtc_state = RTC_OK; uart_puts_P(PSTR("ok")); /* Dummy RTC read to update the year if required */ struct tm time; read_rtc(&time); } else { rtc_state = RTC_INVALID; uart_puts_P(PSTR("invalid")); } } uart_putcrlf(); }
static int ps3_set_time(struct device *dev, struct rtc_time *tm) { unsigned long now; rtc_tm_to_time(tm, &now); ps3_os_area_set_rtc_diff(now - read_rtc()); return 0; }
int ps3_set_rtc_time(struct rtc_time *tm) { u64 now = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); ps3_os_area_set_rtc_diff(now - read_rtc()); return 0; }
void init_rtc(void) { struct tm tm; read_rtc(&tm); start_time = mktime(&tm); printf("System real-time clock: %s", asctime(&tm)); }
//print the time to a string void sprint_time(char *buffer){ unsigned long thetime; struct tm thetm; thetime = read_rtc(); mktm(&thetm, thetime); //sprintf(buffer,"@ %04d.%02d.%02d - %02d:%02d:%02d", // 1900+thetm.tm_year, thetm.tm_mon, thetm.tm_mday, // thetm.tm_hour, thetm.tm_min, thetm.tm_sec); sprintf(buffer,"%02d:%02d",thetm.tm_hour, thetm.tm_min); }
void init_rtc() { read_rtc(&rtc_date_time); kprintf("Initializing real time clock\n"); kprintf("\tCurrent Date Time: %d Century, %d-%d-%d %d:%d:%d\n", rtc_date_time.century, rtc_date_time.year, rtc_date_time.month, rtc_date_time.day, rtc_date_time.hour, rtc_date_time.minute, rtc_date_time.second ); }
//Interrupt receptor void interupt_handler(int time) { int ipc_status; message msg; //int irq_set=timer_subscribe_int(); int error; //ligar RTC unsigned long regB; counter = 0; regB = read_rtc(RTC_REG_B); regB = regB ^ RTC_UIE; write_rtc(RTC_REG_B,regB); while(counter<(time*60) && check_number_of_tries()==0) { /* Get a request message. */ error = driver_receive(ANY, &msg, &ipc_status); if (error != 0 ) { printf("driver_receive failed with: %d",error); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ /*if ((msg.NOTIFY_ARG & BIT(0)) && (counter%60==0)) //subscribed interruptTimer { //timer_int_handler(counter); //same function as in lab3 RTC_handler_date(); counter++; } else*/ if(msg.NOTIFY_ARG & BIT(1)) { keyboard_handler(); //different function from the original } break; default: break; /* no other notifications expected: do nothing */ } } else { /* received a standard message, not a notification */ /* no standard messages expected: do nothing */ } counter++; } return; }
void sys_printf(char *str) { uart_init(); #if 0 read_rtc(&curr_time); chk_date_err(); printf("%u:%u:%u ",(u16)curr_time.hour,(u16)curr_time.min,(u16)curr_time.sec); #endif printf(str); printf("\r\n"); }
int to_sys_clock ( int utc ) { struct timeval tv = { 0, 0 }; const struct timezone tz = { timezone/60 - 60*daylight, 0 }; tv. tv_sec = read_rtc ( utc ); if ( settimeofday ( &tv, &tz )) bb_perror_msg_and_die ( "settimeofday() failed" ); return 0; }
static int cmos_ctl(int minor, void *data, int cmd, void *arg) { switch(cmd) { case CMOS_CMD_READ_RTC: *(long *)arg = read_rtc(); break; default: printk("cmos_ctl: invaild cmd\n"); return -1; } return 0; }
static void to_sys_clock(const char **pp_rtcname, int utc) { struct timeval tv; struct timezone tz; tz.tz_minuteswest = timezone/60 - 60*daylight; tz.tz_dsttime = 0; tv.tv_sec = read_rtc(pp_rtcname, NULL, utc); tv.tv_usec = 0; if (settimeofday(&tv, &tz)) bb_perror_msg_and_die("settimeofday"); }
/* read real time clock and update timers structure */ void update_time_rtc(void) { timers.hour=bcd2bin(read_rtc(0x02) & 0b00111111); timers.minute=bcd2bin(read_rtc(0x01)); timers.second=bcd2bin(read_rtc(0x00) & 0b01111111); timers.day=bcd2bin(read_rtc(0x04)); timers.month=bcd2bin(read_rtc(0x05)); timers.year=bcd2bin(read_rtc(0x06)); }
void gettime(char *intime) { struct tm rtm; // time struct unsigned long t0; // used for date->seconds conversion ////////////////////////////////////////////////// // read current date/time t0 = read_rtc(); // read time in seconds since 1980 mktm(&rtm, t0); sprintf(intime,"%02d/%02d/%04d %02d:%02d:%02d", rtm.tm_mon, rtm.tm_mday, 1900+rtm.tm_year, rtm.tm_hour, rtm.tm_min, rtm.tm_sec); }
int show_clock ( int utc ) { struct tm *ptm; time_t t; char buffer [64]; t = read_rtc ( utc ); ptm = localtime ( &t ); /* Sets 'tzname[]' */ safe_strncpy ( buffer, ctime ( &t ), sizeof( buffer )); if ( buffer [0] ) buffer [bb_strlen ( buffer ) - 1] = 0; //printf ( "%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : ( ptm-> tm_isdst ? tzname [1] : tzname [0] )); printf ( "%s %.6f seconds\n", buffer, 0.0 ); return 0; }
static int show_clock(int utc) { struct tm *ptm; time_t t; RESERVE_CONFIG_BUFFER(buffer, 64); t = read_rtc(utc); ptm = localtime(&t); /* Sets 'tzname[]' */ safe_strncpy(buffer, ctime(&t), 64); if (buffer[0]) buffer[strlen(buffer) - 1] = 0; //printf("%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : (ptm->tm_isdst ? tzname[1] : tzname[0])); printf( "%s %.6f seconds\n", buffer, 0.0); RELEASE_CONFIG_BUFFER(buffer); return 0; }
void set_nist_time(){ int dst, health; struct tm t; unsigned long longsec; char response[100]; int bytes_read,total_bytes; tcp_Socket sock; longword nist_server; printf("Trying to set time from NIST server...\n"); //get the time if (!(nist_server = resolve(NIST_SERVER))) { printf(" ! Could not resolve time host\n"); exit( 3 ); } if( !tcp_open(&sock,0,nist_server,NIST_PORT,NULL)){ printf(" ! Unable to connect to time server\n"); exit( 3 ); } while (!sock_established(&sock) && sock_bytesready(&sock)==-1){ tcp_tick(NULL); } sock_mode(&sock, TCP_MODE_ASCII); total_bytes=0; do{ bytes_read=sock_fastread(&sock,response+total_bytes,sizeof(response)-1-total_bytes); total_bytes+=bytes_read; } while(tcp_tick(&sock) && (total_bytes < sizeof(response)-2)); //parse it t.tm_year = 100 + 10*(response[7]-'0') + (response[8]-'0'); t.tm_mon = 10*(response[10]-'0') + (response[11]-'0'); t.tm_mday = 10*(response[13]-'0') + (response[14]-'0'); t.tm_hour = 10*(response[16]-'0') + (response[17]-'0'); t.tm_min = 10*(response[19]-'0') + (response[20]-'0'); t.tm_sec = 10*(response[22]-'0') + (response[23]-'0'); dst = 10*(response[25]-'0') + (response[26]-'0'); health = response[28]-'0'; longsec = mktime(&t); longsec += 3600ul * NIST_TIMEZONE; // adjust for timezone if (dst != 0) longsec += 3600ul; // DST is in effect if (health < 2) write_rtc(longsec); printf(" Time set to : "); print_time(read_rtc()); }
void *sense_thread() { do { pthread_mutex_lock(&switch_lock); usleep(1000000); if(write_cmd(MSG_GET) != 0 ) printf("\nwrite failed"); adc_data = (read_data() | (read_data() << 4) | (read_data() << 8)); http.adcval = adc_data ; read_rtc(); pthread_mutex_unlock(&switch_lock); }while(end_prog == 0); pthread_exit(NULL); }
/* * Read the current time from the clock chip and convert to UNIX form. * Assumes that the year in the clock chip is valid. * Must be called with tod_lock held. */ static timestruc_t todds_get(void) { timestruc_t ts; todinfo_t tod; struct rtc_t rtc; ASSERT(MUTEX_HELD(&tod_lock)); read_rtc(&rtc); DPRINTF("todds_get: century=%d year=%d dom=%d hrs=%d\n", rtc.rtc_century, rtc.rtc_year, rtc.rtc_dom, rtc.rtc_hrs); /* * tod_year is base 1900 so this code needs to adjust the true * year retrieved from the rtc's century and year fields. */ tod.tod_year = rtc.rtc_year + (rtc.rtc_century * 100) - 1900; tod.tod_month = rtc.rtc_mon; tod.tod_day = rtc.rtc_dom; tod.tod_dow = rtc.rtc_dow; tod.tod_hour = rtc.rtc_hrs; tod.tod_min = rtc.rtc_min; tod.tod_sec = rtc.rtc_sec; ts.tv_sec = tod_to_utc(tod); ts.tv_nsec = 0; /* set the hw watchdog timer if it's been activated */ if (watchdog_activated) { int ret = 0; ret = tod_ops.tod_set_watchdog_timer(watchdog_timeout_seconds); if (ret == 0) cmn_err(CE_WARN, "ds1287: failed to set hardware " "watchdog timer."); } return (ts); }
static void show_clock(const char **pp_rtcname, int utc) { #if SHOW_HWCLOCK_DIFF struct timeval sys_tv; #endif time_t t = read_rtc(pp_rtcname, &sys_tv, utc); #if ENABLE_LOCALE_SUPPORT /* Standard hwclock uses locale-specific output format */ char cp[64]; struct tm *ptm = localtime(&t); strftime(cp, sizeof(cp), "%c", ptm); #else char *cp = ctime(&t); strchrnul(cp, '\n')[0] = '\0'; #endif #if !SHOW_HWCLOCK_DIFF printf("%s 0.000000 seconds\n", cp); #else { long diff = sys_tv.tv_sec - t; if (diff < 0 /*&& tv.tv_usec != 0*/) { /* Why we need diff++? */ /* diff >= 0 is ok: | diff < 0, can't just use tv.tv_usec: */ /* 45.520820 | 43.520820 */ /* - 44.000000 | - 45.000000 */ /* = 1.520820 | = -1.479180, not -2.520820! */ diff++; /* Should be 1000000 - tv.tv_usec, but then we must check tv.tv_usec != 0 */ sys_tv.tv_usec = 999999 - sys_tv.tv_usec; } printf("%s %ld.%06lu seconds\n", cp, diff, (unsigned long)sys_tv.tv_usec); } #endif }
//------------------------------------------------------------------------ // Display the Date and Time on the LCD display //------------------------------------------------------------------------ int dispDate( void ) { static int status; auto int wKey; costate { // Get current Date/Time status = 0; ulTime = read_rtc (); // get the RTC value mktm( &CurTime, ulTime ); // convert seconds to date values FormatDateTime(); // convert to text waitfor(DelayMs(5)); // Display Date and Time glBuffLock(); TextGotoXY(&textWindow, 0, 0); TextPrintf(&textWindow, "%s\n", szTime); waitfor(DelayMs(5)); // Display user exit message TextGotoXY(&textWindow, 0, 3); TextPrintf(&textWindow, "Press Key to EXIT"); waitfor(DelayMs(5)); glBuffUnlock(); // Wait for key to be pressed to exit waitfor(((wKey = keyGet()) != 0) || DelayMs(100)); if(wKey != 0) { glBlankScreen(); status = 1; } } return(status); }