Exemple #1
0
/*! \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();
}
Exemple #2
0
//! [setup_rtc]
void configure_rtc_count(void)
{
//! [setup_rtc_event]
	struct rtc_count_events  rtc_event;
//! [setup_rtc_event]

//! [setup_rtc_config]
	struct rtc_count_config config_rtc_count;
//! [setup_rtc_config]

//! [setup_rtc_config_defaults]
	rtc_count_get_config_defaults(&config_rtc_count);
//! [setup_rtc_config_defaults]

//! [setup_rtc_modify_conf]
	config_rtc_count.prescaler           = RTC_COUNT_PRESCALER_DIV_1;
	config_rtc_count.mode                = RTC_COUNT_MODE_16BIT;
#ifdef FEATURE_RTC_CONTINUOUSLY_UPDATED
	config_rtc_count.continuously_update = true;
#endif
//! [setup_rtc_modify_conf]

//! [init_rtc_count]
	rtc_count_init(&rtc_instance, RTC, &config_rtc_count);
//! [init_rtc_count]

//! [setup_rtc_overflow_event]
	rtc_event.generate_event_on_overflow = true;
//! [setup_rtc_overflow_event]

//! [enable_rtc_overflow_event]
	rtc_count_enable_events(&rtc_instance, &rtc_event);
//! [enable_rtc_overflow_event]

//! [enable_rtc]
	rtc_count_enable(&rtc_instance);
//! [enable_rtc]
}
Exemple #3
0
/**
 * \brief Initialize the TC3 & RTC for unit test
 *
 * Initializes the RTC module and TC3 module which are used as
 * event generator and event user respectively.
 */
static void test_event_gen_user_init(void)
{
	enum status_code status;
	init_success = true;

	/* Timer configuration (Event User) */
	struct tc_config config_tc;

	tc_get_config_defaults(&config_tc);
	config_tc.counter_16_bit.compare_capture_channel[0]
		= (0xFFFF / 4);

	/* Initialize the TC3 */
	status = tc_init(&tc_inst, TC3, &config_tc);
	if (status != STATUS_OK) {
		init_success = false;
	}

	struct tc_events events_tc;

	events_tc.on_event_perform_action = true;
	events_tc.event_action = TC_EVENT_ACTION_START;

	tc_enable_events(&tc_inst, &events_tc);

	/* Enable the TC3 */
	tc_enable(&tc_inst);

	/* RTC configuration (Event Generator) */
	struct rtc_count_config config_rtc_count;
	struct rtc_count_events config_rtc_event
		= { .generate_event_on_overflow = true };

	/* Initialize the RTC module */
	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
	config_rtc_count.continuously_update = true;
#endif
	config_rtc_count.compare_values[0]   = 50;
	status = rtc_count_init(&rtc_inst, RTC, &config_rtc_count);

	if (status != STATUS_OK) {
		init_success = false;
	}

	/* Enable RTC events */
	config_rtc_event.generate_event_on_overflow = true;
	rtc_count_enable_events(&rtc_inst, &config_rtc_event);
}

/**
 * \internal
 * \brief Setup Function: Synchronous event propagation.
 *
 * This function initializes the event system channel 0 and the RTC
 * module (event generator) to be in the same clock domain for
 * synchronous event propagation.
 *
 * \param test Current test case.
 */
static void setup_synchronous_event_test(const struct test_case *test)
{
	struct events_config   events_conf;

	/* Get default event channel configuration */
	events_get_config_defaults(&events_conf);

	events_conf.clock_source   = GCLK_GENERATOR_2;
	events_conf.edge_detect    = EVENTS_EDGE_DETECT_RISING;
	events_conf.path           = EVENTS_PATH_SYNCHRONOUS;
	events_conf.generator      = TEST_EVENT_GEN;

	events_allocate(&events, &events_conf);
	events_attach_user(&events, TEST_EVENT_USER);
}

/**
 * \internal
 * \brief Test for event system in synchronous mode.
 *
 * This test waits for event channel and user to be ready and then
 * starts the RTC to generate overflow event. It waits until the timer
 * is started. If the timer starts running then it can be assumed that
 * the event has been propagated properly.
 *
 * \param test Current test case.
 */
static void run_synchronous_event_test(const struct test_case *test)
{
	uint32_t timeout_cycles = 1000;

	/* Skip test if initialization failed */
	test_assert_true(test, init_success,
			"Skipping test due to failed initialization");

	/* Check whether event user is ready */
	do {

		timeout_cycles--;
		if (events_is_users_ready(&events)) {
			break;
		}

	} while (timeout_cycles > 0);

	test_assert_true(test, timeout_cycles > 0,
			"Timeout error: Event user not ready");

	/* Check whether event channel is ready */
	timeout_cycles = 1000;
	do {

		timeout_cycles--;
		if (!events_is_busy(&events)) {
			break;
		}

	} while (timeout_cycles > 0);

	test_assert_true(test, timeout_cycles > 0,
			"Timeout error: Event channel not ready");

	/* Event action test */
	rtc_count_enable(&rtc_inst);
	rtc_count_set_period(&rtc_inst, 100);
	timeout_cycles = 10000;

	do {

		timeout_cycles--;
		if (tc_get_count_value(&tc_inst)) {
			break;
		}

	} while (timeout_cycles > 0);

	test_assert_true(test, timeout_cycles > 0,
			"Error: Timeout in event reception/action");
}