Ejemplo n.º 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();
}
Ejemplo n.º 2
0
//! [setup_dac]
void configure_dac(void)
{
//! [setup_dac_config]
	struct dac_config config_dac;
//! [setup_dac_config]

//! [setup_dac_config_default]
	dac_get_config_defaults(&config_dac);
//! [setup_dac_config_default]

//! [setup_dac_start_on_event]
#if (SAML21)
	dac_instance.start_on_event[DAC_CHANNEL_0] = true;
#else
	dac_instance.start_on_event = true;
#endif
//! [setup_dac_start_on_event]

//! [setup_dac_instance]
	dac_init(&dac_instance, DAC, &config_dac);
//! [setup_dac_instance]

//! [setup_dac_on_event_start_conversion]
	struct dac_events events =
#if (SAML21)
		{ .on_event_chan0_start_conversion = true };
#else
		{ .on_event_start_conversion = true };
#endif
//! [setup_dac_on_event_start_conversion]

//! [enable_dac_event]
	dac_enable_events(&dac_instance, &events);
//! [enable_dac_event]
}
//! [setup_dac]

//! [setup_dac_channel]
void configure_dac_channel(void)
{
//! [setup_dac_chan_config]
	struct dac_chan_config config_dac_chan;
//! [setup_dac_chan_config]

//! [setup_dac_chan_config_default]
	dac_chan_get_config_defaults(&config_dac_chan);
//! [setup_dac_chan_config_default]

//! [set_dac_chan_config]
	dac_chan_set_config(&dac_instance, DAC_CHANNEL_0,
			&config_dac_chan);
//! [set_dac_chan_config]

//! [enable_dac_channel]
	dac_chan_enable(&dac_instance, DAC_CHANNEL_0);
//! [enable_dac_channel]
}
//! [setup_dac_channel]

int main(void)
{
//! [data_length_var]
	uint32_t i;
//! [data_length_var]
	system_init();

//! [setup_init]
//! [init_rtc]
	configure_rtc_count();
//! [init_rtc]

//! [set_rtc_period]
	rtc_count_set_period(&rtc_instance, 1);
//! [set_rtc_period]

//! [init_dac]
	configure_dac();
//! [init_dac]

//! [init_dac_chan]
	configure_dac_channel();
//! [init_dac_chan]

//! [enable_dac]
	dac_enable(&dac_instance);
//! [enable_dac]

//! [init_event_resource]
	configure_event_resource();
//! [init_event_resource]

//! [register_dac_callback]
	dac_register_callback(&dac_instance, DAC_CHANNEL_0,
			dac_callback,DAC_CALLBACK_TRANSFER_COMPLETE);
//! [register_dac_callback]

//! [enable_dac_callback]
	dac_chan_enable_callback(&dac_instance, DAC_CHANNEL_0,
			DAC_CALLBACK_TRANSFER_COMPLETE);
//! [enable_dac_callback]

//! [setup_dac_data]
	for (i = 0;i < DATA_LENGTH;i++) {
		dac_data[i] = 0xfff * i;
	}
//! [setup_dac_data]
//! [setup_init]

//! [main_start]
//! [main_write]
	dac_chan_write_buffer_job(&dac_instance, DAC_CHANNEL_0,
			dac_data, DATA_LENGTH);
//! [main_write]

//! [main_check_transfer_done]
	while (!transfer_is_done) {
		/* Wait for transfer done */
	}
//! [main_check_transfer_done]

//! [main_loop]
	while (1) {
	}
//! [main_loop]
//! [main_start]
}