/* Given a desired period and the clock period (both in ns), return the proper counter value (divider-1). Sets the original period to be the true value. Note: you have to check if the value is larger than the counter range!  */
static int rtd_ns_to_timer_base(unsigned int *nanosec, int round_mode, int base)
/* Given a desired period and the clock period (both in ns), return the proper counter value (divider-1). Sets the original period to be the true value. Note: you have to check if the value is larger than the counter range!  */
static int rtd_ns_to_timer_base(unsigned int *nanosec, int round_mode, int base)
{
	int divider;
	switch (round_mode) {
	case TRIG_ROUND_NEAREST:
	default:
		divider = (*nanosec + base / 2) / base;
		break;
	case TRIG_ROUND_DOWN:
		divider = (*nanosec) / base;
		break;
	case TRIG_ROUND_UP:
		divider = (*nanosec + base - 1) / base;
		break;
	}
	if (divider < 2)
		divider = 2;
	*nanosec = base * divider;
	return divider - 1;
}