示例#1
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;
		}
	}
}
示例#2
0
int main(void)
{
	/* Use static volatile to make it available in debug watch */
	static volatile ioport_port_mask_t port_val;

	sysclk_init();
	board_init();
	ioport_init();

	delay_init(sysclk_get_cpu_hz());

	/* Set output direction on the given LED IOPORTs */
	ioport_set_port_dir(EXAMPLE_LED_PORT, EXAMPLE_LED_MASK,
			IOPORT_DIR_OUTPUT);

#ifdef EXAMPLE_BUTTON_PORT
	/* Set direction and pullup on the given button IOPORT */
	ioport_set_port_dir(EXAMPLE_BUTTON_PORT, EXAMPLE_BUTTON_MASK,
			IOPORT_DIR_INPUT);
	ioport_set_port_mode(EXAMPLE_BUTTON_PORT, EXAMPLE_BUTTON_MASK,
			IOPORT_MODE_PULLUP);

	/* Set LED IOPORTs high */
	ioport_set_port_level(EXAMPLE_LED_PORT, EXAMPLE_LED_MASK,
			IOPORT_PIN_LEVEL_HIGH);
#endif

	while (true) {
		/* Toggle LED IOPORTs with half a second interval */
		ioport_toggle_port_level(EXAMPLE_LED_PORT, EXAMPLE_LED_MASK);
		delay_ms(500);

#ifdef EXAMPLE_BUTTON_PORT
		/* Get value from button port */
		/* Use watch with debugger to see it */
		port_val = ioport_get_port_level(EXAMPLE_BUTTON_PORT,
				EXAMPLE_BUTTON_MASK);
#endif
	}
}
示例#3
0
/**
 * \brief Application entry point for eic example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	struct eic_line_config eic_line_conf;

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

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

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

	eic_line_conf.eic_mode = EIC_MODE_EDGE_TRIGGERED;
	eic_line_conf.eic_edge = EIC_EDGE_FALLING_EDGE;
	eic_line_conf.eic_level = EIC_LEVEL_LOW_LEVEL;
	eic_line_conf.eic_filter = EIC_FILTER_DISABLED;
	eic_line_conf.eic_async = EIC_ASYNCH_MODE;

	eic_enable(EIC);
	eic_line_set_config(EIC, GPIO_PUSH_BUTTON_EIC_LINE, 
		&eic_line_conf);
	eic_line_set_callback(EIC, GPIO_PUSH_BUTTON_EIC_LINE, set_toggle_flag, 
		GPIO_PUSH_BUTTON_EIC_IRQ, 1);
	eic_line_enable(EIC, GPIO_PUSH_BUTTON_EIC_LINE);

	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;
		}
	}
}
示例#4
0
文件: unit_tests.c 项目: 70year/MICO
/**
 * \brief Test IOPORT port level is getting changed.
 *
 * This function set the direction of CONF_PORT_OUT_PIN_MASK to output mode with
 * pull-up enabled and read the status of pin using CONF_PORT_IN_PIN_MASK which
 * is configured in input mode.
 * The pin CONF_PORT_OUT_PIN_MASK and CONF_PORT_IN_PIN_MASK are shorted using a
 * jumper.
 *
 * \param test Current test case.
 */
static void run_ioport_port_test(const struct test_case *test)
{
	static volatile pin_mask_t port_val;

	/* Set direction and pull-up on the given IOPORT */
	ioport_set_port_dir(CONF_PORT, CONF_PORT_IN_PIN_MASK, IOPORT_DIR_INPUT);
	ioport_set_port_mode(CONF_PORT, CONF_PORT_IN_PIN_MASK,
			IOPORT_MODE_PULLUP);

	/* Set output direction on the given IOPORT */
	ioport_set_port_dir(CONF_PORT, CONF_PORT_OUT_PIN_MASK,
			IOPORT_DIR_OUTPUT);

	/* Set  IOPORT as high */
	ioport_set_port_level(CONF_PORT, CONF_PORT_OUT_PIN_MASK,
			IOPORT_PIN_LEVEL_HIGH);
	delay_ms(10);
	port_val = ioport_get_port_level(CONF_PORT, CONF_PORT_IN_PIN_MASK);
	test_assert_true(test, port_val == CONF_PORT_IN_PIN_MASK,
			"IOPORT Set port level high test failed.");

	/* Set  IOPORT as low */
	ioport_set_port_level(CONF_PORT, CONF_PORT_OUT_PIN_MASK,
			IOPORT_PIN_LEVEL_LOW);
	delay_ms(10);
	port_val = ioport_get_port_level(CONF_PORT, CONF_PORT_IN_PIN_MASK);
	test_assert_true(test, port_val == 0,
			"IOPORT Set port level low test failed.");

	/* Toggle  IOPORT */
	ioport_toggle_port_level(CONF_PORT, CONF_PORT_OUT_PIN_MASK);
	delay_ms(10);
	port_val = ioport_get_port_level(CONF_PORT, CONF_PORT_IN_PIN_MASK);
	test_assert_true(test, port_val == CONF_PORT_IN_PIN_MASK,
			"IOPORT Set port level toggle test failed.");
}