Beispiel #1
0
static void* blink_loop(void* data)
{
	g_blink_led = 1;

	printf("Blink Start!\n");

	while (g_blink_led) {
		if (is_led_chaged) {
			iotbus_gpio_write(g_led_gpio, g_power);
			is_led_chaged = 0;
		}
		usleep(100 * 1000);
	}
	printf("Blink End!\n");

	return NULL;
}
Beispiel #2
0
/******************************
     GPIO TEST
 ******************************/
int systemio_test_gpio(char *failstr)
{
	int result = SYSIO_RESULT_FAIL;
	int fail_flag = 0;
	int ret;
	int i, j;
	int value;
	iotbus_gpio_edge_e edgemode;
	int signals[] = { 1, 0, 1 };
	int total_signals = sizeof(signals) / sizeof(int);
	int edges[] = { 2 /*GPIO_EDGE_RISING */ , 3 /*GPIO_EDGE_FALLING */ };
	int total_edges = sizeof(edges) / sizeof(int);
	struct gpio_s {
		iotbus_gpio_context_h cxt;
		int num;
	};
	static struct gpio_s gpio[] = { {NULL, 12}, {NULL, 14} };
	int totalGpios = sizeof(gpio) / sizeof(struct gpio_s);

	/* open */
	for (i = 0; i < totalGpios; i++) {
		/* open */
		gpio[i].cxt = iotbus_gpio_open(gpio[i].num);
		if (gpio[i].cxt == NULL) {
			SYSIO_DEBUG("[IOTAPI] iotbus_gpio_open(gpio%d) fail \n", gpio[i].num);
			REGISTER_FAIL_REASON("iotbus_gpio_open() fail", &fail_flag);
			continue;
		} else {
			SYSIO_DEBUG("[IOTAPI] iotbus_gpio_open(gpio%d) success \n", gpio[i].num);
		}

		/* write/read signal test */
		for (j = 0; j < total_signals; j++) {
			/* write */
			ret = iotbus_gpio_write(gpio[i].cxt, signals[j]);
			if (ret != IOTBUS_ERROR_NONE) {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_write(gpio%d, signal=%d) fail \n",
							gpio[i].num,
							signals[j]);
				REGISTER_FAIL_REASON("iotbus_gpio_write() fail", &fail_flag);

			} else {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_write(gpio%d, signal=%d) success \n",
							gpio[i].num,
							signals[j]);
			}

			/* read */
			value = iotbus_gpio_read(gpio[i].cxt);
			if (value < 0) {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_read(gpio%d) fail \n", gpio[i].num);
				REGISTER_FAIL_REASON("iotbus_gpio_read() fail", &fail_flag);

			} else {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_read(gpio%d) success \n", gpio[i].num);
				SYSIO_DEBUG("[IOTAPI] gpio%d signal verification : %s (expected val: %d, read val: %d) \n",
							gpio[i].num,
							signals[j] == value ? "SUCCESS" : "FAIL",
							signals[j],
							value);
			}
		}

		/* set/get edge test */
		for (j = 0; j < total_edges; j++) {
			/* set edge */
			ret = iotbus_gpio_set_edge_mode(gpio[i].cxt, edges[j]);
			if (ret != IOTBUS_ERROR_NONE) {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_set_edge_mode(gpio%d, edge=%d) fail \n",
							gpio[i].num,
							edges[j]);
				REGISTER_FAIL_REASON("iotbus_gpio_set_edge_mode() fail", &fail_flag);

			} else {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_set_edge_mode(gpio%d, edge=%d) success \n",
							gpio[i].num,
							edges[j]);
			}

			/* get edge */
			ret = iotbus_gpio_get_edge_mode(gpio[i].cxt, &edgemode);
			if (ret < 0) {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_get_edge_mode(gpio%d) fail \n", gpio[i].num);
				REGISTER_FAIL_REASON("iotbus_gpio_get_edge_mode() fail", &fail_flag);

			} else {
				SYSIO_DEBUG("[IOTAPI] iotbus_gpio_get_edge_mode(gpio%d) success \n", gpio[i].num);
				SYSIO_DEBUG("[IOTAPI] gpio%d edge verification : %s (expected val: %d, read val: %d) \n",
							gpio[i].num,
							edges[j] == edgemode ? "SUCCESS" : "FAIL",
							edges[j],
							edgemode);
			}
		}

		/* get gpio pin number */
		value = iotbus_gpio_get_pin(gpio[i].cxt);
		SYSIO_DEBUG("[IOTAPI] iotbus_gpio_get_pin(gpio%d) success \n", gpio[i].num);
		SYSIO_DEBUG("[IOTAPI] gpio%d pin_number verification : %s (expected val: %d, read val: %d) \n",
					gpio[i].num,
					gpio[i].num == value ? "SUCCESS" : "FAIL",
					gpio[i].num,
					value);
		if (gpio[i].num != value) {
			REGISTER_FAIL_REASON("iotbus_gpio_get_pin() fail", &fail_flag);
		}

		/* close */
		ret = iotbus_gpio_close(gpio[i].cxt);
		if (ret != IOTBUS_ERROR_NONE) {
			SYSIO_DEBUG("[IOTAPI] iotbus_gpio_close(gpio%d) fail \n", gpio[i].num);
			REGISTER_FAIL_REASON("iotbus_gpio_close() fail", &fail_flag);

		} else {
			SYSIO_DEBUG("[IOTAPI] iotbus_gpio_close(gpio%d) success \n", gpio[i].num);
		}

		SYSIO_DEBUG("\n");
	}

	/* check if succeed */
	if (fail_flag == 0) {
		result = SYSIO_RESULT_SUCCESS;
	}

	return result;
}