int bcm_timer_change_expirytime(bcm_timer_id timer_id, const struct itimerspec *timer_spec) { bcm_timer_cancel(timer_id); bcm_timer_settime(timer_id, timer_spec); return 1; }
int bcmgpio_strobe_start (int gpio_pin, bcmgpio_strobe_t *strobe_info) { unsigned long regout; int status; struct itimerspec its; assert ((gpio_pin >= 0) && (gpio_pin <= BCMGPIO_MAXINDEX)); if (! strobe_info->timer_module) { GPIO_ERROR ("bcmgpio_strobe: Invalid timer module ID\n"); return -1; } if (! bcmgpio_info[gpio_pin].connected) return -1; if (bcmgpio_info[gpio_pin].dirn == BCMGPIO_DIRN_IN) return -1; if (bcmgpio_info[gpio_pin].strobing) return 0; if ((status = bcm_timer_create (strobe_info->timer_module, &bcmgpio_info[gpio_pin].timer_id)) != 0) { bcmgpio_info[gpio_pin].timer_id = 0; GPIO_ERROR ("bcmgpio_strobe: Timer creation failed with error %d\n", status); return -1; } if ((status = bcm_timer_connect (bcmgpio_info[gpio_pin].timer_id, (bcm_timer_cb) bcmgpio_timercb, (int) gpio_pin)) != 0) { bcm_timer_delete (bcmgpio_info[gpio_pin].timer_id); bcmgpio_info[gpio_pin].timer_id = 0; GPIO_ERROR ("bcmgpio_strobe: Timer connect failed with error %d\n", status); return -1; } its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = BCMGPIO_STRB_NS_TIME; its.it_value.tv_sec = 0; its.it_value.tv_nsec = BCMGPIO_STRB_NS_TIME; if ((status = bcm_timer_settime (bcmgpio_info[gpio_pin].timer_id, &its)) != 0) { bcm_timer_delete (bcmgpio_info[gpio_pin].timer_id); bcmgpio_info[gpio_pin].timer_id = 0; GPIO_ERROR ("bcmgpio_strobe: Timer set failed with error %d\n", status); return -1; } regout = bcmgpio_ioctl (BCMGPIO_REG_OUT, 0, 0); bcmgpio_info[gpio_pin].orig_state = regout & ((unsigned long) 1 << gpio_pin); bcmgpio_info[gpio_pin].strobe_period = strobe_info->strobe_period_in_ms / BCMGPIO_STRB_MS_TIME; bcmgpio_info[gpio_pin].on_time = (strobe_info->duty_percent * bcmgpio_info[gpio_pin].strobe_period) / 100; bcmgpio_info[gpio_pin].tot_strobes = strobe_info->num_strobes; bcmgpio_info[gpio_pin].strobe_count = 0; bcmgpio_info[gpio_pin].timer_count = 0; bcmgpio_info[gpio_pin].strobing = 1; bcmgpio_info[gpio_pin].strobe_done = strobe_info->strobe_done; if (bcmgpio_info[gpio_pin].strobe_done != NULL) *(bcmgpio_info[gpio_pin].strobe_done) = 0; return 0; }