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 }
static void gpio_sch_poll_status(void *arg1, void *unused1, void *unused2) { struct device *dev = (struct device *)arg1; const struct gpio_sch_config *info = dev->config->config_info; struct gpio_sch_data *gpio = dev->driver_data; ARG_UNUSED(unused1); ARG_UNUSED(unused2); /* Cleaning up GTS first */ z_write_gts(z_read_gts(info->regs), info->regs); while (gpio->poll) { u32_t status; status = z_read_gts(info->regs); if (!status) { goto loop; } gpio_fire_callbacks(&gpio->callbacks, dev, status); /* It's not documented but writing the same status value * into GTS tells to the controller it got handled. */ z_write_gts(status, info->regs); loop: k_timer_start(&gpio->poll_timer, GPIO_SCH_POLLING_MSEC, 0); k_timer_status_sync(&gpio->poll_timer); } }
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 }