Beispiel #1
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);
	}
}
Beispiel #2
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
}
Beispiel #3
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);
}
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);
}
Beispiel #5
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);
	}
}
Beispiel #6
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
}
Beispiel #7
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;
}
Beispiel #8
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);
}
Beispiel #9
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);
	}
}
Beispiel #10
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
}
Beispiel #11
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
}