Ejemplo n.º 1
0
/**
 * \brief Execute oven control step.
 *
 * This function takes information from the user interface, temperature sensor
 * and plate (QTouch) sensing and controls the output to the induction elements
 * via a frequency signal.
 *
 * The oven has three states:
 *    - POWER_OFF where we just wait for input from the user interface to turn
 *      on.
 *    - ON_NO_POT where the user has indicated that power should be applied, but
 *      there is no pot in the plate. A safety timer changes the state back to
 *      POWER_OFF.
 *    - ON_ACTUATING where we have a pot on the oven, and actuate the induction
 *      elements while waiting for user input, and check if there is a pot on
 *      the oven.
 *
 * \param time Current system time in milliseconds.
 * \param *wattage Pointer to the variable representing the desired effect
 * \param *power Pointer to the variable controlling whether the induction
 * coils should be actuated.
 * \param potstate A variable representing the latest information on whether
 * anything is present on the plate (QTouch sensor)
 */
void ovenctl_execute_control_step(uint32_t time, uint8_t *wattage, bool *power,
		enum pot_t potstate)
{
	/* Current state of the oven */
	static enum ovenctl_plate_state plate_control_state = POWER_OFF;
	static uint32_t time_pot_off = 0;

	switch (plate_control_state) {
	case POWER_OFF:
		/* If the user has requested that the power be turned on,
		 * run Class B tests and go to ON_NO_POT
		 */
		if (*wattage > 0) {
			ovenctl_turn_on_plate();
			time_pot_off = rtc_get_time();
			plate_control_state = ON_NO_POT;
		}
		break;

	case ON_NO_POT:
		/* If too long has passed without pot on the plate, turn off
		 * oven
		 */
		if ((rtc_get_time() - time_pot_off) > (20 * 1000)) {
			ovenctl_turn_off_plate(wattage, power);
			plate_control_state = POWER_OFF;

		/* If user turned off power, turn off power. */
		} else if (*wattage == 0) {
			ovenctl_turn_off_plate(wattage, power);
			plate_control_state = POWER_OFF;

		/* If pot is put back before timeout, go back to active mode */
		} else if (potstate == POT_ON) {
			*power = true;
			plate_control_state = ON_ACTUATING;
		}
		break;

	case ON_ACTUATING:
		/* Check if pot is on. If it is not, go to inactive mode. */
		if (potstate == POT_OFF) {
			*power = false;
			time_pot_off = rtc_get_time();
			plate_control_state = ON_NO_POT;

		/* If user turned off power, turn off power. */
		} else if (*wattage == 0) {
			ovenctl_turn_off_plate(wattage, power);
			plate_control_state = POWER_OFF;
		}

		break;
	}

	/* Update the output signal to the induction element according to
	 * selected power level, and whether power should be applied.
	 */
	ovenctl_actuate_induction_element(*power ? *wattage : 0);
}
Ejemplo n.º 2
0
/**
 * rtc_show_configuration - output configuration to uart
 */
void rtc_show_configuration(void)
{
	uart_send_text_sram("Time: ");
	uint8_t i;
	char time[3][3];
	for (i = RTC_SECOND; i < (RTC_SECOND + 3); i++)	{
		uint8_t time_temp;
		rtc_get_time(i, &time_temp);
		int_to_string_fixed_length(time[i], 3, time_temp);
	}

	uart_send_text_buffer(time[2]);
	uart_send_text_sram(":");
	uart_send_text_buffer(time[1]);
	uart_send_text_sram(":");
	uart_send_text_buffer(time[0]);
	UART_NEWLINE();

	uart_send_text_sram("Date: ");
	for (i = RTC_DATE; i < (RTC_DATE + 3); i++)	{
		uint8_t time_temp;
		rtc_get_time(i, &time_temp);
		int_to_string_fixed_length(time[i - RTC_DATE], 3, time_temp);
	}

	uart_send_text_sram("20");
	uart_send_text_buffer(time[2]);
	uart_send_text_sram("-");
	uart_send_text_buffer(time[1]);
	uart_send_text_sram("-");
	uart_send_text_buffer(time[0]);
	UART_NEWLINE();


}
Ejemplo n.º 3
0
/**
 * Initialize the system controller. In particular:
 *   - Load settings
 *   - Setup the log interval alarm.
 */
Controller::Controller() {

  m_sleeping=false;
  m_powerup=false;
  //m_log_interval_seconds = 60*30;
  m_log_interval_seconds = 0;  // default set to zero to save power
  rtc_clear_alarmed();
  rtc_enable_alarm(RTC);
  m_interval_stored = rtc_get_time(RTC);
  m_counts_stored = 0;
  m_alarm_log = false;
  system_controller = this;
  m_last_switch_state = true;
  m_never_dim = false;

  bool sstate = switch_state();
  m_last_switch_state = sstate;

  m_warning_raised = false;
  m_dim_off = false;

  m_cpm_cps_switch = false;
  m_current_units = 2;
  m_cpm_cps_threshold = 1100.0;
  m_cps_cpm_threshold = 1000.0;

  // Get warning cpm from flash
  m_warncpm = 0;
  const char *swarncpm = flashstorage_keyval_get("WARNCPM");
  if(swarncpm != 0) {
    int32_t c;
    sscanf(swarncpm, "%"PRIu32"", &c);
    m_warncpm = c;
  }

  // Get never dim from flash
  m_warncpm = -1;
  const char *sneverdim = flashstorage_keyval_get("NEVERDIM");
  if(sneverdim != 0) {
    if(strcmp(sneverdim,"true") == 0) m_never_dim=true;
                                 else m_never_dim=false;
  } else m_never_dim=false;

  if(m_never_dim) tick_item("Never Dim" ,true);

  // Get logging interval from flash
  const char *sloginter = flashstorage_keyval_get("LOGINTERVAL");
  if(sloginter != 0) {
    int32_t c;
    sscanf(sloginter, "%"PRIu32"", &c);
    m_log_interval_seconds = c;
  } else {
   // m_log_interval_seconds = 30*60;
    m_log_interval_seconds = 0;  // default set to zero to save power
  }
  rtc_set_alarm(RTC,rtc_get_time(RTC)+m_log_interval_seconds);
}
Ejemplo n.º 4
0
/*
 * Hah!  We'll see if this works (switching from usecs to nsecs).
 */
static unsigned long tmu_timer_get_frequency(void)
{
	u32 freq;
	struct timespec ts1, ts2;
	unsigned long diff_nsec;
	unsigned long factor;

	/* Setup the timer:  We don't want to generate interrupts, just
	 * have it count down at its natural rate.
	 */
	ctrl_outb(0, TMU_TSTR);
#if !defined(CONFIG_CPU_SUBTYPE_SH7300) && !defined(CONFIG_CPU_SUBTYPE_SH7760)
	ctrl_outb(TMU_TOCR_INIT, TMU_TOCR);
#endif
	ctrl_outw(TMU0_TCR_CALIB, TMU0_TCR);
	ctrl_outl(0xffffffff, TMU0_TCOR);
	ctrl_outl(0xffffffff, TMU0_TCNT);

	rtc_get_time(&ts2);

	do {
		rtc_get_time(&ts1);
	} while (ts1.tv_nsec == ts2.tv_nsec && ts1.tv_sec == ts2.tv_sec);

	/* actually start the timer */
	ctrl_outb(TMU_TSTR_INIT, TMU_TSTR);

	do {
		rtc_get_time(&ts2);
	} while (ts1.tv_nsec == ts2.tv_nsec && ts1.tv_sec == ts2.tv_sec);

	freq = 0xffffffff - ctrl_inl(TMU0_TCNT);
	if (ts2.tv_nsec < ts1.tv_nsec) {
		ts2.tv_nsec += 1000000000;
		ts2.tv_sec--;
	}

	diff_nsec = (ts2.tv_sec - ts1.tv_sec) * 1000000000 + (ts2.tv_nsec - ts1.tv_nsec);

	/* this should work well if the RTC has a precision of n Hz, where
	 * n is an integer.  I don't think we have to worry about the other
	 * cases. */
	factor = (1000000000 + diff_nsec/2) / diff_nsec;

	if (factor * diff_nsec > 1100000000 ||
	    factor * diff_nsec <  900000000)
		panic("weird RTC (diff_nsec %ld)", diff_nsec);

	return freq * factor;
}
Ejemplo n.º 5
0
/**
 * Append a new entry to the log if necessary. Checks the
 * state of m_alarm_log to determine if we should append a log
 * entry.
 */
void Controller::do_logging() {
  if(rtc_alarmed()) {
    m_alarm_log = true;
    m_last_alarm_time = rtc_get_time(RTC);
    #ifndef DISABLE_ACCEL
    accel_read_state(&m_accel_x_stored,&m_accel_y_stored,&m_accel_z_stored);
    #endif
    //m_magsensor_stored = gpio_read_bit(PIN_MAP[29].gpio_device,PIN_MAP[29].gpio_bit);


    // set new alarm for log_interval_seconds from now.
    rtc_clear_alarmed();
  }

  if(m_alarm_log == true) {
    if(system_geiger->is_cpm30_valid()) {

      log_data_t data;
      #ifndef DISABLE_ACCEL
      accel_read_state(&data.accel_x_end,&data.accel_y_end,&data.accel_z_end);
      #endif
      //data.magsensor_end = gpio_read_bit(PIN_MAP[29].gpio_device,PIN_MAP[29].gpio_bit);

      data.time  = rtc_get_time(RTC);
      data.cpm   = system_geiger->get_cpm30();

      data.accel_x_start = m_accel_x_stored;
      data.accel_y_start = m_accel_y_stored;
      data.accel_z_start = m_accel_z_stored;
      //data.magsensor_start = m_magsensor_stored;
      data.log_type      = UINT_MAX;

      flashstorage_log_pushback((uint8_t *) &data,sizeof(log_data_t));

      bool full = flashstorage_log_isfull();
      if((full == true) && (!m_sleeping)) {
        m_gui->show_dialog("Flash Log","is full",0,0,0,43,44,255,255);
      }

      m_alarm_log = false;

      rtc_set_alarm(RTC,m_last_alarm_time+m_log_interval_seconds);
      rtc_enable_alarm(RTC);
      if(m_sleeping) {
        power_standby();
      }
    }
  }
}
Ejemplo n.º 6
0
Archivo: lcd.c Proyecto: dpmjoshi/ARM7
void lcd_scroll_disp(unsigned char *scroll_data,  unsigned char position)
{
 unsigned char i, j, *d;
 

 position += 0x80;
 d = scroll_data;		
 comdr(position);
 for(j = 15; j>0 ; j--)
 {
  position = j + 0x80;
  comdr(position);
  ms_delay(5);
  for(i=0; *d!='\0'; i++)
  {
   datar(*d);
   ms_delay(1);
   d++;
  }
  d = scroll_data++;
  rtc_get_time();  //--------------
  lcd_line4_disp(&Uc_real_time[0],12); //------------------
  ms_delay(9000);
  clrscr();
 }
}
Ejemplo n.º 7
0
static void app_neb_insert_abs_time(struct nbps_neb_record_send_req *req)
{
    #if (RTC_SUPPORT)
    struct rtc_time time;

    // Get time stamp from RTC
    rtc_get_time(&time);

    // Format result
    req->neb_rec.timestamp.year     = time.tm_year;
    req->neb_rec.timestamp.month    = time.tm_mon;
    req->neb_rec.timestamp.day      = time.tm_mday;
    req->neb_rec.timestamp.hour     = time.tm_hour;
    req->neb_rec.timestamp.min      = time.tm_min;
    req->neb_rec.timestamp.sec      = time.tm_sec;

    #else //(RTC_SUPPORT)
    // Default time
    req->neb_rec.timestamp.year     = 2015;
    req->neb_rec.timestamp.month    = 10;
    req->neb_rec.timestamp.day      = 21;
    req->neb_rec.timestamp.hour     = 16;
    req->neb_rec.timestamp.min      = 29;
    req->neb_rec.timestamp.sec      = 0;
    #endif //(RTC_SUPPORT)
}
Ejemplo n.º 8
0
void ZP_CreateLogFile(void)
{
	char file[50];
	uint32_t ul_hour, ul_minute, ul_second;
	uint32_t ul_year, ul_month, ul_day, ul_week;
	rtc_get_time(RTC, &ul_hour, &ul_minute, &ul_second);
	rtc_get_date(RTC, &ul_year, &ul_month, &ul_day, &ul_week);
	
	f_mkdir("0:Logs");
	sprintf(file, "0:logs/%04u", ul_year);
	f_mkdir((char const *)file);
	sprintf(file, "0:logs/%04u/%02u", ul_year, ul_month);
	f_mkdir((char const *)file);
	sprintf(file, "0:logs/%04u/%02u/%02u", ul_year, ul_month, ul_day);
	f_mkdir((char const *)file);
	
	sprintf(file, "0:Logs/%04u/%02u/%02u/Flight_Log_%02u.%02u.%02u.log", ul_year, ul_month, ul_day, ul_hour, ul_minute, ul_second);
	f_open(&f_log, (char const *)file, FA_CREATE_ALWAYS | FA_WRITE);
	f_puts("Goblin-Tech", &f_log);
	f_puts("GT101-0001", &f_log);
	f_puts("00.00.00", &f_log);
	uint16_t size = f_size(&f_script);
	uint8_t dummy;
	f_write(&f_log, &size, 2, &dummy);
	f_write(&f_log, &Script, size, &dummy);
	f_sync(&f_log);
}
Ejemplo n.º 9
0
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;
	}
}
Ejemplo n.º 10
0
void __init time_init(void)
{
	if (board_time_init)
		board_time_init();

	clk_init();

	if (rtc_get_time) {
		rtc_get_time(&xtime);
	} else {
		xtime.tv_sec = mktime(2000, 1, 1, 0, 0, 0);
		xtime.tv_nsec = 0;
	}

        set_normalized_timespec(&wall_to_monotonic,
                                -xtime.tv_sec, -xtime.tv_nsec);

	/*
	 * Find the timer to use as the system timer, it will be
	 * initialized for us.
	 */
	sys_timer = get_sys_timer();
	printk(KERN_INFO "Using %s for system timer\n", sys_timer->name);

#if defined(CONFIG_SH_KGDB)
	/*
	 * Set up kgdb as requested. We do it here because the serial
	 * init uses the timer vars we just set up for figuring baud.
	 */
	kgdb_init();
#endif
}
Ejemplo n.º 11
0
void __init time_init(void)
{
	int ret;

	/*
	 * Make sure we don't get any COMPARE interrupts before we can
	 * handle them.
	 */
	sysreg_write(COMPARE, 0);

	xtime.tv_sec = rtc_get_time();
	xtime.tv_nsec = 0;

	set_normalized_timespec(&wall_to_monotonic,
				-xtime.tv_sec, -xtime.tv_nsec);

	ret = avr32_hpt_init();
	if (ret) {
		pr_debug("timer: failed setup: %d\n", ret);
		return;
	}

	ret = clocksource_register(&clocksource_avr32);
	if (ret)
		pr_debug("timer: could not register clocksource: %d\n", ret);

	ret = avr32_hpt_start();
	if (ret) {
		pr_debug("timer: failed starting: %d\n", ret);
		return;
	}
}
Ejemplo n.º 12
0
/**
 * \brief Callback function for ADC interrupts
 *
 * \param adc Pointer to ADC module.
 * \param channel ADC channel number.
 * \param result Conversion result from ADC channel.
 */
static void app_sampling_handler(ADC_t *adc, uint8_t channel,
		adc_result_t result)
{
	/* Store ADC convertion result for the coresponding on-board sensor */
	switch (adc_conv[adc_mux_index]) {
	case LIGHT_SENSOR_ADC_INPUT:
		light = 2048 - result;
		break;

	default:
		break;
	}

	/* Parse table of ADC conversions */
	if (++adc_mux_index < sizeof(adc_conv)) {
		app_sampling_start_next_conversion();
		return;
	}

	/* End of all conversions */
	adc_mux_index = 0;

	/* Save values in FIFO */
	if (2 > fifo_get_free_size(&app_sampling_fifo_desc)) {
		return; /* Error */
	}

	fifo_push_uint16_nocheck(&app_sampling_fifo_desc, rtc_get_time());
	fifo_push_uint16_nocheck(&app_sampling_fifo_desc, (uint16_t)light);
	LED_Off(LED1_GPIO);

	/* Enable the next RTC alarm */
	app_sampling_rtc_run = true;
	rtc_set_alarm_relative(app_sampling_rate - 1);
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
/**
 * RTCの時間を取得します。
 *
 * @param[out] year 年の格納先を指定します。
 * @param[out] mon  月の格納先を指定します。
 * @param[out] day  日の格納先を指定します。
 * @param[out] hour 時の格納先を指定します。
 * @param[out] min  分の格納先を指定します。
 * @param[out] sec  秒の格納先を指定します。
 * @param[out] week 曜日の格納先を指定します。
 *
 * @return 時間の取得に成功した場合はtrueを返却します。失敗した場合はfalseを返却します。
 *
 * @attention なし
 ***************************************************************************/
bool RTC::getDateTime(int &year, int &mon, int &day, int &hour, int &min, int &sec, int &week)
{
	bool bError = true;
	RTC_TIMETYPE time;

	if (rtc_get_time(&time) == 0) {
		year = 0;
		mon  = 0;
		day  = 0;
		hour = 0;
		sec  = 0;
		week = 0;
		bError = false;
	}
	else {
		year = time.year;
		mon  = time.mon;
		day  = time.day;
		hour = time.hour;
		min  = time.min;
		sec  = time.second;
		week = time.weekday;
	}

	return (bError);
}
Ejemplo n.º 15
0
void __init time_init(void)
{
	if (board_time_init)
		board_time_init();

	xtime.tv_sec = rtc_get_time();
	xtime.tv_usec = 0;

	/* choose appropriate gettimeoffset routine */
	do_gettimeoffset = null_gettimeoffset;


	/* 
	 * Call board specific timer interrupt setup.
	 *
	 * this pointer must be setup in machine setup routine. 
	 *
	 * Even if the machine choose to use low-level timer interrupt,
	 * it still needs to setup the timer_irqaction.
	 * In that case, it might be better to set timer_irqaction.handler 
	 * to be NULL function so that we are sure the high-level code
	 * is not invoked accidentally.
	 */
	board_timer_setup(&timer_irqaction);
}
Ejemplo n.º 16
0
/**
 * \brief Set the time using a spinner widget
 */
static void set_time_application(void)
{
    struct keyboard_event input;
    struct calendar_date date;
    uint32_t timestamp;
    uint8_t tz_hours;
    uint8_t tz_minutes;
    struct gfx_mono_spinctrl hour_spinner;
    struct gfx_mono_spinctrl minute_spinner;
    struct gfx_mono_spinctrl_spincollection time_spinners;
    uint8_t spinner_status;
    int16_t spinner_results[2];

    // Prepare the spinner widget for time selection
    gfx_mono_spinctrl_init(&hour_spinner, SPINTYPE_INTEGER,
                           datetime_date_spinner_string_hour, NULL, 0, 23, 0);
    gfx_mono_spinctrl_init(&minute_spinner, SPINTYPE_INTEGER,
                           datetime_date_spinner_string_minute, NULL, 0, 59, 0);

    // Create time spincollector
    gfx_mono_spinctrl_spincollection_init(&time_spinners);
    gfx_mono_spinctrl_spincollection_add_spinner(&hour_spinner,
            &time_spinners);
    gfx_mono_spinctrl_spincollection_add_spinner(&minute_spinner,
            &time_spinners);

    // Get timezone settings
    tz_hours = timezone_get_hours();
    tz_minutes = timezone_get_minutes();

    timestamp = rtc_get_time();

    calendar_timestamp_to_date_tz(timestamp, tz_hours, tz_minutes, &date);

    // Set spinners to current time as initial position
    hour_spinner.integer_data = date.hour;
    minute_spinner.integer_data = date.minute;

    gfx_mono_spinctrl_spincollection_show(&time_spinners);

    do {
        do {
            keyboard_get_key_state(&input);
            // Wait for key release
        } while (input.type != KEYBOARD_RELEASE);
        // Send key to spinnercollection
        spinner_status = gfx_mono_spinctrl_spincollection_process_key(
                             &time_spinners, input.keycode, spinner_results);
    } while (spinner_status != GFX_MONO_SPINCTRL_EVENT_FINISH);

    date.hour = spinner_results[0];
    date.minute = spinner_results[1];

    timestamp = calendar_date_to_timestamp_tz(&date, tz_hours, tz_minutes);

    if(timestamp != 0) {
        rtc_set_time(timestamp);
    }
}
Ejemplo n.º 17
0
 void gettime()
 {
  if(time_start){ 
  rtc_get_time(&t.hour,&t.min,&t.sec);  
  rtc_get_date(&t.dow,&t.date,&t.month,&t.year);  
  time_start=0;
  }
 } 
Ejemplo n.º 18
0
static void _prepare_next_alarm(void)
{
    struct tm time;
    rtc_get_time(&time);
    /* set initial alarm */
    time.tm_sec += PERIOD;
    mktime(&time);
    rtc_set_alarm(&time, rtc_cb, NULL);
}
Ejemplo n.º 19
0
//returns timestamp as string YYYY-MM-DD HH:MM:SS
void rtc_get_time_str(char* buf, int buf_size){
  uint32_t ul_year, ul_month, ul_day, ul_week;
  uint32_t ul_hour, ul_minute, ul_second;
  rtc_get_date(NULL,&ul_year,&ul_month,&ul_day,&ul_week);
  rtc_get_time(NULL,&ul_hour,&ul_minute,&ul_second);
  snprintf(buf,buf_size,"%02lu-%02lu-%02lu %02lu:%02lu:%02lu",ul_year,ul_month,ul_day,
	  ul_hour,ul_minute,ul_second);
  return;
}
Ejemplo n.º 20
0
static void rtc_set_time(RTCState *s)
{
    struct tm tm;

    rtc_get_time(s, &tm);
    s->base_rtc = mktimegm(&tm);
    s->last_update = qemu_clock_get_ns(rtc_clock);

    qapi_event_send_rtc_change(qemu_timedate_diff(&tm), &error_abort);
}
Ejemplo n.º 21
0
// ------------------------------------------------------------------------------------------------
static void cmd_datetime(uint argc, const char** argv)
{
    char buf[TIME_STRING_SIZE];

    DateTime dt;
    rtc_get_time(&dt);
    format_time(buf, sizeof(buf), &dt);

    console_print("%s\n", buf);
}
Ejemplo n.º 22
0
static void _rtc_gettime(void)
{
    struct tm t;
    if (rtc_get_time(&t) == 0) {
        _print_time(&t);
    }
    else {
        puts("rtc: error getting time");
    }
}
Ejemplo n.º 23
0
static void rtc_set_time(RTCState *s)
{
    struct tm tm;

    rtc_get_time(s, &tm);
    s->base_rtc = mktimegm(&tm);
    s->last_update = qemu_get_clock_ns(rtc_clock);

    rtc_change_mon_event(&tm);
}
Ejemplo n.º 24
0
void draw_time() {
    unsigned long ts = rtc_get_time();
    struct calendar_date rtc_date;
    uint8_t hour[] = {12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    // might need to build in something for daylight savings time
    calendar_timestamp_to_date_tz(ts, -6, 0, &rtc_date);
    char string_buf[15];

    snprintf(string_buf, sizeof(string_buf),"%d:%.2d", hour[rtc_date.hour], rtc_date.minute);
    gfx_draw_string_aligned(string_buf, gfx_get_width()-35, 2, &sysfont, GFX_COLOR_TRANSPARENT, GFX_COLOR_WHITE, TEXT_POS_CENTER_X, TEXT_ALIGN_LEFT);
}
Ejemplo n.º 25
0
static void run_test_clock_ver2(void)
{
    unsigned int seconds = rtc_get_time().second;
    for (uint8_t i = 0; i < 60; i++) {
        if (i <= seconds)
            display_watch_set_led_color(&m_watch_frame2, i, &c_lightblue_dim);
        else
            display_watch_set_led_color(&m_watch_frame2, i, &c_yellow_dim);
    }

    display_watch_write_frame(&m_watch_frame2);
}
Ejemplo n.º 26
0
extern int
rtc_get_time_test(int autotest)
{
	rtc_time_t time;
	
	rtc_get_time(&time);
	
	printf("RTC Time = W%d %d%d:%d%d:%d%d:%d\n", time.dow, time.ten_hr, time.hr,	\
				time.ten_min, time.min, time.ten_sec, time.sec, time.sos);

	return 0;
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
0
void main(void)
{
	struct tm* t = NULL;
	char buf[32];
	uint8_t hour, min, sec;

	uartInit();
	uartSetBaudRate(9600);
	uartSendString("DS RTC Library Test\n");

	LED_DDR  |= _BV(LED_BIT); // indicator led

	for (int i = 0; i < 5; i++) {
		LED_HIGH;
		_delay_ms(100);
		LED_LOW;
		_delay_ms(100);
	}

	uartSendString("Before Init\n");
	twi_init_master();
	rtc_init();
	rtc_set_time_s(12, 0, 50);

	uartSendString("After Init\n");
	if (rtc_is_ds1307())
		uartSendString("DS1307\n");
	else
		uartSendString("DS3231\n");

	rtc_set_alarm_s(12, 1, 0);
	
	rtc_get_alarm_s(&hour, &min, &sec);

	sprintf(buf, "Alarm is set -%d:%d:%d-\n", hour, min, sec);
	uartSendString(buf);	
	uartSendString("---\n");
	uartSendString("---\n");
	uartSendString("---\n");

	while (1) {
		t = rtc_get_time();

		sprintf(buf, "%d:%d:%d\n", t->hour, t->min, t->sec);
		uartSendString(buf);
		uartSendString("---\n");

		if (rtc_check_alarm())
			uartSendString("ALARM!\n");

	   	_delay_ms(500);
	}
}
Ejemplo n.º 29
0
time_t time(time_t *timer)
{
	struct tm timedate;
	ER     ercd;

	if(timer == NULL)
		return 0;
	ercd = rtc_get_time(&timedate);
	if(ercd == E_OK)
		*timer = mktime(&timedate);
	else
		*timer = 0;
	return *timer;
}
Ejemplo n.º 30
0
void get_time(unsigned char time[][6], int sensor_count)
{
    time[sensor_count][0] = rtc_get_time(0x00);     //get second
    time[sensor_count][1] = rtc_get_time(0x01);     //get minute
    time[sensor_count][2] = rtc_get_time(0x02);     //get hour
    time[sensor_count][3] = rtc_get_time(0x04);     //get day
    time[sensor_count][4] = rtc_get_time(0x05);     //get month
    time[sensor_count][5] = rtc_get_time(0x06);     //get year
}