void rtc_init(struct domain *d) { RTCState *s = domain_vrtc(d); if ( !has_vrtc(d) ) return; spin_lock_init(&s->lock); init_timer(&s->update_timer, rtc_update_timer, s, smp_processor_id()); init_timer(&s->update_timer2, rtc_update_timer2, s, smp_processor_id()); init_timer(&s->alarm_timer, rtc_alarm_cb, s, smp_processor_id()); register_portio_handler(d, RTC_PORT(0), 2, handle_rtc_io); rtc_reset(d); spin_lock(&s->lock); s->hw.cmos_data[RTC_REG_A] = RTC_REF_CLCK_32KHZ | 6; /* ~1kHz */ s->hw.cmos_data[RTC_REG_B] = RTC_24H; s->hw.cmos_data[RTC_REG_C] = 0; s->hw.cmos_data[RTC_REG_D] = RTC_VRT; s->current_tm = gmtime(get_localtime(d)); s->start_time = NOW(); rtc_copy_date(s); check_update_timer(s); spin_unlock(&s->lock); }
static void rtc_attach(device_t parent, device_t self, void *aux) { struct rtc_softc *sc = device_private(self); struct apb_attach_args *aa = aux; static int rtc_attached = 0; sc->sc_dev = self; sc->sc_iot = aa->aa_iot; if (rtc_attached) { aprint_error_dev(sc->sc_dev, "rtc is already attached\n"); return; } if (bus_space_map(sc->sc_iot, aa->aa_addr, aa->aa_size, 0, &sc->sc_hdl)) { aprint_error_dev(sc->sc_dev, "Unable to map bus space\n"); return; } rtc_init(sc); rtc_reset(sc); aprint_normal("\n"); rtc_attached = 1; return; }
int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { struct rtc_time tm; int rcode = 0; int old_bus; /* switch to correct I2C bus */ old_bus = I2C_GET_BUS(); I2C_SET_BUS(CONFIG_SYS_RTC_BUS_NUM); switch (argc) { case 2: /* set date & time */ if (strcmp(argv[1],"reset") == 0) { puts ("Reset RTC...\n"); rtc_reset (); } else { /* initialize tm with current time */ rcode = rtc_get (&tm); if(!rcode) { /* insert new date & time */ if (mk_date (argv[1], &tm) != 0) { puts ("## Bad date format\n"); break; } /* and write to RTC */ rcode = rtc_set (&tm); if(rcode) puts("## Set date failled\n"); } else { puts("## Get date failled\n"); } } /* FALL TROUGH */ case 1: /* get date & time */ rcode = rtc_get (&tm); if (rcode) { puts("## Get date failled\n"); break; } printf ("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n", tm.tm_year, tm.tm_mon, tm.tm_mday, (tm.tm_wday<0 || tm.tm_wday>6) ? "unknown " : RELOC(weekdays[tm.tm_wday]), tm.tm_hour, tm.tm_min, tm.tm_sec); break; default: cmd_usage(cmdtp); rcode = 1; } /* switch back to original I2C bus */ I2C_SET_BUS(old_bus); return rcode; }
static int rtc_sub_alarm_test(u32 f_time, u32 f_date) { volatile int hit; int result = 0; rtc_reset(); printf("RTC Time = W%d %d%d:%d%d:%d%d:%d\n", tm.dow, tm.ten_hr, tm.hr, \ tm.ten_min, tm.min, tm.ten_sec, tm.sec, tm.sos); printf("RTC Date = C%d%d %d%d/%d%d/%d%d\n", dt.ten_cent, dt.cent, dt.ten_yr, dt.yr, \ dt.ten_mth, dt.mth, dt.ten_day, dt.day); printf("Alarm Time = W%d %d%d:%d%d:%d%d:%d\n", tm_a.dow, tm_a.ten_hr, tm_a.hr, \ tm_a.ten_min, tm_a.min, tm_a.ten_sec, tm_a.sec, tm_a.sos); printf("Alarm Date = C%d%d %d%d/%d%d/%d%d\n", dt_a.ten_cent, dt_a.cent, dt_a.ten_yr, dt_a.yr, \ dt_a.ten_mth, dt_a.mth, dt_a.ten_day, dt_a.day); printf("Alarm Time on: "); if (f_time & SOCLE_RTC_TALRM_CSOS) printf("\"Sixteen of Second\" "); if (f_time & SOCLE_RTC_TALRM_CS) printf("\"Second\" "); if (f_time & SOCLE_RTC_TALRM_CM) printf("\"Minute\" "); if (f_time & SOCLE_RTC_TALRM_CH) printf("\"Hour\" "); if (f_time & SOCLE_RTC_TALRM_CDOW) printf("\"Day of Week\""); printf("\n"); printf("Alarm Date on: "); if (f_date & SOCLE_RTC_DALRM_CD) printf("\"Day\" "); if (f_date & SOCLE_RTC_DALRM_CM) printf("\"Month\" "); if (f_date & SOCLE_RTC_DALRM_CY) printf("\"Year\" "); if (f_date & SOCLE_RTC_DALRM_CC) printf("\"Century\""); printf("\n"); rtc_set_time_alarm(&tm_a, f_time); rtc_set_date_alarm(&dt_a, f_date); hit = 0; rtc_set_date(&dt); rtc_set_time(&tm); printf("alarm after 15 second...\n"); return result; }
int board_early_init_r(void) { const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; int flash_esel = find_tlb_idx((void *)flashbase, 1); volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); unsigned int orig_bus = i2c_get_bus_num(); u8 i2c_data; i2c_set_bus_num(1); if (i2c_read(CONFIG_SYS_I2C_PCA9557_ADDR, 0, 1, &i2c_data, sizeof(i2c_data)) == 0) { if (i2c_data & 0x2) puts("NOR Flash Bank : Secondary\n"); else puts("NOR Flash Bank : Primary\n"); if (i2c_data & 0x1) { setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA); puts("SD/MMC : 8-bit Mode\n"); puts("eSPI : Disabled\n"); } else { puts("SD/MMC : 4-bit Mode\n"); puts("eSPI : Enabled\n"); } } else { puts("Failed reading I2C Chip 0x18 on bus 1\n"); } i2c_set_bus_num(orig_bus); /* * Remap Boot flash region to caching-inhibited * so that flash can be erased properly. */ /* Flush d-cache and invalidate i-cache of any FLASH data */ flush_dcache(); invalidate_icache(); if (flash_esel == -1) { /* very unlikely unless something is messed up */ puts("Error: Could not find TLB for FLASH BASE\n"); flash_esel = 2; /* give our best effort to continue */ } else { /* invalidate existing TLB entry for flash */ disable_tlb(flash_esel); } set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, 0, flash_esel, BOOKE_PAGESZ_16M, 1); rtc_reset(); return 0; }
extern int auto_poweroff_alarm_test(int autotest) { int count_down_s = 5; rtc_reset(); // Set alarm date and alarm time // alarm date = C21 06/12/31 dt_a.ten_cent = 2; dt_a.cent = 1; dt_a.ten_yr = 0; dt_a.yr = 6; dt_a.ten_mth = 1; dt_a.mth = 2; dt_a.ten_day = 3; dt_a.day = 1; rtc_set_date_alarm(&dt_a, SOCLE_RTC_DALRM_CD | SOCLE_RTC_DALRM_CM | SOCLE_RTC_DALRM_CY | SOCLE_RTC_DALRM_CC); // alarm time = Wed 17:58:1count_down_s.10 tm_a.dow = 3; tm_a.ten_hr = 1; tm_a.hr = 7; tm_a.ten_min = 5; tm_a.min = 8; tm_a.ten_sec = 1; tm_a.sec = count_down_s; tm_a.sos = 10; rtc_set_time_alarm(&tm_a, SOCLE_RTC_TALRM_CSOS | SOCLE_RTC_TALRM_CS | SOCLE_RTC_TALRM_CM | SOCLE_RTC_TALRM_CH | SOCLE_RTC_TALRM_CDOW); // Set date and time // date = C21 06/12/31 dt.ten_cent = 2; dt.cent = 1; dt.ten_yr = 0; dt.yr = 6; dt.ten_mth = 1; dt.mth = 2; dt.ten_day = 3; dt.day = 1; rtc_set_date(&dt); // time = Wed 17:58:10.2 tm.dow = 3; tm.ten_hr = 1; tm.hr = 7; tm.ten_min = 5; tm.min = 8; tm.ten_sec = 1; tm.sec = 0; tm.sos = 2; rtc_set_time(&tm); printf("Count down %d seconds...\n", count_down_s); printf("Sleeping...\n"); EN_RTC_ALARM_POWER_ON(); ENTER_RTC_POWER_OFF_MODE(); return 0; }
static int rtc_sub_alarm_test(u32_t f_time, u32_t f_date) { volatile int hit; int result = 0; rtc_reset(); printf("RTC Time = W%d %d%d:%d%d:%d%d:%d\n", tm.dow, tm.ten_hr, tm.hr, \ tm.ten_min, tm.min, tm.ten_sec, tm.sec, tm.sos); printf("RTC Date = C%d%d %d%d/%d%d/%d%d\n", dt.ten_cent, dt.cent, dt.ten_yr, dt.yr, \ dt.ten_mth, dt.mth, dt.ten_day, dt.day); printf("Alarm Time = W%d %d%d:%d%d:%d%d:%d\n", tm_a.dow, tm_a.ten_hr, tm_a.hr, \ tm_a.ten_min, tm_a.min, tm_a.ten_sec, tm_a.sec, tm_a.sos); printf("Alarm Date = C%d%d %d%d/%d%d/%d%d\n", dt_a.ten_cent, dt_a.cent, dt_a.ten_yr, dt_a.yr, \ dt_a.ten_mth, dt_a.mth, dt_a.ten_day, dt_a.day); printf("Alarm Time on: "); if (f_time & SOCLE_RTC_TALRM_CSOS) printf("\"Sixteen of Second\" "); if (f_time & SOCLE_RTC_TALRM_CS) printf("\"Second\" "); if (f_time & SOCLE_RTC_TALRM_CM) printf("\"Minute\" "); if (f_time & SOCLE_RTC_TALRM_CH) printf("\"Hour\" "); if (f_time & SOCLE_RTC_TALRM_CDOW) printf("\"Day of Week\""); printf("\n"); printf("Alarm Date on: "); if (f_date & SOCLE_RTC_DALRM_CD) printf("\"Day\" "); if (f_date & SOCLE_RTC_DALRM_CM) printf("\"Month\" "); if (f_date & SOCLE_RTC_DALRM_CY) printf("\"Year\" "); if (f_date & SOCLE_RTC_DALRM_CC) printf("\"Century\""); printf("\n"); rtc_set_time_alarm(&tm_a, f_time); rtc_set_date_alarm(&dt_a, f_date); hit = 0; // enable interrupt request_irq(RTC_INT, rtc_isr_alarm_hit, (void *)&hit); rtc_set_date(&dt); rtc_set_time(&tm); printf("Waiting for the alarm...\n"); if (socle_wait_for_int(&hit, 10)) { printf("Timeout!!\n"); result = -1; } // disable interrupt free_irq(RTC_INT); return result; }
static int do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct rtc_time tm; int rcode = 0; int old_bus __maybe_unused; /* switch to correct I2C bus */ #ifdef CONFIG_DM_RTC struct udevice *dev; rcode = uclass_get_device(UCLASS_RTC, 0, &dev); if (rcode) { printf("Cannot find RTC: err=%d\n", rcode); return CMD_RET_FAILURE; } #elif defined(CONFIG_SYS_I2C) old_bus = i2c_get_bus_num(); i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM); #else old_bus = I2C_GET_BUS(); I2C_SET_BUS(CONFIG_SYS_RTC_BUS_NUM); #endif switch (argc) { case 2: /* set date & time */ if (strcmp(argv[1],"reset") == 0) { puts ("Reset RTC...\n"); #ifdef CONFIG_DM_RTC rcode = dm_rtc_reset(dev); if (!rcode) rcode = dm_rtc_set(dev, &default_tm); #else rtc_reset(); rcode = rtc_set(&default_tm); #endif if (rcode) puts("## Failed to set date after RTC reset\n"); } else { /* initialize tm with current time */ #ifdef CONFIG_DM_RTC rcode = dm_rtc_get(dev, &tm); #else rcode = rtc_get(&tm); #endif if (!rcode) { /* insert new date & time */ if (mk_date(argv[1], &tm) != 0) { puts ("## Bad date format\n"); break; } /* and write to RTC */ #ifdef CONFIG_DM_RTC rcode = dm_rtc_set(dev, &tm); #else rcode = rtc_set(&tm); #endif if (rcode) { printf("## Set date failed: err=%d\n", rcode); } } else { puts("## Get date failed\n"); } } /* FALL TROUGH */ case 1: /* get date & time */ #ifdef CONFIG_DM_RTC rcode = dm_rtc_get(dev, &tm); #else rcode = rtc_get(&tm); #endif if (rcode) { puts("## Get date failed\n"); break; } printf ("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n", tm.tm_year, tm.tm_mon, tm.tm_mday, (tm.tm_wday<0 || tm.tm_wday>6) ? "unknown " : RELOC(weekdays[tm.tm_wday]), tm.tm_hour, tm.tm_min, tm.tm_sec); break; default: rcode = CMD_RET_USAGE; } /* switch back to original I2C bus */ #ifdef CONFIG_SYS_I2C i2c_set_bus_num(old_bus); #elif !defined(CONFIG_DM_RTC) I2C_SET_BUS(old_bus); #endif return rcode ? CMD_RET_FAILURE : 0; }
void set_date(int argc, char **argv) { unsigned char *str_rtc; struct rtc_time tmku; int ret; time_t clk; rtc_reset(); rtc_init(); rtc_start(); str_rtc = pvPortMalloc(512); if (str_rtc == NULL) { printf("ERR: alok failed\r\n"); //free(str_rtc); vPortFree(str_rtc); return; } //printf("dapat free %X\r\n", str_rtc); memset(str_rtc, 0, 512); printf(" set_date tahun bulan tanggal jam menit\r\n"); printf(" misalnya : set_date 2010 3 5 10 22\r\n"); printf(" artinya : set waktu ke tgl 5 Maret 2010, jam 10:22 pagi\r\n"); if (argc < 5) { printf("Argument kurang !\r\n"); vPortFree(str_rtc); return; } //display_args(argc, argv); sprintf(str_rtc, "%s:%s:%s:%s:%s", argv[1], argv[2], argv[3], argv[4], argv[5]); ret = sscanf(str_rtc, "%d:%d:%d:%d:%d", &tmku.tm_year, &tmku.tm_mon, &tmku.tm_mday, &tmku.tm_hour, &tmku.tm_min); if (ret < 5) { printf(" ERR: format salah !\r\n"); vPortFree(str_rtc); return; } printf(" Set : %d-%d-%d %d:%d ", tmku.tm_year, tmku.tm_mon, tmku.tm_mday, tmku.tm_hour, tmku.tm_min); tmku.tm_year = tmku.tm_year - 1900; tmku.tm_mon = tmku.tm_mon - 1; tmku.tm_sec = 0; debug_printf(" OK : %d-%d-%d %d:%d\r\n", tmku.tm_year, tmku.tm_mon, tmku.tm_mday, tmku.tm_hour, tmku.tm_min); /* if (rtc_valid_tm(&tmku)) { printf(" ERR: waktu tidak mungkin !\r\n"); return; }*/ //rtc_set_time_tm( tmku ); rtcWrite( &tmku ); //clk = mktime(&tmku); //ret = rtc_time_to_bfin(clk); //bfin_write_RTC_STAT(ret); vPortFree(str_rtc); printf(" ..OK\r\n"); }
static PyObject * py_ds1302_reset_clock(PyObject *self, PyObject *args) { rtc_reset(); Py_RETURN_NONE; }
int misc_init_r(void) { rtc_reset(); return 0; }
void sysinit (void) { /* Setup Allowed Power modes */ SMC_PMPROT = (SMC_PMPROT_AVLP_MASK | SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLLS_MASK); /* Read RCM for identification of Chip Reset reason */ if (RCM_SRS0 & RCM_SRS0_WAKEUP_MASK) { /* Releases hold with ACKISO: Only has an effect if recovering from VLLS1, VLLS2, or VLLS3 if ACKISO is set you must clear ackiso before calling pll_init or pll init hangs waiting for OSC to initialize if osc enabled in low power modes - enable it first before ack if I/O needs to be maintained without glitches enable outputs and modules first before ack. */ if (PMC_REGSC & PMC_REGSC_ACKISO_MASK) { PMC_REGSC |= PMC_REGSC_ACKISO_MASK; /* Clear ACKISO bit */ LLWU_ME &= ~LLWU_ME_WUME4_MASK; /* TSI LLWU Input Disable = LLWU_M4IF */ } } else if (RCM_SRS0 & RCM_SRS0_LOC_MASK) { /* Loss of clock case */ } /* Enable all of the port clocks. These have to be enabled to configure * pin muxing options, so most code will need all of these on anyway. */ SIM_SCGC5 |= (SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK ); clk_out_init(); #if defined(NO_PLL_INIT) mcg_clk_hz = 21000000; //FEI mode #else /* Ramp up the system clock */ /* Set the system dividers */ /* NOTE: The PLL init will not configure the system clock dividers, * so they must be configured appropriately before calling the PLL * init function to ensure that clocks remain in valid ranges. */ SIM_CLKDIV1 = ( 0 | SIM_CLKDIV1_OUTDIV1(0) | SIM_CLKDIV1_OUTDIV4(1) ); #if !defined(FRDM_KL02Z48) /* Reset RTC if it was started from the startup */ rtc_reset(); #endif /* Initialize PLL */ /* PLL will be the source for MCG CLKOUT so the core, system, and flash clocks are derived from it */ mcg_clk_hz = fei_fee(CLK0_FREQ_HZ,HIGH_GAIN,CLK0_TYPE); /* Check the value returned from pll_init() to make sure there wasn't an error */ if (mcg_clk_hz < 0x100) while(1); #endif }