Ejemplo n.º 1
0
void upm_delay_ms(unsigned int time)
{
    if (time <= 0)
        time = 1;

#if defined(UPM_PLATFORM_LINUX)

    struct timespec delay_time;

    delay_time.tv_sec  = time / 1000;
    delay_time.tv_nsec = (time % 1000) * 1000000;
    // here we spin until the delay is complete - detecting signals
    // and continuing where we left off
    while (nanosleep(&delay_time, &delay_time) && errno == EINTR)
        ; // loop

#elif defined(UPM_PLATFORM_ZEPHYR)
# if KERNEL_VERSION_MAJOR == 1 && KERNEL_VERSION_MINOR >= 6

    struct k_timer timer;
    k_timer_init(&timer, NULL, NULL);
    k_timer_start(&timer, time, 0);
    k_timer_status_sync(&timer);

# else

    struct nano_timer timer;
    void *timer_data[1];
    nano_timer_init(&timer, timer_data);
    nano_timer_start(&timer, MSEC(time) + 1);
    nano_timer_test(&timer, TICKS_UNLIMITED);

# endif
#endif
}
Ejemplo n.º 2
0
void initNanoObjects(void)
{
	nano_stack_init(&nanoStackObj,  stack1);
	nano_stack_init(&nanoStackObj2, stack2);
	nano_sem_init(&nanoSemObj);
	nano_timer_init(&timer, timerData);
} /* initNanoObjects */
Ejemplo n.º 3
0
void main(void)
{
  struct nano_timer timer;
	uint32_t data[2] = {0, 0};

  struct device *tmp36;

  PRINT("Zephyr WebBluetooth demo\n");

  if ((tmp36 = device_get_binding(ADC_DEVICE_NAME)) == NULL) {
      printk("device_get_binding: failed for ADC\n");
      printk("Temperature (celsius): %d\n\n\n", tmp36_read());
  }

	nano_timer_init(&timer, data);
	adc_enable(tmp36);

  while (1) {
    tmp36_read();

    nano_timer_start(&timer, SLEEPTICKS);
    nano_timer_test(&timer, TICKS_UNLIMITED);
  }

  adc_disable(tmp36);
}
Ejemplo n.º 4
0
static inline void do_init(struct timer *t)
{
  if (t && !t->init_done) {
    nano_timer_init(&t->nano_timer, NULL);
    t->init_done = true;
  }
}
Ejemplo n.º 5
0
void main(void)
{
	struct device *adc;
	struct nano_timer timer;
	uint32_t data[2] = {0, 0};

	DBG("ADC sample started on %s\n", ADC_DEVICE_NAME);

	adc = device_get_binding(ADC_DEVICE_NAME);
	if (!adc) {
		DBG("Cannot get adc controller\n");
		return;
	}

	nano_timer_init(&timer, data);
	adc_enable(adc);
	while (1) {
		if (adc_read(adc, &table) != DEV_OK) {
			DBG("Sampling could not proceed, an error occurred\n");
		} else {
			DBG("Sampling is done\n");
			_print_sample_in_hex(seq_buffer, BUFFER_SIZE);
		}
		nano_timer_start(&timer, SLEEPTICKS);
		nano_timer_test(&timer, TICKS_UNLIMITED);
	}
	adc_disable(adc);
}
Ejemplo n.º 6
0
/*
 * This program toggles PIN IO 8 so if you connect an LED to that pin you
 * should see something.
 */
void main(void)
{
	struct device *gpio_device;

	struct nano_timer timer;
	void *timer_data[1];

	int ret;
	int pin_state = 1;

	nano_timer_init(&timer, timer_data);

	gpio_device = device_get_binding(GPIO_DRV_NAME);
	if (!gpio_device) {
		return;
	}

	ret = gpio_pin_configure(gpio_device, GPIO_OUT_PIN, (GPIO_DIR_OUT));
	if (ret) {
		return;
	}

	while (1) {

		gpio_pin_write(gpio_device, GPIO_OUT_PIN, pin_state);

		pin_state = !pin_state;

		nano_timer_start(&timer, SECONDS(1));
		nano_timer_test(&timer, TICKS_UNLIMITED);
	}
}
Ejemplo n.º 7
0
void main(void)
{
	uint32_t timer_data[2] = {0, 0};
	struct device *aon_gpio;
	struct nano_timer timer;

	nano_timer_init(&timer, timer_data);

	aon_gpio = device_get_binding("GPIO_AON_0");
	if (!aon_gpio) {
		printf("aon_gpio device not found.\n");
		return;
	}

	ipm = device_get_binding("bmi160_ipm");
	if (!ipm) {
		printf("ipm device not found.\n");
		return;
	}

	gpio_init_callback(&cb, aon_gpio_callback, BIT(BMI160_INTERRUPT_PIN));
	gpio_add_callback(aon_gpio, &cb);

	gpio_pin_configure(aon_gpio, BMI160_INTERRUPT_PIN,
			   GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
			   GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);

	gpio_pin_enable_callback(aon_gpio, BMI160_INTERRUPT_PIN);

	while (1) {
		nano_task_timer_start(&timer, SLEEPTIME);
		nano_task_timer_test(&timer, TICKS_UNLIMITED);
	}
}
Ejemplo n.º 8
0
void fiber_sending(void)
{
	struct nano_timer timer;
	uint32_t data[2] = {0, 0};
	struct net_context *ctx;
	int i = 0;

	ctx = get_context(&loopback_addr, DEST_PORT, &any_addr, SRC_PORT);
	if (!ctx) {
		PRINT("Cannot get network context\n");
		return;
	}

	nano_timer_init(&timer, data);

	while (1) {
		if (CONFIG_NET_15_4_LOOPBACK_NUM != 0 &&
					i >= CONFIG_NET_15_4_LOOPBACK_NUM) {
			nano_fiber_timer_stop(&timer);
			return;
		}

		send_data("sendFiber", ctx);

		nano_fiber_timer_start(&timer, SLEEPTICKS);
		nano_fiber_timer_test(&timer, TICKS_UNLIMITED);
		i++;
	}
}
Ejemplo n.º 9
0
void main(void)
{
	struct nano_timer timer;
	void *timer_data[1];
	struct device *gpio_dev;
	int ret;
	int toggle = 1;

	nano_timer_init(&timer, timer_data);

	gpio_dev = device_get_binding(GPIO_DRV_NAME);
	if (!gpio_dev) {
		printk("Cannot find %s!\n", GPIO_DRV_NAME);
	}

	/* Setup GPIO output */
	ret = gpio_pin_configure(gpio_dev, GPIO_OUT_PIN, (GPIO_DIR_OUT));
	if (ret) {
		printk("Error configuring " GPIO_NAME "%d!\n", GPIO_OUT_PIN);
	}

	/* Setup GPIO input, and triggers on rising edge. */
	ret = gpio_pin_configure(gpio_dev, GPIO_INT_PIN,
			(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE
			 | GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE));
	if (ret) {
		printk("Error configuring " GPIO_NAME "%d!\n", GPIO_INT_PIN);
	}

	gpio_init_callback(&gpio_cb, gpio_callback, BIT(GPIO_INT_PIN));

	ret = gpio_add_callback(gpio_dev, &gpio_cb);
	if (ret) {
		printk("Cannot setup callback!\n");
	}

	ret = gpio_pin_enable_callback(gpio_dev, GPIO_INT_PIN);
	if (ret) {
		printk("Error enabling callback!\n");
	}

	while (1) {
		printk("Toggling " GPIO_NAME "%d\n", GPIO_OUT_PIN);

		ret = gpio_pin_write(gpio_dev, GPIO_OUT_PIN, toggle);
		if (ret) {
			printk("Error set " GPIO_NAME "%d!\n", GPIO_OUT_PIN);
		}

		if (toggle) {
			toggle = 0;
		} else {
			toggle = 1;
		}

		nano_timer_start(&timer, SLEEPTICKS);
		nano_timer_test(&timer, TICKS_UNLIMITED);
	}
}
Ejemplo n.º 10
0
void initNanoObjects(void)
{
	nano_sem_init(&testSem);
	nano_sem_init(&multi_waiters);
	nano_sem_init(&reply_multi_waiters);
	nano_timer_init(&timer, timerData);

	TC_PRINT("Nano objects initialized\n");
}
Ejemplo n.º 11
0
void upm_delay_us(int time){
#if defined(linux)
    usleep(time);
#elif defined(CONFIG_BOARD_ARDUINO_101) || defined(CONFIG_BOARD_ARDUINO_101_SSS) || defined(CONFIG_BOARD_QUARK_D2000_CRB)
    struct nano_timer timer;
    void *timer_data[1];
    nano_timer_init(&timer, timer_data);
    nano_timer_start(&timer, USEC(time));
    nano_timer_test(&timer, TICKS_UNLIMITED);
#endif
}
Ejemplo n.º 12
0
static int ti_adc108s102_read(struct device *dev,
					struct adc_seq_table *seq_table)
{
	struct ti_adc108s102_config *config = dev->config->config_info;
	struct ti_adc108s102_data *adc = dev->driver_data;
	struct spi_config spi_conf;
	uint32_t data[2] = {0, 0};
	struct nano_timer timer;
	int ret = 0;
	int32_t delay;

	spi_conf.config = config->spi_config_flags;
	spi_conf.max_sys_freq = config->spi_freq;

	nano_timer_init(&timer, data);

	if (spi_configure(adc->spi, &spi_conf)) {
		return -EIO;
	}

	if (spi_slave_select(adc->spi, config->spi_slave)) {
		return -EIO;
	}

	/* Resetting all internal channel data */
	memset(adc->chans, 0, ADC108S102_CHANNELS_SIZE);

	if (_verify_entries(seq_table) == 0) {
		return -EINVAL;
	}

	adc->seq_table = seq_table;

	/* Sampling */
	while (1) {
		delay = _ti_adc108s102_prepare(dev);
		if (delay == ADC108S102_DONE) {
			break;
		}

		nano_timer_start(&timer, delay);
		nano_task_timer_test(&timer, TICKS_UNLIMITED);

		ret = _ti_adc108s102_sampling(dev);
		if (ret != 0) {
			break;
		}

		_ti_adc108s102_handle_result(dev);
	}

	return ret;
}
Ejemplo n.º 13
0
int gpio_sch_init(struct device *dev)
{
	struct gpio_sch_data *gpio = dev->driver_data;

	dev->driver_api = &gpio_sch_api;

	nano_timer_init(&gpio->poll_timer, NULL);

	DBG("SCH GPIO Intel Driver initialized on device: %p\n", dev);

	return 0;
}
Ejemplo n.º 14
0
void initNanoObjects(void)
{
	nano_lifo_init(&test_lifo);   /* Initialize the LIFO */
	nano_sem_init(&taskWaitSem);   /* Initialize the task waiting semaphore */
	nano_sem_init(&fiberWaitSem);  /* Initialize the fiber waiting semaphore */
	nano_timer_init(&timer, timerData);

	nano_lifo_init(&multi_waiters);
	nano_sem_init(&reply_multi_waiters);

	TC_PRINT("Nano objects initialized\n");
}
Ejemplo n.º 15
0
static void myDelay(int ticks)
{
#ifdef CONFIG_MICROKERNEL
    task_sleep(ticks);
#else
    struct nano_timer timer;

    nano_timer_init(&timer, (void *) 0);
    nano_fiber_timer_start(&timer, ticks);
    nano_fiber_timer_test(&timer, TICKS_UNLIMITED);
#endif
}
Ejemplo n.º 16
0
void initNanoObjects(void)
{
	nano_fifo_init(&nanoFifoObj);
	nano_fifo_init(&nanoFifoObj2);

	nano_sem_init(&nanoSemObj1);
	nano_sem_init(&nanoSemObj2);
	nano_sem_init(&nanoSemObj3);
	nano_sem_init(&nanoSemObjTask);

	nano_timer_init(&timer, timerData);

} /* initNanoObjects */
Ejemplo n.º 17
0
int initNanoObjects(void)
{
	nano_sem_init(&wakeFiber);
	nano_timer_init(&timer, timerData);
	nano_fifo_init(&timeout_order_fifo);

/* no nanoCpuExcConnect on Cortex-M3/M4 */
#if !defined(CONFIG_CPU_CORTEX_M3_M4)
	nanoCpuExcConnect(IV_DIVIDE_ERROR, exc_divide_error_handler);
#endif

	return TC_PASS;
}
Ejemplo n.º 18
0
void initNanoObjects(void)
{
	struct isrInitInfo i = {
	{isr_sem_give, isr_sem_take},
	{&isrSemInfo, &isrSemInfo},
	};

	(void)initIRQ(&i);

	nano_sem_init(&testSem);
	nano_sem_init(&multi_waiters);
	nano_sem_init(&reply_multi_waiters);
	nano_timer_init(&timer, timerData);

	TC_PRINT("Nano objects initialized\n");
}
Ejemplo n.º 19
0
void main(void)
{
	mraa_init();
	struct nano_timer timer;
	void *timer_data[1];
	nano_timer_init(&timer, timer_data);
	mvs0608_context dev = mvs0608_init(2);
	bool abc = 0;
	while(1){
		if(mvs0608_is_colliding(dev, &abc) != UPM_SUCCESS){
			printf("an error has occured\n");
		}
		nano_timer_start(&timer, SLEEPTICKS);
		nano_timer_test(&timer, TICKS_UNLIMITED);
		printf("value retrieved: %d\n", abc);
	}
	mvs0608_close(dev);
}
Ejemplo n.º 20
0
static void test_nano_timers(int unused1, int unused2)
{
	struct nano_timer timer;

	ARG_UNUSED(unused1);
	ARG_UNUSED(unused2);

	nano_timer_init(&timer, (void *)0xdeadbeef);
	TC_PRINT("starting nano timer to expire in %d seconds\n",
				TEST_NANO_TIMERS_DELAY);
	nano_fiber_timer_start(&timer, SECONDS(TEST_NANO_TIMERS_DELAY));
	TC_PRINT("fiber pending on timer\n");
	nano_fiber_timer_wait(&timer);
	TC_PRINT("fiber back from waiting on timer: giving semaphore.\n");
	nano_task_sem_give(&test_nano_timers_sem);
	TC_PRINT("fiber semaphore given.\n");

	/* on failure, don't give semaphore, main test will not obtain it */
}
Ejemplo n.º 21
0
void main(void)
{
	struct nano_timer timer;
	void *timer_data[1];
	struct device *pwm_dev;
	uint32_t period;
	uint8_t dir;

	nano_timer_init(&timer, timer_data);

	PRINT("PWM_DW demo app\n");

	pwm_dev = device_get_binding(CONFIG_PWM_DW_DEV_NAME);
	if (!pwm_dev) {
		PRINT("Cannot find %s!\n", CONFIG_PWM_DW_DEV_NAME);
	}

	period = MAX_PERIOD;
	dir = 0;

	while (1) {
		pwm_pin_set_values(pwm_dev, 0, period, period);

		if (dir) {
			period *= 2;

			if (period > MAX_PERIOD) {
				dir = 0;
				period = MAX_PERIOD;
			}
		} else {
			period /= 2;

			if (period < MIN_PERIOD) {
				dir = 1;
				period = MIN_PERIOD;
			}
		}

		nano_timer_start(&timer, SLEEPTICKS);
		nano_timer_test(&timer, TICKS_UNLIMITED);
	}
}
Ejemplo n.º 22
0
void initNanoObjects(void)
{
	struct isrInitInfo i = {
	{isr_fifo_put, isr_fifo_get},
	{&isrFifoInfo, &isrFifoInfo},
	};

	(void)initIRQ(&i);

	nano_fifo_init(&nanoFifoObj);
	nano_fifo_init(&nanoFifoObj2);

	nano_sem_init(&nanoSemObj1);
	nano_sem_init(&nanoSemObj2);
	nano_sem_init(&nanoSemObj3);
	nano_sem_init(&nanoSemObjTask);

	nano_timer_init(&timer, timerData);

} /* initNanoObjects */
Ejemplo n.º 23
0
void fiberEntry(void)
{
	struct nano_timer timer;
	uint32_t data[2] = {0, 0};

	nano_sem_init(&nanoSemFiber);
	nano_timer_init(&timer, data);

	while (1) {
		/* wait for task to let us have a turn */
		nano_fiber_sem_take_wait(&nanoSemFiber);

		/* say "hello" */
		PRINT("%s: Hello World!\n", __FUNCTION__);

		/* wait a while, then let task have a turn */
		nano_fiber_timer_start(&timer, SLEEPTICKS);
		nano_fiber_timer_wait(&timer);
		nano_fiber_sem_give(&nanoSemTask);
	}
}
Ejemplo n.º 24
0
/**
 * Initialize the resources used by the framework's timer services
 *
 * IMPORTANT : this function must be called during the initialization
 *             of the OS abstraction layer.
 *             this function shall only be called once after reset, otherwise
 *             it may cause the take/lock and give/unlock services to fail
 */
void framework_init_timer(void)
{
    uint8_t idx;

#ifdef CONFIG_NANOKERNEL
    nano_sem_init ( &g_TimerSem );
    nano_timer_init (&g_NanoTimer, &g_NanoTimerData);
#else
    g_TimerSem = OS_TIMER_SEM;
#endif

    /* start with empty list of active timers: */
    g_CurrentTimerHead = NULL;

    /* memset ( g_TimerPool_elements, 0 ):  */
    for (idx = 0; idx < TIMER_POOL_SIZE; idx++)
    {
        g_TimerPool_elements[idx].desc.callback = NULL;
        g_TimerPool_elements[idx].desc.data = NULL;
        g_TimerPool_elements[idx].desc.delay = 0;
        g_TimerPool_elements[idx].desc.expiration = 0;
        g_TimerPool_elements[idx].desc.repeat = false;
        g_TimerPool_elements[idx].prev = NULL;
        g_TimerPool_elements[idx].next = NULL;
        /* hopefully, the init function is performed before
         *  timer_create and timer_stop can be called,
         *  hence there is no need for a critical section
         *  here */
    }

    /* start "timer_task" in a new fiber for NanoK, or a new task for microK */
#ifdef CONFIG_NANOKERNEL
        fiber_fiber_start ((char *) g_TimerFiberStack, TIMER_CBK_TASK_STACK_SIZE,
                timer_task,0,0,
                TIMER_CBK_TASK_PRIORITY, TIMER_CBK_TASK_OPTIONS);
#else
        task_start(OS_TASK_TIMER);
#endif
}
Ejemplo n.º 25
0
void upm_delay(unsigned int time)
{
    if (time <= 0)
        time = 1;

#if defined(UPM_PLATFORM_LINUX)

    struct timespec delay_time;

    delay_time.tv_sec  = time;
    delay_time.tv_nsec = 0;
    // The advantage over sleep(3) here is that it will not use
    // an alarm signal or handler.

    // here we spin until the delay is complete - detecting signals
    // and continuing where we left off
    while (nanosleep(&delay_time, &delay_time) && errno == EINTR)
        ; // loop

#elif defined(UPM_PLATFORM_ZEPHYR)
# if KERNEL_VERSION_MAJOR == 1 && KERNEL_VERSION_MINOR >= 6

    struct k_timer timer;
    k_timer_init(&timer, NULL, NULL);
    k_timer_start(&timer, time * 1000, 0);
    k_timer_status_sync(&timer);

# else

    struct nano_timer timer;
    void *timer_data[1];
    nano_timer_init(&timer, timer_data);
    nano_timer_start(&timer, SECONDS(time) + 1);
    nano_timer_test(&timer, TICKS_UNLIMITED);

# endif

#endif
}
Ejemplo n.º 26
0
void upm_delay_us(unsigned int time)
{
    if (time <= 0)
        time = 1;

#if defined(UPM_PLATFORM_LINUX)

    struct timespec delay_time;

    delay_time.tv_sec  = time / 1000000;
    delay_time.tv_nsec = (time % 1000000) * 1000;
    // here we spin until the delay is complete - detecting signals
    // and continuing where we left off
    while (nanosleep(&delay_time, &delay_time) && errno == EINTR)
        ; // loop

#elif defined(UPM_PLATFORM_ZEPHYR)
# if KERNEL_VERSION_MAJOR == 1 && KERNEL_VERSION_MINOR >= 6
    // we will use a upm_clock to do microsecond timings here as k_timer has
    // only a millisecond resolution.  So we init a clock and spin.

    upm_clock_t timer;
    upm_clock_init(&timer);
    while (upm_elapsed_us(&timer) < time)
        ; // spin

# else

    struct nano_timer timer;
    void *timer_data[1];
    nano_timer_init(&timer, timer_data);
    nano_timer_start(&timer, USEC(time) + 1);
    nano_timer_test(&timer, TICKS_UNLIMITED);

# endif

#endif
}
Ejemplo n.º 27
0
void main(void)
{
	struct nano_timer timer;
	uint32_t data[2] = {0, 0};

	task_fiber_start(&fiberStack[0], STACKSIZE,
			(nano_fiber_entry_t) fiberEntry, 0, 0, 7, 0);

	nano_sem_init(&nanoSemTask);
	nano_timer_init(&timer, data);

	while (1) {
		/* say "hello" */
		PRINT("%s: Hello Screen!\n", __FUNCTION__);

		/* wait a while, then let fiber have a turn */
		nano_task_timer_start(&timer, SLEEPTICKS);
		nano_task_timer_wait(&timer);
		nano_task_sem_give(&nanoSemFiber);

		/* now wait for fiber to let us have a turn */
		nano_task_sem_take_wait(&nanoSemTask);
	}
}
Ejemplo n.º 28
0
static void test_polling_mode(struct device *bmg160)
{
	uint32_t timer_data[2] = {0, 0};
	int32_t remaining_test_time = MAX_TEST_TIME;
	struct nano_timer timer;

	nano_timer_init(&timer, timer_data);

	do {
		if (sensor_sample_fetch(bmg160) < 0) {
			printf("Gyro sample update error.\n");
		}

		print_gyro_data(bmg160);

		print_temp_data(bmg160);

		/* wait a while */
		nano_task_timer_start(&timer, SLEEPTIME);
		nano_task_timer_test(&timer, TICKS_UNLIMITED);

		remaining_test_time -= SLEEPTIME;
	} while (remaining_test_time > 0);
}
Ejemplo n.º 29
0
void main(void)
{
	struct nano_timer timer;
	uint32_t timer_data[2] = {0, 0};
	struct device *glcd;
	char str[20];
	int rgb[] = { 0x0, 0x0, 0x0 };
	uint8_t rgb_chg[3];
	const uint8_t rgb_step = 16;
	uint8_t set_config;
	int i, j, m;
	int cnt;

	nano_timer_init(&timer, timer_data);

	glcd = device_get_binding(GROVE_LCD_NAME);
	if (!glcd) {
		printk("Grove LCD: Device not found.\n");
	}

	/* Now configure the LCD the way we want it */

	set_config = GLCD_FS_ROWS_2
			| GLCD_FS_DOT_SIZE_LITTLE
			| GLCD_FS_8BIT_MODE;

	glcd_function_set(glcd, set_config);

	set_config = GLCD_DS_DISPLAY_ON | GLCD_DS_CURSOR_ON | GLCD_DS_BLINK_ON;

	glcd_display_state_set(glcd, set_config);

	/* Setup variables /*/
	for (i = 0; i < sizeof(str); i++) {
		str[i] = '\0';
	}

	/* Starting counting */
	cnt = 0;

	while (1) {
		glcd_cursor_pos_set(glcd, 0, 0);

		/* RGB values are from 0 - 511.
		 * First half means incrementally brighter.
		 * Second half is opposite (i.e. goes darker).
		 */

		/* Update the RGB values for backlight */
		m = (rgb[2] > 255) ? (512 - rgb[2]) : (rgb[2]);
		rgb_chg[2] = clamp_rgb(m);

		m = (rgb[1] > 255) ? (512 - rgb[1]) : (rgb[1]);
		rgb_chg[1] = clamp_rgb(m);

		m = (rgb[0] > 255) ? (512 - rgb[0]) : (rgb[0]);
		rgb_chg[0] = clamp_rgb(m);

		glcd_color_set(glcd, rgb_chg[0], rgb_chg[1], rgb_chg[2]);

		/* Display the counter
		 *
		 * well... sprintf() might be easier,
		 * but this is more fun.
		 */
		m = cnt;
		i = 1000000000;
		j = 0;
		while (i > 0) {
			str[j] = '0' + (m / i);

			m = m % i;
			i = i / 10;
			j++;
		}
		cnt++;

		glcd_print(glcd, str, j);

		/* Rotate RGB values */
		rgb[2] += rgb_step;
		if (rgb[2] > 511) {
			rgb[2] = 0;
			rgb[1] += rgb_step;
		}
		if (rgb[1] > 511) {
			rgb[1] = 0;
			rgb[0] += rgb_step;
		}
		if (rgb[0] > 511) {
			rgb[0] = 0;
		}

		/* wait a while */
		nano_task_timer_start(&timer, SLEEPTICKS);
		nano_task_timer_test(&timer, TICKS_UNLIMITED);
	}
}
Ejemplo n.º 30
0
static void test_trigger_mode(struct device *bmg160)
{
	uint32_t timer_data[2] = {0, 0};
	int32_t remaining_test_time = MAX_TEST_TIME;
	struct nano_timer timer;
	struct sensor_trigger trig;
	struct sensor_value attr;

	nano_timer_init(&timer, timer_data);

	trig.type = SENSOR_TRIG_DELTA;
	trig.chan = SENSOR_CHAN_GYRO_ANY;

	printf("Gyro: Testing anymotion trigger.\n");

	/* set up the trigger */

	/* set slope threshold to 10 dps */

	sensor_degrees_to_rad(10, &attr); /* convert to rad/s */

	if (sensor_attr_set(bmg160, SENSOR_CHAN_GYRO_ANY,
			    SENSOR_ATTR_SLOPE_TH, &attr) < 0) {
		printf("Gyro: cannot set slope threshold.\n");
		return;
	}

	/* set slope duration to 4 samples */
	attr.type = SENSOR_VALUE_TYPE_INT;
	attr.val1 = 4;

	if (sensor_attr_set(bmg160, SENSOR_CHAN_GYRO_ANY,
			    SENSOR_ATTR_SLOPE_DUR, &attr) < 0) {
		printf("Gyro: cannot set slope duration.\n");
		return;
	}

	if (sensor_trigger_set(bmg160, &trig, trigger_handler) < 0) {
		printf("Gyro: cannot set trigger.\n");
		return;
	}

	printf("Gyro: rotate the device and wait for events.\n");
	do {
		nano_task_timer_start(&timer, SLEEPTIME);
		nano_task_timer_test(&timer, TICKS_UNLIMITED);

		remaining_test_time -= SLEEPTIME;
	} while (remaining_test_time > 0);

	if (sensor_trigger_set(bmg160, &trig, NULL) < 0) {
		printf("Gyro: cannot clear trigger.\n");
		return;
	}

	printf("Gyro: Anymotion trigger test finished.\n");

	printf("Gyro: Testing data ready trigger.\n");

	attr.type = SENSOR_VALUE_TYPE_INT;
	attr.val1 = 100;
	attr.val2 = 0;

	if (sensor_attr_set(bmg160, SENSOR_CHAN_GYRO_ANY,
			    SENSOR_ATTR_SAMPLING_FREQUENCY, &attr) < 0) {
		printf("Gyro: cannot set sampling frequency.\n");
		return;
	}

	trig.type = SENSOR_TRIG_DATA_READY;
	trig.chan = SENSOR_CHAN_GYRO_ANY;

	if (sensor_trigger_set(bmg160, &trig, trigger_handler) < 0) {
		printf("Gyro: cannot set trigger.\n");
		return;
	}

	remaining_test_time = MAX_TEST_TIME;

	do {
		nano_task_timer_start(&timer, SLEEPTIME);
		nano_task_timer_test(&timer, TICKS_UNLIMITED);

		remaining_test_time -= SLEEPTIME;
	} while (remaining_test_time > 0);

	if (sensor_trigger_set(bmg160, &trig, NULL) < 0) {
		printf("Gyro: cannot clear trigger.\n");
		return;
	}

	printf("Gyro: Data ready trigger test finished.\n");
}