Exemplo n.º 1
0
static void run_usb_msc_test(const struct test_case *test)
{
	memories_initialization();

	// Start USB stack to authorize VBus monitoring
	udc_start();

	if (!udc_include_vbus_monitoring()) {
		// VBUS monitoring is not available on this product
		// thereby VBUS has to be considered as present
		main_vbus_action(true);
	}

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (!main_b_msc_read) {

		if (main_b_msc_enumerated) {
			if (!udi_msc_process_trans()) {
				sleepmgr_enter_sleep();
			}
		}else{
			sleepmgr_enter_sleep();
		}
	}
	test_assert_true(test, main_b_msc_enumerated, "MSC enumeration fails");

	udc_stop();
}
Exemplo n.º 2
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	sysclk_init();
	board_init();
	ui_init();
	ui_powerdown();

	memories_initialization();

	// Start USB stack to authorize VBus monitoring
	udc_start();

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {

		if (main_b_msc_enable) {
			if (!udi_msc_process_trans()) {
				sleepmgr_enter_sleep();
			}
		}else{
			sleepmgr_enter_sleep();
		}
	}
}
Exemplo n.º 3
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	//Initialize interrupt controller
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize sleep manager
	sleepmgr_init();
	// Initialize clock tree
	sysclk_init();
	// Initialize hardware board resources
	board_init();

	// Initialize user interface
	ui_init();
	ui_powerdown();

	// Sanity check about Silicon revision Vs Firmware build
	// for Silicon revision A, firmware should be specific
	if ((!firmware_rev_a) && (nvm_read_device_rev()==0)) {
		ui_si_revision_error();
		while(ui_button()!=1);
		while(ui_button()!=2);
		while(ui_button()!=4);
		while(ui_button()!=8);
	}

	// Initialize DATA Flash
	at45dbx_init();

	// Initialize ADC for on-board sensors
	adc_sensors_init();

	// Initialize USB HID report protocol
	usb_hid_com_init();

	// Start USB stack
	main_build_usb_serial_number();
	udc_start();

	// The main loop manages only the power mode
	// because everything else is managed by interrupt.
	// The USB Start of Frame event manages internal tick events for
	// on-board sensor updates as well as LCD display update.
	while (true) {
		if (main_b_msc_enable) {
			if (!udi_msc_process_trans()) {
				sleepmgr_enter_sleep();
			}
		} else {
			sleepmgr_enter_sleep();
		}
		if (usb_hid_com_is_start_dfu()) {
			main_start_dfu_session();
		}
	}
}
Exemplo n.º 4
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	/* Initialize the synchronous clock system to the default configuration
	   set in conf_clock.h.
	   \note All non-essential peripheral clocks are initially disabled. */
	sysclk_init();

	/* Initialize interrupts */
	irq_initialize_vectors();
	cpu_irq_enable();

	/* Initialize the sleep manager, lock initial mode. */
	sleepmgr_init();

	/* Initialize the resources used by this example to the default
	   configuration set in conf_board.h */
	board_init();

	/* Initialize the user interface */
	ui_init();

	/* Start USB host stack */
	uhc_start();

	/* The main loop manages only the power mode
	   because the USB management is done by interrupt */
	while (true) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: Mazetti/asf
/*! \brief Main function. Execution starts here.
 */
int main(void)
{

	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

#if !SAM0
	sysclk_init();
	board_init();
#else
	system_init();
#endif
	ui_init();
	ui_powerdown();

	// Start USB stack to authorize VBus monitoring
	udc_start();

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {
		sleepmgr_enter_sleep();
	}
}
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	sysclk_init();
	board_init();
	ui_init();
	ui_powerdown();

	// Start USB stack to authorize VBus monitoring
	udc_start();

	if (!udc_include_vbus_monitoring()) {
		// VBUS monitoring is not available on this product
		// thereby VBUS has to be considered as present
		main_vbus_action(true);
	}
	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 7
0
/**
 * \brief Run low power demo
 *
 * This function initializes the XMEGA to the least power consuming state,
 * before initializing the sleep manager interrupts on switchports.
 * The device is then put to sleep, and the sleep mode is configured by the
 * interrupt routines.
 */
int main(void)
{
	board_init();
	sysclk_init();
	lowpower_init();

	/* Initialize the sleep manager. */
	sleepmgr_init();

	/* Enable interrupts from switchports on
	 * low level to sense all interrupts */
	pmic_init();
	SWITCHPORT0.INTCTRL = SWITCHPORT_INT_LEVEL;
	SWITCHPORT1.INTCTRL = SWITCHPORT_INT_LEVEL;
	SWITCHPORT0.INT0MASK = SWITCHMASK0;
	SWITCHPORT1.INT0MASK = SWITCHMASK1;
	ioport_configure_port_pin(&SWITCHPORT0,
			SWITCHMASK0, IOPORT_LEVEL | IOPORT_PULL_UP);
	ioport_configure_port_pin(&SWITCHPORT1,
			SWITCHMASK1, IOPORT_LEVEL | IOPORT_PULL_UP);
	cpu_irq_enable();

	/* Start in active mode */
	sleepmgr_lock_mode(SLEEPMGR_ACTIVE);

	/* Go to sleep, sleep modes are configured by interrupt routines. */
	while (1) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 8
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
#if SAMD21 || SAML21 || SAMDA1
	system_init();
#else
	sysclk_init();
	board_init();
#endif
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	ui_init();

	// Start USB host stack
	uhc_start();

	// The USB management is entirely managed by interrupts.
	// As a consequence, the user application does only have to play with the power modes.
	while (true) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 9
0
Arquivo: main.c Projeto: marekr/asf
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	irq_initialize_vectors();
	cpu_irq_enable();

	/* Initialize the sleep manager */
	sleepmgr_init();
#if !SAMD21 && !SAMR21
	sysclk_init();
	board_init();
#else
	system_init();
#endif
	ui_init();
	ui_powerdown();

	/* Start USB stack to authorize VBus monitoring */
	udc_start();

	/* The main loop manages only the power mode
	 * because the USB management is done by interrupt
	 */
	while (true) {
		sleepmgr_enter_sleep();
		if (main_b_phdc_enable) {
			if (ieee11073_skeleton_process()) {
				ui_association(true); /* Association Ok */
			} else {
				ui_association(false); /* No association */
			}
		}
	}
}
Exemplo n.º 10
0
/**
 * \brief main function
 */
int main(void)
{
	pmic_init();
	board_init();
	sysclk_init();
	sleepmgr_init();

	rtc_init();
	rtc_set_callback(alarm);

	cpu_irq_enable();

	/* The lowest value which is safe to use is 3. This the use of 2 could
	 * happen in a second change, and we would not get an interrupt. A
	 * value of 3 causes the alarm to be set of in 3-4 seconds.
	 */
	rtc_set_alarm_relative(3);

	while (true) {
		/* Alarm action is handled in alarm callback so we just go to
		 * sleep here.
		 */
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 11
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
#if SAMD21 || SAML21
	system_init();
#else
	sysclk_init();
	board_init();
#endif

	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	ui_init();

	// Start USB dual mode which will start the correct mode (device or host)
	// corresponding at USB ID signal.
	uhc_start();

	// The main loop manages only the power mode
	// because the USB stack is full interrupt driven.
	while (true) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 12
0
/**
 * \brief Test interrupt is getting triggered in various Sleep mode.
 *
 * This function put the device in Idle and Power Save sleep mode and check
 * whether the ADC conversion complete interrupt is executed only in Idle sleep
 * mode.
 * The device will wakeup from power save mode when Timer/Counter2 overflow
 * occur.
 *
 * \param test Current test case.
 */
static void run_sleep_trigger_test(const struct test_case *test)
{
    /* Disable Global interrupt */
    cpu_irq_disable();
    /* Initialize the lock counts */
    sleepmgr_init();
    /* Initialize the ADC */
    adc_initialisation();
    /* Initialize the Timer/Counter2 */
    timer2_initialisation();
    /* Lock Idle Sleep mode */
    sleepmgr_lock_mode(SLEEPMGR_IDLE);
    /* Clear Timer/Counter2 Register */
    TCNT2 = 0;
    /* Wait for TCNT2 register to get updated */
    while (ASSR & (1 << TCN2UB)) {
    }
    /* Start ADC Conversion */
    adc_start_conversion();
    /* Enable Global interrupt */
    cpu_irq_enable();
    /* Go to sleep in the deepest allowed mode */
    sleepmgr_enter_sleep();
    /* Unlock Idle Sleep mode */
    sleepmgr_unlock_mode(SLEEPMGR_IDLE);
    /* Lock Power Save mode */
    sleepmgr_lock_mode(SLEEPMGR_PSAVE);
    /* Clear Timer/Counter2 Register */
    TCNT2 = 0;
    /* Wait for TCNT2 register to get updated */
    while (ASSR & (1 << TCN2UB)) {
    }
    /* Start ADC Conversion */
    adc_start_conversion();
    /* Go to sleep in the deepest allowed mode */
    sleepmgr_enter_sleep();
    /* Disable ADC */
    adc_disable();
    /* Unlock Power Save mode */
    sleepmgr_unlock_mode(SLEEPMGR_PSAVE);

    /* Disable Global interrupt */
    cpu_irq_disable();

    test_assert_true(test, trigger_count == 2,
                     "ADC interrupt trigger failed.");
}
Exemplo n.º 13
0
int main(void)
{
	pmic_init();
	board_init();
	sysclk_init();
	sleepmgr_init();

	cpu_irq_enable();

#if (BOARD == XMEGA_A3BU_XPLAINED)
	/* The status LED must be used as LED2, so we turn off
	 * the green led which is in the same packaging. */
	ioport_set_pin_high(LED3_GPIO);
#endif

	/*
	* Unmask clock for TIMER_EXAMPLE
	*/
	tc_enable(&TIMER_EXAMPLE);

	/*
	* Configure interrupts callback functions for TIMER_EXAMPLE
	* overflow interrupt, CCA interrupt and CCB interrupt
	*/
	tc_set_overflow_interrupt_callback(&TIMER_EXAMPLE,
			example_ovf_interrupt_callback);
	tc_set_cca_interrupt_callback(&TIMER_EXAMPLE,
			example_cca_interrupt_callback);
	tc_set_ccb_interrupt_callback(&TIMER_EXAMPLE,
			example_ccb_interrupt_callback);

	/*
	* Configure TC in normal mode, configure period, CCA and CCB
	* Enable both CCA and CCB channels
	*/

	tc_set_wgm(&TIMER_EXAMPLE, TC_WG_NORMAL);
	tc_write_period(&TIMER_EXAMPLE, TIMER_EXAMPLE_PERIOD);
	tc_write_cc(&TIMER_EXAMPLE, TC_CCA, TIMER_EXAMPLE_PERIOD / 2);
	tc_write_cc(&TIMER_EXAMPLE, TC_CCB, TIMER_EXAMPLE_PERIOD / 4);
	tc_enable_cc_channels(&TIMER_EXAMPLE,(enum tc_cc_channel_mask_enable_t)(TC_CCAEN | TC_CCBEN));

	/*
	* Enable TC interrupts (overflow, CCA and CCB)
	*/
	tc_set_overflow_interrupt_level(&TIMER_EXAMPLE, TC_INT_LVL_LO);
	tc_set_cca_interrupt_level(&TIMER_EXAMPLE, TC_INT_LVL_LO);
	tc_set_ccb_interrupt_level(&TIMER_EXAMPLE, TC_INT_LVL_LO);

	/*
	* Run TIMER_EXAMPLE at TIMER_EXAMPLE_PERIOD(31250Hz) resolution
	*/
	tc_set_resolution(&TIMER_EXAMPLE, TIMER_EXAMPLE_PERIOD);

	do {
		/* Go to sleep, everything is handled by interrupts. */
		sleepmgr_enter_sleep();
	} while (1);
}
Exemplo n.º 14
0
Arquivo: main.c Projeto: Mazetti/asf
/*! \brief Main File Section:
 *          - Initialization (CPU, Controller Task,... )
 *          - Main loop with task management (ADC, DAC, CAN and GUI)
 */
int main(void)
{
	irq_initialize_vectors();

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();

	/* Initialize the clocks.
	 * The clock-specific conf_clocks.h file contains the configuration of
	 * the clocks initialization.
	 */
	sysclk_init();

	// Initialize the sleep manager
	sleepmgr_init();
	sleepmgr_lock_mode(SLEEPMGR_IDLE);

        /* Initialize the required Task.
	 * - Initialize the DAC task to start the signal generator,
	 * - Initialize the ADC task to start the scope acquisition,
	 * - Initialize the Noise Task to add digital noise to the signal,
	 * - Initialize the Filter Task to remove the digital noise of the signal,
	 * - Initialize the GUI Task to display signals as a scope on the LCD,
	 * - Initialize the Remote Task to display signals as a scope on the LCD,
	 */
	dac_task_init();
	adc_task_init();
	noise_task_init();
	filter_task_init();
	gui_task_init();
	controller_task_init();
	remote_task_init();

	cpu_irq_enable();

	// Free running scheduler loop
	while (true) {
		// Enter Sleep Mode
		sleepmgr_enter_sleep();
		// Call ADC task
		adc_task();
		// Call DAC task
		dac_task();
		// Call Noise task
		noise_task();
		// Filter Task
		filter_task();
		// Call Gui task for update
		gui_task();
		// Call Controller Task for control Update
		controller_task();
		// Send data to the PC Application
		remote_task();
	}
}
Exemplo n.º 15
0
int main(void)
{
	struct adc_config         adc_conf;
	struct adc_channel_config adcch_conf;

	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();
	gfx_mono_init();

	// Enable back light of display
	ioport_set_pin_high(LCD_BACKLIGHT_ENABLE_PIN);

	// Initialize configuration structures.
	adc_read_configuration(&ADCA, &adc_conf);
	adcch_read_configuration(&ADCA, ADC_CH0, &adcch_conf);

	/* Configure the ADC module:
	 * - unsigned, 12-bit results
	 * - VCC voltage reference
	 * - 200 kHz maximum clock rate
	 * - manual conversion triggering
	 * - temperature sensor enabled
	 * - callback function
	 */
	adc_set_conversion_parameters(&adc_conf, ADC_SIGN_ON, ADC_RES_12,
			ADC_REF_VCC);
	adc_set_clock_rate(&adc_conf, 200000UL);
	adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);
	adc_enable_internal_input(&adc_conf, ADC_INT_TEMPSENSE);

	adc_write_configuration(&ADCA, &adc_conf);
	adc_set_callback(&ADCA, &adc_handler);

	/* Configure ADC channel 0:
	 * - single-ended measurement from temperature sensor
	 * - interrupt flag set on completed conversion
	 * - interrupts disabled
	 */
	adcch_set_input(&adcch_conf, ADCCH_POS_PIN1, ADCCH_NEG_NONE,
			1);
	adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);
	adcch_enable_interrupt(&adcch_conf);

	adcch_write_configuration(&ADCA, ADC_CH0, &adcch_conf);

	// Enable the ADC and start the first conversion.
	adc_enable(&ADCA);
	adc_start_conversion(&ADCA, ADC_CH0);

	do {
		// Sleep until ADC interrupt triggers.
		sleepmgr_enter_sleep();
	} while (1);
}
Exemplo n.º 16
0
int main(void)
{
	/* Usual initializations */
	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();

	/* Unmask clock for TCC4 */
	tc45_enable(&TCC4);

	/* Configure TC in normal mode */
	tc45_set_wgm(&TCC4, TC45_WG_NORMAL);

	/* Configure period equal to resolution to obtain 1Hz */
	tc45_write_period(&TCC4, TIMER_EXAMPLE_RESOLUTION);

	/* Configure CCA to occur at the middle of TC period */
	tc45_write_cc(&TCC4, TC45_CCA, TIMER_EXAMPLE_RESOLUTION / 2);

	/* Configure CCB to occur at the quarter of TC period */
	tc45_write_cc(&TCC4, TC45_CCB, TIMER_EXAMPLE_RESOLUTION / 4);

	/* Enable both CCA and CCB channels */
	tc45_enable_cc_channels(&TCC4, TC45_CCACOMP);
	tc45_enable_cc_channels(&TCC4, TC45_CCBCOMP);

	/*
	 * Configure interrupts callback functions for TCC4
	 * overflow interrupt, CCA interrupt and CCB interrupt
	 */
	tc45_set_overflow_interrupt_callback(&TCC4,
			example_ovf_interrupt_callback);
	tc45_set_cca_interrupt_callback(&TCC4,
			example_cca_interrupt_callback);
	tc45_set_ccb_interrupt_callback(&TCC4,
			example_ccb_interrupt_callback);

	/*
	 * Enable TC interrupts (overflow, CCA and CCB)
	 */
	tc45_set_overflow_interrupt_level(&TCC4, TC45_INT_LVL_LO);
	tc45_set_cca_interrupt_level(&TCC4, TC45_INT_LVL_LO);
	tc45_set_ccb_interrupt_level(&TCC4, TC45_INT_LVL_LO);

	/*
	 * Run TCC4 
	 */
	tc45_set_resolution(&TCC4, TIMER_EXAMPLE_RESOLUTION);

	do {
		/* Go to sleep, everything is handled by interrupts. */
		sleepmgr_enter_sleep();
	} while (1);
}
Exemplo n.º 17
0
int main(void)
{
    struct adc_config         adc_conf;
    struct adc_channel_config adcch_conf;

    board_init();
    sysclk_init();
    sleepmgr_init();
    irq_initialize_vectors();
    cpu_irq_enable();

    // Initialize configuration structures.
    adc_read_configuration(&ADCA, &adc_conf);
    adcch_read_configuration(&ADCA, ADC_CH0, &adcch_conf);

    /* Configure the ADC module:
     * - unsigned, 12-bit results
     * - bandgap (1 V) voltage reference
     * - 200 kHz maximum clock rate
     * - manual conversion triggering
     * - temperature sensor enabled
     * - callback function
     */
    adc_set_conversion_parameters(&adc_conf, ADC_SIGN_OFF, ADC_RES_12,
                                  ADC_REF_BANDGAP);
    adc_set_clock_rate(&adc_conf, 200000UL);
    adc_set_conversion_trigger(&adc_conf, ADC_TRIG_MANUAL, 1, 0);
    adc_enable_internal_input(&adc_conf, ADC_INT_TEMPSENSE);

    adc_write_configuration(&ADCA, &adc_conf);
    adc_set_callback(&ADCA, &adc_handler);

    /* Configure ADC channel 0:
     * - single-ended measurement from temperature sensor
     * - interrupt flag set on completed conversion
     * - interrupts disabled
     */
    adcch_set_input(&adcch_conf, ADCCH_POS_TEMPSENSE, ADCCH_NEG_NONE,
                    1);
    adcch_set_interrupt_mode(&adcch_conf, ADCCH_MODE_COMPLETE);
    adcch_enable_interrupt(&adcch_conf);

    adcch_write_configuration(&ADCA, ADC_CH0, &adcch_conf);

    // Get measurement for 85 degrees C (358 kelvin) from calibration data.
    tempsense = adc_get_calibration_data(ADC_CAL_TEMPSENSE);

    // Enable the ADC and start the first conversion.
    adc_enable(&ADCA);
    adc_start_conversion(&ADCA, ADC_CH0);

    do {
        // Sleep until ADC interrupt triggers.
        sleepmgr_enter_sleep();
    } while (1);
}
Exemplo n.º 18
0
int main(void)
{
	pmic_init();
	board_init();
	sysclk_init();
	sleepmgr_init();
	cpu_irq_enable();

	/* Enables the Timer defined in conf_example.h : TCE0 in this example */
	tc_enable(&TIMER_EXAMPLE);

	/* Configures the interrupt level of CCA and CCB modules : low */
	tc_set_cca_interrupt_level(&TIMER_EXAMPLE, TC_INT_LVL_LO);
	tc_set_ccb_interrupt_level(&TIMER_EXAMPLE, TC_INT_LVL_LO);

	/* Configures the waveform generator of this Timer mode in NORMAL mode */
	tc_set_wgm(&TIMER_EXAMPLE, TC_WG_NORMAL);

	/* Declares the interrupt functions which will be called when CCA and CCB
	interrupts will occur */
	tc_set_cca_interrupt_callback(&TIMER_EXAMPLE,
			example_cca_interrupt_callback);
	tc_set_ccb_interrupt_callback(&TIMER_EXAMPLE,
			example_ccb_interrupt_callback);

	/* Configures the Timer period*/
	tc_write_period(&TIMER_EXAMPLE, TIMER_EXAMPLE_PERIOD);

	/* Configures the CCA and CCB levels*/
	tc_write_cc(&TIMER_EXAMPLE, TC_CCA, TIMER_EXAMPLE_PERIOD/2);
	tc_write_cc(&TIMER_EXAMPLE, TC_CCB, TIMER_EXAMPLE_PERIOD/2);

	/* Enables the CCA and CCB channels*/
	tc_enable_cc_channels(&TIMER_EXAMPLE,TC_CCAEN);
	tc_enable_cc_channels(&TIMER_EXAMPLE,TC_CCAEN);

	/* Configures the waveform genertaor in Dual Slope mode and Top*/
	tc_set_wgm(&TIMER_EXAMPLE,TC_WG_DS_T);

	/* Enables and configures the deadtime of CCA and CCB outputs*/
	tc_awex_enable_cca_deadtime(&AWEXE);
	tc_awex_enable_ccb_deadtime(&AWEXE);
	tc_awex_set_dti_high(&AWEXE, TIMER_EXAMPLE_PERIOD/6);
	tc_awex_set_dti_low(&AWEXE, TIMER_EXAMPLE_PERIOD/6);

	/* Outputs CCA and CCB on Port E0 and E1*/
	tc_awex_set_output_override(&AWEXE, 0x03);

	tc_set_resolution(&TIMER_EXAMPLE, 10000);

	do {
		/* Go to sleep, everything is handled by interrupts. */
		sleepmgr_enter_sleep();
	} while (1);
}
Exemplo n.º 19
0
int main(void)
{
	uint8_t lcd_text[]    = "XmegaB1";
	uint16_t i;

	sysclk_init();
	pmic_init();
	sleepmgr_init();
	board_init();
	c42048a_init();

	c42048a_set_contrast(60);
	c42048a_blinkrate_init(LCD_BLINKRATE_1Hz_gc);

	// Alphanumeric
	c42048a_set_text(lcd_text);
	// Numeric
	c42048a_set_numeric_dec(1245);

	// All pixels "on" blinking
	c42048a_set_blink_screen();
	c42048a_wait_int_period(16);
	c42048a_clear_blink_screen();

	// AVR icon blinking alone
	c42048a_blink_pixel(ICON_AVR);
	c42048a_wait_int_period(16);

	// AVR icon on
	c42048a_set_pixel(ICON_AVR);

	// USB icon blinking
	c42048a_blink_pixel(ICON_USB);
	// AM is not part of blinking icons
	// AM will be ON only
	c42048a_blink_pixel(ICON_AM);

	// Display a progress bar graph value
	for(i=1; i<256; i+=16) {
		c42048a_bar_graph((uint8_t)i);
		c42048a_wait_int_period(1);
	}
	c42048a_wait_int_period(4);

	// Blink entire screen 8 times
	c42048a_set_blink_screen();
	c42048a_wait_int_period(16);

	// Unblink all the screen
	c42048a_clear_blink_screen();

	while(true) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 20
0
void __wait_for_completion( completion_t* flag )
{
	#if USB_LOCK_DEBUG
	printf("DEBUG: Must wait for command completion...\n");
	#endif
	do {
		sleepmgr_enter_sleep();
		completion_t not_ready = *flag;
		if (not_ready == false) {
			break;
		}
	} while(true);
}
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	sysclk_init();
	board_init();
	ui_init();
	ui_powerdown();

#if UC3A3
	// Init Hmatrix bus   
	sysclk_enable_pbb_module(SYSCLK_HMATRIX);
	init_hmatrix();
#endif
#if (defined AT45DBX_MEM) && (AT45DBX_MEM == ENABLE)
	at45dbx_init();
#endif
#if ((defined SD_MMC_MCI_0_MEM) && (SD_MMC_MCI_0_MEM == ENABLE)) \
	|| ((defined SD_MMC_MCI_1_MEM) && (SD_MMC_MCI_1_MEM == ENABLE))
	// Initialize SD/MMC with MCI PB clock.
	sysclk_enable_pbb_module(SYSCLK_MCI);
	sysclk_enable_hsb_module(SYSCLK_DMACA);
	sd_mmc_mci_resources_init();
#endif

	// Start USB stack to authorize VBus monitoring
	udc_start();

	if (!udc_include_vbus_monitoring()) {
		// VBUS monitoring is not available on this product
		// thereby VBUS has to be considered as present
		main_vbus_action(true);
	}

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {

		sleepmgr_enter_sleep();
		if (main_b_msc_enable) {
         udi_msc_process_trans();
      }
	}
}
Exemplo n.º 22
0
/*! \brief Main function.
 */
int main(void)
{
	uint8_t tx_buf[] = "\n\rHello AVR world ! : ";
	uint8_t i;

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	sysclk_init();
	pmic_init();
	cpu_irq_enable();
	sleepmgr_init();
	sleepmgr_lock_mode(SLEEPMGR_STDBY);

	/* USART options. */
	static usart_xmegae_rs232_options_t USART_SERIAL_OPTIONS = {
		.baudrate = USART_SERIAL_EXAMPLE_BAUDRATE,
		.charlength = USART_SERIAL_CHAR_LENGTH,
		.paritytype = USART_SERIAL_PARITY,
		.stopbits = USART_SERIAL_STOP_BIT,
		.start_frame_detection = false,
		.one_wire = false,
		.pec_length = USART_SERIAL_VARIABLE_CHAR_LENGTH,
		.pec_action = USART_PECACT_PERC01_gc,
		.encoding_type = USART_DECTYPE_DATA_gc,
		.encoding_stream = USART_LUTACT_OFF_gc,
	};

	/* Initialize usart driver in RS232 mode */
	usart_xmegae_init_rs232(USART_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS);
	usart_set_rx_interrupt_level(USART_SERIAL_EXAMPLE, USART_INT_LVL_LO);

	/* Send "message header" */
	for (i = 0; i < sizeof(tx_buf); i++) {
		usart_putchar(USART_SERIAL_EXAMPLE, tx_buf[i]);
		while (!usart_tx_is_complete(USART_SERIAL_EXAMPLE)) {
		}
		usart_clear_tx_complete(USART_SERIAL_EXAMPLE);
	}

	/* Incoming character is process under interrupt
	 * main loop simply enters sleep mode */
	while (true) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 23
0
/** \brief Main function.
 */
int main(void)
{
	/* Set the sleep mode to initially lock. */
	volatile enum sleepmgr_mode mode = SLEEPMGR_ACTIVE;
    /* Initialize the pins for input and output. */
	board_init();
    /* Initialize the clock and disable clock unused modules */
	sysclk_init();
    /* Initialize the IOPORT */
	ioport_init();
	delay_init(sysclk_get_cpu_hz());

	/* Set the pin sense mode */
	ioport_set_pin_sense_mode(BUTTON_PIN, IOPORT_SENSE_LEVEL);
    
    /* Enable external interrupt */
	external_interrupt_enable(BUTTON_NUMBER);

	/* Turn off the LED		*/
	LED_On(LED_PIN);

	/* Initialize the sleep manager, lock initial mode. */
	sleepmgr_init();
	sleepmgr_lock_mode(mode);

	Enable_global_interrupt();

	do {
		/* Delay for 3 seconds to show the device is awake. */
		delay_ms(3000);

		/* Turn off the LED and go to sleep. */
		LED_Off(LED_PIN);
		sleepmgr_enter_sleep();

		/* Turn on the LED on wake up */
		LED_On(LED_PIN);

		/* Unlock current mode, then lock the next one. */
		sleepmgr_unlock_mode(mode);
		if (++mode < SLEEPMGR_NR_OF_MODES) {
			sleepmgr_lock_mode(mode);
		} else {
			mode = SLEEPMGR_ACTIVE;
			sleepmgr_lock_mode(mode);
		}
	} while (1);
}
Exemplo n.º 24
0
int main(void)
{
	/* Usual initializations */
	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();
        
	/*
	 * Configure TCC4 to generate 50ms overflow interrupt
	 * using 500kHz (2us) resolution clock (50ms = 25000 * 2us)
	 */
	/* Unmask clock for TCC4 */
	tc45_enable(&TCC4);
	/* Enable overflow interrupt */
	tc45_set_overflow_interrupt_level(&TCC4, TC45_INT_LVL_LO);
	/* Configure TC in normal mode */
	tc45_set_wgm(&TCC4, TC45_WG_NORMAL);
	/* Configure call back interrupt */
	tc45_set_overflow_interrupt_callback(&TCC4,
			example_overflow_interrupt_callback);
	/* Configure TC period and resolution */
	tc45_write_period(&TCC4, 25000);
	tc45_set_resolution(&TCC4, 500000);

	/*
	 * Configure TCD5 to generate 2ms Single Slope PWM
	 */
	/* Unmask clock for TCD5 */
	tc45_enable(&TCD5);
	/* Configure TC in PWM Single Slope PWM */
	tc45_set_wgm(&TCD5, TC45_WG_SS);
	/* Use the max period (2MHz / FFFFh = 30Hz) */
	tc45_write_period(&TCC4, 0xFFFF);
	/* Initialize and enable Channel A */
	tc45_write_cc(&TCD5, TC45_CCA, 0);
	tc45_enable_cc_channels(&TCD5, TC45_CCACOMP);
	/* Run TC at 2MHz clock resolution (CPU frequency 32MHz) */
	tc45_set_resolution(&TCD5, 20000000);

	do {
		/* Go to sleep, everything is handled by interrupts. */
		sleepmgr_enter_sleep();
	} while (1);
}
Exemplo n.º 25
0
/*! \brief Main function.
 */
int main(void)
{
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	sysclk_init();
	sleepmgr_init();
	irq_initialize_vectors();
	cpu_irq_enable();

	/* Configure the XCL module:
	 * - Asynchronous mode usage (locks Power Down sleep mode)
	 * - Configure XCL to use XMEGA port D
	 * - Configure LUT in 1 LUTs with 3 differents inputs
	 * - LUT IN0 input on pin 2 or port D
	 * - LUT IN1 input on XCL LUT OUT1
	 * - LUT OUT0 output on pin 4 or port D
	 * - LUT IN2 input on pin 1 or port D
	 * - LUT IN3 input on pin 3 or port D
	 * - LUT OUT1 output on LUT IN1
	 * - No time Delay for both LUT0 and LUT1
	 * - LUT0 performs XOR operation
	 * - LUT1 performs XOR operation
	 */
	xcl_enable(XCL_ASYNCHRONOUS);
	xcl_port(PD);
	xcl_lut_type(LUT_1LUT3IN);
	xcl_lut_in0(LUT_IN_PINL);
	xcl_lut_in1(LUT_IN_XCL);
	xcl_lut_in2(LUT_IN_PINL);
	xcl_lut_in3(LUT_IN_PINL);
	xcl_lut0_output(LUT0_OUT_PIN4);
	xcl_lut_config_delay(DLY11, LUT_DLY_DISABLE, LUT_DLY_DISABLE);
	xcl_lut0_truth(XOR);
	xcl_lut1_truth(XOR);

	/*
	 * main loop simply enters sleep mode
	 */
	while (true) {
		sleepmgr_enter_sleep();
	}
}
Exemplo n.º 26
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	static bool qtb0_last_state = false;
	static bool qtb1_last_state = false;
	bool qtb_state;

	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize ASF services
	sleepmgr_init();
	sysclk_init();
	board_init();

	// Initialize sub task
	app_touch_init();

	// The main loop
	while (true) {
		// Enter in sleep mode
		sleepmgr_enter_sleep();

		// Check state of QTouch buttons
		qtb_state = app_touch_check_key_pressed(0);
		if (qtb_state != qtb0_last_state) {
			// QTouch button have changed
			qtb0_last_state = qtb_state;
			if (!qtb_state) {
				LED_On(LED0_GPIO);
			} else {
				LED_Off(LED0_GPIO);
			}
		}
		qtb_state = app_touch_check_key_pressed(1);
		if (qtb_state != qtb1_last_state) {
			// QTouch button have changed
			qtb1_last_state = qtb_state;
			if (!qtb_state) {
				LED_On(LED1_GPIO);
			} else {
				LED_Off(LED1_GPIO);
			}
		}
	}
}
Exemplo n.º 27
0
static void record_events(void)
{
	uint16_t i=0;
	while(1) {
		while (!main_events) {
			sleepmgr_enter_sleep(); \
		}
		if (i < NB_EVENTS) {
			// Register events
			irqflags_t flags = cpu_irq_save();
			list_event[i].event = main_events;
			list_event[i++].timestamp =
				cpu_cy_2_us(Get_system_register(AVR32_COUNT),sysclk_get_cpu_hz());
			main_events=0;
			cpu_irq_restore(flags);
		}
	}
}
Exemplo n.º 28
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	sysclk_init();
	board_init();
	ui_init();
	ui_powerdown();

	// Start USB stack to authorize VBus monitoring
	udc_start();

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {
		sleepmgr_enter_sleep();
		if (main_b_cdc_enable) {
			// Here CPU wakeup at each SOF (1ms)
			for (uint8_t port = 0; port < UDI_CDC_PORT_NB; port++) {
				if (!(main_port_open & (1 << port))) {
					// Port not open
					continue;
				}
				if (!udi_cdc_multi_is_rx_ready(port)) {
					// No data received
					continue;
				}
				int value = udi_cdc_multi_getc(port);
				if (value != 'p') {
					// Ignore this value
					continue;
				}
				udi_cdc_multi_write_buf(port, "PORT", sizeof("PORT")-1);
				udi_cdc_multi_putc(port, port+'0');
				udi_cdc_multi_putc(port, '\n');
				udi_cdc_multi_putc(port, '\r');
			}
		}
	}
}
Exemplo n.º 29
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{

	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

#if !SAMD21 && !SAMR21 && !SAMD11 && !SAML21
	sysclk_init();
	board_init();
#else
	system_init();
#endif
	ui_init();
	ui_powerdown();


	// Start USB stack to authorize VBus monitoring
	udc_start();

	// The main loop manages only the power mode
	// because the USB management is done by interrupt
	while (true) {
#ifdef   USB_DEVICE_LOW_SPEED
		// No USB "Keep a live" interrupt available in low speed
		// to scan generic interface then use main loop
		if (main_b_generic_enable) {
			static volatile uint16_t virtual_sof_sub = 0;
			static uint16_t virtual_sof = 0;
			if (sysclk_get_cpu_hz()/50000 ==
				virtual_sof_sub++) {
				virtual_sof_sub = 0;
				static uint16_t virtual_sof = 0;
				ui_process(virtual_sof++);
			}
		}
#else
		sleepmgr_enter_sleep();
#endif

	}
}
Exemplo n.º 30
0
/**
 * \brief Application entry point for sdramc_example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the system */
	sysclk_init();
	board_init();
	sleepmgr_init();

	/* Configure the console uart */
	configure_console();

	/* Output example information */
	puts(STRING_HEADER);

	/* Systick configuration */
	if (SysTick_Config(SystemCoreClock / (1000))) {
		puts("-F- Systick configuration error.\r");
	}

	/* Enable SMC peripheral clock */
	pmc_enable_periph_clk(ID_SDRAMC);

	/* Complete SDRAM configuration */
	sdramc_init((sdramc_memory_dev_t *)&SDRAM_ISSI_IS42S16100E,
			sysclk_get_cpu_hz());
	sdram_enable_unaligned_support();

	/* Test external SDRAM access */
	puts("Test external SDRAM access. \r");

	if (sdram_access_test() == SDRAMC_OK) {
		puts("SDRAM access is successful.\n\r");
	} else {
		puts("SDRAM access is failed.\r");
	}

	if (sdram_benchmarks() == SDRAMC_OK) {
		puts("SDRAM test: pass.\r");
	}

	for (;;) {
		sleepmgr_enter_sleep();
	}
}