示例#1
0
/**
 * \brief Application entry point for pdc_uart example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	board_init();    

	/* Initialize the UART console */
	configure_console();

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

	/* Get pointer to UART PDC register base */
	g_p_uart_pdc = uart_get_pdc_base(CONSOLE_UART);

	/* Initialize PDC data packet for transfer */
	g_pdc_uart_packet.ul_addr = (uint32_t) g_uc_pdc_buffer;
	g_pdc_uart_packet.ul_size = BUFFER_SIZE;

	/* Configure PDC for data receive */
	pdc_rx_init(g_p_uart_pdc, &g_pdc_uart_packet, NULL);

	/* Enable PDC transfers */
	pdc_enable_transfer(g_p_uart_pdc, PERIPH_PTCR_RXTEN | PERIPH_PTCR_TXTEN);

	/* Enable UART IRQ */
	uart_enable_interrupt(CONSOLE_UART, UART_IER_RXBUFF);

	/* Enable UART interrupt */
	NVIC_EnableIRQ(CONSOLE_UART_IRQn);

	while (1) {
	}
}
示例#2
0
文件: main.c 项目: InSoonPark/asf
/**
 * \brief Main application
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();

	/* Initialize the board */
	board_init();

	/*Configure UART console.*/
	configure_console();

	/* Configure the I2C master module */
	configure_i2c_master();

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

	/* Show the extension boards information */
	show_extension_boards_information();

#ifdef CONF_KIT_DATA_EXIST
	/* Show the kit data */
	show_kit_data();
#endif

	while (1) {
		/* Infinite loop */
	}

}
示例#3
0
/**
 * \brief Application entry point for the example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	board_init();    

	/* Initialize the UART console */
	configure_console();

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

	/* First test sleepwalking in active mode */
	uart_sleepwalking_test_active();

	delay_s(1);

	/* Then test sleepwalking in wait mode */
	uart_sleepwalking_test_wait();

	puts("All test are done.\r\n\r");

	while (1) {
	}
}
/**
 *  \brief pmc_clock_failure_detect_example Application entry point.
 *
 *  Enable Clock Failure Detection function in PMC, turn on a LED to indicate
 *  that a clock failure is detected.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Initialize the console UART. */
	configure_console();

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

	/* Turn off the LED. */
#if (SAM4E || SAM4N || SAM4C)
		LED_Off(LED0);
#elif (SAM4CM)
		LED_Off(LED4);
#else
		LED_Off(EXAMPLE_LED);
#endif

	/* Enable Clock Failure Detector. */
	pmc_enable_clock_failure_detector();

	/* Enable Clock Failure Detector Event interrupt. */
	NVIC_EnableIRQ(PMC_IRQn);
	pmc_enable_interrupt(PMC_IER_CFDEV);

	puts("-I- Short XIN or XOUT to ground to force a clock failure.\n\r");

	while (1) {
		/* Infinite loop */
	}
}
示例#5
0
文件: main.c 项目: kajm/PingPong
/* HUVUDPROGRAM */
int main (void)
{
	/* INITIERING */
	sysclk_init();			// Systemklocka.
	board_init();			// Arduino-kort.
	configure_console();	// Konsoll-/terminalfönster.
	adc_setup();			// AD-omvandlare.
	pwm_setup();			// PWM-signal.
	motor_shield_setup();	// Motor-shield.

	/* PROCESS 1 - PID-REGLERING */
	if (xTaskCreate(pid, (const signed char * const) "PID-reglering", 1024, NULL, 2, NULL) != pdPASS)
	{
		printf("Misslyckades med att skapa process för PID-reglering.\r\n");
	}
	
	/* PROCESS 2 - KOMMUNIKATION MATLAB */
	if (xTaskCreate(matlab, (const signed char * const) "Matlab-kommunikation", 1024, NULL, 1, NULL) != pdPASS)
	{
		printf("Misslyckades med att skapa process för kommunikation med Matlab.\r\n");
	}
	
	// Schemaläggning startar.
	vTaskStartScheduler();
}
示例#6
0
int main (void)
{
	uint8_t tiles[6] = {0,0,0,0,0,0}, receivedData,i = 0;
	int quotient;
	system_init();
	ext_usart_clock_init();
	ext_usart_pin_init();
	ext_usart_init();
	configure_console();
	printf("Up and running!\r");
	while (1) {
		receivedData = USART_Receive();
		quotient = receivedData;
		i = 0;
		while(quotient != 0) {
			tiles[i] = quotient%2;
			quotient /= 2;
			i++;
		}
		for(int i = 0; i < 6; i++) {
			printf("%d",tiles[i]);
			tiles[i] = 0;
		}
	printf("\n");
	}
}
示例#7
0
/**
 * \brief main function : do init and loop
 */
int main(void)
{
	system_init();
	configure_console();
	delay_init();

	/* Turn on the backlight. */
	port_pin_set_output_level(SLCD_BACLKLIGHT,true);

	printf("Start SLCD test\r\n");
	/* Initialize the C42412A LCD glass component. */
	c42412a_init();

	c42412a_show_all();
	c42412a_set_contrast(0x8);
	delay_s(1);
	c42412a_clear_all();

	c42412a_icon_test();
	delay_s(1);
	c42412a_blink_test();
	delay_s(1);
	c42412a_text_test();
	delay_s(1);
	c42412a_num_dec_test();
	delay_s(1);
	c42412a_animation_test();
	while (1) {
	}
}
示例#8
0
文件: main.c 项目: Realtime-7/asf
/**
 *  \brief FreeRTOS Real Time Kernel example entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
    /* Initilize the SAM system */
    sysclk_init();
    board_init();

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

    /* Output demo infomation. */
    printf("-- Freertos Example --\n\r");
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* Create task to monitor processor activity */
    if (xTaskCreate(task_monitor, "Monitor", TASK_MONITOR_STACK_SIZE, NULL,
                    TASK_MONITOR_STACK_PRIORITY, NULL) != pdPASS) {
        printf("Failed to create Monitor task\r\n");
    }

    /* Create task to make led blink */
    if (xTaskCreate(task_led, "Led", TASK_LED_STACK_SIZE, NULL,
                    TASK_LED_STACK_PRIORITY, NULL) != pdPASS) {
        printf("Failed to create test led task\r\n");
    }

    /* Start the scheduler. */
    vTaskStartScheduler();

    /* Will only get here if there was insufficient memory to create the idle task. */
    return 0;
}
示例#9
0
/**
 * \brief Application entry point for eic example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Initialize the UART console. */
	configure_console();

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

	eic_setup();

	puts("--Push the button to toggle the LED--\r\n\r");

	while (1) {
		if (bToggle == 1) {
			puts("--Toggle the LED--\r");
			ioport_toggle_port_level(EXAMPLE_LED_PORT,
					EXAMPLE_LED_MASK);
			bToggle = 0;
		}
	}
}
示例#10
0
int main(void)
{
	/* Initiera SAM systemet */
	sysclk_init();
	board_init();
	configure_console();
	/* Print demo information */
	printf("-- Freertos Exempel - Semaforer --\n\r");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Kompilerad: %s %s --\n\r", __DATE__, __TIME__);
	/* a semaphore cannot be used wihtout calling vSemaphoreCreateBinary() */
	vSemaphoreCreateBinary(semafor_signal);
	/* Create the task giving the semaphore */
	if (xTaskCreate(task1, (const signed char * const) "Task1", 1024, NULL, 1,
	NULL) != pdPASS)
	{
		printf("Misslyckades med att skapa Boss tasken\r\n");
	}
	/* Create a task taking the semaphore and doing it’s stuff */
	if (xTaskCreate(task2, (const signed char * const) "Task2", 1024, NULL, 2,
	NULL) != pdPASS)
	{
		printf("Misslyckades med att skapa Employee tasken\r\n");
	}
	/* Start the scheduler */
	vTaskStartScheduler();
}
示例#11
0
/**
 * \brief Application entry point for TRNG example.
 *
 * Enable the TRNG, display the generated random value.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Configure console UART */
	configure_console();

	/* Output example information */
	printf("-- TRNG Example --\n\r");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Configure PMC */
	pmc_enable_periph_clk(ID_TRNG);

	/* Enable TRNG */
	trng_enable(TRNG);

	/* Enable TRNG interrupt */
	NVIC_DisableIRQ(TRNG_IRQn);
	NVIC_ClearPendingIRQ(TRNG_IRQn);
	NVIC_SetPriority(TRNG_IRQn, 0);
	NVIC_EnableIRQ(TRNG_IRQn);
	trng_enable_interrupt(TRNG);

	/* User input loop */
	while (1) {
	}
}
示例#12
0
/**
 * \brief Application entry point for pdca_usart example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Initialize the UART console */
	configure_console();

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

	/* Enable PDCA module clock */
	pdca_enable(PDCA);

	/* Init PDCA channel with the pdca_options.*/
	pdca_channel_set_config(PDCA_TX_CHANNEL, &pdca_tx_configs);

	/* Enable PDCA channel */
	pdca_channel_enable(PDCA_TX_CHANNEL);

	pdca_channel_set_callback(PDCA_TX_CHANNEL, pdca_tranfer_done, PDCA_0_IRQn,
		1, PDCA_IER_RCZ);

	while (1) {
	}
}
/**
 * \brief Application entry point for AT30TS(E)75x Component Example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	double temp = 0;

	/* Initialize the SAM system */
	sysclk_init();

	/* Initialize the board */
	board_init();

	/* Initialize the console UART */
	configure_console();

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

	memset(tx, 0xFF, NB_BYTE);

	/* Initialize AT30TS(E)75x */
	at30tse_init();

#if BOARD_USING_AT30TSE != AT30TS75
	uint32_t i;
	/* Write pages in EEPROM */
	for (i = 0; i < NB_PAGE; i++) {
		tx[NB_PAGE - 1] = i;
		if (at30tse_eeprom_write(tx, NB_BYTE, 0, i) != TWI_SUCCESS) {
			puts("Write EEPROM error\r");
			return 0;
		}
		delay_ms(5);
	}
	puts("Write EEPROM OK\r");

	/* Read each page in EEPROM and compare them */
	for (i = 0; i < NB_PAGE; i++) {
		memset(rx, 0, NB_BYTE);
		if (at30tse_eeprom_read(rx, NB_BYTE, 0, i) != TWI_SUCCESS) {
			puts("Read EEPROM error\r");
			return 0;
		} else {
			if (memcmp(tx, rx, NB_BYTE - 1) && (rx[NB_PAGE - 1] != i)) {
				puts("Comparison error\r");
				return 0;
			}
		}
	}
	puts("Read EEPROM & Compare OK\r");
#endif

	/* Read temperature every second */
	while (1) {
		if (at30tse_read_temperature(&temp) != TWI_SUCCESS) {
			puts("Read temperature error\r");
			return 0;
		}
		printf("Read temperature:\t%d\r\n", (int)temp);
		delay_ms(1000);
	}
}
示例#14
0
/**
 * \brief Low power application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	g_ul_current_mck = sysclk_get_cpu_hz();
	board_init();

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

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

	/* Initialize the chip for the power consumption test */
	init_chip();

	/* Set default clock and re-configure UART */
	set_default_working_clock();
	reconfigure_console(g_ul_current_mck, CONF_UART_BAUDRATE);

	/* Test core consumption */
	test_core();

	while (1) {
	}
}
示例#15
0
文件: main.c 项目: navinars/etz-main
int main (void)
{
	/* Initialize the SAM system */
	sysclk_init();
	
	/* Initialize mcu's peripheral.*/
	board_init();
	
	/* Initialize the console uart */
	configure_console();
	
	/* Output demo information. */
	RS232printf("\n\r-- FreeRTOS Example --\n\r");
	
	/* Initialize the SPI0. */
//	spi_set_clock_configuration(0);
	
	/* Ensure all priority bits are assigned as preemption priority bits. */
	NVIC_SetPriorityGrouping( 0 );
		
	/* Create freeRTOS START task.*/
	xTaskCreate(task_start, (signed char *)"START", TASK_START_STACKSIZE, NULL,
				TASK_START_PRIORITY, NULL);
	
	/* Start the scheduler. */
	vTaskStartScheduler();
	
	/* Will only get here if there was insufficient memory to create the idle task. */
	return 0;
}
示例#16
0
/**
 * \brief main function : do init and print the unique ID through the
 * serial console.
 */
int main(void)
{
	uint32_t i;
	volatile uint8_t* unique_id_addr = (volatile uint8_t*) UNIQUE_ID_ADDR;

	/* Initialize the SAM system */
	sysclk_init();
	board_init();

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

	/* Output example information */
	printf("-- FLASHCALW Example2 --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	printf("ID: ");

	/* Read the unique id and print it */
	for (i=0; i<15; i++) {
		printf("%02x",*unique_id_addr++);
	}

	while (true) {
	}
}
示例#17
0
/**
 * \brief Application entry point for smc_lcd example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	sysclk_init();

	board_init();

	/** Initialize debug console */
	configure_console();

	/* Disable the watchdog */
	WDT->WDT_MR = WDT_MR_WDDIS;

	/** Configura o timer */
	configure_tc();
	
	/* Configura os botões */
	configure_buttons();
	configure_display();
	init_tela();
	
	/** Draw text, image and basic shapes on the LCD */
		//ili93xx_set_foreground_color(COLOR_BLACK);
		//ili93xx_draw_string(10, 20, (uint8_t *)"ili93xx_lcd example");
	


	while (1) {
	}
}
示例#18
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_key;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	configure_console();

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

	g_afec0_sample_data = 0;
	g_afec1_sample_data = 0;
	g_max_digital = MAX_DIGITAL_12_BIT;

	set_afec_test();

	while (1) {
		afec_start_software_conversion(AFEC0);
		delay_ms(g_delay_cnt);

		/* Check if the user enters a key. */
		if (!uart_read(CONF_UART, &uc_key)) {
			/* Disable all afec interrupt. */
			afec_disable_interrupt(AFEC0, AFEC_INTERRUPT_ALL);
			afec_disable_interrupt(AFEC1, AFEC_INTERRUPT_ALL);
			tc_stop(TC0, 0);
			set_afec_test();
		}
	}
}
示例#19
0
/**
 * \brief The main function.
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Initialize the console  */
	configure_console();

	/* Output example information */
	printf("-- CMCC Example --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Enable the CMCC module. */
	cmcc_get_config_defaults(&g_cmcc_cfg);
	cmcc_init(CMCC_BASE, &g_cmcc_cfg);
	cmcc_enable(CMCC_BASE);

	/* Do the Fibonacci calculation. */
	recfibo(FIBONACCI_NUM);
	printf("Fibonacci calculation completed \r\n");
	printf("Cache Data hit: %ld \r\n", cmcc_get_monitor_cnt(CMCC_BASE));

	while (true) {
	}
}
示例#20
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	int32_t ul_vol;
	int32_t ul_temp;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	configure_console();

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

	afec_enable(AFEC0);

	struct afec_config afec_cfg;

	afec_get_config_defaults(&afec_cfg);

	afec_init(AFEC0, &afec_cfg);

	afec_set_trigger(AFEC0, AFEC_TRIG_SW);

	struct afec_ch_config afec_ch_cfg;
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_ch_set_config(AFEC0, AFEC_TEMPERATURE_SENSOR, &afec_ch_cfg);

	/*
	 * Because the internal ADC offset is 0x800, it should cancel it and shift
	 * down to 0.
	 */
	afec_channel_set_analog_offset(AFEC0, AFEC_TEMPERATURE_SENSOR, 0x800);

	struct afec_temp_sensor_config afec_temp_sensor_cfg;

	afec_temp_sensor_get_config_defaults(&afec_temp_sensor_cfg);
	afec_temp_sensor_cfg.rctc = true;
	afec_temp_sensor_set_config(AFEC0, &afec_temp_sensor_cfg);

	afec_set_callback(AFEC0, AFEC_INTERRUPT_EOC_15,
			afec_temp_sensor_end_conversion, 1);

	while (1) {

		if(is_conversion_done == true) {

			ul_vol = g_ul_value * VOLT_REF / MAX_DIGITAL;

			/*
			 * According to datasheet, The output voltage VT = 1.44V at 27C
			 * and the temperature slope dVT/dT = 4.7 mV/C
			 */
			ul_temp = (ul_vol - 1440)  * 100 / 470 + 27;

			printf("Temperature is: %4d\r", (int)ul_temp);
			is_conversion_done = false;
		}
	}
}
示例#21
0
文件: main21.c 项目: malachi-iot/asf
/**
 * \brief Main application function.
 *
 * Application entry point.
 *
 * \return program return value.
 */
int main(void)
{
	tstrWifiInitParam param;
	int8_t ret;

	/* Initialize the board. */
	system_init();

	/* Initialize the UART console. */
	configure_console();
	printf(STRING_HEADER);

	/* Initialize the BSP. */
	nm_bsp_init();

	/* Initialize Wi-Fi parameters structure. */
	memset((uint8_t *)&param, 0, sizeof(tstrWifiInitParam));

	/* Initialize Wi-Fi driver with data and status callbacks. */
	ret = m2m_wifi_init(&param);
	if (M2M_SUCCESS != ret) {
		printf("main: m2m_wifi_init call error!(%d)\r\n", ret);
		while (1) {
		}
	}

	/**
	 * Station mode.
	 * Device started as station mode basically.
	 */
	if (1) {
	}

	/**
	 * AP mode.
	 * On and off AP mode.
	 */
	ret = enable_disable_ap_mode();
	if (M2M_SUCCESS != ret) {
		printf("main: enable_disable_ap_mode call error!\r\n");
		while (1) {
		}
	}

	nm_bsp_sleep(DELAY_FOR_MODE_CHANGE);

	/**
	 * P2P mode.
	 * On and off P2P mode.
	 */
	ret = enable_disable_p2p_mode();
	if (M2M_SUCCESS != ret) {
		printf("main: enable_disable_p2p_mode call error!\r\n");
		while (1) {
		}
	}

	return 0;
}
示例#22
0
/**
 * \brief adc_temp_sensor Application entry point.
 *
 * Initialize adc to 12-bit, enable channel 15,turn on
 * temp sensor, pdc channel interrupt for temp sensor
 * and start conversion.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Disable watchdog. */
	WDT->WDT_MR = WDT_MR_WDDIS;

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

	/* 10 ms timer */
	if (SysTick_Config(sysclk_get_cpu_hz() / 100)) {
		puts("-F- Systick configuration error\r");
		while (1) {
		}
	}
	/* Enable peripheral clock. */
	pmc_enable_periph_clk(ID_ADC);
	/* Initialize ADC. */
	/*  startup = 8:    512 periods of ADCClock
	 * for prescale = 4
	 *     prescale: ADCClock = MCK / ( (PRESCAL+1) * 2 ) => 64MHz / ((4+1)*2) = 6.4MHz
	 *     ADC clock = 6.4 MHz
	 */
	adc_init(ADC, sysclk_get_cpu_hz(), 6400000, 8);

	adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1);

	adc_configure_trigger(ADC, ADC_TRIG_SW, 0);

	adc_check(ADC, sysclk_get_cpu_hz());

	/* Enable channel for potentiometer. */
	adc_enable_channel(ADC, ADC_TEMPERATURE_SENSOR);

	/* Enable the temperature sensor. */
	adc_enable_ts(ADC);

	/* Enable ADC interrupt. */
	NVIC_EnableIRQ(ADC_IRQn);
	
	/* Start conversion. */
	adc_start(ADC);

	adc_read_buffer(ADC, gs_s_adc_values, BUFFER_SIZE);
	
	/* Enable PDC channel interrupt. */
	adc_enable_interrupt(ADC, ADC_ISR_RXBUFF);

	while (1) {
	}
}
示例#23
0
/**
 * \brief Application entry point for TWI Slave example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t i;

	/* Initialize the SAM system */
	sysclk_init();

#if (SAM4S || SAM4E)
	/* Select PB4 and PB5 function, this will cause JTAG discconnect */
	REG_CCFG_SYSIO |= CCFG_SYSIO_SYSIO4;
	REG_CCFG_SYSIO |= CCFG_SYSIO_SYSIO5;
#endif

	/* Initialize the board */
	board_init();

	/* Initialize the console UART */
	configure_console();

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

#if (SAMG55)
	/* Enable the peripheral and set TWI mode. */
	flexcom_enable(BOARD_FLEXCOM_TWI);
	flexcom_set_opmode(BOARD_FLEXCOM_TWI, FLEXCOM_TWI);
#else
	/* Enable the peripheral clock for TWI */
	pmc_enable_periph_clk(BOARD_ID_TWI_SLAVE);
#endif

	for (i = 0; i < MEMORY_SIZE; i++) {
		emulate_driver.uc_memory[i] = 0;
	}
	emulate_driver.us_offset_memory = 0;
	emulate_driver.uc_acquire_address = 0;
	emulate_driver.us_page_address = 0;

	/* Configure TWI as slave */
	puts("-I- Configuring the TWI in slave mode\n\r");
	twi_slave_init(BOARD_BASE_TWI_SLAVE, SLAVE_ADDRESS);

	/* Clear receipt buffer */
	twi_read_byte(BOARD_BASE_TWI_SLAVE);

	/* Configure TWI interrupts */
	NVIC_DisableIRQ(BOARD_TWI_IRQn);
	NVIC_ClearPendingIRQ(BOARD_TWI_IRQn);
	NVIC_SetPriority(BOARD_TWI_IRQn, 0);
	NVIC_EnableIRQ(BOARD_TWI_IRQn);
	twi_enable_interrupt(BOARD_BASE_TWI_SLAVE, TWI_SR_SVACC);

	while (1) {
	}
}
示例#24
0
/**
 * \brief main function : do init and loop.
 */
int main(void)
{
	uint32_t ast_alarm, ast_counter;
	uint8_t key;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Initialize the console uart. */
	configure_console();

	/* Output example information. */
	printf("-- AST Example 2 in counter mode --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	printf("Config AST with 32 KHz oscillator.\r\n");
	printf("Use alarm0 to wakeup from low power mode.\r\n");
	config_ast();

	/* AST and EIC can wakeup the device. */
	config_wakeup();

	while (1) {

		/* let the user select the low power mode. */
		key = 0;
		while ((key < 0x31) || (key > 0x37)) {
			/* Display menu */
			display_menu();
			scanf("%c", (char *)&key);
		}
		key = key - '0';

		/* ast_init_counter Set Alarm to current time+6 seconds. */
		ast_counter = ast_read_counter_value(AST);
		ast_alarm = ast_counter + 6;
		ast_write_alarm0_value(AST, ast_alarm);

		ast_enable_interrupt(AST, AST_INTERRUPT_ALARM);

		/* Go into selected low power mode. */
		bpm_sleep(BPM, key);
		while (flag == false);
		flag = true;

		/* After wake up, clear the Alarm0. */
		ast_clear_interrupt_flag(AST, AST_INTERRUPT_ALARM);

		/* Output the counter value. */
		ast_counter = ast_read_counter_value(AST);
		printf("\n\r Counter value: %02u \n\r", ast_counter);
	}
}
示例#25
0
文件: main.c 项目: malachi-iot/asf
/**
 * \brief Main application function.
 *
 * Application entry point.
 *
 * \return program return value.
 */
int main(void)
{
	tstrWifiInitParam param;
	int8_t ret;

	/* Initialize the board. */
	sysclk_init();
	board_init();

	/* Initialize the UART console. */
	configure_console();
	printf(STRING_HEADER);

	/* Initialize the BSP. */
	nm_bsp_init();

	/* Initialize Wi-Fi parameters structure. */
	memset((uint8_t *)&param, 0, sizeof(tstrWifiInitParam));

	/* Initialize Wi-Fi driver with data and status callbacks. */
	param.pfAppWifiCb = wifi_cb;
	ret = m2m_wifi_init(&param);
	if (M2M_SUCCESS != ret) {
		printf("main: m2m_wifi_init call error!(%d)\r\n", ret);
		while (1) {
		}
	}

	/* Set device name to be shown in peer device. */
	ret = m2m_wifi_set_device_name((uint8_t *)MAIN_WLAN_DEVICE_NAME, strlen(MAIN_WLAN_DEVICE_NAME));
	if (M2M_SUCCESS != ret) {
		printf("main: m2m_wifi_set_device_name call error!\r\n");
		while (1) {
		}
	}

	/* Bring up P2P mode with channel number. */
	ret = m2m_wifi_p2p(M2M_WIFI_CH_6);
	if (M2M_SUCCESS != ret) {
		printf("main: m2m_wifi_p2p call error!\r\n");
		while (1) {
		}
	}

	printf("P2P mode started. You can connect to %s.\r\n", (char *)MAIN_WLAN_DEVICE_NAME);

	while (1) {
		/* Handle pending events from network controller. */
		while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) {
		}
	}

	return 0;
}
示例#26
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_key;

	/* Initialize the SAM3 system */
	SystemInit();
	board_init();

	WDT->WDT_MR = WDT_MR_WDDIS;

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

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

	/* configure LED. */
	led_config();

	/* configure push buttons. */
	configure_buttons();

	/* Set default priorities for 2 buttons. */
	puts("Set INT1's priority higher than INT2.\r");
	set_interrupt_priority(INT_PRIOR_HIGH, INT_PRIOR_LOW);

	/* Display the main menu. */
	display_menu();

	// Flash the LED.
	while (1) {
		while (uart_read(CONSOLE_UART, &uc_key));

		switch (uc_key) {
		case '1':
			set_interrupt_priority(INT_PRIOR_LOW, INT_PRIOR_HIGH);
			puts("Set INT2's priority higher than INT1.\n\r\r");
			break;

		case '2':
			set_interrupt_priority(INT_PRIOR_HIGH, INT_PRIOR_LOW);
			puts("Set INT1's priority higher than INT2.\n\r\r");
			break;

		case 'h':
			display_menu();
			break;

		default:
			puts("Invalid input.\r");
			break;
		}
	}
}
示例#27
0
/**
 * \brief main function. Do the Fibonacci calculation with and without
 * PicoCache and print the calculation time to the UART console.
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	board_init();

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

	/* Output example information */
	printf("-- FLASHCALW Example3 --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Intialize time tick utilities */
	time_tick_init(sysclk_get_cpu_hz());

	/* Calculate the Fibonacci without PicoCache */
	flash_picocache_example(
		"Fibonacci calculation without PicoCache at 48MHz",
		false);

	/* Calculate the Fibonacci with PicoCache */
	flash_picocache_example(
		"Fibonacci calculation with PicoCache at 48MHz",
		true);

	puts("From now on, System is running at 12MHz\r");
	puts("Please check the power consumption\r");
	printf("Push %s to continue\r\n", BUTTON_0_NAME);
	wait_for_pushbutton();
	sysclk_set_prescalers(2, 0, 0, 0, 0);
	reconfigure_com_port();

	flashcalw_set_wait_state(0);
	/* Calculate the Fibonacci without PicoCache */
	flash_picocache_example(
		"Fibonacci calculation without PicoCache at 12MHz",
		false);

	puts("Please check the power consumption\r");
	printf("Push %s to continue\r\n", BUTTON_0_NAME);
	wait_for_pushbutton();

	/* Calculate the Fibonacci with PicoCache */
	flash_picocache_example(
		"Fibonacci calculation with PicoCache at 12MHz",
		true);

	puts("End");

	while (true) {
	}
}
示例#28
0
/**
 * \brief Application entry point for adcife example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint32_t uc_key = 0;

	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Initialize the UART console */
	configure_console();

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

	/* Set default ADCIFE test mode. */
	g_adc_test_mode.uc_trigger_mode = TRIGGER_MODE_SOFTWARE;
	g_adc_test_mode.uc_pdc_en = 1;
	g_adc_test_mode.uc_gain_en = 0;

	display_menu();

	start_dac();

	start_adc();

	while (1) {
		/* ADCIFE software trigger per 1s */
		if (g_adc_test_mode.uc_trigger_mode == TRIGGER_MODE_SOFTWARE) {
			adc_start_software_conversion(&g_adc_inst);
		}
		if (!usart_read(CONF_UART, &uc_key)) {
			adc_disable_interrupt(&g_adc_inst, ADC_SEQ_SEOC);
			display_menu();
			set_adc_test_mode();
			start_adc();
			puts("Press any key to display configuration menu.\r");
		}
		delay_ms(1000);
		if (g_uc_condone_flag == 1) {
			if(g_adc_test_mode.uc_pdc_en == 0) {
				printf("Internal DAC Voltage = %4d mv  \r\n",
						(int)(g_adc_sample_data[0] * VOLT_REF / MAX_DIGITAL));
			} else {
				printf("Internal DAC Voltage = %4d mv  \r\n",
						(int)(g_adc_sample_data[0] * VOLT_REF /
							MAX_DIGITAL));
				printf("Scaled VCC Voltage = %4d mv  \r\n",
						(int)(g_adc_sample_data[1] * VOLT_REF /
							MAX_DIGITAL));
			}
			g_uc_condone_flag = 0;
		}
	}
}
示例#29
0
static void configure_console(void) {

	sysclk_enable_peripheral_clock(PRINTF_USART_ID);

	//const usart_serial_options_t uart_serial_options = { .baudrate = CONF_UART_BAUDRATE, .paritytype = CONF_UART_PARITY, };

	const usart_serial_options_t uart_serial_options = {
	      .baudrate = USART_BAUDRATE,
	      .charlength =   USART_CHAR_LENGTH,
	      .paritytype = USART_PARITY,
	      .stopbits = false
	      //US_MR_CHMODE_NORMAL
	   };

	usart_serial_init(PRINTF_USART, &uart_serial_options);
	stdio_serial_init(PRINTF_USART, &uart_serial_options);

	usart_enable_tx(PRINTF_USART);
	usart_enable_rx(PRINTF_USART);
}

int main(void) {
	sysclk_init();
	board_init();

	configure_console();
	printf("CPH BaseStation v%d\r\n", 1);

	printf("create_uart_cli_task\r\n");
	create_uart_cli_task(CONSOLE_UART, mainUART_CLI_TASK_STACK_SIZE, mainUART_CLI_TASK_PRIORITY);
//	printf("create_dialer_task\r\n");
//	create_dialer_task(mainDIALER_TASK_STACK_SIZE, mainDIALER_TASK_PRIORITY);

	printf("create_comm_task\r\n");
	create_comm_task(mainCOMM_TASK_STACK_SIZE, mainCOMM_TASK_PRIORITY);

	printf("create_apptask_task\r\n");
	create_app_task(mainAPPTASK_TASK_STACK_SIZE, mainAPPTASK_TASK_PRIORITY);

	printf("create_led_task\r\n");
	create_led_task();


	printf("starting task scheduler\r\n");
	/* Start the scheduler. */
	vTaskStartScheduler();

	for (;;) {
	}

	/* Will only get here if there was insufficient memory to create the idle task. */
	return 0;
}
示例#30
0
/**
 * \brief Application entry point for SPI example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_key;

	/* Initialize the SAM system. */
	sysclk_init();
	board_init();

	/* Initialize the console UART. */
	configure_console();

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

	/* Configure SPI interrupts for slave only. */
	NVIC_ClearPendingIRQ(SPI_IRQn);
	NVIC_DisableIRQ(SPI_IRQn);
	NVIC_SetPriority(SPI_IRQn, 0);
	NVIC_EnableIRQ(SPI_IRQn);

	spi_slave_initialize();
	spi_xdmac_configure(SPI0);

	/* Display menu. */
	display_menu();

	while (1) {
		scanf("%c", (char *)&uc_key);

		switch (uc_key) {
		case 'h':
			display_menu();
			break;

		case 't':
			spi_disable_xdmac();
			NVIC_ClearPendingIRQ(SPI_IRQn);
			NVIC_DisableIRQ(SPI_IRQn);
			NVIC_SetPriority(SPI_IRQn, 0);
			NVIC_EnableIRQ(SPI_IRQn);
			spi_master_go();
			break;

		default:
			/* Set configuration #n. */
			if ((uc_key >= '0')
					&& (uc_key <= ('0' + NUM_SPCK_CONFIGURATIONS - 1))) {
				spi_set_clock_configuration(uc_key - '0');
			}
			break;
		}
	}
}