#include <rtl.h>
#include <rtl_sched.h>
#include <rtl_compat.h>
+#include <asm/div64.h>
#ifndef RTLINUX_VERSION_CODE
#define RTLINUX_VERSION_CODE 0
// this function sole purpose is to divide a long long by 838
static inline RTIME nano2count(long long ns)
{
- unsigned long denom = 838; // divisor
- long ms32 = ns >> 32; // most significant 32 bits
- unsigned long ms32rem = ms32 % denom; // remainder of ms32 / denom
- unsigned long ls32 = ns & 0xffffffff; // least significant 32 bits
- unsigned long ls32rem = ls32 % denom;
- unsigned long big = 0xffffffff;
- unsigned long big_rem = big % denom;
- unsigned long rem_rem;
-
- // divide most significant bits
- ns = ms32 / denom;
- ns = ns << 32;
- // add corrections due to rounding errors
- ns += ms32rem * (big / denom) + (ms32rem * (big_rem + 1)) / denom;
- // divide least significant bits
- ns += ls32 / denom;
- // add really small correction
- rem_rem = (ms32rem * (big_rem + 1)) % denom;
- ns += (ls32rem + rem_rem) / denom;
-
+ do_div(ns, 838);
return ns;
}
#ifdef rt_get_time()
#include <linux/time.h>
#include <linux/init.h>
#include <linux/comedidev.h>
+#include <asm/div64.h>
/* Board descriptions */
typedef struct waveform_board_struct{
return 0;
}
-// divides an unsigned long long
-static unsigned long long my_ull_div(unsigned long long numerator, unsigned long denominator)
-{
- u32 value;
- unsigned long long remainder;
- unsigned int shift = 0;
- const unsigned long max_u32 = 0xffffffff;
-
- if(numerator <= max_u32)
- {
- // numerator is small enough that we can return correct result
- value = numerator;
- return value / denominator;
- }
-
- remainder = numerator;
-
- // otherwise shift most significant bits into 32 bit variable
- while(numerator > max_u32)
- {
- numerator >>= 1;
- shift++;
- }
- value = numerator;
- value /= denominator;
- value <<= shift;
-
- remainder -= ((unsigned long long) value) * denominator;
-
- return value + my_ull_div(remainder, denominator);
-}
-
static sampl_t fake_sawtooth(comedi_device *dev, unsigned int range_index, unsigned long current_time)
{
comedi_subdevice *s = dev->read_subdev;
unsigned int offset = s->maxdata / 2;
- unsigned long long value;
+ u64 value;
comedi_krange *krange = &s->range_table->range[range_index];
- unsigned long long binary_amplitude;
+ u64 binary_amplitude;
binary_amplitude = s->maxdata;
binary_amplitude *= devpriv->uvolt_amplitude;
- binary_amplitude = my_ull_div(binary_amplitude, krange->max - krange->min);
+ do_div(binary_amplitude, krange->max - krange->min);
current_time %= devpriv->usec_period;
value = current_time;
value *= binary_amplitude * 2;
- value = my_ull_div(value, devpriv->usec_period);
+ do_div(value, devpriv->usec_period);
value -= binary_amplitude; // get rid of sawtooth's dc offset
return offset + value;
{
comedi_subdevice *s = dev->read_subdev;
unsigned int offset = s->maxdata / 2;
- unsigned long long value;
+ u64 value;
comedi_krange *krange = &s->range_table->range[range_index];
current_time %= devpriv->usec_period;
value = s->maxdata;
value *= devpriv->uvolt_amplitude;
- value = my_ull_div(value, krange->max - krange->min);
+ do_div(value, krange->max - krange->min);
if(current_time < devpriv->usec_period / 2)
value *= -1;