示例#1
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.");
}
示例#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
int port_read(port_t *obj)
{
    MBED_ASSERT(obj);
    return ioport_get_port_level(obj->port, obj->mask);
}