/* * Test command to set RTC Alarm time, and start RTC: rtc alarm <rtc_alarm_time> * * @param[in] argc Number of arguments in the Test Command (including group and name) * @param[in] argv Table of null-terminated buffers containing the arguments * @param[in] ctx The context to pass back to responses */ void rtc_alarm_tcmd(int argc, char *argv[], struct tcmd_handler_ctx *ctx) { struct rtc_config config = { 0 }; struct device *rtc_dev; uint32_t keys = 0; if (argc == RTC_ARG_NO && isdigit(argv[RTC_TIME_IDX][0])) { keys = irq_lock(); tcmd_user_alarm_rtc_val = (uint32_t)strtoul(argv[RTC_TIME_IDX], NULL, 10); test_rtc = 0; config.alarm_val = tcmd_user_alarm_rtc_val; config.alarm_enable = true; config.cb_fn = test_rtc_interrupt_fn; alarm_pending = true; irq_unlock(keys); rtc_dev = device_get_binding(RTC_DRV_NAME); assert(rtc_dev != NULL); rtc_dev->driver_data = (void *)ctx; rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); rtc_set_alarm(rtc_dev, config.alarm_val); } else { TCMD_RSP_ERROR(ctx, "Usage: rtc alarm <alarm_time>"); } }
void main(void) { struct device *rtc_dev; struct rtc_config config; u32_t now; printk("LMT: Quark SE PM Multicore Demo\n"); k_fifo_init(&fifo); build_suspend_device_list(); ipm = device_get_binding("alarm_notification"); if (!ipm) { printk("Error: Failed to get IPM device\n"); return; } rtc_dev = device_get_binding("RTC_0"); if (!rtc_dev) { printk("Error: Failed to get RTC device\n"); return; } rtc_enable(rtc_dev); /* In QMSI, in order to save the alarm callback we must set * 'alarm_enable = 1' during configuration. However, this * automatically triggers the alarm underneath. So, to avoid * the alarm being fired any time soon, we set the 'init_val' * to 1 and the 'alarm_val' to 0. */ config.init_val = 1; config.alarm_val = 0; config.alarm_enable = 1; config.cb_fn = alarm_handler; rtc_set_config(rtc_dev, &config); while (1) { /* Simulate some task handling by busy waiting. */ printk("LMT: busy\n"); k_busy_wait(TASK_TIME_IN_SEC * 1000 * 1000); now = rtc_read(rtc_dev); rtc_set_alarm(rtc_dev, now + (RTC_ALARM_SECOND * IDLE_TIME_IN_SEC)); printk("LMT: idle\n"); k_fifo_get(&fifo, K_FOREVER); } }
static void setup_rtc(void) { struct rtc_config cfg; /* Configure RTC device. RTC interrupt is used as 'wake event' when we * are in C2LP state. */ cfg.init_val = 0; cfg.alarm_enable = 0; cfg.alarm_val = 0; cfg.cb_fn = NULL; rtc_dev = device_get_binding(CONFIG_RTC_0_NAME); rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &cfg); }
static void setup_rtc(void) { struct rtc_config config; rtc_dev = device_get_binding("RTC_0"); config.init_val = 0; config.alarm_enable = 0; config.alarm_val = ALARM; config.cb_fn = rtc_interrupt_fn; rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); }
void main(void) { struct rtc_config config; struct device *rtc_dev; printk("Test RTC driver\n"); rtc_dev = device_get_binding(CONFIG_RTC_0_NAME); config.init_val = 0; config.alarm_enable = 1; config.alarm_val = ALARM; config.cb_fn = test_rtc_interrupt_fn; rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); while (1) { /* do nothing */ } }
/* * Test command to set initial RTC time: rtc set <time> * * @param[in] argc Number of arguments in the Test Command (including group and name) * @param[in] argv Table of null-terminated buffers containing the arguments * @param[in] ctx The context to pass back to responses */ void rtc_set(int argc, char *argv[], struct tcmd_handler_ctx *ctx) { struct rtc_config config = { 0 }; uint32_t keys = 0; struct device *rtc_dev; if (argc == RTC_ARG_NO && isdigit(argv[RTC_TIME_IDX][0])) { rtc_dev = device_get_binding(RTC_DRV_NAME); assert(rtc_dev != NULL); keys = irq_lock(); tcmd_user_initial_rtc_val = (uint32_t)strtoul( argv[RTC_TIME_IDX], NULL, 10); config.init_val = tcmd_user_initial_rtc_val; irq_unlock(keys); rtc_set_config(rtc_dev, &config); TCMD_RSP_FINAL(ctx, NULL); } else { TCMD_RSP_ERROR(ctx, "Usage: rtc set <initial_time>"); } }
void main(void) { struct rtc_config config; PRINT("Power Management Demo\n"); config.init_val = 0; config.alarm_enable = 0; config.alarm_val = RTC_ALARM_SECOND; config.cb_fn = NULL; rtc_dev = device_get_binding(CONFIG_RTC_DRV_NAME); rtc_enable(rtc_dev); rtc_set_config(rtc_dev, &config); create_device_list(); while (1) { task_sleep(SLEEPTICKS); } }