/**
 * \brief Main Application Routine
 *  - Initialize the system clocks
 *  - Initialize the sleep manager
 *  - Initialize the power save measures
 *  - Initialize the ACIFB module
 *  - Initialize the AST to trigger ACIFB at regular intervals
 *  - Go to STATIC sleep mode and wake up on a touch status change
 */
int main(void)
{
	/* Switch on the STATUS LED */
	gpio_clr_gpio_pin(STATUS_LED);
	/* Switch off the error LED. */
	gpio_set_gpio_pin(ERROR_LED);

	/*
	 * Initialize the system clock.
	 * Note: Clock settings are specified in conf_clock.h
	 */
	sysclk_init();

	/*
	 * Initialize the sleep manager.
	 * Note: CONFIG_SLEEPMGR_ENABLE should have been defined in conf_sleepmgr.h
	 */
	sleepmgr_init();
	/* Lock required sleep mode. */
	sleepmgr_lock_mode(SLEEPMGR_STATIC);

	/* Initialize the delay routines */
	delay_init(sysclk_get_cpu_hz());

	/* Initialize the power saving features */
	power_save_measures_init();

	/* Switch off the error LED. */
	gpio_set_gpio_pin(ERROR_LED);

#if DEBUG_MESSAGES
	/* Enable the clock to USART interface */
	sysclk_enable_peripheral_clock(DBG_USART);
	/* Initialize the USART interface to print trace messages */
	init_dbg_rs232(sysclk_get_pba_hz());

	print_dbg("\r Sleepwalking with ACIFB Module in UC3L \n");
	print_dbg("\r Initializing ACIFB Module..... \n");
#endif

	/* Initialize the Analog Comparator peripheral */
	if (ac_init() != STATUS_OK) {
#if DEBUG_MESSAGES
		/* Error initializing the ACIFB peripheral */
		print_dbg("\r Error initializing Analog Comparator module \n");
#endif
		while (1) {
			delay_ms(LED_DELAY);
			gpio_tgl_gpio_pin(ERROR_LED);
		}
	}

#if DEBUG_MESSAGES
	print_dbg("\r ACIFB Module initialized. \n");
	print_dbg("\r Initializing AST Module..... \n");
#endif

	/* Initialize the AST peripheral */
	if (ast_init() != STATUS_OK) {
#if DEBUG_MESSAGES
		print_dbg("\r Error initializing AST module \n");
#endif
		/* Error initializing the AST peripheral */
		while (1) {
			delay_ms(LED_DELAY);
			gpio_tgl_gpio_pin(ERROR_LED);
		}
	}

#if DEBUG_MESSAGES
	print_dbg("\r AST Module initialized. \n");
#endif

	/* Application routine */
	while (1) {
		/* Enable Asynchronous wake-up for ACIFB */
		pm_asyn_wake_up_enable(AVR32_PM_AWEN_ACIFBWEN_MASK);

#if DEBUG_MESSAGES
		print_dbg("\r Going to STATIC sleep mode \n");
		print_dbg(
				"\r Wake up only when input is higher than threshold \n");
#endif

		/* Switch off the status LED */
		gpio_set_gpio_pin(STATUS_LED);
		/* Disable GPIO clock before entering sleep mode */
		sysclk_disable_pba_module(SYSCLK_GPIO);
		AVR32_INTC.ipr[0];
		/* Enter STATIC sleep mode */
		sleepmgr_enter_sleep();
		/* Enable GPIO clock after waking from sleep mode */
		sysclk_enable_pba_module(SYSCLK_GPIO);
		/* Switch on the status LED */
		gpio_clr_gpio_pin(STATUS_LED);

#if DEBUG_MESSAGES
		print_dbg("\r Output higher than threshold \n");
		print_dbg("\n");
#else
		/* LED on for few ms */
		delay_ms(LED_DELAY);
#endif

		/* Clear the wake up & enable it to enter sleep mode again */
		pm_asyn_wake_up_disable(AVR32_PM_AWEN_ACIFBWEN_MASK);
		/* Clear All AST Interrupt request and clear SR */
		ast_clear_all_status_flags(&AVR32_AST);
	}

	return 0;
} /* End of main() */
Beispiel #2
0
/** \brief main function : do init and loop to display ACIFA values */
int main( void )
{
	/* Init system clocks */
	sysclk_init();

	/* init debug serial line */
	init_dbg_rs232(sysclk_get_cpu_hz());

	/* Assign and enable GPIO pins to the AC function. */
	gpio_enable_module(ACIFA_GPIO_MAP, sizeof(ACIFA_GPIO_MAP) /
			sizeof(ACIFA_GPIO_MAP[0]));

	/* Configure ACIFA0 */
	acifa_configure(&AVR32_ACIFA0,
			ACIFA_COMP_SELA,
			EXAMPLE_AC_ACMP1_INPUT,
			EXAMPLE_AC_ACMPN1_INPUT,
			FOSC0);
	acifa_configure(&AVR32_ACIFA0,
			ACIFA_COMP_SELB,
			EXAMPLE_AC_ACMP2_INPUT,
			EXAMPLE_AC_ACMPN2_INPUT,
			FOSC0);

	/* Start the ACIFA0. */
	acifa_start(&AVR32_ACIFA0,
			(ACIFA_COMP_SELA | ACIFA_COMP_SELB));

	/* Configure ACIFA1 */
	acifa_configure(&AVR32_ACIFA1,
			ACIFA_COMP_SELA,
			EXAMPLE_AC_ACMP0_INPUT,
			EXAMPLE_AC_ACMPN0_INPUT,
			FOSC0);

	/* Start the ACIFA1. */
	acifa_start(&AVR32_ACIFA1,
			ACIFA_COMP_SELA);

	/* Display a header to user */
	print_dbg("\x1B[2J\x1B[H\r\nACIFA Example\r\n");

	while (true) {
		if (acifa_is_aca_inp_higher(&AVR32_ACIFA1)) {
			print_dbg("ACMP0 > ACMPN0");
			print_dbg("\r\n");
		} else {
			print_dbg("ACMP0 < ACMPN0");
			print_dbg("\r\n");
		}

		if (acifa_is_aca_inp_higher(&AVR32_ACIFA0)) {
			print_dbg("ACMP1 > ACMPN1");
			print_dbg("\r\n");
		} else {
			print_dbg("ACMP1 < ACMPN1");
			print_dbg("\r\n");
		}

		if (acifa_is_acb_inp_higher(&AVR32_ACIFA0)) {
			print_dbg("ACMP2 > ACMPN2");
			print_dbg("\r\n");
		} else {
			print_dbg("ACMP2 < ACMPN2");
			print_dbg("\r\n");
		}

		/* Slow down display of comparison values */
		delay_ms(100);
	}
}
Beispiel #3
0
/*! \brief This example shows how to access an external RAM connected to the SMC module.
 */
int main(void)
{
    // Get base address of SRAM module
    volatile uint32_t *sram = SRAM;

    // Switch to external oscillator 0.
    pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

    // Initialize debug serial line
    init_dbg_rs232(FOSC0);

    // Display a header to user
    print_dbg("\x1B[2J\x1B[H\r\nSMC Example\r\n");

    print_dbg("Board running at ");
    print_dbg_ulong(FOSC0 / 1000000);
    print_dbg(" MHz\r\n");

    print_dbg("Initializing SRAM...");

    // Initialize the external SRAM chip.
    smc_init(FOSC0);
    print_dbg("done\r\n\r\n");

    print_dbg("Testing SRAM...\r\n");

    // Test each address location inside the chip with a write/readback
    uint32_t total_tests  = 0;
    uint32_t total_errors = 0;

    for (uint32_t total_tests = 0; total_tests < SRAM_SIZE; total_tests++) {
        sram[total_tests] = total_tests;

        if (total_tests != sram[total_tests]) {
            total_errors++;

            print_dbg("Error at 0x");
            print_dbg_hex((uint32_t)&sram[total_tests]);
            print_dbg("\r\n");
        }
    }

    if (total_errors == 0) {
        print_dbg("SRAM test successfully completed\r\n");
    }
    else {
        print_dbg("SRAM test completed with ");
        print_dbg_ulong(total_errors);
        print_dbg(" errors out of ");
        print_dbg_ulong(total_tests);
        print_dbg(" tests\r\n");
    }

    while (true);

    return 0;
}