/*! \brief Configure the RTC timer count after which interrupts comes */ void configure_rtc_count(void) { //! [init_conf] struct rtc_count_config config_rtc_count; typedef enum rtc_count_prescaler rtc_count_prescaler_t; #if DEF_SURF_LOW_POWER_SENSOR_ENABLE == 1 struct rtc_count_events config_rtc_event = { .generate_event_on_periodic[DEF_LOWPOWER_SENSOR_EVENT_PERIODICITY] = true }; #endif rtc_count_get_config_defaults(&config_rtc_count); volatile uint16_t temp; //! [set_config] config_rtc_count.prescaler = (rtc_count_prescaler_t)RTC_MODE0_CTRL_PRESCALER_DIV2; config_rtc_count.mode = RTC_COUNT_MODE_32BIT; #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED config_rtc_count.continuously_update = true; #endif config_rtc_count.clear_on_match = true; //! [init_rtc] rtc_count_init(&rtc_instance, RTC, &config_rtc_count); #if DEF_SURF_LOW_POWER_SENSOR_ENABLE == 1 /* Enable RTC events */ config_rtc_event.generate_event_on_periodic[DEF_LOWPOWER_SENSOR_EVENT_PERIODICITY] = true; rtc_count_enable_events(&rtc_instance, &config_rtc_event); #endif /*Set timer period */ temp = TIME_PERIOD_1MSEC * rtc_timer_msec; rtc_count_set_compare(&rtc_instance, temp, RTC_COUNT_COMPARE_0); //! [enable] rtc_count_enable(&rtc_instance); //! [enable] } /*! \brief Initialize timer * */ void timer_init(void) { /* Configure and enable RTC */ configure_rtc_count(); /* Configure and enable callback */ configure_rtc_callbacks(); }
/** * \brief This function Initializes the Sleep functions * Enable RTC Clock in conf_clocks.h */ void sm_init(void) { struct rtc_count_config config_rtc_count; rtc_count_get_config_defaults(&config_rtc_count); config_rtc_count.prescaler = RTC_COUNT_PRESCALER_DIV_1; config_rtc_count.mode = RTC_COUNT_MODE_16BIT; #ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED /** Continuously update the counter value so no synchronization is * needed for reading. */ config_rtc_count.continuously_update = true; #endif rtc_count_init(&rtc_instance, RTC, &config_rtc_count); configure_rtc_callbacks(); }
int main(void) { //! [run_initialize_rtc] //! [system_init] system_init(); //! [system_init] //! [time] struct rtc_calendar_time time; rtc_calendar_get_time_defaults(&time); time.year = 2012; time.month = 12; time.day = 31; time.hour = 23; time.minute = 59; time.second = 59; //! [time] /* Configure and enable RTC */ //! [run_conf] configure_rtc_calendar(); //! [run_conf] /* Configure and enable callback */ //! [run_callback] configure_rtc_callbacks(); //! [run_callback] /* Set current time. */ //! [set_time] rtc_calendar_set_time(&rtc_instance, &time); //! [set_time] //! [run_initialize_rtc] //! [while] //! [main_loop] while (true) { //! [main_loop] /* Infinite loop */ } //! [while] }